New API to get the firewall section of a router

Change-Id: I327f0a0f3e6751297afbca1bbeba86da1e9ec0cf
This commit is contained in:
Adit Sarfaty 2017-05-21 13:32:55 +03:00
parent 741e9fb0b1
commit c9c0bf02d9
3 changed files with 33 additions and 2 deletions

View File

@ -106,11 +106,17 @@ FAKE_CONTAINER_PORT = {
FAKE_ROUTER_UUID = uuidutils.generate_uuid()
FAKE_ROUTER_FW_SEC_UUID = uuidutils.generate_uuid()
FAKE_ROUTER = {
"resource_type": "LogicalRouter",
"revision": 0,
"id": FAKE_ROUTER_UUID,
"display_name": FAKE_NAME
"display_name": FAKE_NAME,
"firewall_sections": [{
"is_valid": True,
"target_type": "FirewallSection",
"target_id": FAKE_ROUTER_FW_SEC_UUID
}],
}
FAKE_ROUTER_PORT_UUID = uuidutils.generate_uuid()

View File

@ -23,6 +23,7 @@ from vmware_nsxlib.tests.unit.v3 import mocks
from vmware_nsxlib.tests.unit.v3 import nsxlib_testcase
from vmware_nsxlib.tests.unit.v3 import test_client
from vmware_nsxlib.tests.unit.v3 import test_constants
from vmware_nsxlib.v3 import core_resources
from vmware_nsxlib.v3 import exceptions
from vmware_nsxlib.v3 import nsx_constants
from vmware_nsxlib.v3 import resources
@ -434,7 +435,8 @@ class LogicalRouterTestCase(nsxlib_testcase.NsxClientTestCase):
def _mocked_lrouter(self, session_response=None):
return self.mocked_resource(
resources.LogicalRouter, session_response=session_response)
core_resources.NsxLibLogicalRouter,
session_response=session_response)
def test_create_logical_router(self):
"""Test creating a router returns the correct response and 201 status.
@ -479,6 +481,14 @@ class LogicalRouterTestCase(nsxlib_testcase.NsxClientTestCase):
'delete', router,
'https://1.2.3.4/api/v1/logical-routers/%s?force=True' % uuid)
def test_get_logical_router_fw_section(self):
fake_router = test_constants.FAKE_ROUTER.copy()
router = self._mocked_lrouter()
section_id = router.get_firewall_section_id(
test_constants.FAKE_ROUTER_UUID, router_body=fake_router)
self.assertEqual(test_constants.FAKE_ROUTER_FW_SEC_UUID, section_id)
class LogicalRouterPortTestCase(nsxlib_testcase.NsxClientTestCase):

View File

@ -515,6 +515,21 @@ class NsxLibLogicalRouter(utils.NsxLibApiBase):
return _do_update()
def get_firewall_section_id(self, lrouter_id, router_body=None):
"""Return the id of the auto created firewall section of the router
If the router was already retrieved from the backend it is possible
to give it as an input to avoid another backend call.
"""
if not router_body:
router_body = self.get(lrouter_id)
if 'firewall_sections' in router_body:
firewall_sections = router_body['firewall_sections']
for sec in firewall_sections:
if (sec.get('is_valid') and
sec.get('target_type') == "FirewallSection"):
return firewall_sections[0].get('target_id')
class NsxLibEdgeCluster(utils.NsxLibApiBase):