NSX|V3 reuse code for re-initializing the AZs in the unit tests

Change-Id: Icc2503b0d24ed6ed13f39b9f3f04288377a0ff3d
This commit is contained in:
Adit Sarfaty 2018-12-31 11:52:32 +02:00
parent 5b95817834
commit 2a75de0bc8
2 changed files with 8 additions and 10 deletions

View File

@ -75,8 +75,7 @@ class NsxNativeDhcpTestCase(test_plugin.NsxV3PluginTestCaseMixin):
self._patcher.start() self._patcher.start()
# Need to run some plugin init methods manually because plugin was # Need to run some plugin init methods manually because plugin was
# started before setUp() overrides CONF.nsx_v3.native_dhcp_metadata. # started before setUp() overrides CONF.nsx_v3.native_dhcp_metadata.
self.plugin.init_availability_zones() self._initialize_azs()
self.plugin._translate_configured_names_to_uuids()
self.plugin._init_dhcp_metadata() self.plugin._init_dhcp_metadata()
def tearDown(self): def tearDown(self):
@ -925,8 +924,7 @@ class NsxNativeMetadataTestCase(test_plugin.NsxV3PluginTestCaseMixin):
self._patcher = mock.patch.object(core_resources.NsxLibMetadataProxy, self._patcher = mock.patch.object(core_resources.NsxLibMetadataProxy,
'get') 'get')
self._patcher.start() self._patcher.start()
self.plugin.init_availability_zones() self._initialize_azs()
self.plugin._translate_configured_names_to_uuids()
self.plugin._init_dhcp_metadata() self.plugin._init_dhcp_metadata()
def tearDown(self): def tearDown(self):

View File

@ -283,6 +283,10 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase,
with ctx.session.begin(subtransactions=True): with ctx.session.begin(subtransactions=True):
ctx.session.add(models_v2.Network(id=network_id)) ctx.session.add(models_v2.Network(id=network_id))
def _initialize_azs(self):
self.plugin.init_availability_zones()
self.plugin._translate_configured_names_to_uuids()
def _enable_dhcp_relay(self): def _enable_dhcp_relay(self):
# Add the relay service to the config and availability zones # Add the relay service to the config and availability zones
cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3') cfg.CONF.set_override('native_dhcp_metadata', True, 'nsx_v3')
@ -291,9 +295,7 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase,
mock_nsx_version = mock.patch.object( mock_nsx_version = mock.patch.object(
self.plugin.nsxlib, 'feature_supported', return_value=True) self.plugin.nsxlib, 'feature_supported', return_value=True)
mock_nsx_version.start() mock_nsx_version.start()
self.plugin.init_availability_zones() self._initialize_azs()
for az in self.plugin.get_azs_list():
az.translate_configured_names_to_uuids(self.plugin.nsxlib)
class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin): class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
@ -3012,6 +3014,7 @@ class TestL3NatTestCase(L3NatTest,
"get_id_by_name_or_id", "get_id_by_name_or_id",
return_value=edge_cluster).start() return_value=edge_cluster).start()
cfg.CONF.set_override('edge_cluster', edge_cluster, 'nsx_v3') cfg.CONF.set_override('edge_cluster', edge_cluster, 'nsx_v3')
self._initialize_azs()
with self.address_scope(name='as1') as addr_scope, \ with self.address_scope(name='as1') as addr_scope, \
self._create_l3_ext_network() as ext_net: self._create_l3_ext_network() as ext_net:
ext_subnet = self._prepare_external_subnet_on_address_scope( ext_subnet = self._prepare_external_subnet_on_address_scope(
@ -3021,9 +3024,6 @@ class TestL3NatTestCase(L3NatTest,
with self.router() as r, \ with self.router() as r, \
self._mock_add_remove_service_router() as change_sr: self._mock_add_remove_service_router() as change_sr:
router_id = r['router']['id'] router_id = r['router']['id']
self.plugin.init_availability_zones()
for az in self.plugin.get_azs_list():
az.translate_configured_names_to_uuids(self.plugin.nsxlib)
self._add_external_gateway_to_router( self._add_external_gateway_to_router(
router_id, ext_subnet['network_id']) router_id, ext_subnet['network_id'])
change_sr.assert_called_once_with(mock.ANY, edge_cluster) change_sr.assert_called_once_with(mock.ANY, edge_cluster)