diff options
Diffstat (limited to 'openstackclient/tests')
13 files changed, 466 insertions, 242 deletions
diff --git a/openstackclient/tests/functional/network/v2/common.py b/openstackclient/tests/functional/network/v2/common.py new file mode 100644 index 00000000..bed07878 --- /dev/null +++ b/openstackclient/tests/functional/network/v2/common.py @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from openstackclient.tests.functional import base + + +class NetworkTests(base.TestCase): + """Functional tests for Network commands""" + + @classmethod + def setUpClass(cls): + # super(NetworkTests, cls).setUp() + cls.haz_network = base.is_service_enabled('network') diff --git a/openstackclient/tests/functional/network/v2/test_address_scope.py b/openstackclient/tests/functional/network/v2/test_address_scope.py index eaf88969..e5156d7f 100644 --- a/openstackclient/tests/functional/network/v2/test_address_scope.py +++ b/openstackclient/tests/functional/network/v2/test_address_scope.py @@ -13,10 +13,10 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class AddressScopeTests(base.TestCase): +class AddressScopeTests(common.NetworkTests): """Functional tests for address scope. """ # NOTE(dtroyer): Do not normalize the setup and teardown of the resource @@ -24,6 +24,12 @@ class AddressScopeTests(base.TestCase): # has its own needs and there are collisions when running # tests in parallel. + def setUp(self): + super(AddressScopeTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_address_scope_delete(self): """Test create, delete multiple""" name1 = uuid.uuid4().hex diff --git a/openstackclient/tests/functional/network/v2/test_floating_ip.py b/openstackclient/tests/functional/network/v2/test_floating_ip.py index 5da0e474..ccb954e9 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+)") - - # 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) + 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 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 - - 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) + # 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) + + # 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) @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 7440f250..b9cac024 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_agent.py b/openstackclient/tests/functional/network/v2/test_network_agent.py index 6da721d1..16487955 100644 --- a/openstackclient/tests/functional/network/v2/test_network_agent.py +++ b/openstackclient/tests/functional/network/v2/test_network_agent.py @@ -13,39 +13,85 @@ import json import uuid -from openstackclient.tests.functional import base - - -class NetworkAgentTests(base.TestCase): - """Functional tests for network agent. """ - IDs = None - HEADERS = ['ID'] - FIELDS = ['id'] - - @classmethod - def test_network_agent_list(cls): - opts = cls.get_opts(cls.HEADERS) - raw_output = cls.openstack('network agent list' + opts) - # get the list of network agent IDs. - cls.IDs = raw_output.split('\n') - - def test_network_agent_show(self): - opts = self.get_opts(self.FIELDS) - raw_output = self.openstack('network agent show ' + self.IDs[0] + opts) - self.assertEqual(self.IDs[0] + "\n", raw_output) - - def test_network_agent_set(self): - opts = self.get_opts(['admin_state_up']) - self.openstack('network agent set --disable ' + self.IDs[0]) - raw_output = self.openstack('network agent show ' + self.IDs[0] + opts) - self.assertEqual("DOWN\n", raw_output) - self.openstack('network agent set --enable ' + self.IDs[0]) - raw_output = self.openstack('network agent show ' + self.IDs[0] + opts) - self.assertEqual("UP\n", raw_output) - - -class NetworkAgentListTests(base.TestCase): - """Functional test for network agent list --network. """ +from openstackclient.tests.functional.network.v2 import common + + +class NetworkAgentTests(common.NetworkTests): + """Functional tests for network agent""" + + def setUp(self): + super(NetworkAgentTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + + def test_network_agent_list_show_set(self): + """Test network agent list, set, show commands + + Do these serially because show and set rely on the existing agent IDs + from the list output and we had races when run in parallel. + """ + + # agent list + agent_list = json.loads(self.openstack( + 'network agent list -f json' + )) + self.assertIsNotNone(agent_list[0]) + + agent_ids = list([row["ID"] for row in agent_list]) + + # agent show + cmd_output = json.loads(self.openstack( + 'network agent show -f json ' + + agent_ids[0] + )) + self.assertEqual( + agent_ids[0], + cmd_output['id'], + ) + + # agent set + raw_output = self.openstack( + 'network agent set ' + + '--disable ' + + agent_ids[0] + ) + self.assertOutput('', raw_output) + + cmd_output = json.loads(self.openstack( + 'network agent show -f json ' + + agent_ids[0] + )) + self.assertEqual( + "DOWN", + cmd_output['admin_state_up'], + ) + + raw_output = self.openstack( + 'network agent set ' + + '--enable ' + + agent_ids[0] + ) + self.assertOutput('', raw_output) + + cmd_output = json.loads(self.openstack( + 'network agent show -f json ' + + agent_ids[0] + )) + self.assertEqual( + "UP", + cmd_output['admin_state_up'], + ) + + +class NetworkAgentListTests(common.NetworkTests): + """Functional test for network agent""" + + def setUp(self): + super(NetworkAgentListTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_network_dhcp_agent_list(self): """Test network agent list""" diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor.py b/openstackclient/tests/functional/network/v2/test_network_flavor.py index 74340790..47e7b440 100644 --- a/openstackclient/tests/functional/network/v2/test_network_flavor.py +++ b/openstackclient/tests/functional/network/v2/test_network_flavor.py @@ -14,15 +14,20 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkFlavorTests(base.TestCase): - """Functional tests for network flavor.""" +class NetworkFlavorTests(common.NetworkTests): + """Functional tests for network flavor""" - def test_add_remove_network_flavor_profile(self): - """Test add and remove network flavor to/from profile""" + def setUp(self): + super(NetworkFlavorTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_network_flavor_add_remove_profile(self): + """Test add and remove network flavor to/from profile""" # Create Flavor name1 = uuid.uuid4().hex cmd_output1 = json.loads(self.openstack( diff --git a/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py b/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py index 1a82c82b..2207c847 100644 --- a/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py +++ b/openstackclient/tests/functional/network/v2/test_network_flavor_profile.py @@ -12,30 +12,40 @@ import json -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkFlavorProfileTests(base.TestCase): - """Functional tests for network flavor-profile.""" +class NetworkFlavorProfileTests(common.NetworkTests): + """Functional tests for network flavor profile""" DESCRIPTION = 'fakedescription' METAINFO = 'Extrainfo' + def setUp(self): + super(NetworkFlavorProfileTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_network_flavor_profile_create(self): json_output = json.loads(self.openstack( - ' network flavor profile create -f json --description ' - + self.DESCRIPTION + ' --enable --metainfo ' + self.METAINFO)) + 'network flavor profile create -f json ' + + '--description ' + self.DESCRIPTION + ' ' + + '--enable --metainfo ' + self.METAINFO + )) ID = json_output.get('id') self.assertIsNotNone(ID) self.assertEqual( True, - json_output.get('enabled')) + json_output.get('enabled'), + ) self.assertEqual( 'fakedescription', - json_output.get('description')) + json_output.get('description'), + ) self.assertEqual( 'Extrainfo', - json_output.get('meta_info') + json_output.get('meta_info'), ) # Clean up @@ -44,40 +54,51 @@ class NetworkFlavorProfileTests(base.TestCase): def test_network_flavor_profile_list(self): json_output = json.loads(self.openstack( - ' network flavor profile create -f json --description ' - + self.DESCRIPTION + ' --enable --metainfo ' + self.METAINFO)) + 'network flavor profile create -f json ' + + '--description ' + self.DESCRIPTION + ' ' + + '--enable ' + + '--metainfo ' + self.METAINFO + )) ID1 = json_output.get('id') self.assertIsNotNone(ID1) self.assertEqual( True, - json_output.get('enabled')) + json_output.get('enabled'), + ) self.assertEqual( 'fakedescription', - json_output.get('description')) + json_output.get('description'), + ) self.assertEqual( 'Extrainfo', - json_output.get('meta_info') + json_output.get('meta_info'), ) json_output = json.loads(self.openstack( - ' network flavor profile create -f json --description ' - + self.DESCRIPTION + ' --disable --metainfo ' + self.METAINFO)) + 'network flavor profile create -f json ' + + '--description ' + self.DESCRIPTION + ' ' + + '--disable ' + + '--metainfo ' + self.METAINFO + )) ID2 = json_output.get('id') self.assertIsNotNone(ID2) self.assertEqual( False, - json_output.get('enabled')) + json_output.get('enabled'), + ) self.assertEqual( 'fakedescription', - json_output.get('description')) + json_output.get('description'), + ) self.assertEqual( 'Extrainfo', - json_output.get('meta_info') + json_output.get('meta_info'), ) # Test list json_output = json.loads(self.openstack( - 'network flavor profile list -f json')) + 'network flavor profile list -f json' + )) self.assertIsNotNone(json_output) id_list = [item.get('ID') for item in json_output] @@ -86,39 +107,48 @@ class NetworkFlavorProfileTests(base.TestCase): # Clean up raw_output = self.openstack( - 'network flavor profile delete ' + ID1 + " " + ID2) + 'network flavor profile delete ' + ID1 + ' ' + ID2 + ) self.assertOutput('', raw_output) def test_network_flavor_profile_set(self): json_output_1 = json.loads(self.openstack( - ' network flavor profile create -f json --description ' - + self.DESCRIPTION + ' --enable --metainfo ' + self.METAINFO)) + 'network flavor profile create -f json ' + + '--description ' + self.DESCRIPTION + ' ' + + '--enable ' + + '--metainfo ' + self.METAINFO + )) ID = json_output_1.get('id') self.assertIsNotNone(ID) self.assertEqual( True, - json_output_1.get('enabled')) + json_output_1.get('enabled'), + ) self.assertEqual( 'fakedescription', - json_output_1.get('description')) + json_output_1.get('description'), + ) self.assertEqual( 'Extrainfo', - json_output_1.get('meta_info') + json_output_1.get('meta_info'), ) self.openstack('network flavor profile set --disable ' + ID) - json_output = json.loads(self.openstack('network flavor profile show ' - '-f json ' + ID)) + json_output = json.loads(self.openstack( + 'network flavor profile show -f json ' + ID + )) self.assertEqual( False, - json_output.get('enabled')) + json_output.get('enabled'), + ) self.assertEqual( 'fakedescription', - json_output.get('description')) + json_output.get('description'), + ) self.assertEqual( 'Extrainfo', - json_output.get('meta_info') + json_output.get('meta_info'), ) # Clean up @@ -127,24 +157,32 @@ class NetworkFlavorProfileTests(base.TestCase): def test_network_flavor_profile_show(self): json_output_1 = json.loads(self.openstack( - ' network flavor profile create -f json --description ' - + self.DESCRIPTION + ' --enable --metainfo ' + self.METAINFO)) + 'network flavor profile create -f json ' + + '--description ' + self.DESCRIPTION + ' ' + + '--enable ' + + '--metainfo ' + self.METAINFO + )) ID = json_output_1.get('id') self.assertIsNotNone(ID) - json_output = json.loads(self.openstack('network flavor profile show ' - '-f json ' + ID)) + json_output = json.loads(self.openstack( + 'network flavor profile show -f json ' + ID + )) self.assertEqual( ID, - json_output["id"]) + json_output["id"], + ) self.assertEqual( True, - json_output["enabled"]) + json_output["enabled"], + ) self.assertEqual( 'fakedescription', - json_output["description"]) + json_output["description"], + ) self.assertEqual( 'Extrainfo', - json_output["meta_info"]) + json_output["meta_info"], + ) # Clean up raw_output = self.openstack('network flavor profile delete ' + ID) diff --git a/openstackclient/tests/functional/network/v2/test_network_meter.py b/openstackclient/tests/functional/network/v2/test_network_meter.py index f73f4812..7f6da28d 100644 --- a/openstackclient/tests/functional/network/v2/test_network_meter.py +++ b/openstackclient/tests/functional/network/v2/test_network_meter.py @@ -16,26 +16,33 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class TestMeter(base.TestCase): - """Functional tests for network meter.""" +class TestMeter(common.NetworkTests): + """Functional tests for network meter""" # NOTE(dtroyer): Do not normalize the setup and teardown of the resource # creation and deletion. Little is gained when each test # has its own needs and there are collisions when running # tests in parallel. + def setUp(self): + super(TestMeter, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_meter_delete(self): """Test create, delete multiple""" name1 = uuid.uuid4().hex name2 = uuid.uuid4().hex description = 'fakedescription' json_output = json.loads(self.openstack( - 'network meter create -f json ' + name1 + ' --description ' - + description) - ) + 'network meter create -f json ' + + ' --description ' + description + ' ' + + name1 + )) self.assertEqual( name1, json_output.get('name'), @@ -43,17 +50,18 @@ class TestMeter(base.TestCase): # Check if default shared values self.assertEqual( False, - json_output.get('shared') + json_output.get('shared'), ) self.assertEqual( 'fakedescription', - json_output.get('description') + json_output.get('description'), ) json_output_2 = json.loads(self.openstack( - 'network meter create -f json ' + name2 + ' --description ' - + description) - ) + 'network meter create -f json ' + + '--description ' + description + ' ' + + name2 + )) self.assertEqual( name2, json_output_2.get('name'), @@ -61,11 +69,11 @@ class TestMeter(base.TestCase): # Check if default shared values self.assertEqual( False, - json_output_2.get('shared') + json_output_2.get('shared'), ) self.assertEqual( 'fakedescription', - json_output_2.get('description') + json_output_2.get('description'), ) raw_output = self.openstack( @@ -77,10 +85,15 @@ class TestMeter(base.TestCase): """Test create, list filters, delete""" name1 = uuid.uuid4().hex json_output = json.loads(self.openstack( - 'network meter create -f json --description Test1 --share ' - + name1) + 'network meter create -f json ' + + '--description Test1 ' + + '--share ' + + name1 + )) + self.addCleanup( + self.openstack, + 'network meter delete ' + name1 ) - self.addCleanup(self.openstack, 'network meter delete ' + name1) self.assertEqual( 'Test1', @@ -93,18 +106,20 @@ class TestMeter(base.TestCase): name2 = uuid.uuid4().hex json_output_2 = json.loads(self.openstack( - 'network meter create -f json --description Test2 --no-share ' - + name2) - ) + 'network meter create -f json ' + + '--description Test2 ' + + '--no-share ' + + name2 + )) self.addCleanup(self.openstack, 'network meter delete ' + name2) self.assertEqual( 'Test2', - json_output_2.get('description') + json_output_2.get('description'), ) self.assertEqual( False, - json_output_2.get('shared') + json_output_2.get('shared'), ) raw_output = json.loads(self.openstack('network meter list -f json')) @@ -117,42 +132,43 @@ class TestMeter(base.TestCase): name1 = uuid.uuid4().hex description = 'fakedescription' json_output = json.loads(self.openstack( - 'network meter create -f json ' + name1 + ' --description ' - + description) - ) + 'network meter create -f json ' + + ' --description ' + description + ' ' + + name1 + )) meter_id = json_output.get('id') self.addCleanup(self.openstack, 'network meter delete ' + name1) # Test show with ID json_output = json.loads(self.openstack( - 'network meter show -f json ' + meter_id) - ) + 'network meter show -f json ' + meter_id + )) self.assertEqual( False, - json_output.get('shared') + json_output.get('shared'), ) self.assertEqual( 'fakedescription', - json_output.get('description') + json_output.get('description'), ) self.assertEqual( name1, - json_output.get('name') + json_output.get('name'), ) # Test show with name json_output = json.loads(self.openstack( - 'network meter show -f json ' + name1) - ) + 'network meter show -f json ' + name1 + )) self.assertEqual( meter_id, - json_output.get('id') + json_output.get('id'), ) self.assertEqual( False, - json_output.get('shared') + json_output.get('shared'), ) self.assertEqual( 'fakedescription', - json_output.get('description') + json_output.get('description'), ) 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 d15cdf77..f0c1aa2f 100644 --- a/openstackclient/tests/functional/network/v2/test_network_meter_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_meter_rule.py @@ -16,31 +16,40 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class TestMeterRule(base.TestCase): +class TestMeterRule(common.NetworkTests): """Functional tests for meter rule""" + METER_NAME = uuid.uuid4().hex METER_ID = None METER_RULE_ID = None @classmethod def setUpClass(cls): - json_output = json.loads(cls.openstack( - 'network meter create -f json ' + cls.METER_NAME - )) - - cls.METER_ID = json_output.get('id') + common.NetworkTests.setUpClass() + if cls.haz_network: + json_output = json.loads(cls.openstack( + 'network meter create -f json ' + cls.METER_NAME + )) + cls.METER_ID = json_output.get('id') @classmethod def tearDownClass(cls): - raw_output = cls.openstack('network meter delete ' + cls.METER_ID) - cls.assertOutput('', raw_output) + common.NetworkTests.tearDownClass() + if cls.haz_network: + raw_output = cls.openstack('network meter delete ' + cls.METER_ID) + cls.assertOutput('', raw_output) + + def setUp(self): + super(TestMeterRule, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_meter_rule_delete(self): """test create, delete""" - json_output = json.loads(self.openstack( 'network meter rule create -f json ' + '--remote-ip-prefix 10.0.0.0/8 ' + @@ -49,8 +58,10 @@ class TestMeterRule(base.TestCase): rule_id = json_output.get('id') re_ip = json_output.get('remote_ip_prefix') - self.addCleanup(self.openstack, - 'network meter rule delete ' + rule_id) + self.addCleanup( + self.openstack, + 'network meter rule delete ' + rule_id + ) self.assertIsNotNone(re_ip) self.assertIsNotNone(rule_id) self.assertEqual( @@ -65,8 +76,10 @@ class TestMeterRule(base.TestCase): self.METER_ID )) rule_id_1 = json_output.get('id') - self.addCleanup(self.openstack, - 'network meter rule delete ' + rule_id_1) + self.addCleanup( + self.openstack, + 'network meter rule delete ' + rule_id_1 + ) self.assertEqual( '10.0.0.0/8', json_output.get('remote_ip_prefix') @@ -78,15 +91,18 @@ class TestMeterRule(base.TestCase): self.METER_ID )) rule_id_2 = json_output_1.get('id') - self.addCleanup(self.openstack, - 'network meter rule delete ' + rule_id_2) + self.addCleanup( + self.openstack, + 'network meter rule delete ' + rule_id_2 + ) self.assertEqual( '11.0.0.0/8', json_output_1.get('remote_ip_prefix') ) - json_output = json.loads(self.openstack('network meter rule list -f ' - 'json')) + json_output = json.loads(self.openstack( + 'network meter rule list -f json' + )) rule_id_list = [item.get('ID') for item in json_output] ip_prefix_list = [item.get('Remote IP Prefix') for item in json_output] self.assertIn(rule_id_1, rule_id_list) @@ -95,7 +111,6 @@ class TestMeterRule(base.TestCase): self.assertIn('11.0.0.0/8', ip_prefix_list) def test_meter_rule_show(self): - """Test create, show, delete""" json_output = json.loads(self.openstack( 'network meter rule create -f json ' + @@ -110,14 +125,16 @@ class TestMeterRule(base.TestCase): json_output.get('direction') ) - json_output = json.loads(self.openstack('network meter rule show' - ' -f json ' + rule_id)) - + json_output = json.loads(self.openstack( + 'network meter rule show -f json ' + rule_id + )) self.assertEqual( '10.0.0.0/8', json_output.get('remote_ip_prefix') ) self.assertIsNotNone(rule_id) - self.addCleanup(self.openstack, - 'network meter rule delete ' + rule_id) + self.addCleanup( + self.openstack, + 'network meter rule delete ' + rule_id + ) 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 07dea31b..e5b97573 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 af0c9bac..f0506356 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 7dff0cbd..d7612936 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 6f9f05e7..0d5492e5 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) |
