From a96f87bc91cc164d1a29d087125a3edcb58cb0e9 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 25 Jul 2018 15:00:15 +0300 Subject: Add: "archive: systree" action, name_from field to populate actions --- NEWS | 11 +++++++---- ick2/actions.py | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index 794dd33..ae147a0 100644 --- a/NEWS +++ b/NEWS @@ -29,13 +29,16 @@ Version 0.53.2+git, not yet released * The controller now parses, saves resources as YAML files in a faster way. +* The worker manager now supports a new `archive: systree` action, + which allows archiving the current state of the systree. Also, both + the `populate_systree` and `populate_workspace` actions now take an + optional `name_from` field, which gives the name of the project + parameter that gives the name of the artifact to use. The defaults + are `systree_name` and `workspace_name`, respectively. + Version 0.53.2, released 2018-07-18 ------------------------------------ - -Version 0.53.1, released 2018-07-18 ----------------------------------- - * A dummy release to build for stretch. Version 0.53, released 2018-07-18 diff --git a/ick2/actions.py b/ick2/actions.py index 328b08a..33f7362 100644 --- a/ick2/actions.py +++ b/ick2/actions.py @@ -97,13 +97,22 @@ class ActionFactory: ('shell', ShellAction), ('python', PythonAction), ('debootstrap', DebootstrapAction), - ('archive', ArchiveWorkspaceAction), ] for key, klass in rules: if key in spec: return klass(env) + if 'archive' in spec: + rules2 = { + 'workspace': ArchiveWorkspaceAction, + 'systree': ArchiveSystreeAction, + } + kind = spec['archive'] + klass = rules2.get(kind) + if klass: + return klass(env) + if 'action' in spec: rules2 = { 'populate_systree': PopulateSystreeAction, @@ -260,7 +269,10 @@ class CreateWorkspaceAction(Action): return 0 -class ArchiveWorkspaceAction(Action): # pragma: no cover +class ArchiveBaseAction(Action): # pragma: no cover + + def get_dirname(self, env): + raise NotImplementedError() def encode_parameters(self, params): pass @@ -285,16 +297,16 @@ class ArchiveWorkspaceAction(Action): # pragma: no cover url = self.get_blob_upload_url(blob_name) headers = self.get_authz_headers() - self._env.report(None, 'Creating tarball from workspace\n') + self._env.report(None, 'Creating tarball\n') fd, tarball = tempfile.mkstemp() os.close(fd) tar = ['sudo', 'tar', '-zcf', tarball, '-C', dirname] + names exit_code = self._env.host_runcmd(tar) if exit_code != 0: - self._env.report(exit_code, 'tarball generation finished\n') + self._env.report(exit_code, 'Tarball generation failed\n') os.remove(tarball) return exit_code - self._env.report(None, 'tarball generation finished\n') + self._env.report(None, 'Tarball generation finished OK\n') self._env.report(None, 'Uploading tarball to artifact store\n') curl = ['curl', '-sk', '-T', tarball] + [ @@ -305,6 +317,7 @@ class ArchiveWorkspaceAction(Action): # pragma: no cover self._env.report( exit_code, 'curl upload finished (exit code %s)\n' % exit_code) os.remove(tarball) + return exit_code def match_globs(self, workspace, globs): @@ -316,6 +329,18 @@ class ArchiveWorkspaceAction(Action): # pragma: no cover return names +class ArchiveSystreeAction(ArchiveBaseAction): # pragma: no cover + + def get_dirname(self, env): + return env.get_systree_directory() + + +class ArchiveWorkspaceAction(ArchiveBaseAction): # pragma: no cover + + def get_dirname(self, env): + return env.get_workspace_directory() + + class PopulateActionBase(Action): # pragma: no cover step_field = None @@ -327,12 +352,13 @@ class PopulateActionBase(Action): # pragma: no cover def execute(self, params, step): env = self.get_env() - name = step.get(self.step_field) + name = step.get(name_name) if not name or name == 'auto': - name = params.get(self.param_name) + name_name = step.get('name_from', self.param_name) + name = params.get(name_name) if not name: - msg = '{} in action is {}, but no {} params\n'.format( - self.step_field, name, self.param_name) + msg = '{} in action is {}, but no {} parameter\n'.format( + self.step_field, name, name_name) env.report(1, msg) return 1 -- cgit v1.2.1