Merge "Separate namespaces_client from v2 images_client"

This commit is contained in:
Jenkins 2016-06-08 12:35:46 +00:00 committed by Gerrit Code Review
commit b740ff7e0f
5 changed files with 99 additions and 63 deletions

View File

@ -125,6 +125,7 @@ class BaseV2ImageTest(BaseImageTest):
def setup_clients(cls):
super(BaseV2ImageTest, cls).setup_clients()
cls.client = cls.os.image_client_v2
cls.namespaces_client = cls.os.namespaces_client
class BaseV2MemberImageTest(BaseV2ImageTest):

View File

@ -31,7 +31,8 @@ class MetadataNamespacesTest(base.BaseV2ImageTest):
name = [{'name': resource_name}]
namespace_name = data_utils.rand_name('namespace')
# create the metadef namespace
body = self.client.create_namespace(namespace=namespace_name,
body = self.namespaces_client.create_namespace(
namespace=namespace_name,
visibility='public',
description='Tempest',
display_name=namespace_name,
@ -40,14 +41,16 @@ class MetadataNamespacesTest(base.BaseV2ImageTest):
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self._cleanup_namespace, namespace_name)
# get namespace details
body = self.client.show_namespace(namespace_name)
body = self.namespaces_client.show_namespace(namespace_name)
self.assertEqual(namespace_name, body['namespace'])
self.assertEqual('public', body['visibility'])
# unable to delete protected namespace
self.assertRaises(lib_exc.Forbidden, self.client.delete_namespace,
self.assertRaises(lib_exc.Forbidden,
self.namespaces_client.delete_namespace,
namespace_name)
# update the visibility to private and protected to False
body = self.client.update_namespace(namespace=namespace_name,
body = self.namespaces_client.update_namespace(
namespace=namespace_name,
description='Tempest',
visibility='private',
display_name=namespace_name,
@ -55,14 +58,15 @@ class MetadataNamespacesTest(base.BaseV2ImageTest):
self.assertEqual('private', body['visibility'])
self.assertEqual(False, body['protected'])
# now able to delete the non-protected namespace
self.client.delete_namespace(namespace_name)
self.namespaces_client.delete_namespace(namespace_name)
def _cleanup_namespace(self, namespace_name):
body = self.client.show_namespace(namespace_name)
body = self.namespaces_client.show_namespace(namespace_name)
self.assertEqual(namespace_name, body['namespace'])
body = self.client.update_namespace(namespace=namespace_name,
body = self.namespaces_client.update_namespace(
namespace=namespace_name,
description='Tempest',
visibility='private',
display_name=namespace_name,
protected=False)
self.client.delete_namespace(namespace_name)
self.namespaces_client.delete_namespace(namespace_name)

View File

@ -137,6 +137,7 @@ from tempest.services.image.v2.json.images_client import \
ImagesClient as ImagesV2Client
from tempest.services.image.v2.json.members_client import MembersClient \
as MembersClientV2
from tempest.services.image.v2.json.namespaces_client import NamespacesClient
from tempest.services.object_storage.account_client import AccountClient
from tempest.services.object_storage.container_client import ContainerClient
from tempest.services.object_storage.object_client import ObjectClient
@ -359,6 +360,14 @@ class Manager(manager.Manager):
build_interval=CONF.image.build_interval,
build_timeout=CONF.image.build_timeout,
**self.default_params)
self.namespaces_client = NamespacesClient(
self.auth_provider,
CONF.image.catalog_type,
CONF.image.region or CONF.identity.region,
endpoint_type=CONF.image.endpoint_type,
build_interval=CONF.image.build_interval,
build_timeout=CONF.image.build_timeout,
**self.default_params)
self.orchestration_client = OrchestrationClient(
self.auth_provider,
CONF.orchestration.catalog_type,

View File

@ -145,45 +145,3 @@ class ImagesClient(rest_client.RestClient):
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def create_namespace(self, **kwargs):
"""Create a namespace.
Available params: see http://developer.openstack.org/
api-ref-image-v2.html#createNamespace-v2
"""
data = json.dumps(kwargs)
resp, body = self.post('metadefs/namespaces', data)
self.expected_success(201, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def show_namespace(self, namespace):
url = 'metadefs/namespaces/%s' % namespace
resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def update_namespace(self, namespace, **kwargs):
"""Update a namespace.
Available params: see http://developer.openstack.org/
api-ref-image-v2.html#updateNamespace-v2
"""
# NOTE: On Glance API, we need to pass namespace on both URI
# and a request body.
params = {'namespace': namespace}
params.update(kwargs)
data = json.dumps(params)
url = 'metadefs/namespaces/%s' % namespace
resp, body = self.put(url, body=data)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def delete_namespace(self, namespace):
url = 'metadefs/namespaces/%s' % namespace
resp, _ = self.delete(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp)

View File

@ -0,0 +1,64 @@
# Copyright 2013 IBM Corp.
# 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 oslo_serialization import jsonutils as json
from tempest.lib.common import rest_client
class NamespacesClient(rest_client.RestClient):
api_version = "v2"
def create_namespace(self, **kwargs):
"""Create a namespace.
Available params: see http://developer.openstack.org/
api-ref-image-v2.html#createNamespace-v2
"""
data = json.dumps(kwargs)
resp, body = self.post('metadefs/namespaces', data)
self.expected_success(201, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def show_namespace(self, namespace):
url = 'metadefs/namespaces/%s' % namespace
resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def update_namespace(self, namespace, **kwargs):
"""Update a namespace.
Available params: see http://developer.openstack.org/
api-ref-image-v2.html#updateNamespace-v2
"""
# NOTE: On Glance API, we need to pass namespace on both URI
# and a request body.
params = {'namespace': namespace}
params.update(kwargs)
data = json.dumps(params)
url = 'metadefs/namespaces/%s' % namespace
resp, body = self.put(url, body=data)
self.expected_success(200, resp.status)
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def delete_namespace(self, namespace):
url = 'metadefs/namespaces/%s' % namespace
resp, _ = self.delete(url)
self.expected_success(204, resp.status)
return rest_client.ResponseBody(resp)