summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-08-07 10:30:29 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-08-07 10:30:29 -0600
commit8d71b60aa3fc785627b488383c17ef30a3838030 (patch)
treee7e4d69a7c23735a5f9f081843c64538543fb7b6
parent27b8b1c246d63c14f112a99362873fe887c13c10 (diff)
Refactored neutron_utils#get_router_by_name() to get_router()
Added a router_settings (RouterSettings) object parameter in addition to router_name for more robust query options. JIRA: SNAPS-163 Change-Id: I47672f531171d6ee0c90dabb6641640bf97c1d20 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--snaps/openstack/create_instance.py3
-rw-r--r--snaps/openstack/create_router.py4
-rw-r--r--snaps/openstack/tests/create_network_tests.py8
-rw-r--r--snaps/openstack/tests/create_router_tests.py36
-rw-r--r--snaps/openstack/utils/neutron_utils.py25
-rw-r--r--snaps/openstack/utils/tests/neutron_utils_tests.py2
6 files changed, 45 insertions, 33 deletions
diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py
index 2fdff25..b09e879 100644
--- a/snaps/openstack/create_instance.py
+++ b/snaps/openstack/create_instance.py
@@ -187,7 +187,8 @@ class OpenStackVmInstance:
:param router_name: The name of the router to lookup
:return: the external network name or None
"""
- router = neutron_utils.get_router_by_name(self.__neutron, router_name)
+ router = neutron_utils.get_router(
+ self.__neutron, router_name=router_name)
if router and router.external_gateway_info:
network = neutron_utils.get_network_by_id(
self.__neutron,
diff --git a/snaps/openstack/create_router.py b/snaps/openstack/create_router.py
index 877e064..ef27fab 100644
--- a/snaps/openstack/create_router.py
+++ b/snaps/openstack/create_router.py
@@ -64,8 +64,8 @@ class OpenStackRouter:
logger.debug(
'Creating Router with name - ' + self.router_settings.name)
existing = False
- router_inst = neutron_utils.get_router_by_name(
- self.__neutron, self.router_settings.name)
+ router_inst = neutron_utils.get_router(
+ self.__neutron, router_settings=self.router_settings)
if router_inst:
self.__router = router_inst
existing = True
diff --git a/snaps/openstack/tests/create_network_tests.py b/snaps/openstack/tests/create_network_tests.py
index 3a7ab4a..51927dc 100644
--- a/snaps/openstack/tests/create_network_tests.py
+++ b/snaps/openstack/tests/create_network_tests.py
@@ -476,8 +476,8 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase):
self.os_creds, self.net_config.router_settings)
self.router_creator.create()
- retrieved_router = neutron_utils.get_router_by_name(
- self.neutron, self.router_creator.get_router().name)
+ retrieved_router = neutron_utils.get_router(
+ self.neutron, router_settings=self.router_creator.router_settings)
self.assertEqual(
self.router_creator.get_router().id, retrieved_router.id)
@@ -506,8 +506,8 @@ class CreateNetworkSuccessTests(OSIntegrationTestCase):
self.admin_os_creds, self.net_config.router_settings)
self.router_creator.create()
- retrieved_router = neutron_utils.get_router_by_name(
- self.neutron, self.router_creator.get_router().name)
+ retrieved_router = neutron_utils.get_router(
+ self.neutron, router_settings=self.router_creator.router_settings)
self.assertEqual(
self.router_creator.get_router().id, retrieved_router.id)
diff --git a/snaps/openstack/tests/create_router_tests.py b/snaps/openstack/tests/create_router_tests.py
index 6f37445..db3170e 100644
--- a/snaps/openstack/tests/create_router_tests.py
+++ b/snaps/openstack/tests/create_router_tests.py
@@ -162,8 +162,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertIsNotNone(router)
self.assertTrue(verify_router_attributes(
@@ -182,8 +182,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.admin_os_creds, router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertIsNotNone(router)
self.assertTrue(verify_router_attributes(
@@ -202,8 +202,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.os_creds, router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertIsNotNone(router)
self.assertTrue(verify_router_attributes(
@@ -221,14 +221,14 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
self.os_creds, self.router_settings)
created_router = self.router_creator.create()
self.assertIsNotNone(created_router)
- retrieved_router = neutron_utils.get_router_by_name(
- self.neutron, self.router_settings.name)
+ retrieved_router = neutron_utils.get_router(
+ self.neutron, router_settings=self.router_settings)
self.assertIsNotNone(retrieved_router)
neutron_utils.delete_router(self.neutron, created_router)
- retrieved_router = neutron_utils.get_router_by_name(
- self.neutron, self.router_settings.name)
+ retrieved_router = neutron_utils.get_router(
+ self.neutron, router_settings=self.router_settings)
self.assertIsNone(retrieved_router)
# Should not raise an exception
@@ -245,8 +245,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertIsNotNone(router)
self.assertTrue(verify_router_attributes(router, self.router_creator,
@@ -263,8 +263,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertIsNotNone(router)
self.assertTrue(verify_router_attributes(router, self.router_creator,
@@ -321,8 +321,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertTrue(verify_router_attributes(router, self.router_creator))
@@ -364,8 +364,8 @@ class CreateRouterSuccessTests(OSIntegrationTestCase):
router_settings)
self.router_creator.create()
- router = neutron_utils.get_router_by_name(self.neutron,
- router_settings.name)
+ router = neutron_utils.get_router(self.neutron,
+ router_settings=router_settings)
self.assertTrue(verify_router_attributes(
router, self.router_creator, ext_gateway=self.ext_net_name))
diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py
index 4bc1be2..e7b002a 100644
--- a/snaps/openstack/utils/neutron_utils.py
+++ b/snaps/openstack/utils/neutron_utils.py
@@ -218,18 +218,29 @@ def delete_router(neutron, router):
neutron.delete_router(router=router.id)
-def get_router_by_name(neutron, router_name):
+def get_router(neutron, router_settings=None, router_name=None):
"""
- Returns the first router object (dictionary) found with a given name
+ Returns the first router object (dictionary) found the given the settings
+ values if not None, else finds the first with the value of the router_name
+ parameter, else None
:param neutron: the client
+ :param router_settings: the RouterSettings object
:param router_name: the name of the network to retrieve
:return: a SNAPS-OO Router domain object
"""
- routers = neutron.list_routers(**{'name': router_name})
- for router, routerInst in routers.items():
- for inst in routerInst:
- if inst.get('name') == router_name:
- return Router(**inst)
+ router_filter = dict()
+ if router_settings:
+ router_filter['name'] = router_settings.name
+ if router_settings.admin_state_up is not None:
+ router_filter['admin_state_up'] = router_settings.admin_state_up
+ elif router_name:
+ router_filter['name'] = router_name
+ else:
+ return None
+
+ routers = neutron.list_routers(**router_filter)
+ for routerInst in routers['routers']:
+ return Router(**routerInst)
return None
diff --git a/snaps/openstack/utils/tests/neutron_utils_tests.py b/snaps/openstack/utils/tests/neutron_utils_tests.py
index 6929c4b..f6fc2bb 100644
--- a/snaps/openstack/utils/tests/neutron_utils_tests.py
+++ b/snaps/openstack/utils/tests/neutron_utils_tests.py
@@ -828,7 +828,7 @@ def validate_router(neutron, name, exists):
:param exists: Whether or not the network name should exist or not
:return: True/False
"""
- router = neutron_utils.get_router_by_name(neutron, name)
+ router = neutron_utils.get_router(neutron, router_name=name)
if exists and router:
return True
return False