summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Chen <chenrui.momo@gmail.com>2017-06-06 21:03:33 +0800
committerDean Troyer <dtroyer@gmail.com>2017-07-20 16:39:32 +0000
commitf1d32dbe9b6f5f2e47853b9969483fa841e451f4 (patch)
tree1149b1d37c63a81caa58c9f6613f0726b9ddb3b5
parentac8cac4b63590e3b583faee88b6c481f2f3e9d9a (diff)
downloadpython-openstackclient-f1d32dbe9b6f5f2e47853b9969483fa841e451f4.tar.gz
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
-rw-r--r--openstackclient/tests/functional/common/test_extension.py1
-rw-r--r--openstackclient/tests/functional/common/test_help.py14
-rw-r--r--openstackclient/tests/functional/common/test_quota.py1
-rw-r--r--openstackclient/tests/functional/compute/v2/test_flavor.py8
-rw-r--r--openstackclient/tests/functional/compute/v2/test_server.py1
-rw-r--r--openstackclient/tests/functional/identity/v2/common.py29
-rw-r--r--openstackclient/tests/functional/identity/v3/common.py39
-rw-r--r--openstackclient/tests/functional/image/v1/test_image.py23
-rw-r--r--openstackclient/tests/functional/image/v2/test_image.py22
-rw-r--r--openstackclient/tests/functional/network/v2/common.py2
-rw-r--r--openstackclient/tests/functional/network/v2/test_floating_ip.py29
-rw-r--r--openstackclient/tests/functional/network/v2/test_ip_availability.py25
-rw-r--r--openstackclient/tests/functional/network/v2/test_network.py4
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_meter_rule.py16
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_qos_policy.py15
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_qos_rule.py65
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_rbac.py21
-rw-r--r--openstackclient/tests/functional/network/v2/test_network_segment.py13
-rw-r--r--openstackclient/tests/functional/network/v2/test_port.py13
-rw-r--r--openstackclient/tests/functional/network/v2/test_security_group.py31
-rw-r--r--openstackclient/tests/functional/network/v2/test_security_group_rule.py26
-rw-r--r--openstackclient/tests/functional/network/v2/test_subnet.py15
-rw-r--r--openstackclient/tests/functional/object/v1/test_container.py8
-rw-r--r--openstackclient/tests/functional/volume/v1/common.py11
-rw-r--r--openstackclient/tests/functional/volume/v1/test_snapshot.py9
-rw-r--r--openstackclient/tests/functional/volume/v1/test_transfer_request.py15
-rw-r--r--openstackclient/tests/functional/volume/v1/test_volume_type.py7
-rw-r--r--openstackclient/tests/functional/volume/v2/common.py11
-rw-r--r--openstackclient/tests/functional/volume/v2/test_snapshot.py11
-rw-r--r--openstackclient/tests/functional/volume/v2/test_transfer_request.py15
-rw-r--r--openstackclient/tests/functional/volume/v2/test_volume_type.py7
-rw-r--r--openstackclient/tests/functional/volume/v3/common.py11
-rw-r--r--openstackclient/tests/functional/volume/v3/test_qos.py10
-rw-r--r--openstackclient/tests/functional/volume/v3/test_snapshot.py9
-rw-r--r--openstackclient/tests/functional/volume/v3/test_transfer_request.py9
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume.py9
-rw-r--r--openstackclient/tests/functional/volume/v3/test_volume_type.py9
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 d7dc398b..e3a91fe6 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 e31d3b86..7f274099 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 1b13e95e..76c69a4d 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 0b01da51..eefd3fab 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 c9f4d62c..b7a25996 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 69ef728b..f4bc10bd 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 1ec3ac92..6d7896d8 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 901f4337..fa073f99 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 a93fa8cb..278ba5b9 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 bed07878..e3835abf 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 9e34622c..1d11fc5d 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 cb4b8150..86a53c0c 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 b23323a0..91939703 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 71b406b4..31bc0845 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 ccbf437c..53c15ecf 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 6e40d8e0..8b34422f 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 893f1993..2206761f 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 6dec82d9..b34515fa 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 14454454..09ac3566 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 6da7e204..b601c913 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 e153116b..40951a01 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 41375415..040b645b 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 af76efd9..acfbab11 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 f9d96bbb..4978cea3 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 28726762..c60472c5 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 bd612829..73191fc9 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 acad34ad..74e14070 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 1d14719f..38176714 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 2fff43c8..ba6b2c28 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 e9c2236b..33495af6 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 11acf2f8..99630e6b 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 bc8befa6..a710a683 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 a7af3c5b..a6290fc5 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 bf05b9de..38e0563a 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 7b54dd20..b3253237 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 333826d8..283b830f 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 f10e64b4..eb66515e 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'