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

Fix bad output with ssh keys in testflinger reserve command #425

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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
10 changes: 9 additions & 1 deletion cli/testflinger_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ def _add_reserve_args(self, subparsers):
"reserve", help="Install and reserve a system"
)
parser.set_defaults(func=self.reserve)
parser.add_argument(
"--dry-run",
"-d",
action="store_true",
help="Only show the job data, don't submit it",
)
parser.add_argument("--queue", "-q", help="Name of the queue to use")
parser.add_argument(
"--image", "-i", help="Name of the image to use for provisioning"
Expand Down Expand Up @@ -907,10 +913,12 @@ def reserve(self):
ssh_keys:"""
)
for ssh_key in ssh_keys:
template += "\n - {}".format(ssh_key)
template += "\n - {}".format(ssh_key)
job_data = template.format(queue=queue, image=image)
print("\nThe following yaml will be submitted:")
print(job_data)
if self.args.dry_run:
return
answer = input("Proceed? (Y/n) ")
if answer in ("Y", "y", ""):
job_id = self.submit_job_data(job_data)
Expand Down
29 changes: 29 additions & 0 deletions cli/testflinger_cli/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,3 +610,32 @@ def test_submit_no_agents_wait(capsys, tmp_path, requests_mock):
"WARNING: No online agents available for queue fake"
in capsys.readouterr().out
)


def test_reserve(capsys, requests_mock):
"""ensure reserve command generates correct yaml"""
requests_mock.get(URL + "/v1/agents/queues", json={})
requests_mock.get(URL + "/v1/agents/images/fake", json={})
expected_yaml = (
"job_queue: fake\n"
"provision_data:\n"
" url: http://face_image.xz\n"
"reserve_data:\n"
" ssh_keys:\n"
" - lp:fakeuser"
)
sys.argv = [
"",
"reserve",
"-q",
"fake",
"-i",
"http://face_image.xz",
"-k",
"lp:fakeuser",
"-d",
]
tfcli = testflinger_cli.TestflingerCli()
tfcli.reserve()
std = capsys.readouterr()
assert expected_yaml in std.out