Merge ~pwlars/testflinger-cli:artifact-downloading into testflinger-cli:master

Proposed by Paul Larson
Status: Merged
Approved by: Paul Larson
Approved revision: 204ed155c762112a8339fce4a17c05a10f6aa4ca
Merged at revision: 204ed155c762112a8339fce4a17c05a10f6aa4ca
Proposed branch: ~pwlars/testflinger-cli:artifact-downloading
Merge into: testflinger-cli:master
Diff against target: 79 lines (+44/-2)
3 files modified
README.rst (+8/-2)
testflinger-cli (+19/-0)
testflinger_cli/__init__.py (+17/-0)
Reviewer Review Type Date Requested Status
Paul Larson Approve
Review via email: mp+315401@code.launchpad.net

Description of the change

Downloading artifacts is now supported. If you want to test this, I'm also uploading a new snap to --beta right now.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

Minor change s/artifact/artifacts to match the dir name in the tarball and on the agent side

Revision history for this message
Paul Larson (pwlars) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.rst b/README.rst
2index b59ef3e..21b590b 100644
3--- a/README.rst
4+++ b/README.rst
5@@ -56,9 +56,15 @@ job is complete.
6
7 $ testflinger-cli poll <job_id>
8
9-Finally, to get the full json results from the job when it is done running,
10-you can use the 'results' subcommand:
11+To get the full json results from the job when it is done running, you can
12+use the 'results' subcommand:
13 .. code-block:: console
14
15 $ testflinger-cli results <job_id>
16
17+Finally, to download the artifact tarball from the job, you can use the
18+'artifact' subcommand:
19+.. code-block:: console
20+
21+ $ testflinger-cli artifact [--filename <DEFAULT:artifact.tgz>] <job_id>
22+
23diff --git a/testflinger-cli b/testflinger-cli
24index 52ca535..cb0e4b8 100755
25--- a/testflinger-cli
26+++ b/testflinger-cli
27@@ -98,6 +98,25 @@ def results(ctx, job_id):
28
29 @cli.command()
30 @click.argument('job_id', nargs=1)
31+@click.option('--filename', default='artifacts.tgz')
32+@click.pass_context
33+def artifacts(ctx, job_id, filename):
34+ conn = ctx.obj['conn']
35+ print('Downloading artifacts tarball...')
36+ try:
37+ conn.get_artifact(job_id, filename)
38+ except testflinger_cli.HTTPError as e:
39+ if e.status == 204:
40+ print('No artifacts tarball found for that job id.')
41+ elif e.status == 400:
42+ print('Invalid job id specified. Check the job id to be sure it '
43+ 'is correct')
44+ sys.exit(1)
45+ print('Artifacts downloaded to {}'.format(filename))
46+
47+
48+@cli.command()
49+@click.argument('job_id', nargs=1)
50 @click.pass_context
51 def poll(ctx, job_id):
52 conn = ctx.obj['conn']
53diff --git a/testflinger_cli/__init__.py b/testflinger_cli/__init__.py
54index 1d98424..56a1f90 100644
55--- a/testflinger_cli/__init__.py
56+++ b/testflinger_cli/__init__.py
57@@ -92,6 +92,23 @@ class Client():
58 endpoint = '/v1/result/{}'.format(job_id)
59 return json.loads(self.get(endpoint))
60
61+ def get_artifact(self, job_id, path):
62+ """Get results for a specified test job
63+
64+ :param job_id:
65+ ID for the test job
66+ :param path:
67+ Path and filename for the artifact file
68+ """
69+ endpoint = '/v1/result/{}/artifact'.format(job_id)
70+ uri = urllib.parse.urljoin(self.server, endpoint)
71+ req = requests.get(uri)
72+ if req.status_code != 200:
73+ raise HTTPError(req.status_code)
74+ with open(path, 'wb') as artifact:
75+ for chunk in req.iter_content(chunk_size=4096):
76+ artifact.write(chunk)
77+
78 def get_output(self, job_id):
79 """Get the latest output for a specified test job
80

Subscribers

People subscribed via source and target branches