Merge "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"

This commit is contained in:
Jenkins 2016-06-01 05:36:10 +00:00 committed by Gerrit Code Review
commit c564254f33
3 changed files with 46 additions and 1 deletions

View File

@ -2323,7 +2323,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.
@ -2340,6 +2340,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.
@ -2347,6 +2348,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(

View File

@ -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):

View File

@ -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."""