Cleanup the containers at zunclient funtional tests
- Force delete containers. - Consolidate _zun & _zun_osc method. Closes-Bug: #1695992 Change-Id: Ice6d4e00612fb092caeb59b15393d3c37ca4f49d
This commit is contained in:
parent
3a3f4535b9
commit
4f75b4a719
@ -121,19 +121,29 @@ class FunctionalTestBase(base.ClientTestBase):
|
|||||||
return base.execute(cmd, action, flags, params,
|
return base.execute(cmd, action, flags, params,
|
||||||
cli_dir=self.client.cli_dir)
|
cli_dir=self.client.cli_dir)
|
||||||
|
|
||||||
def _zun(self, action, flags='', params=''):
|
def _zun(self, action, cmd='zun', flags='', params='', merge_stderr=False):
|
||||||
"""Execute zun command for the given action.
|
"""Execute Zun command for the given action.
|
||||||
|
|
||||||
:param action: the cli command to run using Container
|
:param action: the cli command to run using Zun
|
||||||
|
:type action: string
|
||||||
|
:param cmd: the base of cli command to run
|
||||||
:type action: string
|
:type action: string
|
||||||
:param flags: any optional cli flags to use
|
:param flags: any optional cli flags to use
|
||||||
:type flags: string
|
:type flags: string
|
||||||
:param params: any optional positional args to use
|
:param params: any optional positional args to use
|
||||||
:type params: string
|
:type params: string
|
||||||
|
:param merge_stderr: whether to merge stderr into the result
|
||||||
|
:type merge_stderr: bool
|
||||||
"""
|
"""
|
||||||
flags += ' --os-endpoint-type publicURL'
|
if cmd == 'openstack':
|
||||||
|
config = self._get_config()
|
||||||
|
id_api_version = config['os_identity_api_version']
|
||||||
|
flags += ' --os-identity-api-version {0}'.format(id_api_version)
|
||||||
|
else:
|
||||||
|
flags += ' --os-endpoint-type publicURL'
|
||||||
|
|
||||||
if hasattr(self, 'os_auth_token'):
|
if hasattr(self, 'os_auth_token'):
|
||||||
return self._cmd_no_auth('appcontainer', action, flags, params)
|
return self._cmd_no_auth(cmd, action, flags, params)
|
||||||
else:
|
else:
|
||||||
for keystone_object in 'user', 'project':
|
for keystone_object in 'user', 'project':
|
||||||
domain_attr = 'os_%s_domain_id' % keystone_object
|
domain_attr = 'os_%s_domain_id' % keystone_object
|
||||||
@ -142,24 +152,8 @@ class FunctionalTestBase(base.ClientTestBase):
|
|||||||
'ks_obj': keystone_object,
|
'ks_obj': keystone_object,
|
||||||
'value': getattr(self, domain_attr)
|
'value': getattr(self, domain_attr)
|
||||||
}
|
}
|
||||||
return self.client.cmd_with_auth('zun',
|
return self.client.cmd_with_auth(
|
||||||
action, flags, params)
|
cmd, action, flags, params, merge_stderr=merge_stderr)
|
||||||
|
|
||||||
def _zun_osc(self, action, flags='', params=''):
|
|
||||||
"""Execute container commands via OpenStack Client."""
|
|
||||||
config = self._get_config()
|
|
||||||
identity_api_version = config.get('os_identity_api_version')
|
|
||||||
flags += ' --os-identity-api-version {0}'.format(identity_api_version)
|
|
||||||
|
|
||||||
for keystone_object in 'user', 'project':
|
|
||||||
domain_attr = 'os_%s_domain_id' % keystone_object
|
|
||||||
if hasattr(self, domain_attr):
|
|
||||||
flags += ' --os-%(ks_obj)s-domain-id %(value)s' % {
|
|
||||||
'ks_obj': keystone_object,
|
|
||||||
'value': getattr(self, domain_attr)
|
|
||||||
}
|
|
||||||
return self.client.cmd_with_auth(
|
|
||||||
'openstack', action, flags, params)
|
|
||||||
|
|
||||||
def zun(self, action, flags='', params='', parse=True):
|
def zun(self, action, flags='', params='', parse=True):
|
||||||
"""Return parsed list of dicts with basic item info.
|
"""Return parsed list of dicts with basic item info.
|
||||||
|
@ -21,7 +21,7 @@ from zunclient.tests.functional import base
|
|||||||
class TestCase(base.FunctionalTestBase):
|
class TestCase(base.FunctionalTestBase):
|
||||||
|
|
||||||
def openstack(self, *args, **kwargs):
|
def openstack(self, *args, **kwargs):
|
||||||
return self._zun_osc(*args, **kwargs)
|
return self._zun(cmd='openstack', *args, **kwargs)
|
||||||
|
|
||||||
def get_opts(self, fields=None, output_format='json'):
|
def get_opts(self, fields=None, output_format='json'):
|
||||||
"""Get options for OSC output fields format.
|
"""Get options for OSC output fields format.
|
||||||
@ -77,7 +77,8 @@ class TestCase(base.FunctionalTestBase):
|
|||||||
self.fail('Container has not run!')
|
self.fail('Container has not run!')
|
||||||
return container
|
return container
|
||||||
|
|
||||||
def container_delete(self, identifier, ignore_exceptions=False):
|
def container_delete(self, identifier, force=True,
|
||||||
|
ignore_exceptions=False):
|
||||||
"""Try to delete container by name or UUID.
|
"""Try to delete container by name or UUID.
|
||||||
|
|
||||||
:param String identifier: Name or UUID of the container
|
:param String identifier: Name or UUID of the container
|
||||||
@ -86,9 +87,10 @@ class TestCase(base.FunctionalTestBase):
|
|||||||
:raise: CommandFailed exception when command fails
|
:raise: CommandFailed exception when command fails
|
||||||
to delete a container
|
to delete a container
|
||||||
"""
|
"""
|
||||||
|
arg = '--force' if force else ''
|
||||||
try:
|
try:
|
||||||
return self.openstack('appcontainer delete {0}'
|
return self.openstack('appcontainer delete {0} {1}'
|
||||||
.format(identifier))
|
.format(arg, identifier))
|
||||||
except exceptions.CommandFailed:
|
except exceptions.CommandFailed:
|
||||||
if not ignore_exceptions:
|
if not ignore_exceptions:
|
||||||
raise
|
raise
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import ddt
|
import ddt
|
||||||
from tempest.lib.common.utils import data_utils
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from zunclient.tests.functional.osc.v1 import base
|
from zunclient.tests.functional.osc.v1 import base
|
||||||
@ -30,7 +29,7 @@ class ContainerTests(base.TestCase):
|
|||||||
"""Check container list command.
|
"""Check container list command.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
container = self.container_create(name='test')
|
container = self.container_create(name='test_list')
|
||||||
container_list = self.container_list()
|
container_list = self.container_list()
|
||||||
self.assertIn(container['name'], [x['name'] for x in
|
self.assertIn(container['name'], [x['name'] for x in
|
||||||
container_list])
|
container_list])
|
||||||
@ -44,12 +43,11 @@ class ContainerTests(base.TestCase):
|
|||||||
"""Check container create command.
|
"""Check container create command.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
name = data_utils.rand_name('test_container')
|
container_info = self.container_create(name='test_create')
|
||||||
container_info = self.container_create(name=name)
|
self.assertEqual(container_info['name'], 'test_create')
|
||||||
self.assertEqual(container_info['name'], name)
|
|
||||||
self.assertEqual(container_info['image'], 'cirros')
|
self.assertEqual(container_info['image'], 'cirros')
|
||||||
container_list = self.container_list()
|
container_list = self.container_list()
|
||||||
self.assertIn(name, [x['name'] for x in container_list])
|
self.assertIn('test_create', [x['name'] for x in container_list])
|
||||||
self.container_delete(container_info['name'])
|
self.container_delete(container_info['name'])
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
@ -58,9 +56,9 @@ class ContainerTests(base.TestCase):
|
|||||||
Test steps:
|
Test steps:
|
||||||
1) Create container in setUp.
|
1) Create container in setUp.
|
||||||
2) Delete container by name/UUID.
|
2) Delete container by name/UUID.
|
||||||
3) Check that node deleted successfully.
|
3) Check that container deleted successfully.
|
||||||
"""
|
"""
|
||||||
container = self.container_create(name='test_del')
|
container = self.container_create(name='test_delete')
|
||||||
container_list = self.container_list()
|
container_list = self.container_list()
|
||||||
self.assertIn(container['name'],
|
self.assertIn(container['name'],
|
||||||
[x['name'] for x in container_list])
|
[x['name'] for x in container_list])
|
||||||
@ -109,6 +107,7 @@ class ContainerTests(base.TestCase):
|
|||||||
self.container_rename(container['name'], new_name)
|
self.container_rename(container['name'], new_name)
|
||||||
container_list = self.container_list()
|
container_list = self.container_list()
|
||||||
self.assertIn(new_name, [x['name'] for x in container_list])
|
self.assertIn(new_name, [x['name'] for x in container_list])
|
||||||
|
self.container_delete(new_name)
|
||||||
|
|
||||||
def test_execute(self):
|
def test_execute(self):
|
||||||
"""Check container execute command with name and UUID arguments.
|
"""Check container execute command with name and UUID arguments.
|
||||||
@ -131,3 +130,4 @@ class ContainerTests(base.TestCase):
|
|||||||
command = "sh -c 'echo hello'"
|
command = "sh -c 'echo hello'"
|
||||||
result = self.container_execute(container['name'], command)
|
result = self.container_execute(container['name'], command)
|
||||||
self.assertIn('hello', result)
|
self.assertIn('hello', result)
|
||||||
|
self.container_delete(container['name'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user