Add a ConsumerClient and consumer API tests
This change adds a ConsumerClient for testing the Barbican consumer API. It adds a consumer test suite and integrates the ConsumerClient with the plugin testing infrastructure. Change-Id: I844d1a97ffb82aa67a4ef3b89bd82c90aa221cbb Depends-On: I930455c6ae1e1127706480f24c0ea46f5cc81e85 Implements: bp tempest-plugin
This commit is contained in:
parent
7be3f7e13c
commit
ee38917832
|
@ -41,6 +41,10 @@ class BarbicanTempestPlugin(plugins.TempestPlugin):
|
|||
'name': 'secret_v1',
|
||||
'service_version': 'secret.v1',
|
||||
'module_path': 'barbican_tempest_plugin.services.key_manager.json',
|
||||
'client_names': ['SecretClient', 'ContainerClient'],
|
||||
'client_names': [
|
||||
'ConsumerClient',
|
||||
'ContainerClient',
|
||||
'SecretClient'
|
||||
],
|
||||
}
|
||||
return [v1_params]
|
||||
|
|
|
@ -12,9 +12,11 @@
|
|||
# License for the specific language governing permissions and limitations under
|
||||
# the License.
|
||||
|
||||
from barbican_tempest_plugin.services.key_manager.json.consumer_client \
|
||||
import ConsumerClient
|
||||
from barbican_tempest_plugin.services.key_manager.json.container_client \
|
||||
import ContainerClient
|
||||
from barbican_tempest_plugin.services.key_manager.json.secret_client import \
|
||||
SecretClient
|
||||
from barbican_tempest_plugin.services.key_manager.json.secret_client \
|
||||
import SecretClient
|
||||
|
||||
__all__ = ['SecretClient', 'ContainerClient']
|
||||
__all__ = ['ConsumerClient', 'ContainerClient', 'SecretClient']
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
# Copyright (c) 2016 Johns Hopkins University Applied Physics Laboratory
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
import json
|
||||
|
||||
from six.moves.urllib import parse as urllib
|
||||
|
||||
from tempest import config
|
||||
from tempest.lib.common import rest_client
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class ConsumerClient(rest_client.RestClient):
|
||||
|
||||
def list_consumers_in_container(self, container_id, **kwargs):
|
||||
uri = "/v1/containers/%s/consumers" % container_id
|
||||
if kwargs:
|
||||
uri += "?%s" % urllib.urlencode(kwargs)
|
||||
|
||||
response, body = self.get(uri)
|
||||
self.expected_success(200, response.status)
|
||||
return json.loads(body)
|
||||
|
||||
def add_consumer_to_container(self, container_id, **kwargs):
|
||||
uri = "/v1/containers/%s/consumers" % container_id
|
||||
|
||||
response, body = self.post(uri, json.dumps(kwargs))
|
||||
self.expected_success(200, response.status)
|
||||
return json.loads(body)
|
||||
|
||||
def delete_consumer_from_container(self, container_id, **kwargs):
|
||||
uri = "/v1/containers/%s/consumers" % container_id
|
||||
|
||||
response, body = self.delete(uri, body=json.dumps(kwargs))
|
||||
self.expected_success(200, response.status)
|
||||
return json.loads(body)
|
|
@ -59,10 +59,13 @@ class BaseKeyManagerTest(test.BaseTestCase):
|
|||
def setup_clients(cls):
|
||||
super(BaseKeyManagerTest, cls).setup_clients()
|
||||
os = getattr(cls, 'os_%s' % cls.credentials[0])
|
||||
cls.secret_client = os.secret_v1.SecretClient(service='key-manager')
|
||||
cls.consumer_client = os.secret_v1.ConsumerClient(
|
||||
service='key-manager'
|
||||
)
|
||||
cls.container_client = os.secret_v1.ContainerClient(
|
||||
service='key-manager'
|
||||
)
|
||||
cls.secret_client = os.secret_v1.SecretClient(service='key-manager')
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
# Copyright (c) 2016 Johns Hopkins University Applied Physics Laboratory
|
||||
#
|
||||
# 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 barbican_tempest_plugin.tests.api import base
|
||||
|
||||
|
||||
class ConsumersTest(base.BaseKeyManagerTest):
|
||||
"""Containers API tests."""
|
||||
|
||||
def test_add_delete_consumers_in_container(self):
|
||||
# Create a container to test against
|
||||
body = self.create_container(
|
||||
type="generic",
|
||||
name="consumer-container"
|
||||
)
|
||||
container_id = base._get_uuid(body.get('container_ref'))
|
||||
|
||||
# Confirm that the container has no consumers
|
||||
body = self.consumer_client.list_consumers_in_container(container_id)
|
||||
self.assertEqual(0, body.get('total'), body)
|
||||
self.assertEmpty(body.get('consumers'), body)
|
||||
|
||||
# Add some consumers to the container
|
||||
body = self.consumer_client.add_consumer_to_container(
|
||||
container_id,
|
||||
name="consumer1",
|
||||
URL="url1"
|
||||
)
|
||||
self.assertEqual(
|
||||
container_id,
|
||||
base._get_uuid(body.get('container_ref')),
|
||||
body
|
||||
)
|
||||
self.assertEqual(1, len(body.get('consumers')), body)
|
||||
body = self.consumer_client.add_consumer_to_container(
|
||||
container_id,
|
||||
name="consumer2",
|
||||
URL="url2"
|
||||
)
|
||||
self.assertEqual(
|
||||
container_id,
|
||||
base._get_uuid(body.get('container_ref')),
|
||||
body
|
||||
)
|
||||
self.assertEqual(2, len(body.get('consumers')), body)
|
||||
|
||||
# Confirm that the consumers are in the container
|
||||
body = self.consumer_client.list_consumers_in_container(container_id)
|
||||
self.assertEqual(2, body.get('total'), body)
|
||||
self.assertEqual(2, len(body.get('consumers')), body)
|
||||
for consumer in body.get('consumers'):
|
||||
self.assertIn(consumer.get('name'), ("consumer1", "consumer2"))
|
||||
self.assertIn(consumer.get('URL'), ("url1", "url2"))
|
||||
|
||||
# Remove the consumers from the container
|
||||
body = self.consumer_client.delete_consumer_from_container(
|
||||
container_id,
|
||||
name="consumer1",
|
||||
URL="url1"
|
||||
)
|
||||
self.assertEqual(
|
||||
container_id,
|
||||
base._get_uuid(body.get('container_ref')),
|
||||
body
|
||||
)
|
||||
self.assertEqual(1, len(body.get('consumers')), body)
|
||||
body = self.consumer_client.delete_consumer_from_container(
|
||||
container_id,
|
||||
name="consumer2",
|
||||
URL="url2"
|
||||
)
|
||||
self.assertEqual(
|
||||
container_id,
|
||||
base._get_uuid(body.get('container_ref')),
|
||||
body
|
||||
)
|
||||
self.assertEqual(0, len(body.get('consumers')), body)
|
||||
|
||||
# Confirm that the container has no consumers
|
||||
body = self.consumer_client.list_consumers_in_container(container_id)
|
||||
self.assertEqual(0, body.get('total'), body)
|
||||
self.assertEqual(0, len(body.get('consumers')), body)
|
||||
|
||||
# Clean up the container
|
||||
self.delete_container(container_id)
|
Loading…
Reference in New Issue