fail at startup with no operating-system element

Raise an error if there is no element with “operating-system”
in the element-provides file.

Change-Id: I2242537abc4c610252984c32c286bc6eb25de672
This commit is contained in:
Gonéri Le Bouder 2014-04-30 17:59:49 +02:00
parent b46ece4de9
commit 1011adf370
3 changed files with 35 additions and 9 deletions

View File

@ -43,7 +43,7 @@ def _get_set(element, fname, elements_dir=None):
sys.stderr.write("ERROR: Element '%s' not found in '%s'\n" % sys.stderr.write("ERROR: Element '%s' not found in '%s'\n" %
(element, elements_dir)) (element, elements_dir))
exit(-1) sys.exit(-1)
def provides(element, elements_dir=None): 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)) check_queue.extend(deps - (final_elements | provided))
final_elements.update(deps) 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 conflicts = set(user_elements) & provided
if conflicts: if conflicts:
sys.stderr.write("ERROR: Following elements were explicitly required " sys.stderr.write("ERROR: Following elements were explicitly required "
"but are provided by other included elements: %s\n" % "but are provided by other included elements: %s\n" %
", ".join(conflicts)) ", ".join(conflicts))
exit(-1) sys.exit(-1)
return final_elements - provided return final_elements - provided

View File

@ -40,7 +40,10 @@ class TestElementDeps(testtools.TestCase):
super(TestElementDeps, self).setUp() super(TestElementDeps, self).setUp()
self.element_dir = self.useFixture(fixtures.TempDir()).path self.element_dir = self.useFixture(fixtures.TempDir()).path
_populate_element(self.element_dir, 'requires-foo', ['foo']) _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, _populate_element(self.element_dir,
'requires-requires-foo', 'requires-requires-foo',
['requires-foo']) ['requires-foo'])
@ -49,15 +52,21 @@ class TestElementDeps(testtools.TestCase):
'provides_virtual', 'provides_virtual',
[], [],
['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, 'virtual', ['extra_dependency'])
_populate_element(self.element_dir, '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, 'circular2', ['circular1'])
_populate_element(self.element_dir, _populate_element(self.element_dir,
'provides_new_virtual', 'provides_new_virtual',
[], [],
['new_virtual']) ['new_virtual', 'operating-system'])
_populate_element(self.element_dir, _populate_element(self.element_dir,
'requires_new_virtual', 'requires_new_virtual',
['new_virtual']) ['new_virtual'])
@ -87,8 +96,8 @@ class TestElementDeps(testtools.TestCase):
def test_self(self): def test_self(self):
result = element_dependencies.expand_dependencies( result = element_dependencies.expand_dependencies(
['self'], elements_dir=self.element_dir) ['self', 'foo'], elements_dir=self.element_dir)
self.assertEqual(set(['self']), result) self.assertEqual(set(['self', 'foo']), result)
def test_circular(self): def test_circular(self):
result = element_dependencies.expand_dependencies( result = element_dependencies.expand_dependencies(
@ -114,6 +123,18 @@ class TestElementDeps(testtools.TestCase):
self.assertEqual(set(['requires_new_virtual', 'provides_new_virtual']), self.assertEqual(set(['requires_new_virtual', 'provides_new_virtual']),
result) 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): class TestElements(testtools.TestCase):
def test_depends_on_env(self): def test_depends_on_env(self):

View File

@ -252,7 +252,7 @@ function create_base () {
if [ -z "$(ls $TMP_MOUNT_PATH | grep -v '^lost+found\|tmp$')" ] ; then if [ -z "$(ls $TMP_MOUNT_PATH | grep -v '^lost+found\|tmp$')" ] ; then
# No root element copied in. Note the test above allows # No root element copied in. Note the test above allows
# root.d elements to put things in /tmp # 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 exit 1
fi fi