Add admin api tests for project-id
1. Test that admin can create a network for another project by
specifying the project_id for that project.
2. Test that admin can create a network for another project by
specifying the project_id and the tenant_id for that project.
(The project_id and tenant_id must be the same.)
3. Verify that creation fails if different values are given
for project_id and tenant_id.
Related Blueprint: keystone-v3
Change-Id: I88df9051943efb69f3494e199e6d11966fd9abbb
diff --git a/neutron/tests/tempest/api/admin/test_networks.py b/neutron/tests/tempest/api/admin/test_networks.py
new file mode 100644
index 0000000..f363e09
--- /dev/null
+++ b/neutron/tests/tempest/api/admin/test_networks.py
@@ -0,0 +1,70 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from oslo_utils import uuidutils
+from tempest.lib import exceptions as lib_exc
+from tempest import test
+
+from neutron.tests.tempest.api import base
+
+
+class NetworksTestAdmin(base.BaseAdminNetworkTest):
+
+ @test.idempotent_id('d3c76044-d067-4cb0-ae47-8cdd875c7f67')
+ @test.requires_ext(extension="project-id", service="network")
+ def test_admin_create_network_keystone_v3(self):
+ project_id = self.client.tenant_id # non-admin
+
+ name = 'admin-created-with-project_id'
+ body = self.admin_client.create_network_keystone_v3(name, project_id)
+ new_net = body['network']
+ self.assertEqual(name, new_net['name'])
+ self.assertEqual(project_id, new_net['project_id'])
+ self.assertEqual(project_id, new_net['tenant_id'])
+
+ body = self.client.list_networks(id=new_net['id'])
+ lookup_net = body['networks'][0]
+ self.assertEqual(name, lookup_net['name'])
+ self.assertEqual(project_id, lookup_net['project_id'])
+ self.assertEqual(project_id, lookup_net['tenant_id'])
+
+ @test.idempotent_id('8d21aaca-4364-4eb9-8b79-44b4fff6373b')
+ @test.requires_ext(extension="project-id", service="network")
+ def test_admin_create_network_keystone_v3_and_tenant(self):
+ project_id = self.client.tenant_id # non-admin
+
+ name = 'created-with-project-and-tenant'
+ body = self.admin_client.create_network_keystone_v3(
+ name, project_id, tenant_id=project_id)
+ new_net = body['network']
+ self.assertEqual(name, new_net['name'])
+ self.assertEqual(project_id, new_net['project_id'])
+ self.assertEqual(project_id, new_net['tenant_id'])
+
+ body = self.client.list_networks(id=new_net['id'])
+ lookup_net = body['networks'][0]
+ self.assertEqual(name, lookup_net['name'])
+ self.assertEqual(project_id, lookup_net['project_id'])
+ self.assertEqual(project_id, lookup_net['tenant_id'])
+
+ @test.idempotent_id('08b92179-669d-45ee-8233-ef6611190809')
+ @test.requires_ext(extension="project-id", service="network")
+ def test_admin_create_network_keystone_v3_and_other_tenant(self):
+ project_id = self.client.tenant_id # non-admin
+ other_tenant = uuidutils.generate_uuid()
+
+ name = 'created-with-project-and-other-tenant'
+ e = self.assertRaises(lib_exc.BadRequest,
+ self.admin_client.create_network_keystone_v3,
+ name, project_id, tenant_id=other_tenant)
+ expected_message = "'project_id' and 'tenant_id' do not match"
+ self.assertEqual(expected_message, e.resp_body['message'])
diff --git a/neutron/tests/tempest/services/network/json/network_client.py b/neutron/tests/tempest/services/network/json/network_client.py
index 4828059..3b1a9a8 100644
--- a/neutron/tests/tempest/services/network/json/network_client.py
+++ b/neutron/tests/tempest/services/network/json/network_client.py
@@ -872,7 +872,7 @@
body = jsonutils.loads(body)
return service_client.ResponseBody(resp, body)
- def create_network_keystone_v3(self, name, project_id):
+ def create_network_keystone_v3(self, name, project_id, tenant_id=None):
uri = '%s/networks' % self.uri_prefix
post_data = {
'network': {
@@ -880,6 +880,8 @@
'project_id': project_id
}
}
+ if tenant_id is not None:
+ post_data['network']['tenant_id'] = tenant_id
resp, body = self.post(uri, self.serialize(post_data))
body = self.deserialize_single(body)
self.expected_success(201, resp.status)