Merge lp:~abentley/workspace-runner/enhanced-artifacts into lp:workspace-runner

Proposed by Aaron Bentley on 2015-07-17
Status: Merged
Merged at revision: 24
Proposed branch: lp:~abentley/workspace-runner/enhanced-artifacts
Merge into: lp:workspace-runner
Diff against target: 86 lines (+33/-5)
2 files modified
workspace_runner/__init__.py (+2/-4)
workspace_runner/tests/__init__.py (+31/-1)
To merge this branch: bzr merge lp:~abentley/workspace-runner/enhanced-artifacts
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code 2015-07-17 Approve on 2015-07-17
Review via email: mp+265126@code.launchpad.net

Commit message

Upload artifacts script after command, customize temp dir name.

Description of the change

This branch tweaks the order of operation so that the upload_artifacts script is run after the main command. That way, if the main command deletes the contents of the workspace, the artifacts are still archived successfully.

run-deploy-job is an example of a command that deletes the contents of the workspace. It uses jujuci.py setup-workspace.

This branch also fixes some lint, and specifies the prefix for temp directory names.

To post a comment you must log in.
Curtis Hovey (sinzui) wrote :

Thank you.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'workspace_runner/__init__.py'
2--- workspace_runner/__init__.py 2015-07-13 14:39:40 +0000
3+++ workspace_runner/__init__.py 2015-07-17 14:10:33 +0000
4@@ -1,7 +1,6 @@
5 from argparse import ArgumentParser
6 from ConfigParser import RawConfigParser
7 from contextlib import contextmanager
8-from itertools import chain
9 import json
10 import logging
11 from pipes import quote
12@@ -144,7 +143,7 @@
13 logging.info('Remote mktmp')
14 return cls.run_python(ssh_connection, dedent("""
15 import tempfile
16- print tempfile.mkdtemp()
17+ print tempfile.mkdtemp(prefix='workspace-runner-')
18 """))
19
20 def destroy(self):
21@@ -234,6 +233,7 @@
22 """Install the files and run the command."""
23 for target, sources in config['install'].items():
24 primitives.install(sources, target)
25+ primitives.run(config['command'], output)
26 if 'artifacts' in config:
27 import upload_artifacts
28 sources = [upload_artifacts.__file__.replace('.pyc', '.py')]
29@@ -246,8 +246,6 @@
30 with temp_config(upload_config) as upload_config_filename:
31 sources.append(upload_config_filename)
32 primitives.install(sources, '.wsr')
33- primitives.run(config['command'], output)
34- if 'artifacts' in config:
35 primitives.run(['python', '.wsr/upload_artifacts.py',
36 '.wsr/upload.json', primitives.workspace], output)
37
38
39=== modified file 'workspace_runner/tests/__init__.py'
40--- workspace_runner/tests/__init__.py 2015-07-13 14:39:40 +0000
41+++ workspace_runner/tests/__init__.py 2015-07-17 14:10:33 +0000
42@@ -248,7 +248,7 @@
43 stdout=subprocess.PIPE)
44 sp_mock.return_value.communicate.assert_called_once_with(dedent("""
45 import tempfile
46- print tempfile.mkdtemp()
47+ print tempfile.mkdtemp(prefix='workspace-runner-')
48 """))
49
50 @contextmanager
51@@ -426,6 +426,36 @@
52 'upload.json', 'upload_artifacts.py'])
53 ])
54
55+ def test_upload_after_delete(self):
56+
57+ class FakePrimitivesNoUpload(FakePrimitives):
58+
59+ def run(self_, args, out_file):
60+ if args == ['run', 'this']:
61+ self.assertFalse(
62+ os.path.exists(os.path.join(self_.workspace, '.wsr')))
63+ return super(FakePrimitivesNoUpload, self_).run(args, out_file)
64+
65+ config = {
66+ 'command': ['run', 'this'],
67+ 'install': {},
68+ 'artifacts': {'foo': ['bar']},
69+ 'bucket': 'baz',
70+ }
71+ with workspace_context('foo', None,
72+ FakePrimitivesNoUpload) as primitives:
73+ run_from_config(primitives, config, {}, None, StringIO())
74+ self.assertEqual(primitives.run_calls, [
75+ ['run', 'this'],
76+ ['python', '.wsr/upload_artifacts.py', '.wsr/upload.json',
77+ primitives.workspace]
78+ ])
79+ self.assertEqual(primitives.walk_results, [
80+ (primitives.workspace, ['.wsr'], []),
81+ (os.path.join(primitives.workspace, '.wsr'), [], [
82+ 'upload.json', 'upload_artifacts.py'])
83+ ])
84+
85
86 class TestWorkspaceRun(TestCase):
87

Subscribers

People subscribed via source and target branches