Merge "Generic "delete volume" method"
diff --git a/releasenotes/notes/image-clients-as-library-86d17caa26ce3961.yaml b/releasenotes/notes/image-clients-as-library-86d17caa26ce3961.yaml
index faae7d0..90a5056 100644
--- a/releasenotes/notes/image-clients-as-library-86d17caa26ce3961.yaml
+++ b/releasenotes/notes/image-clients-as-library-86d17caa26ce3961.yaml
@@ -6,6 +6,7 @@
so the other projects can use these modules as stable libraries
without any maintenance changes.
+ * image_members_client(v1)
* image_members_client(v2)
* images_client(v2)
* namespaces_client(v2)
diff --git a/tempest/api/identity/admin/v2/test_tenant_negative.py b/tempest/api/identity/admin/v2/test_tenant_negative.py
index 5169dae..d1e0217 100644
--- a/tempest/api/identity/admin/v2/test_tenant_negative.py
+++ b/tempest/api/identity/admin/v2/test_tenant_negative.py
@@ -43,7 +43,7 @@
def test_tenant_delete_by_unauthorized_user(self):
# Non-administrator user should not be able to delete a tenant
tenant_name = data_utils.rand_name(name='tenant')
- tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
+ tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.data.tenants.append(tenant)
self.assertRaises(lib_exc.Forbidden,
self.non_admin_tenants_client.delete_tenant,
@@ -54,7 +54,7 @@
def test_tenant_delete_request_without_token(self):
# Request to delete a tenant without a valid token should fail
tenant_name = data_utils.rand_name(name='tenant')
- tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
+ tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.data.tenants.append(tenant)
token = self.client.auth_provider.get_token()
self.client.delete_token(token)
@@ -75,7 +75,7 @@
def test_tenant_create_duplicate(self):
# Tenant names should be unique
tenant_name = data_utils.rand_name(name='tenant')
- body = self.tenants_client.create_tenant(tenant_name)['tenant']
+ body = self.tenants_client.create_tenant(name=tenant_name)['tenant']
tenant = body
self.data.tenants.append(tenant)
tenant1_id = body.get('id')
@@ -83,7 +83,7 @@
self.addCleanup(self.tenants_client.delete_tenant, tenant1_id)
self.addCleanup(self.data.tenants.remove, tenant)
self.assertRaises(lib_exc.Conflict, self.tenants_client.create_tenant,
- tenant_name)
+ name=tenant_name)
@test.attr(type=['negative'])
@test.idempotent_id('d26b278a-6389-4702-8d6e-5980d80137e0')
@@ -92,7 +92,7 @@
tenant_name = data_utils.rand_name(name='tenant')
self.assertRaises(lib_exc.Forbidden,
self.non_admin_tenants_client.create_tenant,
- tenant_name)
+ name=tenant_name)
@test.attr(type=['negative'])
@test.idempotent_id('a3ee9d7e-6920-4dd5-9321-d4b2b7f0a638')
@@ -103,7 +103,7 @@
self.client.delete_token(token)
self.assertRaises(lib_exc.Unauthorized,
self.tenants_client.create_tenant,
- tenant_name)
+ name=tenant_name)
self.client.auth_provider.clear_auth()
@test.attr(type=['negative'])
@@ -121,7 +121,7 @@
tenant_name = 'a' * 65
self.assertRaises(lib_exc.BadRequest,
self.tenants_client.create_tenant,
- tenant_name)
+ name=tenant_name)
@test.attr(type=['negative'])
@test.idempotent_id('bd20dc2a-9557-4db7-b755-f48d952ad706')
@@ -135,7 +135,7 @@
def test_tenant_update_by_unauthorized_user(self):
# Non-administrator user should not be able to update a tenant
tenant_name = data_utils.rand_name(name='tenant')
- tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
+ tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.data.tenants.append(tenant)
self.assertRaises(lib_exc.Forbidden,
self.non_admin_tenants_client.update_tenant,
@@ -146,7 +146,7 @@
def test_tenant_update_request_without_token(self):
# Request to update a tenant without a valid token should fail
tenant_name = data_utils.rand_name(name='tenant')
- tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
+ tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.data.tenants.append(tenant)
token = self.client.auth_provider.get_token()
self.client.delete_token(token)
diff --git a/tempest/api/identity/admin/v2/test_tenants.py b/tempest/api/identity/admin/v2/test_tenants.py
index 8d0b9b1..1aa80df 100644
--- a/tempest/api/identity/admin/v2/test_tenants.py
+++ b/tempest/api/identity/admin/v2/test_tenants.py
@@ -28,7 +28,8 @@
tenants = []
for _ in moves.xrange(3):
tenant_name = data_utils.rand_name(name='tenant-new')
- tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
+ tenant = self.tenants_client.create_tenant(
+ name=tenant_name)['tenant']
self.data.tenants.append(tenant)
tenants.append(tenant)
tenant_ids = map(lambda x: x['id'], tenants)
@@ -49,7 +50,7 @@
# Create tenant with a description
tenant_name = data_utils.rand_name(name='tenant')
tenant_desc = data_utils.rand_name(name='desc')
- body = self.tenants_client.create_tenant(tenant_name,
+ body = self.tenants_client.create_tenant(name=tenant_name,
description=tenant_desc)
tenant = body['tenant']
self.data.tenants.append(tenant)
@@ -68,7 +69,8 @@
def test_tenant_create_enabled(self):
# Create a tenant that is enabled
tenant_name = data_utils.rand_name(name='tenant')
- body = self.tenants_client.create_tenant(tenant_name, enabled=True)
+ body = self.tenants_client.create_tenant(name=tenant_name,
+ enabled=True)
tenant = body['tenant']
self.data.tenants.append(tenant)
tenant_id = tenant['id']
@@ -84,7 +86,8 @@
def test_tenant_create_not_enabled(self):
# Create a tenant that is not enabled
tenant_name = data_utils.rand_name(name='tenant')
- body = self.tenants_client.create_tenant(tenant_name, enabled=False)
+ body = self.tenants_client.create_tenant(name=tenant_name,
+ enabled=False)
tenant = body['tenant']
self.data.tenants.append(tenant)
tenant_id = tenant['id']
@@ -102,7 +105,7 @@
def test_tenant_update_name(self):
# Update name attribute of a tenant
t_name1 = data_utils.rand_name(name='tenant')
- body = self.tenants_client.create_tenant(t_name1)['tenant']
+ body = self.tenants_client.create_tenant(name=t_name1)['tenant']
tenant = body
self.data.tenants.append(tenant)
@@ -129,7 +132,8 @@
# Update description attribute of a tenant
t_name = data_utils.rand_name(name='tenant')
t_desc = data_utils.rand_name(name='desc')
- body = self.tenants_client.create_tenant(t_name, description=t_desc)
+ body = self.tenants_client.create_tenant(name=t_name,
+ description=t_desc)
tenant = body['tenant']
self.data.tenants.append(tenant)
@@ -157,7 +161,7 @@
# Update the enabled attribute of a tenant
t_name = data_utils.rand_name(name='tenant')
t_en = False
- body = self.tenants_client.create_tenant(t_name, enabled=t_en)
+ body = self.tenants_client.create_tenant(name=t_name, enabled=t_en)
tenant = body['tenant']
self.data.tenants.append(tenant)
diff --git a/tempest/api/identity/admin/v2/test_tokens.py b/tempest/api/identity/admin/v2/test_tokens.py
index 2297a9d..1675126 100644
--- a/tempest/api/identity/admin/v2/test_tokens.py
+++ b/tempest/api/identity/admin/v2/test_tokens.py
@@ -27,7 +27,7 @@
user_password = data_utils.rand_password()
# first:create a tenant
tenant_name = data_utils.rand_name(name='tenant')
- tenant = self.tenants_client.create_tenant(tenant_name)['tenant']
+ tenant = self.tenants_client.create_tenant(name=tenant_name)['tenant']
self.data.tenants.append(tenant)
# second:create a user
user = self.users_client.create_user(name=user_name,
@@ -72,11 +72,13 @@
# Create a couple tenants.
tenant1_name = data_utils.rand_name(name='tenant')
- tenant1 = self.tenants_client.create_tenant(tenant1_name)['tenant']
+ tenant1 = self.tenants_client.create_tenant(
+ name=tenant1_name)['tenant']
self.data.tenants.append(tenant1)
tenant2_name = data_utils.rand_name(name='tenant')
- tenant2 = self.tenants_client.create_tenant(tenant2_name)['tenant']
+ tenant2 = self.tenants_client.create_tenant(
+ name=tenant2_name)['tenant']
self.data.tenants.append(tenant2)
# Create a role
diff --git a/tempest/clients.py b/tempest/clients.py
index 7a7d15d..3d9e85c 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -76,6 +76,8 @@
from tempest.lib.services.identity.v2.endpoints_client import EndpointsClient
from tempest.lib.services.identity.v2.token_client import TokenClient
from tempest.lib.services.identity.v3.token_client import V3TokenClient
+from tempest.lib.services.image.v1.image_members_client import \
+ ImageMembersClient
from tempest.lib.services.image.v2.image_members_client import \
ImageMembersClient as ImageMembersClientV2
from tempest.lib.services.image.v2.images_client import \
@@ -141,8 +143,6 @@
from tempest.services.identity.v3.json.trusts_client import TrustsClient
from tempest.services.identity.v3.json.users_clients import \
UsersClient as UsersV3Client
-from tempest.services.image.v1.json.image_members_client import \
- ImageMembersClient
from tempest.services.image.v1.json.images_client import ImagesClient
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.container_client import ContainerClient
diff --git a/tempest/cmd/javelin.py b/tempest/cmd/javelin.py
index 7ce6225..3d57c35 100755
--- a/tempest/cmd/javelin.py
+++ b/tempest/cmd/javelin.py
@@ -319,7 +319,7 @@
existing = [x['name'] for x in body]
for tenant in tenants:
if tenant not in existing:
- admin.tenants.create_tenant(tenant)['tenant']
+ admin.tenants.create_tenant(name=tenant)['tenant']
else:
LOG.warning("Tenant '%s' already exists in this environment"
% tenant)
diff --git a/tempest/lib/api_schema/response/compute/v2_1/instance_usage_audit_logs.py b/tempest/lib/api_schema/response/compute/v2_1/instance_usage_audit_logs.py
index c6c4deb..15224c5 100644
--- a/tempest/lib/api_schema/response/compute/v2_1/instance_usage_audit_logs.py
+++ b/tempest/lib/api_schema/response/compute/v2_1/instance_usage_audit_logs.py
@@ -19,7 +19,23 @@
'type': 'array',
'items': {'type': 'string'}
},
- 'log': {'type': 'object'},
+ 'log': {
+ 'type': 'object',
+ 'patternProperties': {
+ # NOTE: Here is a host name.
+ '^.+$': {
+ 'type': 'object',
+ 'properties': {
+ 'state': {'type': 'string'},
+ 'instances': {'type': 'integer'},
+ 'errors': {'type': 'integer'},
+ 'message': {'type': 'string'}
+ },
+ 'additionalProperties': False,
+ 'required': ['state', 'instances', 'errors', 'message']
+ }
+ }
+ },
'num_hosts': {'type': 'integer'},
'num_hosts_done': {'type': 'integer'},
'num_hosts_not_run': {'type': 'integer'},
diff --git a/tempest/lib/services/image/v1/__init__.py b/tempest/lib/services/image/v1/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/lib/services/image/v1/__init__.py
diff --git a/tempest/services/image/v1/json/image_members_client.py b/tempest/lib/services/image/v1/image_members_client.py
similarity index 100%
rename from tempest/services/image/v1/json/image_members_client.py
rename to tempest/lib/services/image/v1/image_members_client.py
diff --git a/tempest/services/identity/v2/json/tenants_client.py b/tempest/services/identity/v2/json/tenants_client.py
index 97e5c11..77ddaa5 100644
--- a/tempest/services/identity/v2/json/tenants_client.py
+++ b/tempest/services/identity/v2/json/tenants_client.py
@@ -13,6 +13,7 @@
# limitations under the License.
from oslo_serialization import jsonutils as json
+from six.moves.urllib import parse as urllib
from tempest.lib.common import rest_client
@@ -20,40 +21,50 @@
class TenantsClient(rest_client.RestClient):
api_version = "v2.0"
- def create_tenant(self, name, **kwargs):
+ def create_tenant(self, **kwargs):
"""Create a tenant
- name (required): New tenant name
- description: Description of new tenant (default is none)
- enabled <true|false>: Initial tenant status (default is true)
+ Available params: see http://developer.openstack.org/
+ api-ref-identity-v2-ext.html#createTenant
"""
- post_body = {
- 'name': name,
- 'description': kwargs.get('description', ''),
- 'enabled': kwargs.get('enabled', True),
- }
- post_body = json.dumps({'tenant': post_body})
+ post_body = json.dumps({'tenant': kwargs})
resp, body = self.post('tenants', post_body)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def delete_tenant(self, tenant_id):
- """Delete a tenant."""
+ """Delete a tenant.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-identity-v2-ext.html#deleteTenant
+ """
resp, body = self.delete('tenants/%s' % str(tenant_id))
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp, body)
def show_tenant(self, tenant_id):
- """Get tenant details."""
+ """Get tenant details.
+
+ Available params: see
+ http://developer.openstack.org/
+ api-ref-identity-v2-ext.html#admin-showTenantById
+ """
resp, body = self.get('tenants/%s' % str(tenant_id))
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
- def list_tenants(self):
- """Returns tenants."""
- resp, body = self.get('tenants')
+ def list_tenants(self, **params):
+ """Returns tenants.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-identity-v2-ext.html#admin-listTenants
+ """
+ url = 'tenants'
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+ resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
@@ -64,25 +75,24 @@
Available params: see http://developer.openstack.org/
api-ref-identity-v2-ext.html#updateTenant
"""
- body = self.show_tenant(tenant_id)['tenant']
- name = kwargs.get('name', body['name'])
- desc = kwargs.get('description', body['description'])
- en = kwargs.get('enabled', body['enabled'])
- post_body = {
- 'id': tenant_id,
- 'name': name,
- 'description': desc,
- 'enabled': en,
- }
- post_body = json.dumps({'tenant': post_body})
+ if 'id' not in kwargs:
+ kwargs['id'] = tenant_id
+ post_body = json.dumps({'tenant': kwargs})
resp, body = self.post('tenants/%s' % tenant_id, post_body)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
- def list_tenant_users(self, tenant_id):
- """List users for a Tenant."""
- resp, body = self.get('/tenants/%s/users' % tenant_id)
+ def list_tenant_users(self, tenant_id, **params):
+ """List users for a Tenant.
+
+ Available params: see http://developer.openstack.org/
+ api-ref-identity-v2-ext.html#listUsersForTenant
+ """
+ url = '/tenants/%s/users' % tenant_id
+ if params:
+ url += '?%s' % urllib.urlencode(params)
+ resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
diff --git a/tempest/tests/cmd/test_javelin.py b/tempest/tests/cmd/test_javelin.py
index 50660ff..5ec9720 100644
--- a/tempest/tests/cmd/test_javelin.py
+++ b/tempest/tests/cmd/test_javelin.py
@@ -92,7 +92,7 @@
javelin.create_tenants([self.fake_object['name']])
mocked_function = self.fake_client.tenants.create_tenant
- mocked_function.assert_called_once_with(self.fake_object['name'])
+ mocked_function.assert_called_once_with(name=self.fake_object['name'])
def test_create_duplicate_tenant(self):
self.fake_client.tenants.list_tenants.return_value = {'tenants': [
diff --git a/tempest/tests/lib/services/image/v1/__init__.py b/tempest/tests/lib/services/image/v1/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tempest/tests/lib/services/image/v1/__init__.py
diff --git a/tempest/tests/lib/services/image/v1/test_image_members_client.py b/tempest/tests/lib/services/image/v1/test_image_members_client.py
new file mode 100644
index 0000000..a5a6128
--- /dev/null
+++ b/tempest/tests/lib/services/image/v1/test_image_members_client.py
@@ -0,0 +1,84 @@
+# Copyright 2016 NEC Corporation. All rights reserved.
+#
+# 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 tempest.lib.services.image.v1 import image_members_client
+from tempest.tests.lib import fake_auth_provider
+from tempest.tests.lib.services import base
+
+
+class TestImageMembersClient(base.BaseServiceTest):
+ FAKE_LIST_IMAGE_MEMBERS = {
+ "members": [
+ {
+ "created_at": "2013-10-07T17:58:03Z",
+ "image_id": "dbc999e3-c52f-4200-bedd-3b18fe7f87fe",
+ "member_id": "123456789",
+ "status": "pending",
+ "updated_at": "2013-10-07T17:58:03Z"
+ },
+ {
+ "created_at": "2013-10-07T17:58:55Z",
+ "image_id": "dbc999e3-c52f-4200-bedd-3b18fe7f87fe",
+ "member_id": "987654321",
+ "status": "accepted",
+ "updated_at": "2013-10-08T12:08:55Z"
+ }
+ ]
+ }
+
+ def setUp(self):
+ super(TestImageMembersClient, self).setUp()
+ fake_auth = fake_auth_provider.FakeAuthProvider()
+ self.client = image_members_client.ImageMembersClient(fake_auth,
+ 'image',
+ 'regionOne')
+
+ def _test_list_image_members(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.list_image_members,
+ 'tempest.lib.common.rest_client.RestClient.get',
+ self.FAKE_LIST_IMAGE_MEMBERS,
+ bytes_body,
+ image_id="0ae74cc5-5147-4239-9ce2-b0c580f7067e")
+
+ def _test_create_image_member(self, bytes_body=False):
+ self.check_service_client_function(
+ self.client.create_image_member,
+ 'tempest.lib.common.rest_client.RestClient.put',
+ {},
+ bytes_body,
+ image_id="0ae74cc5-5147-4239-9ce2-b0c580f7067e",
+ member_id="8989447062e04a818baf9e073fd04fa7",
+ status=204)
+
+ def test_list_image_members_with_str_body(self):
+ self._test_list_image_members()
+
+ def test_list_image_members_with_bytes_body(self):
+ self._test_list_image_members(bytes_body=True)
+
+ def test_create_image_member_with_str_body(self):
+ self._test_create_image_member()
+
+ def test_create_image_member_with_bytes_body(self):
+ self._test_create_image_member(bytes_body=True)
+
+ def test_delete_image_member(self):
+ self.check_service_client_function(
+ self.client.delete_image_member,
+ 'tempest.lib.common.rest_client.RestClient.delete',
+ {},
+ image_id="0ae74cc5-5147-4239-9ce2-b0c580f7067e",
+ member_id="8989447062e04a818baf9e073fd04fa7",
+ status=204)