diff --git a/diskimage_builder/element_dependencies.py b/diskimage_builder/element_dependencies.py index 6ee85163..c11e8649 100644 --- a/diskimage_builder/element_dependencies.py +++ b/diskimage_builder/element_dependencies.py @@ -151,9 +151,14 @@ def _expand_element_dependencies(user_elements, all_elements): element_deps = element_obj.depends element_provides = element_obj.provides - # save which elements provide another element for potential - # error message + # Check that we are not providing an element which has already + # been provided by someone else, and additionally save which + # elements provide another element 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.update(element_provides) check_queue.extend(element_deps - (final_elements | provided)) diff --git a/diskimage_builder/tests/test_elementdeps.py b/diskimage_builder/tests/test_elementdeps.py index 299ddfe8..b4c8fc37 100644 --- a/diskimage_builder/tests/test_elementdeps.py +++ b/diskimage_builder/tests/test_elementdeps.py @@ -67,6 +67,10 @@ class TestElementDeps(testtools.TestCase): 'provides_virtual', [], ['virtual']) + _populate_element(self.element_dir, + 'also_provides_virtual', + [], + ['virtual']) _populate_element(self.element_dir, 'requires_virtual', ['virtual'], @@ -168,6 +172,14 @@ class TestElementDeps(testtools.TestCase): [self._e('requires_new_virtual'), 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): self.assertRaises(element_dependencies.MissingOSException, element_dependencies.get_elements,