Add unit tests for configurable network resources
This commit adds additional tenant isolation unit tests that cover
configuring which network resources are required for an isolated
tenant. In addition to testing network resource creation for the admin
and alt tenants.
Partially implements bp unit-tests
Change-Id: I8cbe836f9a2357f53bbbaeefd2b4ec74553089fb
diff --git a/tempest/tests/test_tenant_isolation.py b/tempest/tests/test_tenant_isolation.py
index 2e50cfd..ae2e57d 100644
--- a/tempest/tests/test_tenant_isolation.py
+++ b/tempest/tests/test_tenant_isolation.py
@@ -19,6 +19,7 @@
from tempest.common import isolated_creds
from tempest import config
+from tempest import exceptions
from tempest.openstack.common.fixture import mockpatch
from tempest.services.identity.json import identity_client as json_iden_client
from tempest.services.identity.xml import identity_client as xml_iden_client
@@ -334,3 +335,140 @@
self.assertIn('1234', args)
self.assertIn('12345', args)
self.assertIn('123456', args)
+
+ @patch('tempest.common.rest_client.RestClient')
+ def test_network_alt_creation(self, MockRestClient):
+ iso_creds = isolated_creds.IsolatedCreds('test class',
+ password='fake_password')
+ self._mock_user_create('1234', 'fake_alt_user')
+ self._mock_tenant_create('1234', 'fake_alt_tenant')
+ self._mock_network_create(iso_creds, '1234', 'fake_alt_net')
+ self._mock_subnet_create(iso_creds, '1234', 'fake_alt_subnet')
+ self._mock_router_create('1234', 'fake_alt_router')
+ router_interface_mock = self.patch(
+ 'tempest.services.network.json.network_client.NetworkClientJSON.'
+ 'add_router_interface_with_subnet_id')
+ username, tenant_name, password = iso_creds.get_alt_creds()
+ router_interface_mock.called_once_with('1234', '1234')
+ network = iso_creds.get_alt_network()
+ subnet = iso_creds.get_alt_subnet()
+ router = iso_creds.get_alt_router()
+ self.assertEqual(network['id'], '1234')
+ self.assertEqual(network['name'], 'fake_alt_net')
+ self.assertEqual(subnet['id'], '1234')
+ self.assertEqual(subnet['name'], 'fake_alt_subnet')
+ self.assertEqual(router['id'], '1234')
+ self.assertEqual(router['name'], 'fake_alt_router')
+
+ @patch('tempest.common.rest_client.RestClient')
+ def test_network_admin_creation(self, MockRestClient):
+ iso_creds = isolated_creds.IsolatedCreds('test class',
+ password='fake_password')
+ self._mock_user_create('1234', 'fake_admin_user')
+ self._mock_tenant_create('1234', 'fake_admin_tenant')
+ self._mock_network_create(iso_creds, '1234', 'fake_admin_net')
+ self._mock_subnet_create(iso_creds, '1234', 'fake_admin_subnet')
+ self._mock_router_create('1234', 'fake_admin_router')
+ router_interface_mock = self.patch(
+ 'tempest.services.network.json.network_client.NetworkClientJSON.'
+ 'add_router_interface_with_subnet_id')
+ self.useFixture(mockpatch.PatchObject(
+ json_iden_client.IdentityClientJSON,
+ 'list_roles',
+ return_value=({'status': 200},
+ [{'id': '123456', 'name': 'admin'}])))
+ with patch.object(json_iden_client.IdentityClientJSON,
+ 'assign_user_role'):
+ username, tenant_name, password = iso_creds.get_admin_creds()
+ router_interface_mock.called_once_with('1234', '1234')
+ network = iso_creds.get_admin_network()
+ subnet = iso_creds.get_admin_subnet()
+ router = iso_creds.get_admin_router()
+ self.assertEqual(network['id'], '1234')
+ self.assertEqual(network['name'], 'fake_admin_net')
+ self.assertEqual(subnet['id'], '1234')
+ self.assertEqual(subnet['name'], 'fake_admin_subnet')
+ self.assertEqual(router['id'], '1234')
+ self.assertEqual(router['name'], 'fake_admin_router')
+
+ @patch('tempest.common.rest_client.RestClient')
+ def test_no_network_resources(self, MockRestClient):
+ net_dict = {
+ 'network': False,
+ 'router': False,
+ 'subnet': False,
+ 'dhcp': False,
+ }
+ iso_creds = isolated_creds.IsolatedCreds('test class',
+ password='fake_password',
+ network_resources=net_dict)
+ self._mock_user_create('1234', 'fake_prim_user')
+ self._mock_tenant_create('1234', 'fake_prim_tenant')
+ net = patch.object(iso_creds.network_admin_client,
+ 'delete_network')
+ net_mock = net.start()
+ subnet = patch.object(iso_creds.network_admin_client,
+ 'delete_subnet')
+ subnet_mock = subnet.start()
+ router = patch.object(iso_creds.network_admin_client,
+ 'delete_router')
+ router_mock = router.start()
+
+ username, tenant_name, password = iso_creds.get_primary_creds()
+ self.assertEqual(net_mock.mock_calls, [])
+ self.assertEqual(subnet_mock.mock_calls, [])
+ self.assertEqual(router_mock.mock_calls, [])
+ network = iso_creds.get_primary_network()
+ subnet = iso_creds.get_primary_subnet()
+ router = iso_creds.get_primary_router()
+ self.assertIsNone(network)
+ self.assertIsNone(subnet)
+ self.assertIsNone(router)
+
+ @patch('tempest.common.rest_client.RestClient')
+ def test_router_without_network(self, MockRestClient):
+ net_dict = {
+ 'network': False,
+ 'router': True,
+ 'subnet': False,
+ 'dhcp': False,
+ }
+ iso_creds = isolated_creds.IsolatedCreds('test class',
+ password='fake_password',
+ network_resources=net_dict)
+ self._mock_user_create('1234', 'fake_prim_user')
+ self._mock_tenant_create('1234', 'fake_prim_tenant')
+ self.assertRaises(exceptions.InvalidConfiguration,
+ iso_creds.get_primary_creds)
+
+ @patch('tempest.common.rest_client.RestClient')
+ def test_subnet_without_network(self, MockRestClient):
+ net_dict = {
+ 'network': False,
+ 'router': False,
+ 'subnet': True,
+ 'dhcp': False,
+ }
+ iso_creds = isolated_creds.IsolatedCreds('test class',
+ password='fake_password',
+ network_resources=net_dict)
+ self._mock_user_create('1234', 'fake_prim_user')
+ self._mock_tenant_create('1234', 'fake_prim_tenant')
+ self.assertRaises(exceptions.InvalidConfiguration,
+ iso_creds.get_primary_creds)
+
+ @patch('tempest.common.rest_client.RestClient')
+ def test_dhcp_without_subnet(self, MockRestClient):
+ net_dict = {
+ 'network': False,
+ 'router': False,
+ 'subnet': False,
+ 'dhcp': True,
+ }
+ iso_creds = isolated_creds.IsolatedCreds('test class',
+ password='fake_password',
+ network_resources=net_dict)
+ self._mock_user_create('1234', 'fake_prim_user')
+ self._mock_tenant_create('1234', 'fake_prim_tenant')
+ self.assertRaises(exceptions.InvalidConfiguration,
+ iso_creds.get_primary_creds)