Merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-fix-tarball-root-dir into lp:adt-cloud-worker

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: 28
Merged at revision: 27
Proposed branch: lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-fix-tarball-root-dir
Merge into: lp:adt-cloud-worker
Diff against target: 77 lines (+13/-12)
2 files modified
adt_cloud_worker/__init__.py (+8/-7)
adt_cloud_worker/tests/test_cloud_worker.py (+5/-5)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-fix-tarball-root-dir
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Review via email: mp+253454@code.launchpad.net

Commit message

Make the results tarball root folder name more sensible.

Description of the change

Make the results tarball root folder name more sensible.

To post a comment you must log in.
Revision history for this message
Celso Providelo (cprov) wrote :

Thanks Thomi,

Just a minor comments and you can land.

review: Approve
28. By Thomi Richards

Fix comment.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'adt_cloud_worker/__init__.py'
2--- adt_cloud_worker/__init__.py 2015-03-18 23:54:46 +0000
3+++ adt_cloud_worker/__init__.py 2015-03-19 02:37:23 +0000
4@@ -99,10 +99,12 @@
5 arguments = _make_adt_argument_list(adt_kwargs)
6
7 body['exit_code'] = run_adt(arguments)
8- tarball_path = _create_tarball_from_directory(result_dir)
9- # Upload the results tarball to swift with a temporary name
10- # 'adt-<req_id>/results.tgz.tmp', result checker will rename
11- # if after verification.
12+ tarball_path = _create_tarball_from_directory(
13+ result_dir,
14+ 'results_{}'.format(body['request_id'])
15+ )
16+ # Upload the results tarball to swift. This will be made public
17+ # by the adt-result-checker.
18 container_name = 'adt-{}'.format(body['request_id'])
19 upload_tarball_to_swift_container(tarball_path, container_name)
20 except Exception as e:
21@@ -205,7 +207,7 @@
22 os.environ[k.upper()] = str(v)
23
24
25-def _create_tarball_from_directory(directory_to_tar):
26+def _create_tarball_from_directory(directory_to_tar, tarball_root):
27 """Create a gzip'd tarball of the given directory.
28
29 :returns: the path to the newly created tarball. The caller is responsible
30@@ -214,12 +216,11 @@
31 """
32 # Compress the results directory in a temporary file.
33 _unused, tarball_path = tempfile.mkstemp()
34- dirname_for_tarball = os.path.basename(directory_to_tar)
35 with tarfile.open(tarball_path, "w:gz") as tar:
36 for entry in os.listdir(directory_to_tar):
37 tar.add(
38 os.path.join(directory_to_tar, entry),
39- arcname=os.path.join(dirname_for_tarball, entry),
40+ arcname=os.path.join(tarball_root, entry),
41 )
42 return tarball_path
43
44
45=== modified file 'adt_cloud_worker/tests/test_cloud_worker.py'
46--- adt_cloud_worker/tests/test_cloud_worker.py 2015-03-12 15:41:50 +0000
47+++ adt_cloud_worker/tests/test_cloud_worker.py 2015-03-19 02:37:23 +0000
48@@ -142,14 +142,14 @@
49
50 class TarballCreationTests(testtools.TestCase):
51
52- def create_tarball_with_cleanup(self, directory_to_tar):
53- tarball_path = _create_tarball_from_directory(directory_to_tar)
54+ def create_tarball_with_cleanup(self, directory_to_tar, tarball_root):
55+ tarball_path = _create_tarball_from_directory(directory_to_tar, tarball_root)
56 self.addCleanup(os.remove, tarball_path)
57 return tarball_path
58
59 def test_will_tar_empty_directory(self):
60 with tempfile.TemporaryDirectory() as tempdir:
61- tarfile_path = self.create_tarball_with_cleanup(tempdir)
62+ tarfile_path = self.create_tarball_with_cleanup(tempdir, 'root')
63
64 self.assertThat(tarfile_path, FileExists())
65 self.assertTrue(tarfile.is_tarfile(tarfile_path))
66@@ -158,9 +158,9 @@
67 with tempfile.TemporaryDirectory() as tempdir:
68 with open(os.path.join(tempdir, 'testfile'), 'w') as f:
69 f.write("Some Data")
70- tarfile_path = self.create_tarball_with_cleanup(tempdir)
71+ tarfile_path = self.create_tarball_with_cleanup(tempdir, 'root')
72
73- expected = os.path.join(os.path.basename(tempdir), 'testfile')
74+ expected = 'root/testfile'
75 self.assertThat(
76 tarfile_path,
77 TarballContains([expected])

Subscribers

People subscribed via source and target branches

to all changes: