From f1d32dbe9b6f5f2e47853b9969483fa841e451f4 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Tue, 6 Jun 2017 21:03:33 +0800 Subject: [PATCH] Clean up the changes of os.environ in functional tests Use fixtures to restore the API version changes of os.environ in each functional tests, aims to avoid the following test cases failing in unexpected context. And make sure setUpClass/tearDownClass call super class's corresponding methods first. Change-Id: Ie248fe9d3a9e25f1b076c9f2c363200f29a83817 Closes-Bug: #1696080 --- .../tests/functional/common/test_extension.py | 1 + .../tests/functional/common/test_help.py | 14 ++-- .../tests/functional/common/test_quota.py | 1 + .../functional/compute/v2/test_flavor.py | 8 ++- .../functional/compute/v2/test_server.py | 1 + .../tests/functional/identity/v2/common.py | 29 +++++++-- .../tests/functional/identity/v3/common.py | 39 +++++++---- .../tests/functional/image/v1/test_image.py | 23 +++++-- .../tests/functional/image/v2/test_image.py | 22 +++++-- .../tests/functional/network/v2/common.py | 2 +- .../functional/network/v2/test_floating_ip.py | 29 +++++---- .../network/v2/test_ip_availability.py | 25 +++---- .../functional/network/v2/test_network.py | 4 +- .../network/v2/test_network_meter_rule.py | 16 +++-- .../network/v2/test_network_qos_policy.py | 15 +++-- .../network/v2/test_network_qos_rule.py | 65 +++++++++++-------- .../network/v2/test_network_rbac.py | 21 +++--- .../network/v2/test_network_segment.py | 13 ++-- .../tests/functional/network/v2/test_port.py | 13 ++-- .../network/v2/test_security_group.py | 31 +++++---- .../network/v2/test_security_group_rule.py | 26 ++++---- .../functional/network/v2/test_subnet.py | 15 +++-- .../functional/object/v1/test_container.py | 8 ++- .../tests/functional/volume/v1/common.py | 11 ++-- .../functional/volume/v1/test_snapshot.py | 9 ++- .../volume/v1/test_transfer_request.py | 15 +++-- .../functional/volume/v1/test_volume_type.py | 7 +- .../tests/functional/volume/v2/common.py | 11 ++-- .../functional/volume/v2/test_snapshot.py | 11 ++-- .../volume/v2/test_transfer_request.py | 15 +++-- .../functional/volume/v2/test_volume_type.py | 7 +- .../tests/functional/volume/v3/common.py | 11 ++-- .../tests/functional/volume/v3/test_qos.py | 10 +-- .../functional/volume/v3/test_snapshot.py | 9 +-- .../volume/v3/test_transfer_request.py | 9 +-- .../tests/functional/volume/v3/test_volume.py | 9 +-- .../functional/volume/v3/test_volume_type.py | 9 +-- 37 files changed, 336 insertions(+), 228 deletions(-) diff --git a/openstackclient/tests/functional/common/test_extension.py b/openstackclient/tests/functional/common/test_extension.py index d7dc398b5e..e3a91fe657 100644 --- a/openstackclient/tests/functional/common/test_extension.py +++ b/openstackclient/tests/functional/common/test_extension.py @@ -25,6 +25,7 @@ class ExtensionTests(base.TestCase): @classmethod def setUpClass(cls): + super(ExtensionTests, cls).setUpClass() cls.haz_network = base.is_service_enabled('network') def test_extension_list_compute(self): diff --git a/openstackclient/tests/functional/common/test_help.py b/openstackclient/tests/functional/common/test_help.py index e31d3b869c..7f27409956 100644 --- a/openstackclient/tests/functional/common/test_help.py +++ b/openstackclient/tests/functional/common/test_help.py @@ -12,6 +12,8 @@ import os +import fixtures + from openstackclient.tests.functional import base @@ -76,10 +78,11 @@ class HelpTests(base.TestCase): def test_commands_help_no_auth(self): """Check help commands without auth info.""" - # Pop all auth info - auth_info = {key: os.environ.pop(key) - for key in os.environ.keys() - if key.startswith('OS_')} + # Pop all auth info. os.environ will be changed in loop, so do not + # replace os.environ.keys() to os.environ + for key in os.environ.keys(): + if key.startswith('OS_'): + self.useFixture(fixtures.EnvironmentVariable(key, None)) raw_output = self.openstack('help') self.assertIn('usage: openstack', raw_output) @@ -115,6 +118,3 @@ class HelpTests(base.TestCase): self.assertIn('List containers', raw_output) raw_output = self.openstack('container list --help') self.assertIn('List containers', raw_output) - - # Restore auth info - os.environ.update(auth_info) diff --git a/openstackclient/tests/functional/common/test_quota.py b/openstackclient/tests/functional/common/test_quota.py index 1b13e95ed2..76c69a4d03 100644 --- a/openstackclient/tests/functional/common/test_quota.py +++ b/openstackclient/tests/functional/common/test_quota.py @@ -26,6 +26,7 @@ class QuotaTests(base.TestCase): @classmethod def setUpClass(cls): + super(QuotaTests, cls).setUpClass() cls.haz_network = base.is_service_enabled('network') cls.PROJECT_NAME =\ cls.get_openstack_configuration_value('auth.project_name') diff --git a/openstackclient/tests/functional/compute/v2/test_flavor.py b/openstackclient/tests/functional/compute/v2/test_flavor.py index 0b01da5172..eefd3fabd0 100644 --- a/openstackclient/tests/functional/compute/v2/test_flavor.py +++ b/openstackclient/tests/functional/compute/v2/test_flavor.py @@ -23,6 +23,7 @@ class FlavorTests(base.TestCase): @classmethod def setUpClass(cls): + super(FlavorTests, cls).setUpClass() # Make a project cmd_output = json.loads(cls.openstack( "project create -f json --enable " + cls.PROJECT_NAME @@ -31,8 +32,11 @@ class FlavorTests(base.TestCase): @classmethod def tearDownClass(cls): - raw_output = cls.openstack("project delete " + cls.PROJECT_NAME) - cls.assertOutput('', raw_output) + try: + raw_output = cls.openstack("project delete " + cls.PROJECT_NAME) + cls.assertOutput('', raw_output) + finally: + super(FlavorTests, cls).tearDownClass() def test_flavor_delete(self): """Test create w/project, delete multiple""" diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py index c9f4d62c85..b7a2599674 100644 --- a/openstackclient/tests/functional/compute/v2/test_server.py +++ b/openstackclient/tests/functional/compute/v2/test_server.py @@ -25,6 +25,7 @@ class ServerTests(common.ComputeTestCase): @classmethod def setUpClass(cls): + super(ServerTests, cls).setUpClass() cls.haz_network = base.is_service_enabled('network') def test_server_list(self): diff --git a/openstackclient/tests/functional/identity/v2/common.py b/openstackclient/tests/functional/identity/v2/common.py index 69ef728b15..f4bc10bddd 100644 --- a/openstackclient/tests/functional/identity/v2/common.py +++ b/openstackclient/tests/functional/identity/v2/common.py @@ -12,6 +12,7 @@ import os +import fixtures from tempest.lib.common.utils import data_utils from tempest.lib import exceptions as tempest_exceptions @@ -41,17 +42,13 @@ class IdentityTests(base.TestCase): @classmethod def setUpClass(cls): - # prepare v2 env - os.environ['OS_IDENTITY_API_VERSION'] = '2.0' - auth_url = os.environ.get('OS_AUTH_URL') - if auth_url: - os.environ['OS_AUTH_URL'] = auth_url.replace('v3', 'v2.0') - + super(IdentityTests, cls).setUpClass() # create dummy project cls.project_name = data_utils.rand_name('TestProject') cls.project_description = data_utils.rand_name('description') try: cls.openstack( + '--os-identity-api-version 2 ' 'project create ' '--description %(description)s ' '--enable ' @@ -69,7 +66,25 @@ class IdentityTests(base.TestCase): @classmethod def tearDownClass(cls): - cls.openstack('project delete %s' % cls.project_name) + try: + cls.openstack( + '--os-identity-api-version 2 ' + 'project delete %s' % cls.project_name) + finally: + super(IdentityTests, cls).tearDownClass() + + def setUp(self): + super(IdentityTests, self).setUp() + # prepare v2 env + ver_fixture = fixtures.EnvironmentVariable( + 'OS_IDENTITY_API_VERSION', '2.0') + self.useFixture(ver_fixture) + auth_url = os.environ.get('OS_AUTH_URL') + if auth_url: + auth_url_fixture = fixtures.EnvironmentVariable( + 'OS_AUTH_URL', auth_url.replace('v3', 'v2.0') + ) + self.useFixture(auth_url_fixture) def _create_dummy_project(self, add_clean_up=True): project_name = data_utils.rand_name('TestProject') diff --git a/openstackclient/tests/functional/identity/v3/common.py b/openstackclient/tests/functional/identity/v3/common.py index 1ec3ac9281..6d7896d8fe 100644 --- a/openstackclient/tests/functional/identity/v3/common.py +++ b/openstackclient/tests/functional/identity/v3/common.py @@ -12,6 +12,7 @@ import os +import fixtures from tempest.lib.common.utils import data_utils from openstackclient.tests.functional import base @@ -53,16 +54,12 @@ class IdentityTests(base.TestCase): @classmethod def setUpClass(cls): - # prepare v3 env - os.environ['OS_IDENTITY_API_VERSION'] = '3' - auth_url = os.environ.get('OS_AUTH_URL') - if auth_url: - os.environ['OS_AUTH_URL'] = auth_url.replace('v2.0', 'v3') - + super(IdentityTests, cls).setUpClass() # create dummy domain cls.domain_name = data_utils.rand_name('TestDomain') cls.domain_description = data_utils.rand_name('description') cls.openstack( + '--os-identity-api-version 3 ' 'domain create ' '--description %(description)s ' '--enable ' @@ -73,6 +70,7 @@ class IdentityTests(base.TestCase): cls.project_name = data_utils.rand_name('TestProject') cls.project_description = data_utils.rand_name('description') cls.openstack( + '--os-identity-api-version 3 ' 'project create ' '--domain %(domain)s ' '--description %(description)s ' @@ -83,11 +81,30 @@ class IdentityTests(base.TestCase): @classmethod def tearDownClass(cls): - # delete dummy project - cls.openstack('project delete %s' % cls.project_name) - # disable and delete dummy domain - cls.openstack('domain set --disable %s' % cls.domain_name) - cls.openstack('domain delete %s' % cls.domain_name) + try: + # delete dummy project + cls.openstack('--os-identity-api-version 3 ' + 'project delete %s' % cls.project_name) + # disable and delete dummy domain + cls.openstack('--os-identity-api-version 3 ' + 'domain set --disable %s' % cls.domain_name) + cls.openstack('--os-identity-api-version 3 ' + 'domain delete %s' % cls.domain_name) + finally: + super(IdentityTests, cls).tearDownClass() + + def setUp(self): + super(IdentityTests, self).setUp() + # prepare v3 env + ver_fixture = fixtures.EnvironmentVariable( + 'OS_IDENTITY_API_VERSION', '3') + self.useFixture(ver_fixture) + auth_url = os.environ.get('OS_AUTH_URL') + if auth_url: + auth_url_fixture = fixtures.EnvironmentVariable( + 'OS_AUTH_URL', auth_url.replace('v2.0', 'v3') + ) + self.useFixture(auth_url_fixture) def _create_dummy_user(self, add_clean_up=True): username = data_utils.rand_name('TestUser') diff --git a/openstackclient/tests/functional/image/v1/test_image.py b/openstackclient/tests/functional/image/v1/test_image.py index 901f4337a4..fa073f99a3 100644 --- a/openstackclient/tests/functional/image/v1/test_image.py +++ b/openstackclient/tests/functional/image/v1/test_image.py @@ -11,9 +11,10 @@ # under the License. import json -import os import uuid +import fixtures + from openstackclient.tests.functional import base @@ -25,8 +26,9 @@ class ImageTests(base.TestCase): @classmethod def setUpClass(cls): - os.environ['OS_IMAGE_API_VERSION'] = '1' + super(ImageTests, cls).setUpClass() json_output = json.loads(cls.openstack( + '--os-image-api-version 1 ' 'image create -f json ' + cls.NAME )) @@ -35,10 +37,21 @@ class ImageTests(base.TestCase): @classmethod def tearDownClass(cls): - cls.openstack( - 'image delete ' + - cls.image_id + try: + cls.openstack( + '--os-image-api-version 1 ' + 'image delete ' + + cls.image_id + ) + finally: + super(ImageTests, cls).tearDownClass() + + def setUp(self): + super(ImageTests, self).setUp() + ver_fixture = fixtures.EnvironmentVariable( + 'OS_IMAGE_API_VERSION', '1' ) + self.useFixture(ver_fixture) def test_image_list(self): json_output = json.loads(self.openstack( diff --git a/openstackclient/tests/functional/image/v2/test_image.py b/openstackclient/tests/functional/image/v2/test_image.py index a93fa8cbee..278ba5b948 100644 --- a/openstackclient/tests/functional/image/v2/test_image.py +++ b/openstackclient/tests/functional/image/v2/test_image.py @@ -11,9 +11,9 @@ # under the License. import json -import os import uuid +import fixtures # from glanceclient import exc as image_exceptions from openstackclient.tests.functional import base @@ -27,8 +27,9 @@ class ImageTests(base.TestCase): @classmethod def setUpClass(cls): - os.environ['OS_IMAGE_API_VERSION'] = '2' + super(ImageTests, cls).setUpClass() json_output = json.loads(cls.openstack( + '--os-image-api-version 2 ' 'image create -f json ' + cls.NAME )) @@ -37,10 +38,21 @@ class ImageTests(base.TestCase): @classmethod def tearDownClass(cls): - cls.openstack( - 'image delete ' + - cls.image_id + try: + cls.openstack( + '--os-image-api-version 2 ' + 'image delete ' + + cls.image_id + ) + finally: + super(ImageTests, cls).tearDownClass() + + def setUp(self): + super(ImageTests, self).setUp() + ver_fixture = fixtures.EnvironmentVariable( + 'OS_IMAGE_API_VERSION', '2' ) + self.useFixture(ver_fixture) def test_image_list(self): json_output = json.loads(self.openstack( diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py index bed07878f6..e3835abf59 100644 --- a/openstackclient/tests/functional/network/v2/common.py +++ b/openstackclient/tests/functional/network/v2/common.py @@ -18,5 +18,5 @@ class NetworkTests(base.TestCase): @classmethod def setUpClass(cls): - # super(NetworkTests, cls).setUp() + super(NetworkTests, cls).setUpClass() cls.haz_network = base.is_service_enabled('network') diff --git a/openstackclient/tests/functional/network/v2/test_floating_ip.py b/openstackclient/tests/functional/network/v2/test_floating_ip.py index 9e34622cf4..1d11fc5d2d 100644 --- a/openstackclient/tests/functional/network/v2/test_floating_ip.py +++ b/openstackclient/tests/functional/network/v2/test_floating_ip.py @@ -88,19 +88,22 @@ class FloatingIpTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - del_output = cls.openstack( - 'subnet delete ' + - cls.EXTERNAL_SUBNET_NAME + ' ' + - cls.PRIVATE_SUBNET_NAME - ) - cls.assertOutput('', del_output) - del_output = cls.openstack( - 'network delete ' + - cls.EXTERNAL_NETWORK_NAME + ' ' + - cls.PRIVATE_NETWORK_NAME - ) - cls.assertOutput('', del_output) + try: + if cls.haz_network: + del_output = cls.openstack( + 'subnet delete ' + + cls.EXTERNAL_SUBNET_NAME + ' ' + + cls.PRIVATE_SUBNET_NAME + ) + cls.assertOutput('', del_output) + del_output = cls.openstack( + 'network delete ' + + cls.EXTERNAL_NETWORK_NAME + ' ' + + cls.PRIVATE_NETWORK_NAME + ) + cls.assertOutput('', del_output) + finally: + super(FloatingIpTests, cls).tearDownClass() def setUp(self): super(FloatingIpTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_ip_availability.py b/openstackclient/tests/functional/network/v2/test_ip_availability.py index cb4b8150ab..86a53c0ce0 100644 --- a/openstackclient/tests/functional/network/v2/test_ip_availability.py +++ b/openstackclient/tests/functional/network/v2/test_ip_availability.py @@ -41,17 +41,20 @@ class IPAvailabilityTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_subnet = cls.openstack( - 'subnet delete ' + - cls.NAME - ) - raw_network = cls.openstack( - 'network delete ' + - cls.NETWORK_NAME - ) - cls.assertOutput('', raw_subnet) - cls.assertOutput('', raw_network) + try: + if cls.haz_network: + raw_subnet = cls.openstack( + 'subnet delete ' + + cls.NAME + ) + raw_network = cls.openstack( + 'network delete ' + + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_subnet) + cls.assertOutput('', raw_network) + finally: + super(IPAvailabilityTests, cls).tearDownClass() def setUp(self): super(IPAvailabilityTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_network.py b/openstackclient/tests/functional/network/v2/test_network.py index b23323a00e..91939703d1 100644 --- a/openstackclient/tests/functional/network/v2/test_network.py +++ b/openstackclient/tests/functional/network/v2/test_network.py @@ -361,7 +361,7 @@ class NetworkTests(common.NetworkTests): self.assertNotIn(name2, col_name) def test_network_dhcp_agent(self): - if self.haz_network: + if not self.haz_network: self.skipTest("No Network service present") name1 = uuid.uuid4().hex @@ -408,7 +408,7 @@ class NetworkTests(common.NetworkTests): def test_network_set(self): """Tests create options, set, show, delete""" - if self.haz_network: + if not self.haz_network: self.skipTest("No Network service present") name = uuid.uuid4().hex diff --git a/openstackclient/tests/functional/network/v2/test_network_meter_rule.py b/openstackclient/tests/functional/network/v2/test_network_meter_rule.py index 71b406b46e..31bc08453b 100644 --- a/openstackclient/tests/functional/network/v2/test_network_meter_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_meter_rule.py @@ -39,13 +39,15 @@ class TestMeterRule(common.NetworkTests): @classmethod def tearDownClass(cls): - common.NetworkTests.tearDownClass() - if cls.haz_network: - raw_output = cls.openstack( - 'network meter delete ' + - cls.METER_ID - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network meter delete ' + + cls.METER_ID + ) + cls.assertOutput('', raw_output) + finally: + common.NetworkTests.tearDownClass() def setUp(self): super(TestMeterRule, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_policy.py b/openstackclient/tests/functional/network/v2/test_network_qos_policy.py index ccbf437c3b..53c15ecf69 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_policy.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_policy.py @@ -39,12 +39,15 @@ class NetworkQosPolicyTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network qos policy delete ' + - cls.NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network qos policy delete ' + + cls.NAME + ) + cls.assertOutput('', raw_output) + finally: + super(NetworkQosPolicyTests, cls).tearDownClass() def setUp(self): super(NetworkQosPolicyTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py index 6e40d8e0d9..8b34422fb1 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py @@ -51,17 +51,20 @@ class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network qos rule delete ' + - cls.QOS_POLICY_NAME + ' ' + - cls.RULE_ID - ) - cls.openstack( - 'network qos policy delete ' + - cls.QOS_POLICY_NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network qos rule delete ' + + cls.QOS_POLICY_NAME + ' ' + + cls.RULE_ID + ) + cls.openstack( + 'network qos policy delete ' + + cls.QOS_POLICY_NAME + ) + cls.assertOutput('', raw_output) + finally: + super(NetworkQosRuleTestsMinimumBandwidth, cls).tearDownClass() def setUp(self): super(NetworkQosRuleTestsMinimumBandwidth, self).setUp() @@ -123,14 +126,18 @@ class NetworkQosRuleTestsDSCPMarking(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network qos rule delete ' + - cls.QOS_POLICY_NAME + ' ' + - cls.RULE_ID - ) - cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network qos rule delete ' + + cls.QOS_POLICY_NAME + ' ' + + cls.RULE_ID + ) + cls.openstack( + 'network qos policy delete ' + cls.QOS_POLICY_NAME) + cls.assertOutput('', raw_output) + finally: + super(NetworkQosRuleTestsDSCPMarking, cls).tearDownClass() def setUp(self): super(NetworkQosRuleTestsDSCPMarking, self).setUp() @@ -198,14 +205,18 @@ class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network qos rule delete ' + - cls.QOS_POLICY_NAME + ' ' + - cls.RULE_ID - ) - cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network qos rule delete ' + + cls.QOS_POLICY_NAME + ' ' + + cls.RULE_ID + ) + cls.openstack( + 'network qos policy delete ' + cls.QOS_POLICY_NAME) + cls.assertOutput('', raw_output) + finally: + super(NetworkQosRuleTestsBandwidthLimit, cls).tearDownClass() def setUp(self): super(NetworkQosRuleTestsBandwidthLimit, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_network_rbac.py b/openstackclient/tests/functional/network/v2/test_network_rbac.py index 893f199397..2206761f04 100644 --- a/openstackclient/tests/functional/network/v2/test_network_rbac.py +++ b/openstackclient/tests/functional/network/v2/test_network_rbac.py @@ -47,15 +47,18 @@ class NetworkRBACTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output_rbac = cls.openstack( - 'network rbac delete ' + cls.ID - ) - raw_output_network = cls.openstack( - 'network delete ' + cls.OBJECT_ID - ) - cls.assertOutput('', raw_output_rbac) - cls.assertOutput('', raw_output_network) + try: + if cls.haz_network: + raw_output_rbac = cls.openstack( + 'network rbac delete ' + cls.ID + ) + raw_output_network = cls.openstack( + 'network delete ' + cls.OBJECT_ID + ) + cls.assertOutput('', raw_output_rbac) + cls.assertOutput('', raw_output_network) + finally: + super(NetworkRBACTests, cls).tearDownClass() def setUp(self): super(NetworkRBACTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_network_segment.py b/openstackclient/tests/functional/network/v2/test_network_segment.py index 6dec82d9e3..b34515fa41 100644 --- a/openstackclient/tests/functional/network/v2/test_network_segment.py +++ b/openstackclient/tests/functional/network/v2/test_network_segment.py @@ -55,11 +55,14 @@ class NetworkSegmentTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network delete ' + cls.NETWORK_NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network delete ' + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_output) + finally: + super(NetworkSegmentTests, cls).tearDownClass() def setUp(self): super(NetworkSegmentTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py index 14454454e4..09ac3566e4 100644 --- a/openstackclient/tests/functional/network/v2/test_port.py +++ b/openstackclient/tests/functional/network/v2/test_port.py @@ -33,11 +33,14 @@ class PortTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network delete ' + cls.NETWORK_NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network delete ' + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_output) + finally: + super(PortTests, cls).tearDownClass() def setUp(self): super(PortTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_security_group.py b/openstackclient/tests/functional/network/v2/test_security_group.py index 6da7e204d8..b601c913fd 100644 --- a/openstackclient/tests/functional/network/v2/test_security_group.py +++ b/openstackclient/tests/functional/network/v2/test_security_group.py @@ -38,20 +38,23 @@ class SecurityGroupTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - # Rename test - raw_output = cls.openstack( - 'security group set --name ' + - cls.OTHER_NAME + ' ' + - cls.NAME - ) - cls.assertOutput('', raw_output) - # Delete test - raw_output = cls.openstack( - 'security group delete ' + - cls.OTHER_NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + # Rename test + raw_output = cls.openstack( + 'security group set --name ' + + cls.OTHER_NAME + ' ' + + cls.NAME + ) + cls.assertOutput('', raw_output) + # Delete test + raw_output = cls.openstack( + 'security group delete ' + + cls.OTHER_NAME + ) + cls.assertOutput('', raw_output) + finally: + super(SecurityGroupTests, cls).tearDownClass() def setUp(self): super(SecurityGroupTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_security_group_rule.py b/openstackclient/tests/functional/network/v2/test_security_group_rule.py index e153116b14..40951a011d 100644 --- a/openstackclient/tests/functional/network/v2/test_security_group_rule.py +++ b/openstackclient/tests/functional/network/v2/test_security_group_rule.py @@ -51,18 +51,20 @@ class SecurityGroupRuleTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'security group rule delete ' + - cls.SECURITY_GROUP_RULE_ID - ) - cls.assertOutput('', raw_output) - - raw_output = cls.openstack( - 'security group delete ' + - cls.SECURITY_GROUP_NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'security group rule delete ' + + cls.SECURITY_GROUP_RULE_ID + ) + cls.assertOutput('', raw_output) + raw_output = cls.openstack( + 'security group delete ' + + cls.SECURITY_GROUP_NAME + ) + cls.assertOutput('', raw_output) + finally: + super(SecurityGroupRuleTests, cls).tearDownClass() def setUp(self): super(SecurityGroupRuleTests, self).setUp() diff --git a/openstackclient/tests/functional/network/v2/test_subnet.py b/openstackclient/tests/functional/network/v2/test_subnet.py index 413754157a..040b645b1b 100644 --- a/openstackclient/tests/functional/network/v2/test_subnet.py +++ b/openstackclient/tests/functional/network/v2/test_subnet.py @@ -36,12 +36,15 @@ class SubnetTests(common.NetworkTests): @classmethod def tearDownClass(cls): - if cls.haz_network: - raw_output = cls.openstack( - 'network delete ' + - cls.NETWORK_NAME - ) - cls.assertOutput('', raw_output) + try: + if cls.haz_network: + raw_output = cls.openstack( + 'network delete ' + + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_output) + finally: + super(SubnetTests, cls).tearDownClass() def setUp(self): super(SubnetTests, self).setUp() diff --git a/openstackclient/tests/functional/object/v1/test_container.py b/openstackclient/tests/functional/object/v1/test_container.py index af76efd96c..acfbab11de 100644 --- a/openstackclient/tests/functional/object/v1/test_container.py +++ b/openstackclient/tests/functional/object/v1/test_container.py @@ -21,14 +21,18 @@ class ContainerTests(base.TestCase): @classmethod def setUpClass(cls): + super(ContainerTests, cls).setUpClass() opts = cls.get_opts(['container']) raw_output = cls.openstack('container create ' + cls.NAME + opts) cls.assertOutput(cls.NAME + '\n', raw_output) @classmethod def tearDownClass(cls): - raw_output = cls.openstack('container delete ' + cls.NAME) - cls.assertOutput('', raw_output) + try: + raw_output = cls.openstack('container delete ' + cls.NAME) + cls.assertOutput('', raw_output) + finally: + super(ContainerTests, cls).tearDownClass() def test_container_list(self): opts = self.get_opts(['Name']) diff --git a/openstackclient/tests/functional/volume/v1/common.py b/openstackclient/tests/functional/volume/v1/common.py index f9d96bbb6c..4978cea31c 100644 --- a/openstackclient/tests/functional/volume/v1/common.py +++ b/openstackclient/tests/functional/volume/v1/common.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import os +import fixtures from openstackclient.tests.functional.volume import base @@ -18,6 +18,9 @@ from openstackclient.tests.functional.volume import base class BaseVolumeTests(base.BaseVolumeTests): """Base class for Volume functional tests. """ - @classmethod - def setUpClass(cls): - os.environ['OS_VOLUME_API_VERSION'] = '1' + def setUp(self): + super(BaseVolumeTests, self).setUp() + ver_fixture = fixtures.EnvironmentVariable( + 'OS_VOLUME_API_VERSION', '1' + ) + self.useFixture(ver_fixture) diff --git a/openstackclient/tests/functional/volume/v1/test_snapshot.py b/openstackclient/tests/functional/volume/v1/test_snapshot.py index 28726762d7..c60472c55e 100644 --- a/openstackclient/tests/functional/volume/v1/test_snapshot.py +++ b/openstackclient/tests/functional/volume/v1/test_snapshot.py @@ -35,9 +35,12 @@ class VolumeSnapshotTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - cls.wait_for_status('volume', cls.VOLLY, 'available') - raw_output = cls.openstack('volume delete --force ' + cls.VOLLY) - cls.assertOutput('', raw_output) + try: + cls.wait_for_status('volume', cls.VOLLY, 'available') + raw_output = cls.openstack('volume delete --force ' + cls.VOLLY) + cls.assertOutput('', raw_output) + finally: + super(VolumeSnapshotTests, cls).tearDownClass() def test_volume_snapshot__delete(self): """Test create, delete multiple""" diff --git a/openstackclient/tests/functional/volume/v1/test_transfer_request.py b/openstackclient/tests/functional/volume/v1/test_transfer_request.py index bd6128295e..73191fc9d2 100644 --- a/openstackclient/tests/functional/volume/v1/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v1/test_transfer_request.py @@ -37,12 +37,15 @@ class TransferRequestTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - raw_output_transfer = cls.openstack( - 'volume transfer request delete ' + cls.NAME) - raw_output_volume = cls.openstack( - 'volume delete ' + cls.VOLUME_NAME) - cls.assertOutput('', raw_output_transfer) - cls.assertOutput('', raw_output_volume) + try: + raw_output_transfer = cls.openstack( + 'volume transfer request delete ' + cls.NAME) + raw_output_volume = cls.openstack( + 'volume delete ' + cls.VOLUME_NAME) + cls.assertOutput('', raw_output_transfer) + cls.assertOutput('', raw_output_volume) + finally: + super(TransferRequestTests, cls).tearDownClass() def test_volume_transfer_request_accept(self): volume_name = uuid.uuid4().hex diff --git a/openstackclient/tests/functional/volume/v1/test_volume_type.py b/openstackclient/tests/functional/volume/v1/test_volume_type.py index acad34add3..74e1407003 100644 --- a/openstackclient/tests/functional/volume/v1/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v1/test_volume_type.py @@ -31,8 +31,11 @@ class VolumeTypeTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - raw_output = cls.openstack('volume type delete ' + cls.NAME) - cls.assertOutput('', raw_output) + try: + raw_output = cls.openstack('volume type delete ' + cls.NAME) + cls.assertOutput('', raw_output) + finally: + super(VolumeTypeTests, cls).tearDownClass() def test_volume_type_list(self): cmd_output = json.loads(self.openstack('volume type list -f json')) diff --git a/openstackclient/tests/functional/volume/v2/common.py b/openstackclient/tests/functional/volume/v2/common.py index 1d14719fc7..3817671425 100644 --- a/openstackclient/tests/functional/volume/v2/common.py +++ b/openstackclient/tests/functional/volume/v2/common.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import os +import fixtures from openstackclient.tests.functional.volume import base @@ -18,6 +18,9 @@ from openstackclient.tests.functional.volume import base class BaseVolumeTests(base.BaseVolumeTests): """Base class for Volume functional tests. """ - @classmethod - def setUpClass(cls): - os.environ['OS_VOLUME_API_VERSION'] = '2' + def setUp(self): + super(BaseVolumeTests, self).setUp() + ver_fixture = fixtures.EnvironmentVariable( + 'OS_VOLUME_API_VERSION', '2' + ) + self.useFixture(ver_fixture) diff --git a/openstackclient/tests/functional/volume/v2/test_snapshot.py b/openstackclient/tests/functional/volume/v2/test_snapshot.py index 2fff43c820..ba6b2c2837 100644 --- a/openstackclient/tests/functional/volume/v2/test_snapshot.py +++ b/openstackclient/tests/functional/volume/v2/test_snapshot.py @@ -35,10 +35,13 @@ class VolumeSnapshotTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - cls.wait_for_status('volume', cls.VOLLY, 'available') - raw_output = cls.openstack( - 'volume delete --force ' + cls.VOLLY) - cls.assertOutput('', raw_output) + try: + cls.wait_for_status('volume', cls.VOLLY, 'available') + raw_output = cls.openstack( + 'volume delete --force ' + cls.VOLLY) + cls.assertOutput('', raw_output) + finally: + super(VolumeSnapshotTests, cls).tearDownClass() def test_volume_snapshot__delete(self): """Test create, delete multiple""" diff --git a/openstackclient/tests/functional/volume/v2/test_transfer_request.py b/openstackclient/tests/functional/volume/v2/test_transfer_request.py index e9c2236b7d..33495af637 100644 --- a/openstackclient/tests/functional/volume/v2/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v2/test_transfer_request.py @@ -38,12 +38,15 @@ class TransferRequestTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - raw_output_transfer = cls.openstack( - 'volume transfer request delete ' + cls.NAME) - raw_output_volume = cls.openstack( - 'volume delete ' + cls.VOLUME_NAME) - cls.assertOutput('', raw_output_transfer) - cls.assertOutput('', raw_output_volume) + try: + raw_output_transfer = cls.openstack( + 'volume transfer request delete ' + cls.NAME) + raw_output_volume = cls.openstack( + 'volume delete ' + cls.VOLUME_NAME) + cls.assertOutput('', raw_output_transfer) + cls.assertOutput('', raw_output_volume) + finally: + super(TransferRequestTests, cls).tearDownClass() def test_volume_transfer_request_accept(self): volume_name = uuid.uuid4().hex diff --git a/openstackclient/tests/functional/volume/v2/test_volume_type.py b/openstackclient/tests/functional/volume/v2/test_volume_type.py index 11acf2f8a7..99630e6b04 100644 --- a/openstackclient/tests/functional/volume/v2/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v2/test_volume_type.py @@ -31,8 +31,11 @@ class VolumeTypeTests(common.BaseVolumeTests): @classmethod def tearDownClass(cls): - raw_output = cls.openstack('volume type delete ' + cls.NAME) - cls.assertOutput('', raw_output) + try: + raw_output = cls.openstack('volume type delete ' + cls.NAME) + cls.assertOutput('', raw_output) + finally: + super(VolumeTypeTests, cls).tearDownClass() def test_volume_type_list(self): cmd_output = json.loads(self.openstack('volume type list -f json')) diff --git a/openstackclient/tests/functional/volume/v3/common.py b/openstackclient/tests/functional/volume/v3/common.py index bc8befa67d..a710a6835c 100644 --- a/openstackclient/tests/functional/volume/v3/common.py +++ b/openstackclient/tests/functional/volume/v3/common.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -import os +import fixtures from openstackclient.tests.functional.volume import base @@ -18,6 +18,9 @@ from openstackclient.tests.functional.volume import base class BaseVolumeTests(base.BaseVolumeTests): """Base class for Volume functional tests. """ - @classmethod - def setUpClass(cls): - os.environ['OS_VOLUME_API_VERSION'] = '3' + def setUp(self): + super(BaseVolumeTests, self).setUp() + ver_fixture = fixtures.EnvironmentVariable( + 'OS_VOLUME_API_VERSION', '3' + ) + self.useFixture(ver_fixture) diff --git a/openstackclient/tests/functional/volume/v3/test_qos.py b/openstackclient/tests/functional/volume/v3/test_qos.py index a7af3c5b97..a6290fc531 100644 --- a/openstackclient/tests/functional/volume/v3/test_qos.py +++ b/openstackclient/tests/functional/volume/v3/test_qos.py @@ -10,15 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. -import os - from openstackclient.tests.functional.volume.v2 import test_qos as v2 +from openstackclient.tests.functional.volume.v3 import common -class QosTests(v2.QosTests): +class QosTests(common.BaseVolumeTests, v2.QosTests): """Functional tests for volume qos. """ - - @classmethod - def setUpClass(cls): - super(QosTests, cls).setUpClass() - os.environ['OS_VOLUME_API_VERSION'] = '3' diff --git a/openstackclient/tests/functional/volume/v3/test_snapshot.py b/openstackclient/tests/functional/volume/v3/test_snapshot.py index bf05b9de9d..38e0563a7c 100644 --- a/openstackclient/tests/functional/volume/v3/test_snapshot.py +++ b/openstackclient/tests/functional/volume/v3/test_snapshot.py @@ -11,13 +11,8 @@ # under the License. from openstackclient.tests.functional.volume.v2 import test_snapshot as v2 -import os +from openstackclient.tests.functional.volume.v3 import common -class VolumeSnapshotTests(v2.VolumeSnapshotTests): +class VolumeSnapshotTests(common.BaseVolumeTests, v2.VolumeSnapshotTests): """Functional tests for volume snapshot. """ - - @classmethod - def setUpClass(cls): - super(VolumeSnapshotTests, cls).setUpClass() - os.environ['OS_VOLUME_API_VERSION'] = '3' diff --git a/openstackclient/tests/functional/volume/v3/test_transfer_request.py b/openstackclient/tests/functional/volume/v3/test_transfer_request.py index 7b54dd20f5..b325323752 100644 --- a/openstackclient/tests/functional/volume/v3/test_transfer_request.py +++ b/openstackclient/tests/functional/volume/v3/test_transfer_request.py @@ -12,13 +12,8 @@ from openstackclient.tests.functional.volume.v2 import test_transfer_request \ as v2 -import os +from openstackclient.tests.functional.volume.v3 import common -class TransferRequestTests(v2.TransferRequestTests): +class TransferRequestTests(common.BaseVolumeTests, v2.TransferRequestTests): """Functional tests for transfer request. """ - - @classmethod - def setUpClass(cls): - super(TransferRequestTests, cls).setUpClass() - os.environ['OS_VOLUME_API_VERSION'] = '3' diff --git a/openstackclient/tests/functional/volume/v3/test_volume.py b/openstackclient/tests/functional/volume/v3/test_volume.py index 333826d833..283b830f63 100644 --- a/openstackclient/tests/functional/volume/v3/test_volume.py +++ b/openstackclient/tests/functional/volume/v3/test_volume.py @@ -11,13 +11,8 @@ # under the License. from openstackclient.tests.functional.volume.v2 import test_volume as v2 -import os +from openstackclient.tests.functional.volume.v3 import common -class VolumeTests(v2.VolumeTests): +class VolumeTests(common.BaseVolumeTests, v2.VolumeTests): """Functional tests for volume. """ - - @classmethod - def setUpClass(cls): - super(VolumeTests, cls).setUpClass() - os.environ['OS_VOLUME_API_VERSION'] = '3' diff --git a/openstackclient/tests/functional/volume/v3/test_volume_type.py b/openstackclient/tests/functional/volume/v3/test_volume_type.py index f10e64b426..eb66515ed1 100644 --- a/openstackclient/tests/functional/volume/v3/test_volume_type.py +++ b/openstackclient/tests/functional/volume/v3/test_volume_type.py @@ -11,13 +11,8 @@ # under the License. from openstackclient.tests.functional.volume.v2 import test_volume_type as v2 -import os +from openstackclient.tests.functional.volume.v3 import common -class VolumeTypeTests(v2.VolumeTypeTests): +class VolumeTypeTests(common.BaseVolumeTests, v2.VolumeTypeTests): """Functional tests for volume type. """ - - @classmethod - def setUpClass(cls): - super(VolumeTypeTests, cls).setUpClass() - os.environ['OS_VOLUME_API_VERSION'] = '3'