Fail if two elements provide the same thing

The current check only validates that an element that specifies
"element-provides" doesn't conflict with a "real" element.  We also
want to check this against the provides of other elements.

A real example is with a "block-device" element.  There is no actual
"block-device" element; we can have multiple elements provide it
(block-device-[gpt,mbr,efi], say) but we only want one of them at a
time.

Update the unit test for this.

Change-Id: I59d4aa5f6f09e2892b213e154befa10d85e95ca3
This commit is contained in:
Ian Wienand 2018-01-31 13:16:57 +11:00
parent 55b479b54f
commit a32a8f1ce1
2 changed files with 19 additions and 2 deletions

View File

@ -151,9 +151,14 @@ def _expand_element_dependencies(user_elements, all_elements):
element_deps = element_obj.depends element_deps = element_obj.depends
element_provides = element_obj.provides element_provides = element_obj.provides
# save which elements provide another element for potential # Check that we are not providing an element which has already
# error message # been provided by someone else, and additionally save which
# elements provide another element
for provide in element_provides: for provide in element_provides:
if provide in provided:
raise AlreadyProvidedException(
"%s: already provided by %s" %
(provide, provided_by[provide]))
provided_by[provide].append(element) provided_by[provide].append(element)
provided.update(element_provides) provided.update(element_provides)
check_queue.extend(element_deps - (final_elements | provided)) check_queue.extend(element_deps - (final_elements | provided))

View File

@ -67,6 +67,10 @@ class TestElementDeps(testtools.TestCase):
'provides_virtual', 'provides_virtual',
[], [],
['virtual']) ['virtual'])
_populate_element(self.element_dir,
'also_provides_virtual',
[],
['virtual'])
_populate_element(self.element_dir, _populate_element(self.element_dir,
'requires_virtual', 'requires_virtual',
['virtual'], ['virtual'],
@ -168,6 +172,14 @@ class TestElementDeps(testtools.TestCase):
[self._e('requires_new_virtual'), [self._e('requires_new_virtual'),
self._e('provides_new_virtual')], result) self._e('provides_new_virtual')], result)
def test_elements_provide_same(self):
msg = "virtual: already provided by \['provides_virtual'\]"
self.assertRaisesRegexp(element_dependencies.AlreadyProvidedException,
msg,
element_dependencies.get_elements,
['provides_virtual', 'also_provides_virtual'],
self.element_dirs)
def test_no_os_element(self): def test_no_os_element(self):
self.assertRaises(element_dependencies.MissingOSException, self.assertRaises(element_dependencies.MissingOSException,
element_dependencies.get_elements, element_dependencies.get_elements,