Fix NamedExtensionManager fails when loading failing extension in order
NamedExtensionManager refer to extensions by names passed by caller. A keyError is raised when name_order=True and can't load all extensions. Closes-Bug: #1575185 Change-Id: I79769d4296efe98727751adc19bb8f33d75ba729
This commit is contained in:
parent
e3d08cede9
commit
1218ab61a1
@ -62,13 +62,13 @@ class NamedExtensionManager(ExtensionManager):
|
||||
invoke_args,
|
||||
invoke_kwds,
|
||||
verify_requirements)
|
||||
missing_entrypoints = set(names) - set([e.name for e in extensions])
|
||||
if missing_entrypoints:
|
||||
self._missing_names = set(names) - set([e.name for e in extensions])
|
||||
if self._missing_names:
|
||||
if on_missing_entrypoints_callback:
|
||||
on_missing_entrypoints_callback(missing_entrypoints)
|
||||
on_missing_entrypoints_callback(self._missing_names)
|
||||
else:
|
||||
LOG.warning('Could not load %s' %
|
||||
', '.join(missing_entrypoints))
|
||||
', '.join(self._missing_names))
|
||||
self._init_plugins(extensions)
|
||||
|
||||
@classmethod
|
||||
@ -119,13 +119,15 @@ class NamedExtensionManager(ExtensionManager):
|
||||
on_load_failure_callback=on_load_failure_callback)
|
||||
|
||||
self._names = names
|
||||
self._missing_names = set()
|
||||
self._name_order = name_order
|
||||
|
||||
def _init_plugins(self, extensions):
|
||||
super(NamedExtensionManager, self)._init_plugins(extensions)
|
||||
|
||||
if self._name_order:
|
||||
self.extensions = [self[n] for n in self._names]
|
||||
self.extensions = [self[n] for n in self._names
|
||||
if n not in self._missing_names]
|
||||
|
||||
def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds,
|
||||
verify_requirements):
|
||||
|
@ -56,3 +56,26 @@ class TestNamed(utils.TestCase):
|
||||
)
|
||||
actual = em.names()
|
||||
self.assertEqual(actual, ['t2', 't1'])
|
||||
|
||||
def test_load_fail_ignored_when_sorted(self):
|
||||
em = named.NamedExtensionManager(
|
||||
'stevedore.test.extension',
|
||||
names=['e1', 't2', 'e2', 't1'],
|
||||
name_order=True,
|
||||
invoke_on_load=True,
|
||||
invoke_args=('a',),
|
||||
invoke_kwds={'b': 'B'},
|
||||
)
|
||||
actual = em.names()
|
||||
self.assertEqual(['t2', 't1'], actual)
|
||||
|
||||
em = named.NamedExtensionManager(
|
||||
'stevedore.test.extension',
|
||||
names=['e1', 't1'],
|
||||
name_order=False,
|
||||
invoke_on_load=True,
|
||||
invoke_args=('a',),
|
||||
invoke_kwds={'b': 'B'},
|
||||
)
|
||||
actual = em.names()
|
||||
self.assertEqual(['t1'], actual)
|
||||
|
Loading…
Reference in New Issue
Block a user