Merge "Fail if two elements provide the same thing"

This commit is contained in:
Zuul 2018-03-16 08:31:08 +00:00 committed by Gerrit Code Review
commit 45eaace4e3
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_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))

View File

@ -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,