Add more container related test

Change-Id: Ic7ebdb3f57ce44d15fabcacd9a26661dd9da384a
This commit is contained in:
AleptNmarata 2017-02-09 08:34:15 +00:00 committed by Hongbin Lu
parent ed1dd1c286
commit c78933754b
2 changed files with 109 additions and 1 deletions

View File

@ -12,6 +12,9 @@
import json
from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions
from zunclient.tests.functional import base
@ -32,6 +35,43 @@ class TestCase(base.FunctionalTestBase):
return ' -f {0} {1}'.format(output_format,
' '.join(['-c ' + it for it in fields]))
def container_create(self, image='cirros', name=None, params=''):
"""Create container and add cleanup.
:param String image: Image for a new container
:param String name: Name for a new container
:param String params: Additional args and kwargs
:return: JSON object of created container
"""
if not name:
name = data_utils.rand_name('container')
opts = self.get_opts()
output = self.openstack('appcontainer create {0}'
' {1} --name {2} {3}'
.format(opts, image, name, params))
container = json.loads(output)
if not output:
self.fail('Container has not been created!')
return container
def container_delete(self, identifier, ignore_exceptions=False):
"""Try to delete container by name or UUID.
:param String identifier: Name or UUID of the container
:param Bool ignore_exceptions: Ignore exception (needed for cleanUp)
:return: raw values output
:raise: CommandFailed exception when command fails
to delete a container
"""
try:
return self.openstack('appcontainer delete {0}'
.format(identifier))
except exceptions.CommandFailed:
if not ignore_exceptions:
raise
def container_list(self, fields=None, params=''):
"""List Container.
@ -43,3 +83,16 @@ class TestCase(base.FunctionalTestBase):
output = self.openstack('appcontainer list {0} {1}'
.format(opts, params))
return json.loads(output)
def container_show(self, identifier, fields=None, params=''):
"""Show specified baremetal node.
:param String identifier: Name or UUID of the node
:param List fields: List of fields to show
:param List params: Additional kwargs
:return: JSON object of node
"""
opts = self.get_opts(fields)
output = self.openstack('appcontainer show {0} {1} {2}'
.format(opts, identifier, params))
return json.loads(output)

View File

@ -13,6 +13,7 @@
# under the License.
import ddt
from tempest.lib.common.utils import data_utils
from zunclient.tests.functional.osc.v1 import base
@ -28,5 +29,59 @@ class ContainerTests(base.TestCase):
"""Check container list command.
"""
container = self.container_create(name='test')
container_list = self.container_list()
self.assertFalse(container_list)
self.assertIn(container['name'], [x['name'] for x in
container_list])
self.assertIn(container['uuid'], [x['uuid'] for x in
container_list])
# Now delete the container and then see the list
self.container_delete(container['name'])
def test_create(self):
"""Check container create command.
"""
name = data_utils.rand_name('test_container')
container_info = self.container_create(name=name)
self.assertEqual(container_info['name'], name)
self.assertEqual(container_info['image'], 'cirros')
container_list = self.container_list()
self.assertIn(name, [x['name'] for x in container_list])
self.container_delete(container_info['name'])
def test_delete(self):
"""Check container delete command with name/UUID argument.
Test steps:
1) Create container in setUp.
2) Delete container by name/UUID.
3) Check that node deleted successfully.
"""
container = self.container_create(name='test_del')
container_list = self.container_list()
self.assertIn(container['name'],
[x['name'] for x in container_list])
self.assertIn(container['uuid'],
[x['uuid'] for x in container_list])
self.container_delete(container['name'])
container_list = self.container_list()
self.assertNotIn(container['name'],
[x['name'] for x in container_list])
self.assertNotIn(container['uuid'],
[x['uuid'] for x in container_list])
def test_show(self):
"""Check container show command with name and UUID arguments.
Test steps:
1) Create container in setUp.
2) Show container calling it with name and UUID arguments.
3) Check name, uuid and image in container show output.
"""
container = self.container_create(name='test_show')
self.container_show(container['name'])
self.assertEqual(container['name'], container['name'])
self.assertEqual(container['image'], container['image'])
self.container_delete(container['name'])