Add CLI smoke functional tests for containers

Added tests and behaviors for containers.  Also refactored the
PrettyTable parsing to make it more generic so we can use it with
more than just secrets.

Change-Id: Icf3a462d6f24ce887977c07ed310b39c9d928a29
This commit is contained in:
Steve Heyman
2015-05-03 12:23:13 -05:00
parent 82daee29fb
commit 8f1e12eabf
3 changed files with 165 additions and 1 deletions

View File

@@ -0,0 +1,94 @@
# Copyright (c) 2015 Rackspace, Inc.
#
# 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 logging
import base_behaviors
class ContainerBehaviors(base_behaviors.BaseBehaviors):
def __init__(self):
super(ContainerBehaviors, self).__init__()
self.LOG = logging.getLogger(type(self).__name__)
self.container_hrefs_to_delete = []
def delete_container(self, container_href):
""" Delete a container
:param container_href the href to the container to delete
"""
argv = ['container', 'delete']
self.add_auth_and_endpoint(argv)
argv.extend([container_href])
stdout, stderr = self.issue_barbican_command(argv)
self.container_hrefs_to_delete.remove(container_href)
def create_container(self, secret_hrefs=[]):
""" Create a container
:param secret_hrefs A list of existing secrets
:return: the href to the newly created container
"""
argv = ['container', 'create']
self.add_auth_and_endpoint(argv)
for secret_href in secret_hrefs:
argv.extend(['--secret', secret_href])
stdout, stderr = self.issue_barbican_command(argv)
container_data = self._prettytable_to_dict(stdout)
container_href = container_data['Container href']
self.container_hrefs_to_delete.append(container_href)
return container_href
def get_container(self, container_href):
""" Get a container
:param: the href to a container
:return dict of container values, or an empty dict if the container
is not found.
"""
argv = ['container', 'get']
self.add_auth_and_endpoint(argv)
argv.extend([container_href])
stdout, stderr = self.issue_barbican_command(argv)
if '4xx Client error: Not Found' in stderr:
return {}
container_data = self._prettytable_to_dict(stdout)
return container_data
def list_containers(self):
""" List containers
:return: a list of containers
"""
argv = ['container', 'list']
self.add_auth_and_endpoint(argv)
stdout, stderr = self.issue_barbican_command(argv)
container_list = self._prettytable_to_list(stdout)
return container_list
def delete_all_created_containers(self):
""" Delete all containers that we created """
for href in self.container_hrefs_to_delete:
self.delete_container(href)

View File

@@ -17,6 +17,7 @@ import logging
import base_behaviors
class SecretBehaviors(base_behaviors.BaseBehaviors):
def __init__(self):
@@ -118,4 +119,4 @@ class SecretBehaviors(base_behaviors.BaseBehaviors):
def delete_all_created_secrets(self):
""" Delete all secrets that we created """
for href in self.secret_hrefs_to_delete:
self.delete_secret(href)
self.delete_secret(href)

View File

@@ -0,0 +1,69 @@
# Copyright (c) 2015 Rackspace, Inc.
#
# 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 functionaltests.cli.base import CmdLineTestCase
from functionaltests.cli.v1.behaviors import container_behaviors
from functionaltests.cli.v1.behaviors import secret_behaviors
from testtools import testcase
class ContainerTestCase(CmdLineTestCase):
def setUp(self):
super(ContainerTestCase, self).setUp()
self.secret_behaviors = secret_behaviors.SecretBehaviors()
self.container_behaviors = container_behaviors.ContainerBehaviors()
def tearDown(self):
super(ContainerTestCase, self).tearDown()
self.container_behaviors.delete_all_created_containers()
@testcase.attr('positive')
def test_container_create(self):
secret_href = self.secret_behaviors.store_secret()
container_href = self.container_behaviors.create_container(
secret_hrefs=[secret_href])
self.assertIsNotNone(container_href)
container = self.container_behaviors.get_container(container_href)
self.assertEqual(container_href, container['Container href'])
@testcase.attr('positive')
def test_container_list(self):
containers_to_create = 10
for _ in range(containers_to_create):
secret_href = self.secret_behaviors.store_secret()
self.container_behaviors.create_container(
secret_hrefs=[secret_href])
container_list = self.container_behaviors.list_containers()
self.assertGreaterEqual(len(container_list), containers_to_create)
@testcase.attr('positive')
def test_container_delete(self):
secret_href = self.secret_behaviors.store_secret()
container_href = self.container_behaviors.create_container(
secret_hrefs=[secret_href])
self.container_behaviors.delete_container(container_href)
container = self.container_behaviors.get_container(container_href)
self.assertFalse(container)
@testcase.attr('positive')
def test_container_get(self):
secret_href = self.secret_behaviors.store_secret()
container_href = self.container_behaviors.create_container(
secret_hrefs=[secret_href])
container = self.container_behaviors.get_container(container_href)
self.assertIsNotNone(container)