Merge "Fix use of kwargs instead of **kwargs"
diff --git a/tempest/api/compute/security_groups/test_security_group_rules.py b/tempest/api/compute/security_groups/test_security_group_rules.py
index 901c377..45b913a 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules.py
@@ -27,13 +27,9 @@
super(SecurityGroupRulesTestJSON, cls).resource_setup()
cls.client = cls.security_groups_client
cls.neutron_available = CONF.service_available.neutron
-
- @classmethod
- def setUpClass(self):
- super(SecurityGroupRulesTestJSON, self).setUpClass()
- self.ip_protocol = 'tcp'
- self.from_port = 22
- self.to_port = 22
+ cls.ip_protocol = 'tcp'
+ cls.from_port = 22
+ cls.to_port = 22
@test.attr(type='smoke')
@test.services('network')
@@ -54,31 +50,46 @@
@test.attr(type='smoke')
@test.services('network')
- def test_security_group_rules_create_with_optional_arguments(self):
+ def test_security_group_rules_create_with_optional_cidr(self):
# Positive test: Creation of Security Group rule
- # with optional arguments
+ # with optional argument cidr
# should be successful
- secgroup1 = None
- secgroup2 = None
+ # Creating a Security Group to add rules to it
+ resp, security_group = self.create_security_group()
+ parent_group_id = security_group['id']
+
+ # Adding rules to the created Security Group with optional cidr
+ cidr = '10.2.3.124/24'
+ self.client.create_security_group_rule(parent_group_id,
+ self.ip_protocol,
+ self.from_port,
+ self.to_port,
+ cidr=cidr)
+
+ @test.attr(type='smoke')
+ @test.services('network')
+ def test_security_group_rules_create_with_optional_group_id(self):
+ # Positive test: Creation of Security Group rule
+ # with optional argument group_id
+ # should be successful
+
# Creating a Security Group to add rules to it
resp, security_group = self.create_security_group()
secgroup1 = security_group['id']
+
# Creating a Security Group so as to assign group_id to the rule
resp, security_group = self.create_security_group()
secgroup2 = security_group['id']
- # Adding rules to the created Security Group with optional arguments
+
+ # Adding rules to the created Security Group with optional group_id
parent_group_id = secgroup1
- cidr = '10.2.3.124/24'
group_id = secgroup2
- resp, rule = \
- self.client.create_security_group_rule(parent_group_id,
- self.ip_protocol,
- self.from_port,
- self.to_port,
- cidr=cidr,
- group_id=group_id)
- self.assertEqual(200, resp.status)
+ self.client.create_security_group_rule(parent_group_id,
+ self.ip_protocol,
+ self.from_port,
+ self.to_port,
+ group_id=group_id)
@test.attr(type='smoke')
@test.services('network')
diff --git a/tempest/api/network/test_security_groups.py b/tempest/api/network/test_security_groups.py
index 58ad39c..e20b58e 100644
--- a/tempest/api/network/test_security_groups.py
+++ b/tempest/api/network/test_security_groups.py
@@ -222,11 +222,11 @@
_tenant_network_cidr = CONF.network.tenant_network_v6_cidr
@classmethod
- def setUpClass(cls):
+ def resource_setup(cls):
if not CONF.network_feature_enabled.ipv6:
skip_msg = "IPv6 Tests are disabled."
raise cls.skipException(skip_msg)
- super(SecGroupIPv6Test, cls).setUpClass()
+ super(SecGroupIPv6Test, cls).resource_setup()
class SecGroupIPv6TestXML(SecGroupIPv6Test):
diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py
index 2e3091e..97e4cb7 100644
--- a/tempest/api/network/test_security_groups_negative.py
+++ b/tempest/api/network/test_security_groups_negative.py
@@ -198,11 +198,11 @@
_tenant_network_cidr = CONF.network.tenant_network_v6_cidr
@classmethod
- def setUpClass(cls):
+ def resource_setup(cls):
if not CONF.network_feature_enabled.ipv6:
skip_msg = "IPv6 Tests are disabled."
raise cls.skipException(skip_msg)
- super(NegativeSecGroupIPv6Test, cls).setUpClass()
+ super(NegativeSecGroupIPv6Test, cls).resource_setup()
class NegativeSecGroupIPv6TestXML(NegativeSecGroupIPv6Test):
diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py
index 55cc89b..6014cff 100644
--- a/tempest/hacking/checks.py
+++ b/tempest/hacking/checks.py
@@ -24,7 +24,7 @@
PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
TEST_DEFINITION = re.compile(r'^\s*def test.*')
-SETUPCLASS_DEFINITION = re.compile(r'^\s*def setUpClass')
+SETUP_TEARDOWN_CLASS_DEFINITION = re.compile(r'^\s+def (setUp|tearDown)Class')
SCENARIO_DECORATOR = re.compile(r'\s*@.*services\((.*)\)')
VI_HEADER_RE = re.compile(r"^#\s+vim?:.+")
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
@@ -58,15 +58,15 @@
"T104: Scenario tests require a service decorator")
-def no_setupclass_for_unit_tests(physical_line, filename):
+def no_setup_teardown_class_for_tests(physical_line, filename):
if pep8.noqa(physical_line):
return
- if 'tempest/tests' in filename:
- if SETUPCLASS_DEFINITION.match(physical_line):
+ if 'tempest/test.py' not in filename:
+ if SETUP_TEARDOWN_CLASS_DEFINITION.match(physical_line):
return (physical_line.find('def'),
- "T105: setUpClass can not be used with unit tests")
+ "T105: (setUp|tearDown)Class can not be used in tests")
def no_vi_headers(physical_line, line_number, lines):
@@ -119,7 +119,7 @@
def factory(register):
register(import_no_clients_in_api)
register(scenario_tests_need_service_tags)
- register(no_setupclass_for_unit_tests)
+ register(no_setup_teardown_class_for_tests)
register(no_vi_headers)
register(service_tags_not_in_module_path)
register(no_mutable_default_args)
diff --git a/tempest/stress/actions/server_create_destroy.py b/tempest/stress/actions/server_create_destroy.py
index 4a9f0d5..34e299d 100644
--- a/tempest/stress/actions/server_create_destroy.py
+++ b/tempest/stress/actions/server_create_destroy.py
@@ -28,15 +28,13 @@
def run(self):
name = data_utils.rand_name("instance")
self.logger.info("creating %s" % name)
- resp, server = self.manager.servers_client.create_server(
+ _, server = self.manager.servers_client.create_server(
name, self.image, self.flavor)
server_id = server['id']
- assert(resp.status == 202)
self.manager.servers_client.wait_for_server_status(server_id,
'ACTIVE')
self.logger.info("created %s" % server_id)
self.logger.info("deleting %s" % name)
- resp, _ = self.manager.servers_client.delete_server(server_id)
- assert(resp.status == 204)
+ self.manager.servers_client.delete_server(server_id)
self.manager.servers_client.wait_for_server_termination(server_id)
self.logger.info("deleted %s" % server_id)
diff --git a/tempest/stress/actions/ssh_floating.py b/tempest/stress/actions/ssh_floating.py
index d78112c..5bc8cac 100644
--- a/tempest/stress/actions/ssh_floating.py
+++ b/tempest/stress/actions/ssh_floating.py
@@ -74,19 +74,17 @@
self.logger.info("creating %s" % name)
vm_args = self.vm_extra_args.copy()
vm_args['security_groups'] = [self.sec_grp]
- resp, server = servers_client.create_server(name, self.image,
- self.flavor,
- **vm_args)
+ _, server = servers_client.create_server(name, self.image,
+ self.flavor,
+ **vm_args)
self.server_id = server['id']
- assert(resp.status == 202)
if self.wait_after_vm_create:
self.manager.servers_client.wait_for_server_status(self.server_id,
'ACTIVE')
def _destroy_vm(self):
self.logger.info("deleting %s" % self.server_id)
- resp, _ = self.manager.servers_client.delete_server(self.server_id)
- assert(resp.status == 204) # It cannot be 204 if I had to wait..
+ self.manager.servers_client.delete_server(self.server_id)
self.manager.servers_client.wait_for_server_termination(self.server_id)
self.logger.info("deleted %s" % self.server_id)
diff --git a/tempest/stress/actions/volume_attach_delete.py b/tempest/stress/actions/volume_attach_delete.py
index e0238d3..9c4070f 100644
--- a/tempest/stress/actions/volume_attach_delete.py
+++ b/tempest/stress/actions/volume_attach_delete.py
@@ -28,10 +28,9 @@
# Step 1: create volume
name = data_utils.rand_name("volume")
self.logger.info("creating volume: %s" % name)
- resp, volume = self.manager.volumes_client.create_volume(
+ _, volume = self.manager.volumes_client.create_volume(
size=1,
display_name=name)
- assert(resp.status == 200)
self.manager.volumes_client.wait_for_volume_status(volume['id'],
'available')
self.logger.info("created volume: %s" % volume['id'])
@@ -39,20 +38,18 @@
# Step 2: create vm instance
vm_name = data_utils.rand_name("instance")
self.logger.info("creating vm: %s" % vm_name)
- resp, server = self.manager.servers_client.create_server(
+ _, server = self.manager.servers_client.create_server(
vm_name, self.image, self.flavor)
server_id = server['id']
- assert(resp.status == 202)
self.manager.servers_client.wait_for_server_status(server_id, 'ACTIVE')
self.logger.info("created vm %s" % server_id)
# Step 3: attach volume to vm
self.logger.info("attach volume (%s) to vm %s" %
(volume['id'], server_id))
- resp, body = self.manager.servers_client.attach_volume(server_id,
- volume['id'],
- '/dev/vdc')
- assert(resp.status == 200)
+ self.manager.servers_client.attach_volume(server_id,
+ volume['id'],
+ '/dev/vdc')
self.manager.volumes_client.wait_for_volume_status(volume['id'],
'in-use')
self.logger.info("volume (%s) attached to vm %s" %
@@ -60,14 +57,12 @@
# Step 4: delete vm
self.logger.info("deleting vm: %s" % vm_name)
- resp, _ = self.manager.servers_client.delete_server(server_id)
- assert(resp.status == 204)
+ self.manager.servers_client.delete_server(server_id)
self.manager.servers_client.wait_for_server_termination(server_id)
self.logger.info("deleted vm: %s" % server_id)
# Step 5: delete volume
self.logger.info("deleting volume: %s" % volume['id'])
- resp, _ = self.manager.volumes_client.delete_volume(volume['id'])
- assert(resp.status == 202)
+ self.manager.volumes_client.delete_volume(volume['id'])
self.manager.volumes_client.wait_for_resource_deletion(volume['id'])
self.logger.info("deleted volume: %s" % volume['id'])
diff --git a/tempest/stress/actions/volume_attach_verify.py b/tempest/stress/actions/volume_attach_verify.py
index 0d3cb23..a13d890 100644
--- a/tempest/stress/actions/volume_attach_verify.py
+++ b/tempest/stress/actions/volume_attach_verify.py
@@ -24,12 +24,10 @@
def _create_keypair(self):
keyname = data_utils.rand_name("key")
- resp, self.key = self.manager.keypairs_client.create_keypair(keyname)
- assert(resp.status == 200)
+ _, self.key = self.manager.keypairs_client.create_keypair(keyname)
def _delete_keypair(self):
- resp, _ = self.manager.keypairs_client.delete_keypair(self.key['name'])
- assert(resp.status == 202)
+ self.manager.keypairs_client.delete_keypair(self.key['name'])
def _create_vm(self):
self.name = name = data_utils.rand_name("instance")
@@ -38,18 +36,16 @@
vm_args = self.vm_extra_args.copy()
vm_args['security_groups'] = [self.sec_grp]
vm_args['key_name'] = self.key['name']
- resp, server = servers_client.create_server(name, self.image,
- self.flavor,
- **vm_args)
+ _, server = servers_client.create_server(name, self.image,
+ self.flavor,
+ **vm_args)
self.server_id = server['id']
- assert(resp.status == 202)
self.manager.servers_client.wait_for_server_status(self.server_id,
'ACTIVE')
def _destroy_vm(self):
self.logger.info("deleting server: %s" % self.server_id)
- resp, _ = self.manager.servers_client.delete_server(self.server_id)
- assert(resp.status == 204) # It cannot be 204 if I had to wait..
+ self.manager.servers_client.delete_server(self.server_id)
self.manager.servers_client.wait_for_server_termination(self.server_id)
self.logger.info("deleted server: %s" % self.server_id)
@@ -81,10 +77,9 @@
name = data_utils.rand_name("volume")
self.logger.info("creating volume: %s" % name)
volumes_client = self.manager.volumes_client
- resp, self.volume = volumes_client.create_volume(
+ _, self.volume = volumes_client.create_volume(
size=1,
display_name=name)
- assert(resp.status == 200)
volumes_client.wait_for_volume_status(self.volume['id'],
'available')
self.logger.info("created volume: %s" % self.volume['id'])
@@ -92,8 +87,7 @@
def _delete_volume(self):
self.logger.info("deleting volume: %s" % self.volume['id'])
volumes_client = self.manager.volumes_client
- resp, _ = volumes_client.delete_volume(self.volume['id'])
- assert(resp.status == 202)
+ volumes_client.delete_volume(self.volume['id'])
volumes_client.wait_for_resource_deletion(self.volume['id'])
self.logger.info("deleted volume: %s" % self.volume['id'])
@@ -193,10 +187,9 @@
servers_client = self.manager.servers_client
self.logger.info("attach volume (%s) to vm %s" %
(self.volume['id'], self.server_id))
- resp, body = servers_client.attach_volume(self.server_id,
- self.volume['id'],
- self.part_name)
- assert(resp.status == 200)
+ servers_client.attach_volume(self.server_id,
+ self.volume['id'],
+ self.part_name)
self.manager.volumes_client.wait_for_volume_status(self.volume['id'],
'in-use')
if self.enable_ssh_verify:
@@ -204,9 +197,8 @@
% self.server_id)
self.part_wait(self.attach_match_count)
- resp, body = servers_client.detach_volume(self.server_id,
- self.volume['id'])
- assert(resp.status == 202)
+ servers_client.detach_volume(self.server_id,
+ self.volume['id'])
self.manager.volumes_client.wait_for_volume_status(self.volume['id'],
'available')
if self.enable_ssh_verify:
diff --git a/tempest/stress/actions/volume_create_delete.py b/tempest/stress/actions/volume_create_delete.py
index 4e75be0..b1c5bb7 100644
--- a/tempest/stress/actions/volume_create_delete.py
+++ b/tempest/stress/actions/volume_create_delete.py
@@ -20,14 +20,12 @@
name = data_utils.rand_name("volume")
self.logger.info("creating %s" % name)
volumes_client = self.manager.volumes_client
- resp, volume = volumes_client.create_volume(size=1,
- display_name=name)
- assert(resp.status == 200)
+ _, volume = volumes_client.create_volume(size=1,
+ display_name=name)
vol_id = volume['id']
volumes_client.wait_for_volume_status(vol_id, 'available')
self.logger.info("created %s" % volume['id'])
self.logger.info("deleting %s" % name)
- resp, _ = volumes_client.delete_volume(vol_id)
- assert(resp.status == 202)
+ volumes_client.delete_volume(vol_id)
volumes_client.wait_for_resource_deletion(vol_id)
self.logger.info("deleted %s" % vol_id)
diff --git a/tempest/test.py b/tempest/test.py
index adc1d37..2ed6665 100644
--- a/tempest/test.py
+++ b/tempest/test.py
@@ -66,35 +66,6 @@
return decorator
-def safe_setup(f):
- """A decorator used to wrap the setUpClass for cleaning up resources
- when setUpClass failed.
-
- Deprecated, see:
- http://specs.openstack.org/openstack/qa-specs/specs/resource-cleanup.html
- """
- @functools.wraps(f)
- def decorator(cls):
- try:
- f(cls)
- except Exception as se:
- etype, value, trace = sys.exc_info()
- if etype is cls.skipException:
- LOG.info("setUpClass skipped: %s:" % se)
- else:
- LOG.exception("setUpClass failed: %s" % se)
- try:
- cls.tearDownClass()
- except Exception as te:
- LOG.exception("tearDownClass failed: %s" % te)
- try:
- raise etype(value), None, trace
- finally:
- del trace # for avoiding circular refs
-
- return decorator
-
-
def get_service_list():
service_list = {
'compute': CONF.service_available.nova,
diff --git a/tempest/tests/common/utils/test_misc.py b/tempest/tests/common/utils/test_misc.py
index aee9805..554027f 100644
--- a/tempest/tests/common/utils/test_misc.py
+++ b/tempest/tests/common/utils/test_misc.py
@@ -82,7 +82,7 @@
self.assertEqual(':tearDown', tearDown())
def test_find_test_caller_teardown_class(self):
- def tearDownClass(cls):
+ def tearDownClass(cls): # noqa
return misc.find_test_caller()
self.assertEqual('TestMisc:tearDownClass',
tearDownClass(self.__class__))
diff --git a/tempest/tests/test_hacking.py b/tempest/tests/test_hacking.py
index 37ad18e..6857461 100644
--- a/tempest/tests/test_hacking.py
+++ b/tempest/tests/test_hacking.py
@@ -47,13 +47,27 @@
just assertTrue if the check is expected to fail and assertFalse if it
should pass.
"""
- def test_no_setupclass_for_unit_tests(self):
- self.assertTrue(checks.no_setupclass_for_unit_tests(
+ def test_no_setup_teardown_class_for_tests(self):
+ self.assertTrue(checks.no_setup_teardown_class_for_tests(
" def setUpClass(cls):", './tempest/tests/fake_test.py'))
- self.assertIsNone(checks.no_setupclass_for_unit_tests(
+ self.assertIsNone(checks.no_setup_teardown_class_for_tests(
" def setUpClass(cls): # noqa", './tempest/tests/fake_test.py'))
- self.assertFalse(checks.no_setupclass_for_unit_tests(
+ self.assertTrue(checks.no_setup_teardown_class_for_tests(
" def setUpClass(cls):", './tempest/api/fake_test.py'))
+ self.assertTrue(checks.no_setup_teardown_class_for_tests(
+ " def setUpClass(cls):", './tempest/scenario/fake_test.py'))
+ self.assertFalse(checks.no_setup_teardown_class_for_tests(
+ " def setUpClass(cls):", './tempest/test.py'))
+ self.assertTrue(checks.no_setup_teardown_class_for_tests(
+ " def tearDownClass(cls):", './tempest/tests/fake_test.py'))
+ self.assertIsNone(checks.no_setup_teardown_class_for_tests(
+ " def tearDownClass(cls): # noqa", './tempest/tests/fake_test.py'))
+ self.assertTrue(checks.no_setup_teardown_class_for_tests(
+ " def tearDownClass(cls):", './tempest/api/fake_test.py'))
+ self.assertTrue(checks.no_setup_teardown_class_for_tests(
+ " def tearDownClass(cls):", './tempest/scenario/fake_test.py'))
+ self.assertFalse(checks.no_setup_teardown_class_for_tests(
+ " def tearDownClass(cls):", './tempest/test.py'))
def test_import_no_clients_in_api(self):
for client in checks.PYTHON_CLIENTS: