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
=== modified file 'adt_cloud_worker/__init__.py'
--- adt_cloud_worker/__init__.py 2015-03-18 23:54:46 +0000
+++ adt_cloud_worker/__init__.py 2015-03-19 02:37:23 +0000
@@ -99,10 +99,12 @@
99 arguments = _make_adt_argument_list(adt_kwargs)99 arguments = _make_adt_argument_list(adt_kwargs)
100100
101 body['exit_code'] = run_adt(arguments)101 body['exit_code'] = run_adt(arguments)
102 tarball_path = _create_tarball_from_directory(result_dir)102 tarball_path = _create_tarball_from_directory(
103 # Upload the results tarball to swift with a temporary name103 result_dir,
104 # 'adt-<req_id>/results.tgz.tmp', result checker will rename104 'results_{}'.format(body['request_id'])
105 # if after verification.105 )
106 # Upload the results tarball to swift. This will be made public
107 # by the adt-result-checker.
106 container_name = 'adt-{}'.format(body['request_id'])108 container_name = 'adt-{}'.format(body['request_id'])
107 upload_tarball_to_swift_container(tarball_path, container_name)109 upload_tarball_to_swift_container(tarball_path, container_name)
108 except Exception as e:110 except Exception as e:
@@ -205,7 +207,7 @@
205 os.environ[k.upper()] = str(v)207 os.environ[k.upper()] = str(v)
206208
207209
208def _create_tarball_from_directory(directory_to_tar):210def _create_tarball_from_directory(directory_to_tar, tarball_root):
209 """Create a gzip'd tarball of the given directory.211 """Create a gzip'd tarball of the given directory.
210212
211 :returns: the path to the newly created tarball. The caller is responsible213 :returns: the path to the newly created tarball. The caller is responsible
@@ -214,12 +216,11 @@
214 """216 """
215 # Compress the results directory in a temporary file.217 # Compress the results directory in a temporary file.
216 _unused, tarball_path = tempfile.mkstemp()218 _unused, tarball_path = tempfile.mkstemp()
217 dirname_for_tarball = os.path.basename(directory_to_tar)
218 with tarfile.open(tarball_path, "w:gz") as tar:219 with tarfile.open(tarball_path, "w:gz") as tar:
219 for entry in os.listdir(directory_to_tar):220 for entry in os.listdir(directory_to_tar):
220 tar.add(221 tar.add(
221 os.path.join(directory_to_tar, entry),222 os.path.join(directory_to_tar, entry),
222 arcname=os.path.join(dirname_for_tarball, entry),223 arcname=os.path.join(tarball_root, entry),
223 )224 )
224 return tarball_path225 return tarball_path
225226
226227
=== modified file 'adt_cloud_worker/tests/test_cloud_worker.py'
--- adt_cloud_worker/tests/test_cloud_worker.py 2015-03-12 15:41:50 +0000
+++ adt_cloud_worker/tests/test_cloud_worker.py 2015-03-19 02:37:23 +0000
@@ -142,14 +142,14 @@
142142
143class TarballCreationTests(testtools.TestCase):143class TarballCreationTests(testtools.TestCase):
144144
145 def create_tarball_with_cleanup(self, directory_to_tar):145 def create_tarball_with_cleanup(self, directory_to_tar, tarball_root):
146 tarball_path = _create_tarball_from_directory(directory_to_tar)146 tarball_path = _create_tarball_from_directory(directory_to_tar, tarball_root)
147 self.addCleanup(os.remove, tarball_path)147 self.addCleanup(os.remove, tarball_path)
148 return tarball_path148 return tarball_path
149149
150 def test_will_tar_empty_directory(self):150 def test_will_tar_empty_directory(self):
151 with tempfile.TemporaryDirectory() as tempdir:151 with tempfile.TemporaryDirectory() as tempdir:
152 tarfile_path = self.create_tarball_with_cleanup(tempdir)152 tarfile_path = self.create_tarball_with_cleanup(tempdir, 'root')
153153
154 self.assertThat(tarfile_path, FileExists())154 self.assertThat(tarfile_path, FileExists())
155 self.assertTrue(tarfile.is_tarfile(tarfile_path))155 self.assertTrue(tarfile.is_tarfile(tarfile_path))
@@ -158,9 +158,9 @@
158 with tempfile.TemporaryDirectory() as tempdir:158 with tempfile.TemporaryDirectory() as tempdir:
159 with open(os.path.join(tempdir, 'testfile'), 'w') as f:159 with open(os.path.join(tempdir, 'testfile'), 'w') as f:
160 f.write("Some Data")160 f.write("Some Data")
161 tarfile_path = self.create_tarball_with_cleanup(tempdir)161 tarfile_path = self.create_tarball_with_cleanup(tempdir, 'root')
162162
163 expected = os.path.join(os.path.basename(tempdir), 'testfile')163 expected = 'root/testfile'
164 self.assertThat(164 self.assertThat(
165 tarfile_path,165 tarfile_path,
166 TarballContains([expected])166 TarballContains([expected])

Subscribers

People subscribed via source and target branches

to all changes: