Merge ~pwlars/testflinger-cli:reserve-handle-bad-opt-data into testflinger-cli:master

Proposed by Paul Larson
Status: Merged
Approved by: Paul Larson
Approved revision: 7ed2beff3c5f6b60157d630f30588425f3a09fbb
Merged at revision: 5316977258a8d63d7641b150749d2cc9f0d316c1
Proposed branch: ~pwlars/testflinger-cli:reserve-handle-bad-opt-data
Merge into: testflinger-cli:master
Diff against target: 52 lines (+25/-10)
1 file modified
testflinger_cli/__init__.py (+25/-10)
Reviewer Review Type Date Requested Status
Sheila Miguez (community) Approve
Review via email: mp+377888@code.launchpad.net

Description of the change

This handles good *and* bad input a lot better when specifying options you want for testflinger reserve rather than going through the prompts

To post a comment you must log in.
Revision history for this message
Sheila Miguez (codersquid) wrote :

lgtm

review: Approve
Revision history for this message
Chris Wayne (cwayne) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/testflinger_cli/__init__.py b/testflinger_cli/__init__.py
2index 43f3d06..563b2dd 100644
3--- a/testflinger_cli/__init__.py
4+++ b/testflinger_cli/__init__.py
5@@ -292,22 +292,37 @@ def list_queues(ctx):
6 def reserve(ctx, queue, image, ssh_keys):
7 """Install and reserve a system"""
8 conn = ctx.obj['conn']
9+ try:
10+ queues = conn.get_queues()
11+ except Exception:
12+ print("WARNING: unable to get a list of queues from the server!")
13+ queues = {}
14 if not queue:
15- try:
16- queues = conn.get_queues()
17- except Exception:
18- print("WARNING: unable to get a list of queues from the server!")
19- queues = {}
20 queue = _get_queue(queues)
21+ else:
22+ if queue not in queues.keys():
23+ print("WARNING: '{}' is not in the list of known "
24+ "queues".format(queue))
25+ try:
26+ images = conn.get_images(queue)
27+ except Exception:
28+ print("WARNING: unable to get a list of images from the server!")
29+ images = {}
30 if not image:
31- try:
32- images = conn.get_images(queue)
33- except Exception:
34- print("WARNING: unable to get a list of images from the server!")
35- images = {}
36 image = _get_image(images)
37+ else:
38+ if image not in images.keys():
39+ raise SystemExit("ERROR: '{}' is not in the list of known "
40+ "images for that queue, please select "
41+ "another.".format(image))
42+ image = images[image]
43 if not ssh_keys:
44 ssh_keys = _get_ssh_keys()
45+ else:
46+ for ssh_key in ssh_keys:
47+ if not ssh_key.startswith("lp:") and not ssh_key.startswith("gh:"):
48+ raise SystemExit("Please enter keys in the form lp:userid or "
49+ "gh:userid")
50 template = inspect.cleandoc("""job_queue: {queue}
51 provision_data:
52 {image}

Subscribers

People subscribed via source and target branches