Skip to content

Commit

Permalink
Fix bad output with ssh keys in testflinger reserve command
Browse files Browse the repository at this point in the history
  • Loading branch information
plars committed Dec 6, 2024
1 parent 750fe0b commit f522bfc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
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 @@ -861,10 +867,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 @@ -541,3 +541,32 @@ def test_list_queues_connection_error(caplog, requests_mock):
with pytest.raises(SystemExit):
tfcli.list_queues()
assert "Unable to get a list of queues from the server." in caplog.text


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

0 comments on commit f522bfc

Please sign in to comment.