From db7123ec103c192557cbf64656ba4be2499c94da Mon Sep 17 00:00:00 2001 From: James Slagle Date: Wed, 8 Mar 2017 19:01:57 -0500 Subject: [PATCH] Generate and source a dib v2 environment diskimage-builder v2 now relies on the output of "element-info --env " to have been sourced into the shell running the element hooks. Generate the environment and save the output to a file under environment.d so that dib-run-parts will source it prior to running hooks. Change-Id: Ie8ac128e391a7091184b5017959a2a653166062f Closes-Bug: #1671262 --- instack/runner.py | 11 +++++++++++ instack/tests/test_runner.py | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/instack/runner.py b/instack/runner.py index 6c6122e..88f8125 100644 --- a/instack/runner.py +++ b/instack/runner.py @@ -55,6 +55,9 @@ class ElementRunner(object): self.no_cleanup = no_cleanup self.loaded_elements = {} self.tmp_hook_dir = tempfile.mkdtemp() + self.environment_file = os.path.join(self.tmp_hook_dir, + 'environment.d', + '00-dib-v2-env') # the environment variable should override anything passed in if 'ELEMENTS_PATH' in os.environ: @@ -72,6 +75,14 @@ class ElementRunner(object): self.load_dependencies() self.process_exclude_elements() self.copy_elements() + self.generate_environment() + + def generate_environment(self): + """Generate a dib v2 environment.""" + command = ['element-info', '--env'] + list(self.elements) + env_output = subprocess.check_output(command) + with open(self.environment_file, 'w') as f: + f.write(env_output) def run(self): """Apply the elements by running each specified hook.""" diff --git a/instack/tests/test_runner.py b/instack/tests/test_runner.py index 29aad7e..d416f21 100644 --- a/instack/tests/test_runner.py +++ b/instack/tests/test_runner.py @@ -32,11 +32,18 @@ class TestRunner(testtools.TestCase): test_elements = os.path.join(cwd, 'elements') self.element_paths = [test_elements] + self.patcher = mock.patch.object(runner.ElementRunner, + 'generate_environment') + self.mock_env = self.patcher.start() self.runner = runner.ElementRunner(['dep2', 'echo', 'os'], [], self.element_paths) tmp_dir = tempfile.mkdtemp() self.runner.tmp_hook_dir = tmp_dir + def tearDown(self): + super(TestRunner, self).tearDown() + self.patcher.stop() + def test_cleanup(self): self.runner.cleanup() self.assertFalse(os.path.exists(self.runner.tmp_hook_dir))