From 1ba2865197817d772b85c898b418ed54e0d9ded2 Mon Sep 17 00:00:00 2001 From: Lili Nie Date: Wed, 4 Dec 2024 02:34:58 -0500 Subject: [PATCH] Support creating Beaker jobs using `beaker-job-group` key for `mrack` (#3397) --- docs/releases.rst | 5 +++++ tmt/schemas/provision/beaker.yaml | 3 +++ tmt/steps/provision/mrack.py | 24 ++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/releases.rst b/docs/releases.rst index 1f4a8e19c2..6008d4ecbc 100644 --- a/docs/releases.rst +++ b/docs/releases.rst @@ -15,6 +15,11 @@ Add the ``--keep`` option for the ``tmt clean guests`` command. Users can now choose to keep the selected number of latest guests and clean the rest to release the resources. +The :ref:`/plugins/provision/beaker` provision plugin gains +support for submitting jobs on behalf of a group through +``job-group`` key. The submitting user must be a member of +the given job group. + tmt-1.39.0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tmt/schemas/provision/beaker.yaml b/tmt/schemas/provision/beaker.yaml index 50acc91467..197165a113 100644 --- a/tmt/schemas/provision/beaker.yaml +++ b/tmt/schemas/provision/beaker.yaml @@ -49,5 +49,8 @@ properties: beaker-job-owner: type: string + job-group: + type: string + required: - how diff --git a/tmt/steps/provision/mrack.py b/tmt/steps/provision/mrack.py index 148017c687..bdc7726412 100644 --- a/tmt/steps/provision/mrack.py +++ b/tmt/steps/provision/mrack.py @@ -914,6 +914,14 @@ class BeakerGuestData(tmt.steps.provision.GuestSshData): Submitting user must be a submission delegate for the ``USERNAME``. """) + job_group: Optional[str] = field( + default=None, + option='--job-group', + metavar='GROUPNAME', + help=""" + If set, Beaker jobs will be submitted on behalf of ``GROUPNAME``. + """) + @dataclasses.dataclass class ProvisionBeakerData(BeakerGuestData, tmt.steps.provision.ProvisionStepData): @@ -949,7 +957,7 @@ class CreateJobParameters: kickstart: dict[str, str] whiteboard: Optional[str] beaker_job_owner: Optional[str] - group: str = 'linux' + group: Optional[str] def to_mrack(self) -> dict[str, Any]: data = dataclasses.asdict(self) @@ -1071,6 +1079,7 @@ class GuestBeaker(tmt.steps.provision.GuestSsh): kickstart: dict[str, str] beaker_job_owner: Optional[str] = None + job_group: Optional[str] = None # Provided in Beaker response job_id: Optional[str] @@ -1146,7 +1155,8 @@ def _create(self, tmt_name: str) -> None: os=self.image, name=f'{self.image}-{self.arch}', whiteboard=self.whiteboard or tmt_name, - beaker_job_owner=self.beaker_job_owner) + beaker_job_owner=self.beaker_job_owner, + group=self.job_group) try: response = self.api.create(data) @@ -1167,6 +1177,16 @@ def _create(self, tmt_name: str) -> None: f"Failed to create Beaker job, job owner '{self.beaker_job_owner}' " "is not a valid submission delegate.") from exc + if 'is not a valid group' in cause.faultString: + raise ProvisionError( + f"Failed to create Beaker job, job group '{self.job_group}' " + "was refused as unknown.") from exc + + if 'is not a member of group' in cause.faultString: + raise ProvisionError( + "Failed to create Beaker job, submitting user is not " + "a member of group '{self.job_group}'") from exc + raise ProvisionError('Failed to create Beaker job') from exc if response: