From 45e2179790796aef05f13dfb1ef592a6c6b9765c Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 26 Dec 2018 15:57:25 +0200 Subject: Add: allow steps to run someting even if they're skipped The debootstrap step now runs 'apt-get update' even if the step is otherwise skipped. This allows a chroot unpacked from an old tarball to get up-to-date Packages files. --- vmdb/app.py | 15 +++++++++++++-- vmdb/plugins/debootstrap_plugin.py | 4 ++++ vmdb/step_list.py | 3 +++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/vmdb/app.py b/vmdb/app.py index 3a88bba..fb28145 100644 --- a/vmdb/app.py +++ b/vmdb/app.py @@ -84,15 +84,26 @@ class Vmdb2(cliapp.Application): core_meltdown = False steps_taken = [] + even_if_skipped = method_name + '_even_if_skipped' for step in steps: try: logging.info(msg, step) steps_taken.append(step) runner = self.step_runners.find(step) if runner.skip(step, self.settings, state): - logging.info('Skipping as requested') + logging.info('Skipping as requested by unless') + method_names = [even_if_skipped] else: - method = getattr(runner, method_name) + method_names = [method_name, even_if_skipped] + + methods = [ + getattr(runner, name) + for name in method_names + if hasattr(runner, name) + ] + + for method in methods: + logging.info('Calling {}'.format(method)) method(step, self.settings, state) except BaseException as e: vmdb.error(str(e)) diff --git a/vmdb/plugins/debootstrap_plugin.py b/vmdb/plugins/debootstrap_plugin.py index 91fc8d1..f52f718 100644 --- a/vmdb/plugins/debootstrap_plugin.py +++ b/vmdb/plugins/debootstrap_plugin.py @@ -42,4 +42,8 @@ class DebootstrapStepRunner(vmdb.StepRunnerInterface): if not (suite and tag and target and mirror): raise Exception('missing arg for debootstrap step') vmdb.runcmd(['debootstrap', '--variant', variant, suite, target, mirror]) + + def run_even_if_skipped(self, step, settings, state): + tag = step['target'] + target = state.tags.get_mount_point(tag) vmdb.runcmd_chroot(target, ['apt-get', 'update']) diff --git a/vmdb/step_list.py b/vmdb/step_list.py index 1f29072..b8f55f4 100644 --- a/vmdb/step_list.py +++ b/vmdb/step_list.py @@ -27,6 +27,9 @@ class StepRunnerInterface(object): # pragma: no cover def run(self, step_spec, settings, state): raise NotImplementedError() + def run_even_if_skipped(self, step_spec, settings, state): + pass + def teardown(self, step_spec, settings, state): # Default implementation does nop, so that sub-classes don't # need to have a nop teardown. -- cgit v1.2.1