diff --git a/openstackclient/tests/functional/network/v2/test_floating_ip.py b/openstackclient/tests/functional/network/v2/test_floating_ip.py index 5da0e474ca..ccb954e954 100644 --- a/openstackclient/tests/functional/network/v2/test_floating_ip.py +++ b/openstackclient/tests/functional/network/v2/test_floating_ip.py @@ -14,10 +14,10 @@ import random import re import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class FloatingIpTests(base.TestCase): +class FloatingIpTests(common.NetworkTests): """Functional tests for floating ip""" SUBNET_NAME = uuid.uuid4().hex NETWORK_NAME = uuid.uuid4().hex @@ -28,78 +28,97 @@ class FloatingIpTests(base.TestCase): @classmethod def setUpClass(cls): - # Set up some regex for matching below - cls.re_id = re.compile("id\s+\|\s+(\S+)") - cls.re_floating_ip = re.compile("floating_ip_address\s+\|\s+(\S+)") - cls.re_fixed_ip = re.compile("fixed_ip_address\s+\|\s+(\S+)") - cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|") - cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)") - cls.re_port_id = re.compile("\s+id\s+\|\s+(\S+)") - cls.re_fp_port_id = re.compile("\s+port_id\s+\|\s+(\S+)") + common.NetworkTests.setUpClass() + if cls.haz_network: + # Set up some regex for matching below + cls.re_id = re.compile("id\s+\|\s+(\S+)") + cls.re_floating_ip = re.compile("floating_ip_address\s+\|\s+(\S+)") + cls.re_fixed_ip = re.compile("fixed_ip_address\s+\|\s+(\S+)") + cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|") + cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)") + cls.re_port_id = re.compile("\s+id\s+\|\s+(\S+)") + cls.re_fp_port_id = re.compile("\s+port_id\s+\|\s+(\S+)") - # Create a network for the floating ip - raw_output = cls.openstack( - 'network create --external ' + cls.NETWORK_NAME - ) - cls.network_id = re.search(cls.re_id, raw_output).group(1) + # Create a network for the floating ip + raw_output = cls.openstack( + 'network create --external ' + cls.NETWORK_NAME + ) + cls.network_id = re.search(cls.re_id, raw_output).group(1) - # Create a private network for the port - raw_output = cls.openstack( - 'network create ' + cls.PRIVATE_NETWORK_NAME - ) - cls.private_network_id = re.search(cls.re_id, raw_output).group(1) + # Create a private network for the port + raw_output = cls.openstack( + 'network create ' + cls.PRIVATE_NETWORK_NAME + ) + cls.private_network_id = re.search(cls.re_id, raw_output).group(1) - # Try random subnet range for subnet creating - # Because we can not determine ahead of time what subnets are already - # in use, possibly by another test running in parallel, try 4 times - for i in range(4): - # Make a random subnet - cls.subnet = ".".join(map( - str, - (random.randint(0, 223) for _ in range(3)) - )) + ".0/26" - cls.private_subnet = ".".join(map( - str, - (random.randint(0, 223) for _ in range(3)) - )) + ".0/26" - try: - # Create a subnet for the network - raw_output = cls.openstack( - 'subnet create ' + - '--network ' + cls.NETWORK_NAME + ' ' + - '--subnet-range ' + cls.subnet + ' ' + - cls.SUBNET_NAME - ) - # Create a subnet for the private network - priv_raw_output = cls.openstack( - 'subnet create ' + - '--network ' + cls.PRIVATE_NETWORK_NAME + ' ' + - '--subnet-range ' + cls.private_subnet + ' ' + - cls.PRIVATE_SUBNET_NAME - ) - except Exception: - if (i == 3): - # raise the exception at the last time - raise - pass - else: - # break and no longer retry if create sucessfully - break + # Try random subnet range for subnet creating + # Because we can not determine ahead of time what subnets are + # already in use, possibly by another test running in parallel, + # try 4 times + for i in range(4): + # Make a random subnet + cls.subnet = ".".join(map( + str, + (random.randint(0, 223) for _ in range(3)) + )) + ".0/26" + cls.private_subnet = ".".join(map( + str, + (random.randint(0, 223) for _ in range(3)) + )) + ".0/26" + try: + # Create a subnet for the network + raw_output = cls.openstack( + 'subnet create ' + + '--network ' + cls.NETWORK_NAME + ' ' + + '--subnet-range ' + cls.subnet + ' ' + + cls.SUBNET_NAME + ) + # Create a subnet for the private network + priv_raw_output = cls.openstack( + 'subnet create ' + + '--network ' + cls.PRIVATE_NETWORK_NAME + ' ' + + '--subnet-range ' + cls.private_subnet + ' ' + + cls.PRIVATE_SUBNET_NAME + ) + except Exception: + if (i == 3): + # raise the exception at the last time + raise + pass + else: + # break and no longer retry if create sucessfully + break - cls.subnet_id = re.search(cls.re_id, raw_output).group(1) - cls.private_subnet_id = re.search(cls.re_id, priv_raw_output).group(1) + cls.subnet_id = re.search(cls.re_id, raw_output).group(1) + cls.private_subnet_id = re.search( + cls.re_id, priv_raw_output + ).group(1) @classmethod def tearDownClass(cls): - raw_output = cls.openstack('subnet delete ' + cls.SUBNET_NAME) - cls.assertOutput('', raw_output) - raw_output = cls.openstack('subnet delete ' + cls.PRIVATE_SUBNET_NAME) - cls.assertOutput('', raw_output) - raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME) - cls.assertOutput('', raw_output) - raw_output = cls.openstack( - 'network delete ' + cls.PRIVATE_NETWORK_NAME) - cls.assertOutput('', raw_output) + if cls.haz_network: + raw_output = cls.openstack( + 'subnet delete ' + cls.SUBNET_NAME, + ) + cls.assertOutput('', raw_output) + raw_output = cls.openstack( + 'subnet delete ' + cls.PRIVATE_SUBNET_NAME, + ) + cls.assertOutput('', raw_output) + raw_output = cls.openstack( + 'network delete ' + cls.NETWORK_NAME, + ) + cls.assertOutput('', raw_output) + raw_output = cls.openstack( + 'network delete ' + cls.PRIVATE_NETWORK_NAME, + ) + cls.assertOutput('', raw_output) + + def setUp(self): + super(FloatingIpTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_floating_ip_delete(self): """Test create, delete multiple""" diff --git a/openstackclient/tests/functional/network/v2/test_ip_availability.py b/openstackclient/tests/functional/network/v2/test_ip_availability.py index 7440f2507c..b9cac02443 100644 --- a/openstackclient/tests/functional/network/v2/test_ip_availability.py +++ b/openstackclient/tests/functional/network/v2/test_ip_availability.py @@ -13,14 +13,18 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class IPAvailabilityTests(base.TestCase): +class IPAvailabilityTests(common.NetworkTests): """Functional tests for IP availability. """ @classmethod def setUpClass(cls): + common.NetworkTests.setUpClass() + if not cls.haz_network: + common.NetworkTests.skipTest(cls, "No Network service present") + # Create a network for the subnet. cls.NAME = uuid.uuid4().hex cls.NETWORK_NAME = uuid.uuid4().hex 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 07dea31b76..e5b97573ec 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_policy.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_policy.py @@ -15,10 +15,10 @@ import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class QosPolicyTests(base.TestCase): +class NetworkQosPolicyTests(common.NetworkTests): """Functional tests for QoS policy. """ NAME = uuid.uuid4().hex HEADERS = ['Name'] @@ -26,11 +26,18 @@ class QosPolicyTests(base.TestCase): @classmethod def setUpClass(cls): + common.NetworkTests.setUpClass() opts = cls.get_opts(cls.FIELDS) raw_output = cls.openstack('network qos policy create ' + cls.NAME + opts) cls.assertOutput(cls.NAME + "\n", raw_output) + def setUp(self): + super(NetworkQosPolicyTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + @classmethod def tearDownClass(cls): raw_output = cls.openstack('network qos policy delete ' + cls.NAME) 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 af0c9baca7..f050635668 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py @@ -15,10 +15,10 @@ import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkQosRuleTestsMinimumBandwidth(base.TestCase): +class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests): """Functional tests for QoS minimum bandwidth rule.""" RULE_ID = None QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex @@ -31,6 +31,7 @@ class NetworkQosRuleTestsMinimumBandwidth(base.TestCase): @classmethod def setUpClass(cls): + common.NetworkTests.setUpClass() opts = cls.get_opts(cls.FIELDS) cls.openstack('network qos policy create ' + cls.QOS_POLICY_NAME) cls.RULE_ID = cls.openstack('network qos rule create --type ' + @@ -46,20 +47,26 @@ class NetworkQosRuleTestsMinimumBandwidth(base.TestCase): cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME) cls.assertOutput('', raw_output) - def test_qos_policy_list(self): + def setUp(self): + super(NetworkQosRuleTestsMinimumBandwidth, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + + def test_qos_rule_list(self): opts = self.get_opts(self.HEADERS) raw_output = self.openstack('network qos rule list ' + self.QOS_POLICY_NAME + opts) self.assertIn(self.RULE_ID, raw_output) - def test_qos_policy_show(self): + def test_qos_rule_show(self): opts = self.get_opts(self.FIELDS) raw_output = self.openstack('network qos rule show ' + self.QOS_POLICY_NAME + ' ' + self.RULE_ID + opts) self.assertEqual(self.RULE_ID, raw_output) - def test_qos_policy_set(self): + def test_qos_rule_set(self): self.openstack('network qos rule set --min-kbps ' + str(self.MIN_KBPS_MODIFIED) + ' ' + self.QOS_POLICY_NAME + ' ' + self.RULE_ID) @@ -70,7 +77,7 @@ class NetworkQosRuleTestsMinimumBandwidth(base.TestCase): self.assertEqual(str(self.MIN_KBPS_MODIFIED) + "\n", raw_output) -class NetworkQosRuleTestsDSCPMarking(base.TestCase): +class NetworkQosRuleTestsDSCPMarking(common.NetworkTests): """Functional tests for QoS DSCP marking rule.""" RULE_ID = None QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex @@ -82,6 +89,7 @@ class NetworkQosRuleTestsDSCPMarking(base.TestCase): @classmethod def setUpClass(cls): + common.NetworkTests.setUpClass() opts = cls.get_opts(cls.FIELDS) cls.openstack('network qos policy create ' + cls.QOS_POLICY_NAME) cls.RULE_ID = cls.openstack('network qos rule create --type ' + @@ -97,20 +105,26 @@ class NetworkQosRuleTestsDSCPMarking(base.TestCase): cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME) cls.assertOutput('', raw_output) - def test_qos_policy_list(self): + def setUp(self): + super(NetworkQosRuleTestsDSCPMarking, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + + def test_qos_rule_list(self): opts = self.get_opts(self.HEADERS) raw_output = self.openstack('network qos rule list ' + self.QOS_POLICY_NAME + opts) self.assertIn(self.RULE_ID, raw_output) - def test_qos_policy_show(self): + def test_qos_rule_show(self): opts = self.get_opts(self.FIELDS) raw_output = self.openstack('network qos rule show ' + self.QOS_POLICY_NAME + ' ' + self.RULE_ID + opts) self.assertEqual(self.RULE_ID, raw_output) - def test_qos_policy_set(self): + def test_qos_rule_set(self): self.openstack('network qos rule set --dscp-mark ' + str(self.DSCP_MARK_MODIFIED) + ' ' + self.QOS_POLICY_NAME + ' ' + self.RULE_ID) @@ -121,7 +135,7 @@ class NetworkQosRuleTestsDSCPMarking(base.TestCase): self.assertEqual(str(self.DSCP_MARK_MODIFIED) + "\n", raw_output) -class NetworkQosRuleTestsBandwidthLimit(base.TestCase): +class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests): """Functional tests for QoS bandwidth limit rule.""" RULE_ID = None QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex @@ -135,6 +149,7 @@ class NetworkQosRuleTestsBandwidthLimit(base.TestCase): @classmethod def setUpClass(cls): + common.NetworkTests.setUpClass() opts = cls.get_opts(cls.FIELDS) cls.openstack('network qos policy create ' + cls.QOS_POLICY_NAME) cls.RULE_ID = cls.openstack('network qos rule create --type ' + @@ -151,20 +166,26 @@ class NetworkQosRuleTestsBandwidthLimit(base.TestCase): cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME) cls.assertOutput('', raw_output) - def test_qos_policy_list(self): + def setUp(self): + super(NetworkQosRuleTestsBandwidthLimit, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + + def test_qos_rule_list(self): opts = self.get_opts(self.HEADERS) raw_output = self.openstack('network qos rule list ' + self.QOS_POLICY_NAME + opts) self.assertIn(self.RULE_ID, raw_output) - def test_qos_policy_show(self): + def test_qos_rule_show(self): opts = self.get_opts(self.FIELDS) raw_output = self.openstack('network qos rule show ' + self.QOS_POLICY_NAME + ' ' + self.RULE_ID + opts) self.assertEqual(self.RULE_ID, raw_output) - def test_qos_policy_set(self): + def test_qos_rule_set(self): self.openstack('network qos rule set --max-kbps ' + str(self.MAX_KBPS_MODIFIED) + ' --max-burst-kbits ' + str(self.MAX_BURST_KBITS_MODIFIED) + ' ' + diff --git a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py index 7dff0cbdad..d76129367c 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py @@ -13,15 +13,21 @@ # License for the specific language governing permissions and limitations # under the License. -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkQosRuleTypeTests(base.TestCase): +class NetworkQosRuleTypeTests(common.NetworkTests): """Functional tests for Network QoS rule type. """ AVAILABLE_RULE_TYPES = ['dscp_marking', 'bandwidth_limit'] + def setUp(self): + super(NetworkQosRuleTypeTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_qos_rule_type_list(self): raw_output = self.openstack('network qos rule type list') for rule_type in self.AVAILABLE_RULE_TYPES: diff --git a/openstackclient/tests/functional/network/v2/test_network_rbac.py b/openstackclient/tests/functional/network/v2/test_network_rbac.py index 6f9f05e792..0d5492e511 100644 --- a/openstackclient/tests/functional/network/v2/test_network_rbac.py +++ b/openstackclient/tests/functional/network/v2/test_network_rbac.py @@ -12,10 +12,10 @@ import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkRBACTests(base.TestCase): +class NetworkRBACTests(common.NetworkTests): """Functional tests for network rbac. """ NET_NAME = uuid.uuid4().hex PROJECT_NAME = uuid.uuid4().hex @@ -26,24 +26,41 @@ class NetworkRBACTests(base.TestCase): @classmethod def setUpClass(cls): - opts = cls.get_opts(cls.FIELDS) - raw_output = cls.openstack('network create ' + cls.NET_NAME + opts) - cls.OBJECT_ID = raw_output.strip('\n') - opts = cls.get_opts(['id', 'object_id']) - raw_output = cls.openstack('network rbac create ' + - cls.OBJECT_ID + - ' --action access_as_shared' + - ' --target-project admin' + - ' --type network' + opts) - cls.ID, object_id, rol = tuple(raw_output.split('\n')) - cls.assertOutput(cls.OBJECT_ID, object_id) + common.NetworkTests.setUpClass() + if cls.haz_network: + opts = cls.get_opts(cls.FIELDS) + raw_output = cls.openstack( + 'network create ' + cls.NET_NAME + opts + ) + cls.OBJECT_ID = raw_output.strip('\n') + opts = cls.get_opts(['id', 'object_id']) + raw_output = cls.openstack( + 'network rbac create ' + + cls.OBJECT_ID + + ' --action access_as_shared' + + ' --target-project admin' + + ' --type network' + opts + ) + cls.ID, object_id, rol = tuple(raw_output.split('\n')) + cls.assertOutput(cls.OBJECT_ID, object_id) @classmethod def tearDownClass(cls): - 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) + 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) + + def setUp(self): + super(NetworkRBACTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_network_rbac_list(self): opts = self.get_opts(self.HEADERS)