[04/xx] Dispatcher to hold apps by name
Dispatcher loads apps using stevedore, and the order of apps is not guaranteed. Some of our tests access the app objects. In case there's only a single app loaded, it can be found easily, but if several apps are present, finding app by index is more complex. This patch changes dispatcher to hold apps in a dictionary where each apps can be reached by name. Change-Id: I97da830630ef838be3e9433080b389ce89194cc8
This commit is contained in:
parent
1463eb22f2
commit
4ef8522cba
@ -22,7 +22,7 @@ class AppDispatcher(object):
|
||||
|
||||
def __init__(self, app_list):
|
||||
self.apps_list = app_list
|
||||
self.apps = []
|
||||
self.apps = {}
|
||||
|
||||
def load(self, *args, **kwargs):
|
||||
mgr = stevedore.NamedExtensionManager(
|
||||
@ -34,11 +34,11 @@ class AppDispatcher(object):
|
||||
)
|
||||
|
||||
for ext in mgr:
|
||||
self.apps.append(ext.obj)
|
||||
self.apps[ext.name] = ext.obj
|
||||
|
||||
def dispatch(self, method, *args, **kwargs):
|
||||
errors = []
|
||||
for app in self.apps:
|
||||
for app in self.apps.values():
|
||||
handler = getattr(app, method, None)
|
||||
if handler is not None:
|
||||
try:
|
||||
|
@ -29,7 +29,7 @@ class TestChassisSNATApp(test_app_base.DFAppTestBase):
|
||||
self.external_host_ip,
|
||||
group='df')
|
||||
super(TestChassisSNATApp, self).setUp()
|
||||
self.SNAT_app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.SNAT_app = self.open_flow_app.dispatcher.apps['chassis_snat']
|
||||
self.SNAT_app.external_ofport = 99
|
||||
|
||||
def test_switch_features_handler(self):
|
||||
|
@ -47,7 +47,7 @@ class TestClassifierAppForVlan(testscenarios.WithScenarios,
|
||||
topic='fake_tenant1', unique_key=2,
|
||||
name='private')
|
||||
self.controller.update(fake_vlan_switch1)
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['classifier']
|
||||
|
||||
def test_classifier_for_vlan_port(self):
|
||||
fake_local_vlan_port = make_fake_local_port(
|
||||
|
@ -40,7 +40,7 @@ class TestDHCPApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDHCPApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['dhcp']
|
||||
|
||||
def test_host_route_include_metadata_route(self):
|
||||
cfg.CONF.set_override('df_add_link_local_route', True,
|
||||
|
@ -35,9 +35,11 @@ class TestAppDispatcher(tests_base.BaseTestCase):
|
||||
def test_dispatch_with_exception(self):
|
||||
fake_app = mock.MagicMock()
|
||||
capture_e = None
|
||||
self.dispatcher.apps = [FakeAppWithException('fake1'),
|
||||
FakeAppWithException('fake2'),
|
||||
fake_app]
|
||||
self.dispatcher.apps = {
|
||||
'fake1': FakeAppWithException('fake1'),
|
||||
'fake2': FakeAppWithException('fake2'),
|
||||
'fake3': fake_app,
|
||||
}
|
||||
try:
|
||||
self.dispatcher.dispatch('fake_handler')
|
||||
except exceptions.DFMultipleExceptions as e:
|
||||
|
@ -49,7 +49,7 @@ class TestDNATApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestDNATApp, self).setUp(enable_selective_topo_dist=True)
|
||||
self.dnat_app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.dnat_app = self.open_flow_app.dispatcher.apps['dnat']
|
||||
self.dnat_app.external_ofport = 99
|
||||
|
||||
def test_external_bridge_online(self):
|
||||
|
@ -140,7 +140,7 @@ class TestFcApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestFcApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['fc']
|
||||
for attribute in ('_install_flow_classifier',
|
||||
'_uninstall_flow_classifier',
|
||||
'_install_classification_flows',
|
||||
|
@ -36,7 +36,7 @@ class TestL2App(test_app_base.DFAppTestBase):
|
||||
is_external=False,
|
||||
name='private')
|
||||
self.controller.update(fake_local_switch1)
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['l2']
|
||||
|
||||
def test_multicast_local_port(self):
|
||||
fake_local_port1 = test_app_base.make_fake_local_port(
|
||||
|
@ -27,7 +27,7 @@ class TestL3App(test_app_base.DFAppTestBase,
|
||||
|
||||
def setUp(self):
|
||||
super(TestL3App, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['l3_reactive']
|
||||
self.app.mod_flow = mock.Mock()
|
||||
self.router = copy.deepcopy(test_app_base.fake_logic_router1)
|
||||
|
||||
|
@ -28,7 +28,7 @@ class TestL3ProactiveApp(test_app_base.DFAppTestBase,
|
||||
|
||||
def setUp(self):
|
||||
super(TestL3ProactiveApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['l3_proactive']
|
||||
self.app.mod_flow = mock.Mock()
|
||||
self.router = copy.deepcopy(test_app_base.fake_logic_router1)
|
||||
|
||||
|
@ -24,7 +24,7 @@ class TestLegacySNatApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLegacySNatApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['legacy_snat']
|
||||
mock.patch.object(self.app, '_add_router_port',
|
||||
side_effect=self.app._add_router_port).start()
|
||||
mock.patch.object(self.app, '_delete_router_port',
|
||||
|
@ -29,7 +29,7 @@ class TestMetadataServiceApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMetadataServiceApp, self).setUp()
|
||||
self.meta_app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.meta_app = self.open_flow_app.dispatcher.apps['metadata_service']
|
||||
|
||||
def test_metadata_interface_online(self):
|
||||
with mock.patch.object(self.meta_app,
|
||||
|
@ -39,7 +39,7 @@ class TestProviderNetsApp(test_app_base.DFAppTestBase):
|
||||
segmentation_id=10,
|
||||
name='private')
|
||||
self.controller.update(fake_vlan_switch1)
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['provider']
|
||||
self.app.ofproto.OFPVID_PRESENT = 0x1000
|
||||
|
||||
def test_provider_vlan_port(self):
|
||||
|
@ -43,7 +43,7 @@ class TestRyuDFAdapter(tests_base.BaseTestCase):
|
||||
])
|
||||
|
||||
def dispatcher_load(*args, **kwargs):
|
||||
self.ryu_df_adapter.dispatcher.apps = [self.mock_app]
|
||||
self.ryu_df_adapter.dispatcher.apps = {'mock': self.mock_app}
|
||||
self.ryu_df_adapter.dispatcher.load = dispatcher_load
|
||||
self.ryu_df_adapter.load()
|
||||
|
||||
|
@ -185,7 +185,7 @@ class TestSfcApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSfcApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['sfc']
|
||||
self.app._install_flow_classifier_flows = mock.Mock()
|
||||
self.app._uninstall_flow_classifier_flows = mock.Mock()
|
||||
self.app._install_flow_classifier_local_port_flows = mock.Mock()
|
||||
|
@ -31,7 +31,7 @@ class TestSGApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSGApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['sg']
|
||||
self.mock_mod_flow = self.app.mod_flow
|
||||
self.security_group = test_app_base.fake_security_group
|
||||
self.fake_local_lport = test_app_base.fake_local_port1
|
||||
|
@ -45,7 +45,7 @@ class TestTrunkApp(test_app_base.DFAppTestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTrunkApp, self).setUp()
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['trunk']
|
||||
self.mock_mod_flow = self.app.mod_flow
|
||||
self.db_store = db_store.get_instance()
|
||||
self.app.ofproto.OFPVID_PRESENT = 0x1000
|
||||
|
@ -38,7 +38,7 @@ class TestTunnelingApp(test_app_base.DFAppTestBase):
|
||||
network_type='gre',
|
||||
id='fake_gre_switch1')
|
||||
self.controller.update(fake_gre_switch1)
|
||||
self.app = self.open_flow_app.dispatcher.apps[0]
|
||||
self.app = self.open_flow_app.dispatcher.apps['tunneling']
|
||||
|
||||
def test_tunneling_for_local_port(self):
|
||||
fake_local_gre_port1 = make_fake_local_port(
|
||||
|
Loading…
Reference in New Issue
Block a user