From 1011adf37010b052ae1d90c199f09520a6e593cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 30 Apr 2014 17:59:49 +0200 Subject: [PATCH] fail at startup with no operating-system element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Raise an error if there is no element with “operating-system” in the element-provides file. Change-Id: I2242537abc4c610252984c32c286bc6eb25de672 --- diskimage_builder/element_dependencies.py | 9 ++++-- diskimage_builder/tests/test_elementdeps.py | 33 +++++++++++++++++---- lib/common-functions | 2 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/diskimage_builder/element_dependencies.py b/diskimage_builder/element_dependencies.py index 45472ef6..db340cc0 100644 --- a/diskimage_builder/element_dependencies.py +++ b/diskimage_builder/element_dependencies.py @@ -43,7 +43,7 @@ def _get_set(element, fname, elements_dir=None): sys.stderr.write("ERROR: Element '%s' not found in '%s'\n" % (element, elements_dir)) - exit(-1) + sys.exit(-1) def provides(element, elements_dir=None): @@ -98,12 +98,17 @@ def expand_dependencies(user_elements, elements_dir=None): check_queue.extend(deps - (final_elements | provided)) final_elements.update(deps) + if "operating-system" not in provided: + sys.stderr.write( + "ERROR: Please include an operating system element.\n") + sys.exit(-1) + conflicts = set(user_elements) & provided if conflicts: sys.stderr.write("ERROR: Following elements were explicitly required " "but are provided by other included elements: %s\n" % ", ".join(conflicts)) - exit(-1) + sys.exit(-1) return final_elements - provided diff --git a/diskimage_builder/tests/test_elementdeps.py b/diskimage_builder/tests/test_elementdeps.py index cf0f29c0..7bbcdb49 100644 --- a/diskimage_builder/tests/test_elementdeps.py +++ b/diskimage_builder/tests/test_elementdeps.py @@ -40,7 +40,10 @@ class TestElementDeps(testtools.TestCase): super(TestElementDeps, self).setUp() self.element_dir = self.useFixture(fixtures.TempDir()).path _populate_element(self.element_dir, 'requires-foo', ['foo']) - _populate_element(self.element_dir, 'foo') + _populate_element(self.element_dir, + 'foo', + [], + ['operating-system']) _populate_element(self.element_dir, 'requires-requires-foo', ['requires-foo']) @@ -49,15 +52,21 @@ class TestElementDeps(testtools.TestCase): 'provides_virtual', [], ['virtual']) - _populate_element(self.element_dir, 'requires_virtual', ['virtual']) + _populate_element(self.element_dir, + 'requires_virtual', + ['virtual'], + ['operating-system']) _populate_element(self.element_dir, 'virtual', ['extra_dependency']) _populate_element(self.element_dir, 'extra_dependency', []) - _populate_element(self.element_dir, 'circular1', ['circular2']) + _populate_element(self.element_dir, + 'circular1', + ['circular2'], + ['operating-system']) _populate_element(self.element_dir, 'circular2', ['circular1']) _populate_element(self.element_dir, 'provides_new_virtual', [], - ['new_virtual']) + ['new_virtual', 'operating-system']) _populate_element(self.element_dir, 'requires_new_virtual', ['new_virtual']) @@ -87,8 +96,8 @@ class TestElementDeps(testtools.TestCase): def test_self(self): result = element_dependencies.expand_dependencies( - ['self'], elements_dir=self.element_dir) - self.assertEqual(set(['self']), result) + ['self', 'foo'], elements_dir=self.element_dir) + self.assertEqual(set(['self', 'foo']), result) def test_circular(self): result = element_dependencies.expand_dependencies( @@ -114,6 +123,18 @@ class TestElementDeps(testtools.TestCase): self.assertEqual(set(['requires_new_virtual', 'provides_new_virtual']), result) + def test_no_os_element(self): + self.assertRaises(SystemExit, + element_dependencies.expand_dependencies, + ['provides_virtual'], + elements_dir=self.element_dir) + + def test_duplicated_os_passed_as_element(self): + self.assertRaises(SystemExit, + element_dependencies.expand_dependencies, + ['circular1', 'operating-system'], + elements_dir=self.element_dir) + class TestElements(testtools.TestCase): def test_depends_on_env(self): diff --git a/lib/common-functions b/lib/common-functions index 0e1b67bd..4baa359d 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -252,7 +252,7 @@ function create_base () { if [ -z "$(ls $TMP_MOUNT_PATH | grep -v '^lost+found\|tmp$')" ] ; then # No root element copied in. Note the test above allows # root.d elements to put things in /tmp - echo "Please include at least one distribution root element." + echo "Failed to deploy the root element." exit 1 fi