Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing pubkeys to authorized_keys for mrack #3354

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ support for :ref:`system.model-name</spec/hardware/system>`,
The ``tmt lint`` command now reports a failure if empty
environment files are found.

The :ref:`/plugins/provision/beaker` provision plugin gains support
for adding pubkeys to instance by populating the kickstart file.


tmt-1.38.0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 5 additions & 0 deletions tmt/schemas/provision/beaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ properties:
beaker-job-owner:
type: string

public-key:
type: array
items:
type: string

required:
- how
17 changes: 16 additions & 1 deletion tmt/steps/provision/mrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,16 @@ class BeakerGuestData(tmt.steps.provision.GuestSshData):
Submitting user must be a submission delegate for the ``USERNAME``.
""")

public_key: list[str] = field(
default_factory=list,
option='--public-key',
metavar='PUBLICKEY',
help="""
If set, the public keys will be put under ssh authorized_keys.
""",
multiple=True,
normalize=tmt.utils.normalize_string_list)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • public_key + public-key + multiple=True. There is already key/--key key, a singular form, and on the command line I can use it multiple times (--key foo --key bar --public-key baz ...)
  • default_factory=list will be better: it's a list, and an empty list is as good indication of "no keys to install" as None, but it's simpler because it's still just a list. So, list[str] + default_factory=list should work perfectly.
  • help seems to be copy-pasted & deserves an update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated^^ 83d8781



@dataclasses.dataclass
class ProvisionBeakerData(BeakerGuestData, tmt.steps.provision.ProvisionStepData):
Expand Down Expand Up @@ -901,6 +911,7 @@ class CreateJobParameters:
kickstart: dict[str, str]
whiteboard: Optional[str]
beaker_job_owner: Optional[str]
public_key: list[str]
group: str = 'linux'

def to_mrack(self) -> dict[str, Any]:
Expand All @@ -911,6 +922,8 @@ def to_mrack(self) -> dict[str, Any]:
if self.kickstart:
data['beaker']['ks_meta'] = self.kickstart.get('metadata')
data['beaker']['ks_append'] = self.kickstart
if self.public_key:
data['beaker']['pubkeys'] = self.public_key

return data

Expand Down Expand Up @@ -1022,6 +1035,7 @@ class GuestBeaker(tmt.steps.provision.GuestSsh):
# Timeouts and deadlines
provision_timeout: int
provision_tick: int
public_key: list[str]
api_session_refresh_tick: int

_api: Optional[BeakerAPI] = None
Expand Down Expand Up @@ -1090,7 +1104,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,
public_key=self.public_key)

try:
response = self.api.create(data)
Expand Down