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

Proposed by Aaron Bentley
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 Approve
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.
Revision history for this message
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
=== modified file 'workspace_runner/__init__.py'
--- workspace_runner/__init__.py 2015-07-13 14:39:40 +0000
+++ workspace_runner/__init__.py 2015-07-17 14:10:33 +0000
@@ -1,7 +1,6 @@
1from argparse import ArgumentParser1from argparse import ArgumentParser
2from ConfigParser import RawConfigParser2from ConfigParser import RawConfigParser
3from contextlib import contextmanager3from contextlib import contextmanager
4from itertools import chain
5import json4import json
6import logging5import logging
7from pipes import quote6from pipes import quote
@@ -144,7 +143,7 @@
144 logging.info('Remote mktmp')143 logging.info('Remote mktmp')
145 return cls.run_python(ssh_connection, dedent("""144 return cls.run_python(ssh_connection, dedent("""
146 import tempfile145 import tempfile
147 print tempfile.mkdtemp()146 print tempfile.mkdtemp(prefix='workspace-runner-')
148 """))147 """))
149148
150 def destroy(self):149 def destroy(self):
@@ -234,6 +233,7 @@
234 """Install the files and run the command."""233 """Install the files and run the command."""
235 for target, sources in config['install'].items():234 for target, sources in config['install'].items():
236 primitives.install(sources, target)235 primitives.install(sources, target)
236 primitives.run(config['command'], output)
237 if 'artifacts' in config:237 if 'artifacts' in config:
238 import upload_artifacts238 import upload_artifacts
239 sources = [upload_artifacts.__file__.replace('.pyc', '.py')]239 sources = [upload_artifacts.__file__.replace('.pyc', '.py')]
@@ -246,8 +246,6 @@
246 with temp_config(upload_config) as upload_config_filename:246 with temp_config(upload_config) as upload_config_filename:
247 sources.append(upload_config_filename)247 sources.append(upload_config_filename)
248 primitives.install(sources, '.wsr')248 primitives.install(sources, '.wsr')
249 primitives.run(config['command'], output)
250 if 'artifacts' in config:
251 primitives.run(['python', '.wsr/upload_artifacts.py',249 primitives.run(['python', '.wsr/upload_artifacts.py',
252 '.wsr/upload.json', primitives.workspace], output)250 '.wsr/upload.json', primitives.workspace], output)
253251
254252
=== modified file 'workspace_runner/tests/__init__.py'
--- workspace_runner/tests/__init__.py 2015-07-13 14:39:40 +0000
+++ workspace_runner/tests/__init__.py 2015-07-17 14:10:33 +0000
@@ -248,7 +248,7 @@
248 stdout=subprocess.PIPE)248 stdout=subprocess.PIPE)
249 sp_mock.return_value.communicate.assert_called_once_with(dedent("""249 sp_mock.return_value.communicate.assert_called_once_with(dedent("""
250 import tempfile250 import tempfile
251 print tempfile.mkdtemp()251 print tempfile.mkdtemp(prefix='workspace-runner-')
252 """))252 """))
253253
254 @contextmanager254 @contextmanager
@@ -426,6 +426,36 @@
426 'upload.json', 'upload_artifacts.py'])426 'upload.json', 'upload_artifacts.py'])
427 ])427 ])
428428
429 def test_upload_after_delete(self):
430
431 class FakePrimitivesNoUpload(FakePrimitives):
432
433 def run(self_, args, out_file):
434 if args == ['run', 'this']:
435 self.assertFalse(
436 os.path.exists(os.path.join(self_.workspace, '.wsr')))
437 return super(FakePrimitivesNoUpload, self_).run(args, out_file)
438
439 config = {
440 'command': ['run', 'this'],
441 'install': {},
442 'artifacts': {'foo': ['bar']},
443 'bucket': 'baz',
444 }
445 with workspace_context('foo', None,
446 FakePrimitivesNoUpload) as primitives:
447 run_from_config(primitives, config, {}, None, StringIO())
448 self.assertEqual(primitives.run_calls, [
449 ['run', 'this'],
450 ['python', '.wsr/upload_artifacts.py', '.wsr/upload.json',
451 primitives.workspace]
452 ])
453 self.assertEqual(primitives.walk_results, [
454 (primitives.workspace, ['.wsr'], []),
455 (os.path.join(primitives.workspace, '.wsr'), [], [
456 'upload.json', 'upload_artifacts.py'])
457 ])
458
429459
430class TestWorkspaceRun(TestCase):460class TestWorkspaceRun(TestCase):
431461

Subscribers

People subscribed via source and target branches