[ci] Use pseudo-random names for new resources

Random names of resources makes the task impossible to find a test which
doesn't clean resources after a launch.

This patch changes name_generate method to generate names including a name
of the test, which can be really helpful.

Also, the simple script that prints resources after test run is added.

Change-Id: Id3a743afb624dd4bf8ed3523a1916455fd93655a
This commit is contained in:
Andrey Kurilin 2017-07-03 13:26:27 +03:00
parent a8e4521b67
commit 00ffdef3d5
16 changed files with 91 additions and 62 deletions

View File

@ -373,13 +373,20 @@ class ClientTestBase(testtools.TestCase):
else:
self.fail("The resource '%s' still exists." % resource.id)
def name_generate(self, prefix='Entity'):
"""Generate randomized name for some entity.
:param prefix: string prefix
"""
name = "%s-%s" % (prefix, uuidutils.generate_uuid())
return name
def name_generate(self):
"""Generate randomized name for some entity."""
# NOTE(andreykurilin): name_generator method is used for various
# resources (servers, flavors, volumes, keystone users, etc).
# Since the length of name has limits we cannot use the whole UUID,
# so the first 8 chars is taken from it.
# Based on the fact that the new name includes class and method
# names, 8 chars of uuid should be enough to prevent any conflicts,
# even if the single test will be launched in parallel thousand times
return "%(prefix)s-%(test_cls)s-%(test_name)s" % {
"prefix": uuidutils.generate_uuid()[:8],
"test_cls": self.__class__.__name__,
"test_name": self.id().rsplit(".", 1)[-1]
}
def _get_value_from_the_table(self, table, key):
"""Parses table to get desired value.
@ -470,7 +477,7 @@ class ClientTestBase(testtools.TestCase):
def _create_server(self, name=None, flavor=None, with_network=True,
add_cleanup=True, **kwargs):
name = name or self.name_generate(prefix='server')
name = name or self.name_generate()
if with_network:
nics = [{"net-id": self.network.id}]
else:
@ -521,8 +528,8 @@ class TenantTestBase(ClientTestBase):
def setUp(self):
super(TenantTestBase, self).setUp()
user_name = self.name_generate('v' + self.COMPUTE_API_VERSION)
project_name = self.name_generate('v' + self.COMPUTE_API_VERSION)
user_name = uuidutils.generate_uuid()
project_name = uuidutils.generate_uuid()
password = 'password'
if self.keystone.version == "v3":

View File

@ -0,0 +1,30 @@
# 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 novaclient.tests.functional import base
class ResourceChecker(base.ClientTestBase):
def runTest(self):
pass
def check(self):
self.setUp()
print("$ nova list --all-tenants")
print(self.nova("list", params="--all-tenants"))
print("\n")
if __name__ == "__main__":
ResourceChecker().check()

View File

@ -29,7 +29,7 @@ class TestFlvAccessNovaClient(base.TenantTestBase):
# Check that non-public flavor appears in flavor list
# only for admin tenant and only with --all attribute
# and doesn't appear for non-admin tenant
flv_name = self.name_generate(prefix='flv')
flv_name = self.name_generate()
self.nova('flavor-create --is-public false %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
flavor_list1 = self.nova('flavor-list')
@ -42,7 +42,7 @@ class TestFlvAccessNovaClient(base.TenantTestBase):
def test_add_access_non_public_flavor(self):
# Check that it's allowed to grant an access to non-public flavor for
# the given tenant
flv_name = self.name_generate(prefix='flv')
flv_name = self.name_generate()
self.nova('flavor-create --is-public false %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
self.nova('flavor-access-add', params="%s %s" %
@ -55,7 +55,7 @@ class TestFlvAccessNovaClient(base.TenantTestBase):
# successfully for public flavor, but the next operation,
# 'flavor-access-list --flavor %(name_of_public_flavor)' returns
# a CommandError
flv_name = self.name_generate(prefix='flv')
flv_name = self.name_generate()
self.nova('flavor-create %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
self.nova('flavor-access-add %s %s' % (flv_name, self.project_id))

View File

@ -37,7 +37,7 @@ class TestInstanceCLI(base.ClientTestBase):
destroy.
"""
name = self.name_generate('Instance')
name = self.name_generate()
# Boot via the cli, as we're primarily testing the cli in this test
self.nova('boot',

View File

@ -12,7 +12,6 @@
import tempfile
from oslo_utils import uuidutils
from tempest.lib import exceptions
from novaclient.tests.functional import base
@ -36,7 +35,7 @@ class TestKeypairsNovaClient(base.ClientTestBase):
return key_name
def _raw_create_keypair(self, **kwargs):
key_name = 'keypair-' + uuidutils.generate_uuid()
key_name = self.name_generate()
kwargs_str = self._serialize_kwargs(kwargs)
self.nova('keypair-add %s %s' % (kwargs_str, key_name))
return key_name

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import uuidutils
from novaclient.tests.functional import base
@ -22,7 +20,7 @@ class TestServerGroupClient(base.ClientTestBase):
COMPUTE_API_VERSION = "2.1"
def _create_sg(self, policy):
sg_name = 'server_group-' + uuidutils.generate_uuid()
sg_name = self.name_generate()
output = self.nova('server-group-create %s %s' % (sg_name, policy))
sg_id = self._get_column_value_from_single_row_table(output, "Id")
return sg_id

View File

@ -13,7 +13,6 @@
import datetime
from oslo_utils import timeutils
from oslo_utils import uuidutils
from novaclient.tests.functional import base
@ -25,7 +24,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
def _boot_server_with_legacy_bdm(self, bdm_params=()):
volume_size = 1
volume_name = uuidutils.generate_uuid()
volume_name = self.name_generate()
volume = self.cinder.volumes.create(size=volume_size,
name=volume_name,
imageRef=self.image.id)
@ -43,7 +42,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
params = (
"%(name)s --flavor %(flavor)s --poll "
"--block-device-mapping vda=%(volume_id)s%(bdm_params)s" % {
"name": uuidutils.generate_uuid(), "flavor":
"name": self.name_generate(), "flavor":
self.flavor.id,
"volume_id": volume.id,
"bdm_params": bdm_params})
@ -73,7 +72,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
def test_boot_server_with_net_name(self):
server_info = self.nova("boot", params=(
"%(name)s --flavor %(flavor)s --image %(image)s --poll "
"--nic net-name=%(net-name)s" % {"name": uuidutils.generate_uuid(),
"--nic net-name=%(net-name)s" % {"name": self.name_generate(),
"image": self.image.id,
"flavor": self.flavor.id,
"net-name": self.network.name}))
@ -133,7 +132,7 @@ class TestServersListNovaClient(base.ClientTestBase):
return [self._create_server(name) for i in range(number)]
def test_list_with_limit(self):
name = uuidutils.generate_uuid()
name = self.name_generate()
self._create_servers(name, 2)
output = self.nova("list", params="--limit 1 --name %s" % name)
# Cut header and footer of the table
@ -142,7 +141,7 @@ class TestServersListNovaClient(base.ClientTestBase):
def test_list_with_changes_since(self):
now = datetime.datetime.isoformat(timeutils.utcnow())
name = uuidutils.generate_uuid()
name = self.name_generate()
self._create_servers(name, 1)
output = self.nova("list", params="--changes-since %s" % now)
self.assertIn(name, output, output)
@ -151,7 +150,7 @@ class TestServersListNovaClient(base.ClientTestBase):
self.assertNotIn(name, output, output)
def test_list_all_servers(self):
name = uuidutils.generate_uuid()
name = self.name_generate()
precreated_servers = self._create_servers(name, 3)
# there are no possibility to exceed the limit on API side, so just
# check that "-1" limit processes by novaclient side
@ -161,13 +160,12 @@ class TestServersListNovaClient(base.ClientTestBase):
self.assertIn(server.id, output)
def test_list_minimal(self):
name = uuidutils.generate_uuid()
uuid = self._create_server(name).id
server = self._create_server()
server_output = self.nova("list --minimal")
# The only fields output are "ID" and "Name"
output_uuid = self._get_column_value_from_single_row_table(
server_output, 'ID')
output_name = self._get_column_value_from_single_row_table(
server_output, 'Name')
self.assertEqual(output_uuid, uuid)
self.assertEqual(output_name, name)
self.assertEqual(output_uuid, server.id)
self.assertEqual(output_name, server.name)

View File

@ -34,13 +34,13 @@ class TestUsageCLI(base.ClientTestBase):
def test_usage(self):
before = self._get_num_servers_from_usage_output()
self._create_server('some-server')
self._create_server()
after = self._get_num_servers_from_usage_output()
self.assertGreater(after, before)
def test_usage_tenant(self):
before = self._get_num_servers_by_tenant_from_usage_output()
self._create_server('some-server')
self._create_server()
after = self._get_num_servers_by_tenant_from_usage_output()
self.assertGreater(after, before)
@ -51,8 +51,8 @@ class TestUsageClient(base.ClientTestBase):
def _create_servers_in_time_window(self):
start = datetime.datetime.now()
self._create_server('some-server')
self._create_server('another-server')
self._create_server()
self._create_server()
end = datetime.datetime.now()
return start, end

View File

@ -11,8 +11,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import uuidutils
from novaclient.tests.functional import base
@ -21,8 +19,8 @@ class TestAggregatesNovaClient(base.ClientTestBase):
def setUp(self):
super(TestAggregatesNovaClient, self).setUp()
self.agg1 = 'agg-%s' % uuidutils.generate_uuid()
self.agg2 = 'agg-%s' % uuidutils.generate_uuid()
self.agg1 = self.name_generate()
self.agg2 = self.name_generate()
self.addCleanup(self._clean_aggregates)
def _clean_aggregates(self):

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import uuidutils
import six
from tempest.lib import exceptions
@ -33,7 +32,7 @@ class TestBlockDeviceTaggingCLIError(base.ClientTestBase):
'--nic net-id=%(net-uuid)s '
'--block-device '
'source=image,dest=volume,id=%(image)s,size=1,bootindex=0,'
'shutdown=remove,tag=bar' % {'name': uuidutils.generate_uuid(),
'shutdown=remove,tag=bar' % {'name': self.name_generate(),
'flavor': self.flavor.id,
'net-uuid': self.network.id,
'image': self.image.id}))
@ -63,7 +62,7 @@ class TestNICDeviceTaggingCLIError(base.ClientTestBase):
'--nic net-id=%(net-uuid)s,tag=foo '
'--block-device '
'source=image,dest=volume,id=%(image)s,size=1,bootindex=0,'
'shutdown=remove' % {'name': uuidutils.generate_uuid(),
'shutdown=remove' % {'name': self.name_generate(),
'flavor': self.flavor.id,
'net-uuid': self.network.id,
'image': self.image.id}))
@ -90,7 +89,7 @@ class TestBlockDeviceTaggingCLI(base.ClientTestBase):
'--nic net-id=%(net-uuid)s '
'--block-device '
'source=image,dest=volume,id=%(image)s,size=1,bootindex=0,'
'shutdown=remove,tag=bar' % {'name': uuidutils.generate_uuid(),
'shutdown=remove,tag=bar' % {'name': self.name_generate(),
'flavor': self.flavor.id,
'net-uuid': self.network.id,
'image': self.image.id}))
@ -112,7 +111,7 @@ class TestNICDeviceTaggingCLI(base.ClientTestBase):
'--nic net-id=%(net-uuid)s,tag=foo '
'--block-device '
'source=image,dest=volume,id=%(image)s,size=1,bootindex=0,'
'shutdown=remove' % {'name': uuidutils.generate_uuid(),
'shutdown=remove' % {'name': self.name_generate(),
'flavor': self.flavor.id,
'net-uuid': self.network.id,
'image': self.image.id}))

View File

@ -22,7 +22,7 @@ class TestFlvAccessNovaClientV27(test_flavor_access.TestFlvAccessNovaClient):
COMPUTE_API_VERSION = "2.7"
def test_add_access_public_flavor(self):
flv_name = self.name_generate('v' + self.COMPUTE_API_VERSION)
flv_name = self.name_generate()
self.nova('flavor-create %s auto 512 1 1' % flv_name)
self.addCleanup(self.nova, 'flavor-delete %s' % flv_name)
output = self.nova('flavor-access-add %s %s' %

View File

@ -50,7 +50,7 @@ class TestKeypairsNovaClientV210(base.TenantTestBase):
COMPUTE_API_VERSION = "2.10"
def test_create_and_list_keypair(self):
name = self.name_generate("v2_10")
name = self.name_generate()
self.nova("keypair-add %s --user %s" % (name, self.user_id))
self.addCleanup(self.another_nova, "keypair-delete %s" % name)
output = self.nova("keypair-list")
@ -71,7 +71,7 @@ class TestKeypairsNovaClientV210(base.TenantTestBase):
self._get_value_from_the_table(output_1, "user_id"))
def test_create_and_delete(self):
name = self.name_generate("v2_10")
name = self.name_generate()
def cleanup():
# We should check keypair existence and remove it from correct user
@ -101,7 +101,7 @@ class TestKeypairsNovaClientV235(base.TenantTestBase):
def test_create_and_list_keypair_with_marker_and_limit(self):
names = []
for i in range(3):
names.append(self.name_generate("v2_35"))
names.append(self.name_generate())
self.nova("keypair-add %s --user %s" % (names[i], self.user_id))
self.addCleanup(self.another_nova, "keypair-delete %s" % names[i])

View File

@ -66,8 +66,7 @@ class TestServersResize(base.ClientTestBase):
"""Tests creating a server and resizes up and confirms the resize.
Compares quota before, during and after the resize.
"""
server_id = self._create_server('resize-up-confirm',
flavor=self.flavor.id).id
server_id = self._create_server(flavor=self.flavor.id).id
# get the starting quota now that we've created a server
starting_usage = self._get_absolute_limits()
# now resize up
@ -95,16 +94,14 @@ class TestServersResize(base.ClientTestBase):
smaller flavor.
"""
output = self.nova('flavor-create',
params='resize-larger-flavor auto 128 0 1')
params='%s auto 128 0 1' % self.name_generate())
larger_id = self._get_column_value_from_single_row_table(output, "ID")
self.addCleanup(
self.nova, 'flavor-delete', params='resize-larger-flavor')
self.addCleanup(self.nova, 'flavor-delete', params=larger_id)
output = self.nova('flavor-create',
params='resize-smaller-flavor auto 64 0 1')
params='%s auto 64 0 1' % self.name_generate())
smaller_id = self._get_column_value_from_single_row_table(output, "ID")
self.addCleanup(
self.nova, 'flavor-delete', params='resize-smaller-flavor')
self.addCleanup(self.nova, 'flavor-delete', params=smaller_id)
return larger_id, smaller_id
@ -117,8 +114,7 @@ class TestServersResize(base.ClientTestBase):
# create our own flavors.
larger_flavor, smaller_flavor = self._create_resize_down_flavors()
# Now create the server with the larger flavor.
server_id = self._create_server('resize-down-revert',
flavor=larger_flavor).id
server_id = self._create_server(flavor=larger_flavor).id
# get the starting quota now that we've created a server
starting_usage = self._get_absolute_limits()
# now resize down

View File

@ -231,7 +231,7 @@ class TestServersAutoAllocateNetworkCLI(base.ClientTestBase):
self.skipTest('multiple networks available')
server_info = self.nova('boot', params=(
'%(name)s --flavor %(flavor)s --poll '
'--image %(image)s ' % {'name': self.name_generate('server'),
'--image %(image)s ' % {'name': self.name_generate(),
'flavor': self.flavor.id,
'image': self.image.id}))
server_id = self._get_value_from_the_table(server_info, 'id')
@ -251,7 +251,7 @@ class TestServersAutoAllocateNetworkCLI(base.ClientTestBase):
server_info = self.nova('boot', params=(
'%(name)s --flavor %(flavor)s --poll '
'--image %(image)s --nic none' %
{'name': self.name_generate('server'),
{'name': self.name_generate(),
'flavor': self.flavor.id,
'image': self.image.id}))
server_id = self._get_value_from_the_table(server_info, 'id')

View File

@ -119,7 +119,7 @@ class TestTriggerCrashDumpNovaClientV217(base.TenantTestBase):
self._assert_nmi(server.id)
def test_trigger_crash_dump_in_locked_state_nonadmin(self):
name = self.name_generate(prefix='server')
name = self.name_generate()
server = self.another_nova('boot --flavor %s --image %s --poll %s' %
(self.flavor.name, self.image.name, name))
self.addCleanup(self.another_nova, 'delete', params=name)

View File

@ -46,7 +46,9 @@ passenv = OS_NOVACLIENT_TEST_NETWORK
setenv =
{[testenv]setenv}
OS_TEST_PATH = ./novaclient/tests/functional
commands = bash tools/pretty_tox.sh '--concurrency=1 {posargs}'
commands =
bash tools/pretty_tox.sh '--concurrency=1 {posargs}'
python novaclient/tests/functional/hooks/check_resources.py
[testenv:functional-py35]
basepython = python3.5
@ -54,7 +56,9 @@ passenv = OS_NOVACLIENT_TEST_NETWORK
setenv =
{[testenv]setenv}
OS_TEST_PATH = ./novaclient/tests/functional
commands = bash tools/pretty_tox.sh '--concurrency=1 {posargs}'
commands =
bash tools/pretty_tox.sh '--concurrency=1 {posargs}'
python novaclient/tests/functional/hooks/check_resources.py
[testenv:cover]
commands =