From c56d8e0f3858304f09469ebf8c728966ed0e810c Mon Sep 17 00:00:00 2001 From: mariojmdavid Date: Mon, 16 May 2016 17:42:53 +0100 Subject: [PATCH] incorporate unit test in test_shade.py, remove test_router.py fix tenant_id in router add functional test test_create_router_project to functional/test_router.py add unit/test_router.py add project_id to create_router Change-Id: Ie6775a99a84aa32b7b93bd399856972b7212d5c0 --- shade/openstackcloud.py | 5 ++++- shade/tests/functional/test_router.py | 29 +++++++++++++++++++++++++++ shade/tests/unit/test_shade.py | 13 ++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 24fc10653..8aed13dc6 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -2314,7 +2314,7 @@ class OpenStackCloud(object): def create_router(self, name=None, admin_state_up=True, ext_gateway_net_id=None, enable_snat=None, - ext_fixed_ips=None): + ext_fixed_ips=None, project_id=None): """Create a logical router. :param string name: The router name. @@ -2331,6 +2331,7 @@ class OpenStackCloud(object): "ip_address": "192.168.10.2" } ] + :param string project_id: Project ID for the router. :returns: The router object. :raises: OpenStackCloudException on operation error. @@ -2338,6 +2339,8 @@ class OpenStackCloud(object): router = { 'admin_state_up': admin_state_up } + if project_id is not None: + router['tenant_id'] = project_id if name: router['name'] = name ext_gw_info = self._build_external_gateway_info( diff --git a/shade/tests/functional/test_router.py b/shade/tests/functional/test_router.py index 49aad9a74..986650744 100644 --- a/shade/tests/functional/test_router.py +++ b/shade/tests/functional/test_router.py @@ -111,6 +111,35 @@ class TestRouter(base.BaseFunctionalTestCase): self.assertEqual(net1['id'], ext_gw_info['network_id']) self.assertTrue(ext_gw_info['enable_snat']) + def test_create_router_project(self): + project = self.operator_cloud.get_project('demo') + self.assertIsNotNone(project) + proj_id = project['id'] + net1_name = self.network_prefix + '_net1' + net1 = self.operator_cloud.create_network( + name=net1_name, external=True, project_id=proj_id) + + router_name = self.router_prefix + '_create_project' + router = self.operator_cloud.create_router( + name=router_name, + admin_state_up=True, + ext_gateway_net_id=net1['id'], + project_id=proj_id + ) + + for field in EXPECTED_TOPLEVEL_FIELDS: + self.assertIn(field, router) + + ext_gw_info = router['external_gateway_info'] + for field in EXPECTED_GW_INFO_FIELDS: + self.assertIn(field, ext_gw_info) + + self.assertEqual(router_name, router['name']) + self.assertEqual('ACTIVE', router['status']) + self.assertEqual(proj_id, router['tenant_id']) + self.assertEqual(net1['id'], ext_gw_info['network_id']) + self.assertTrue(ext_gw_info['enable_snat']) + def _create_and_verify_advanced_router(self, external_cidr, external_gateway_ip=None): diff --git a/shade/tests/unit/test_shade.py b/shade/tests/unit/test_shade.py index 114219cb4..54bceac47 100644 --- a/shade/tests/unit/test_shade.py +++ b/shade/tests/unit/test_shade.py @@ -156,6 +156,19 @@ class TestShade(base.TestCase): self.cloud.create_router(name='goofy', admin_state_up=True) self.assertTrue(mock_client.create_router.called) + @mock.patch.object(shade.OpenStackCloud, 'neutron_client') + def test_create_router_specific_tenant(self, mock_client): + self.cloud.create_router("goofy", project_id="project_id_value") + mock_client.create_router.assert_called_once_with( + body=dict( + router=dict( + name='goofy', + admin_state_up=True, + tenant_id="project_id_value", + ) + ) + ) + @mock.patch.object(shade.OpenStackCloud, 'neutron_client') def test_create_router_with_enable_snat_True(self, mock_client): """Do not send enable_snat when same as neutron default."""