Browse Source

Clean up tier0 link port if failed to create peer tier1 link port

When creating a pair of link ports for a t1 router, if failed to
create the tier1 link port, we need to cleanup the already-created
peer tier0 link port to avoid leaving any orphaned link port.

Change-Id: Ice7c25d362b54024634f311c2df1465089bad1b4
(cherry picked from commit 5b29902ae9)
tags/16.0.5
Shih-Hao Li 1 month ago
parent
commit
2c83c7ea22
2 changed files with 32 additions and 6 deletions
  1. +18
    -0
      vmware_nsxlib/tests/unit/v3/test_router.py
  2. +14
    -6
      vmware_nsxlib/v3/router.py

+ 18
- 0
vmware_nsxlib/tests/unit/v3/test_router.py View File

@@ -84,6 +84,24 @@ class TestRouter(nsxlib_testcase.NsxClientTestCase):
tier1_uuid, tier0_uuid, tags))
self.assertEqual(port_create.call_count, 2)

def test_add_router_link_port_fail(self):
tags = [{'scope': 'a', 'tag': 'b'}]
tier0_uuid = uuidutils.generate_uuid()
tier1_uuid = uuidutils.generate_uuid()
tier0_link_port_id = uuidutils.generate_uuid()
with mock.patch.object(self.nsxlib.router._router_port_client,
'create') as port_create,\
mock.patch.object(self.nsxlib.router._router_port_client,
'delete') as port_delete:
tier0_link_port = {'id': tier0_link_port_id}
port_create.side_effect = [tier0_link_port,
nsxlib_exc.ManagerError]
self.assertRaises(
nsxlib_exc.ManagerError,
self.nsxlib.router.add_router_link_port,
tier1_uuid, tier0_uuid, tags)
port_delete.assert_called_once_with(tier0_link_port_id)

def test_remove_router_link_port(self):
tier1_uuid = uuidutils.generate_uuid()
with mock.patch.object(


+ 14
- 6
vmware_nsxlib/v3/router.py View File

@@ -94,12 +94,20 @@ class RouterLib(object):
# Create Tier1 logical router link port
t1_tags = copy.copy(tags)
t1_tags = utils.add_v3_tag(t1_tags, 'os-tier1-uuid', tier1_uuid)
tier1_link_port = self._router_port_client.create(
tier1_uuid, display_name=TIER1_ROUTER_LINK_PORT_NAME, tags=t1_tags,
resource_type=nsx_constants.LROUTERPORT_LINKONTIER1,
logical_port_id=linked_logical_port_id,
address_groups=None)
return tier0_link_port, tier1_link_port
try:
tier1_link_port = self._router_port_client.create(
tier1_uuid, display_name=TIER1_ROUTER_LINK_PORT_NAME,
tags=t1_tags,
resource_type=nsx_constants.LROUTERPORT_LINKONTIER1,
logical_port_id=linked_logical_port_id,
address_groups=None)
return tier0_link_port, tier1_link_port
except Exception as e:
LOG.warning("Failed to create tier1 link port for tier1 router "
"%s, deleting peer tier0 link port %s: %s",
tier1_uuid, linked_logical_port_id, e)
self._router_port_client.delete(linked_logical_port_id)
raise e

def remove_router_link_port(self, tier1_uuid, tier0_uuid=None):
# Note(asarfaty): tier0_uuid is not used by this method and can


Loading…
Cancel
Save