Merge "Nsxv: Fix db out of sync with backend"

This commit is contained in:
Jenkins 2015-08-28 16:01:22 +00:00 committed by Gerrit Code Review
commit 6067b28d7d
3 changed files with 45 additions and 14 deletions

View File

@ -1344,13 +1344,18 @@ class NsxVPluginV2(agents_db.AgentDbMixin,
with context.session.begin(subtransactions=True): with context.session.begin(subtransactions=True):
router_db = self._get_router(context, lrouter['id']) router_db = self._get_router(context, lrouter['id'])
self._process_nsx_router_create(context, router_db, r) self._process_nsx_router_create(context, router_db, r)
router_driver = self._get_router_driver(context, router_db) try:
router_driver.create_router( router_driver = self._get_router_driver(context, router_db)
context, lrouter, router_driver.create_router(
allow_metadata=(allow_metadata and self.metadata_proxy_handler)) context, lrouter,
if gw_info != attr.ATTR_NOT_SPECIFIED: allow_metadata=(allow_metadata and
router_driver._update_router_gw_info( self.metadata_proxy_handler))
context, lrouter['id'], gw_info) if gw_info != attr.ATTR_NOT_SPECIFIED:
router_driver._update_router_gw_info(
context, lrouter['id'], gw_info)
except Exception:
with excutils.save_and_reraise_exception():
self.delete_router(context, lrouter['id'])
return self.get_router(context, lrouter['id']) return self.get_router(context, lrouter['id'])
def update_router(self, context, router_id, router): def update_router(self, context, router_id, router):
@ -1382,8 +1387,8 @@ class NsxVPluginV2(agents_db.AgentDbMixin,
def delete_router(self, context, id): def delete_router(self, context, id):
self._check_router_in_use(context, id) self._check_router_in_use(context, id)
router_driver = self._find_router_driver(context, id) router_driver = self._find_router_driver(context, id)
router_driver.delete_router(context, id)
super(NsxVPluginV2, self).delete_router(context, id) super(NsxVPluginV2, self).delete_router(context, id)
router_driver.delete_router(context, id)
def get_router(self, context, id, fields=None): def get_router(self, context, id, fields=None):
router = super(NsxVPluginV2, self).get_router(context, id, fields) router = super(NsxVPluginV2, self).get_router(context, id, fields)

View File

@ -62,12 +62,10 @@ class RouterExclusiveDriver(router_driver.RouterBaseDriver):
return self.plugin.get_router(context, router_id) return self.plugin.get_router(context, router_id)
def delete_router(self, context, router_id): def delete_router(self, context, router_id):
with locking.LockManager.get_lock( self.edge_manager.delete_lrouter(context, router_id, dist=False)
self._get_router_edge_id(context, router_id), external=True): if self.plugin.metadata_proxy_handler:
self.edge_manager.delete_lrouter(context, router_id, dist=False) self.plugin.metadata_proxy_handler.cleanup_router_edge(
if self.plugin.metadata_proxy_handler: router_id)
self.plugin.metadata_proxy_handler.cleanup_router_edge(
router_id)
def update_routes(self, context, router_id, nexthop): def update_routes(self, context, router_id, nexthop):
with locking.LockManager.get_lock( with locking.LockManager.get_lock(

View File

@ -1527,6 +1527,20 @@ class TestExclusiveRouterTestCase(L3NatTest, L3NatTestCaseBase,
for k, v in expected: for k, v in expected:
self.assertEqual(net['network'][k], v) self.assertEqual(net['network'][k], v)
def test_create_router_fail_at_the_backend(self):
p = manager.NeutronManager.get_plugin()
edge_manager = p.edge_manager
with mock.patch.object(edge_manager, 'create_lrouter',
side_effect=[n_exc.NeutronException]):
router = {'router': {'admin_state_up': True,
'name': 'e161be1d-0d0d-4046-9823-5a593d94f72c',
'router_type': 'exclusive'}}
self.assertRaises(n_exc.NeutronException,
p.create_router,
context.get_admin_context(),
router)
self._test_list_resources('router', ())
def test_create_l3_ext_network_with_dhcp(self): def test_create_l3_ext_network_with_dhcp(self):
with self._create_l3_ext_network() as net: with self._create_l3_ext_network() as net:
with testlib_api.ExpectedException( with testlib_api.ExpectedException(
@ -1976,6 +1990,20 @@ class TestVdrTestCase(L3NatTest, L3NatTestCaseBase,
test_l3_plugin.L3NatDBIntTestCase, test_l3_plugin.L3NatDBIntTestCase,
NsxVPluginV2TestCase): NsxVPluginV2TestCase):
def test_create_router_fail_at_the_backend(self):
p = manager.NeutronManager.get_plugin()
edge_manager = p.edge_manager
with mock.patch.object(edge_manager, 'create_lrouter',
side_effect=[n_exc.NeutronException]):
router = {'router': {'admin_state_up': True,
'name': 'e161be1d-0d0d-4046-9823-5a593d94f72c',
'distributed': True}}
self.assertRaises(n_exc.NeutronException,
p.create_router,
context.get_admin_context(),
router)
self._test_list_resources('router', ())
def test_update_port_device_id_to_different_tenants_router(self): def test_update_port_device_id_to_different_tenants_router(self):
self.skipTest('TBD') self.skipTest('TBD')