NSX: ensure dhcp port is setup on metadata network

Change in scheduling behavior caused a regression
where the dhcp port is no longer provisioned on
the (admin) metadata network created when a subnet
is uplinked to a router.

This change recovers the past behavior and extend UT
coverage to avoid further regression.

Closes-bug: #1304127

Change-Id: I8420203f68a43368f3784adb0c4cbbe55f048662
This commit is contained in:
armando-migliaccio 2014-04-08 08:43:00 -07:00
parent f6515fb40d
commit aa7a4f297d
2 changed files with 37 additions and 22 deletions

View File

@ -164,6 +164,8 @@ def _create_metadata_access_network(plugin, context, router_id):
meta_net = plugin.create_network(context, meta_net = plugin.create_network(context,
{'network': net_data}) {'network': net_data})
greenthread.sleep(0) # yield greenthread.sleep(0) # yield
plugin.schedule_network(context, meta_net)
greenthread.sleep(0) # yield
# From this point on there will be resources to garbage-collect # From this point on there will be resources to garbage-collect
# in case of failures # in case of failures
meta_sub = None meta_sub = None
@ -187,6 +189,8 @@ def _create_metadata_access_network(plugin, context, router_id):
plugin.add_router_interface(context, router_id, plugin.add_router_interface(context, router_id,
{'subnet_id': meta_sub['id']}) {'subnet_id': meta_sub['id']})
greenthread.sleep(0) # yield greenthread.sleep(0) # yield
# Tell to start the metadata agent proxy, only if we had success
_notify_rpc_agent(context, {'subnet': meta_sub}, 'subnet.create.end')
except (ntn_exc.NeutronException, except (ntn_exc.NeutronException,
nsx_exc.NsxPluginException, nsx_exc.NsxPluginException,
api_exc.NsxApiException): api_exc.NsxApiException):
@ -194,9 +198,6 @@ def _create_metadata_access_network(plugin, context, router_id):
# as it will be removed with the network # as it will be removed with the network
plugin.delete_network(context, meta_net['id']) plugin.delete_network(context, meta_net['id'])
# Tell to start the metadata agent proxy
_notify_rpc_agent(context, {'network': meta_net}, 'network.create.end')
def _destroy_metadata_access_network(plugin, context, router_id, ports): def _destroy_metadata_access_network(plugin, context, router_id, ports):
if not ports: if not ports:

View File

@ -767,6 +767,7 @@ class TestL3NatTestCase(L3NatTest,
def test_metadatata_network_created_with_router_interface_add(self): def test_metadatata_network_created_with_router_interface_add(self):
self._metadata_setup() self._metadata_setup()
with mock.patch.object(self._plugin_class, 'schedule_network') as f:
with self.router() as r: with self.router() as r:
with self.subnet() as s: with self.subnet() as s:
self._router_interface_action('add', self._router_interface_action('add',
@ -786,6 +787,19 @@ class TestL3NatTestCase(L3NatTest,
r['router']['id'], r['router']['id'],
s['subnet']['id'], s['subnet']['id'],
None) None)
# Verify that the metadata network gets scheduled first, so that
# an active dhcp agent can pick it up
expected_meta_net = {
'status': 'ACTIVE',
'subnets': [],
'name': 'meta-%s' % r['router']['id'],
'admin_state_up': True,
'tenant_id': '',
'port_security_enabled': False,
'shared': False,
'id': mock.ANY
}
f.assert_called_once_with(mock.ANY, expected_meta_net)
self._metadata_teardown() self._metadata_teardown()
def test_metadata_network_create_rollback_on_create_subnet_failure(self): def test_metadata_network_create_rollback_on_create_subnet_failure(self):