Merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-export-payload-metadata into lp:adt-cloud-worker

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: 28
Merged at revision: 28
Proposed branch: lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-export-payload-metadata
Merge into: lp:adt-cloud-worker
Diff against target: 104 lines (+64/-1)
2 files modified
adt_cloud_worker/__init__.py (+25/-0)
adt_cloud_worker/tests/test_cloud_worker.py (+39/-1)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/adt-cloud-worker/trunk-export-payload-metadata
Reviewer Review Type Date Requested Status
Paul Larson Approve
Celso Providelo (community) Approve
Review via email: mp+253457@code.launchpad.net

Commit message

Add the nova-metadata file to the results tarball, which contains some metadata from the test request payload.

Description of the change

Add the nova-metadata file to the results tarball, which contains some metadata from the test request payload.

To post a comment you must log in.
28. By Thomi Richards

Merge trunk, resolve conflicts.

Revision history for this message
Celso Providelo (cprov) wrote :

Thanks for implementing this.

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

+1

review: Approve

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-19 02:37:02 +0000
+++ adt_cloud_worker/__init__.py 2015-03-19 03:09:10 +0000
@@ -99,6 +99,7 @@
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 _create_run_metadata_file(result_dir, body)
102 tarball_path = _create_tarball_from_directory(103 tarball_path = _create_tarball_from_directory(
103 result_dir,104 result_dir,
104 'results_{}'.format(body['request_id'])105 'results_{}'.format(body['request_id'])
@@ -123,6 +124,30 @@
123 logger.info('Done!')124 logger.info('Done!')
124125
125126
127def _create_run_metadata_file(directory, request):
128 """Create a metadata file in 'directory' with some of the data from 'request'
129
130 We want to make sure that, as (potentially confidential) items are added to
131 the request that we don't blindly add them to the metadata file, so we
132 have a whitelist of keys we allow.
133
134 """
135 key_whitelist = [
136 'apt_pocket',
137 'architecture',
138 'exit_code',
139 'nova_image',
140 'package_name',
141 'platform',
142 'request_id',
143 'series',
144 ]
145 with open(os.path.join(directory, 'nova-metadata'), 'w') as outfile:
146 for key in key_whitelist:
147 if key in request:
148 outfile.write("{}\t{}\n".format(key, request[key]))
149
150
126def _validate_request_contents(request):151def _validate_request_contents(request):
127 """Validates that 'request' contains everything we need to process it.152 """Validates that 'request' contains everything we need to process it.
128153
129154
=== modified file 'adt_cloud_worker/tests/test_cloud_worker.py'
--- adt_cloud_worker/tests/test_cloud_worker.py 2015-03-19 02:10:42 +0000
+++ adt_cloud_worker/tests/test_cloud_worker.py 2015-03-19 03:09:10 +0000
@@ -19,7 +19,10 @@
19import tempfile19import tempfile
20import tarfile20import tarfile
2121
22from fixtures import Fixture22from fixtures import (
23 Fixture,
24 TempDir,
25)
23import testtools26import testtools
24from testtools.matchers import (27from testtools.matchers import (
25 FileExists,28 FileExists,
@@ -32,6 +35,7 @@
32 _make_adt_argument_list,35 _make_adt_argument_list,
33 _set_nova_environment_variables,36 _set_nova_environment_variables,
34 _validate_request_contents,37 _validate_request_contents,
38 _create_run_metadata_file,
35)39)
3640
3741
@@ -192,3 +196,37 @@
192 _validate_request_contents(196 _validate_request_contents(
193 dict(nova_image='foo', request_id='123', package_name='librepng')197 dict(nova_image='foo', request_id='123', package_name='librepng')
194 )198 )
199
200
201class TestMetadataFileCreation(testtools.TestCase):
202
203 def assertRequestResultsInFileContents(self, request, expected_contents):
204 with TempDir() as t:
205 _create_run_metadata_file(t.path, request)
206 expected_path = os.path.join(t.path, 'nova-metadata')
207
208 self.assertThat(
209 expected_path,
210 FileExists()
211 )
212 with open(expected_path) as infile:
213 contents = infile.read()
214 self.assertEquals(contents, expected_contents)
215
216 def test_ignores_non_whitelisted_keys(self):
217 self.assertRequestResultsInFileContents(
218 dict(secret="Wouldn't you like to know!"),
219 ''
220 )
221
222 def test_writes_exit_code(self):
223 self.assertRequestResultsInFileContents(
224 dict(exit_code='100'),
225 'exit_code\t100\n'
226 )
227
228 def test_writes_multiple_whitelisted_keys(self):
229 self.assertRequestResultsInFileContents(
230 dict(series='trusty', exit_code='100'),
231 'exit_code\t100\nseries\ttrusty\n'
232 )

Subscribers

People subscribed via source and target branches

to all changes: