diff --git a/openstackclient/tests/functional/common/test_extension.py b/openstackclient/tests/functional/common/test_extension.py index 7c527eaecb..cc4cb7e160 100644 --- a/openstackclient/tests/functional/common/test_extension.py +++ b/openstackclient/tests/functional/common/test_extension.py @@ -18,25 +18,66 @@ import json from openstackclient.tests.functional import base -class TestExtension(base.TestCase): - """Functional tests for extension.""" +class ExtensionTests(base.TestCase): + """Functional tests for extension""" - def test_extension_list(self): - """Test extension list.""" + @classmethod + def setUpClass(cls): + # super(NetworkTests, cls).setUp() + cls.haz_network = base.is_service_enabled('network') + + def test_extension_list_compute(self): + """Test compute extension list""" json_output = json.loads(self.openstack( - 'extension list -f json ' + '--network') - ) - self.assertEqual( - 'Default Subnetpools', - json_output[0]['Name'], + 'extension list -f json ' + + '--compute' + )) + name_list = [item.get('Name') for item in json_output] + self.assertIn( + 'ImageSize', + name_list, ) - def test_extension_show(self): - """Test extension show.""" + def test_extension_list_network(self): + """Test network extension list""" + if not self.haz_network: + self.skipTest("No Network service present") + + json_output = json.loads(self.openstack( + 'extension list -f json ' + + '--network' + )) + name_list = [item.get('Name') for item in json_output] + self.assertIn( + 'Default Subnetpools', + name_list, + ) + + # NOTE(dtroyer): Only network extensions are currently supported but + # I am going to leave this here anyway as a reminder + # fix that. + # def test_extension_show_compute(self): + # """Test compute extension show""" + # json_output = json.loads(self.openstack( + # 'extension show -f json ' + + # 'ImageSize' + # )) + # self.assertEqual( + # 'OS-EXT-IMG-SIZE', + # json_output.get('Alias'), + # ) + + def test_extension_show_network(self): + """Test network extension show""" + if not self.haz_network: + self.skipTest("No Network service present") + name = 'agent' json_output = json.loads(self.openstack( - 'extension show -f json ' + name) - ) + 'extension show -f json ' + + name + )) self.assertEqual( name, - json_output.get('Alias')) + json_output.get('Alias'), + ) diff --git a/openstackclient/tests/functional/compute/v2/test_server.py b/openstackclient/tests/functional/compute/v2/test_server.py index 76255c69e6..a86c0c679d 100644 --- a/openstackclient/tests/functional/compute/v2/test_server.py +++ b/openstackclient/tests/functional/compute/v2/test_server.py @@ -15,6 +15,7 @@ import uuid from tempest.lib import exceptions +from openstackclient.tests.functional import base from openstackclient.tests.functional.compute.v2 import common from openstackclient.tests.functional.volume.v2 import test_volume @@ -22,6 +23,10 @@ from openstackclient.tests.functional.volume.v2 import test_volume class ServerTests(common.ComputeTestCase): """Functional tests for openstack server commands""" + @classmethod + def setUpClass(cls): + cls.haz_network = base.is_service_enabled('network') + def test_server_list(self): """Test server list, set""" cmd_output = self.server_create() @@ -202,6 +207,15 @@ class ServerTests(common.ComputeTestCase): name = cmd_output['name'] self.wait_for_status(name, "ACTIVE") + if not self.haz_network: + # nova-net needs a public subnet + cmd_output = json.loads(self.openstack( + 'network create -f json ' + + '--subnet 8.6.7.5/28 ' + + 'public' + )) + self.addCleanup(self.openstack, 'network delete public') + # attach ip cmd_output = json.loads(self.openstack( 'floating ip create -f json ' + diff --git a/openstackclient/tests/functional/network/v2/test_address_scope.py b/openstackclient/tests/functional/network/v2/test_address_scope.py index e5156d7f2e..ebd2ba86c6 100644 --- a/openstackclient/tests/functional/network/v2/test_address_scope.py +++ b/openstackclient/tests/functional/network/v2/test_address_scope.py @@ -17,7 +17,7 @@ from openstackclient.tests.functional.network.v2 import common class AddressScopeTests(common.NetworkTests): - """Functional tests for address scope. """ + """Functional tests for address scope""" # NOTE(dtroyer): Do not normalize the setup and teardown of the resource # creation and deletion. Little is gained when each test diff --git a/openstackclient/tests/functional/network/v2/test_ip_availability.py b/openstackclient/tests/functional/network/v2/test_ip_availability.py index b9cac02443..1aa0f64a7b 100644 --- a/openstackclient/tests/functional/network/v2/test_ip_availability.py +++ b/openstackclient/tests/functional/network/v2/test_ip_availability.py @@ -17,31 +17,46 @@ from openstackclient.tests.functional.network.v2 import common class IPAvailabilityTests(common.NetworkTests): - """Functional tests for IP availability. """ + """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 - cls.openstack('network create ' + cls.NETWORK_NAME) - cmd_output = json.loads(cls.openstack( - 'subnet create -f json --network ' + cls.NETWORK_NAME + - ' --subnet-range 10.10.10.0/24 ' + - cls.NAME - )) - cls.assertOutput(cls.NAME, cmd_output['name']) + if cls.haz_network: + # Create a network for the subnet. + cls.NAME = uuid.uuid4().hex + cls.NETWORK_NAME = uuid.uuid4().hex + cls.openstack( + 'network create ' + + cls.NETWORK_NAME + ) + cmd_output = json.loads(cls.openstack( + 'subnet create -f json ' + + '--network ' + cls.NETWORK_NAME + ' ' + + '--subnet-range 10.10.10.0/24 ' + + cls.NAME + )) + cls.assertOutput(cls.NAME, cmd_output['name']) @classmethod def tearDownClass(cls): - 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) + 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) + + def setUp(self): + super(IPAvailabilityTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_ip_availability_list(self): """Test ip availability list""" diff --git a/openstackclient/tests/functional/network/v2/test_network.py b/openstackclient/tests/functional/network/v2/test_network.py index 91500e0dd2..b23323a00e 100644 --- a/openstackclient/tests/functional/network/v2/test_network.py +++ b/openstackclient/tests/functional/network/v2/test_network.py @@ -13,17 +13,17 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkTests(base.TestCase): +class NetworkTests(common.NetworkTests): """Functional tests for network""" - @classmethod - def setUpClass(cls): - cls.haz_network = base.is_service_enabled('network') - cls.PROJECT_NAME =\ - cls.get_openstack_configuration_value('auth.project_name') + def setUp(self): + super(NetworkTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_network_create_compute(self): """Test Nova-net create options, delete""" 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 f0c1aa2f48..b7090707b1 100644 --- a/openstackclient/tests/functional/network/v2/test_network_meter_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_meter_rule.py @@ -31,7 +31,8 @@ class TestMeterRule(common.NetworkTests): common.NetworkTests.setUpClass() if cls.haz_network: json_output = json.loads(cls.openstack( - 'network meter create -f json ' + cls.METER_NAME + 'network meter create -f json ' + + cls.METER_NAME )) cls.METER_ID = json_output.get('id') @@ -39,7 +40,10 @@ class TestMeterRule(common.NetworkTests): def tearDownClass(cls): common.NetworkTests.tearDownClass() if cls.haz_network: - raw_output = cls.openstack('network meter delete ' + cls.METER_ID) + raw_output = cls.openstack( + 'network meter delete ' + + cls.METER_ID + ) cls.assertOutput('', raw_output) def setUp(self): 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 e5b97573ec..282efbfa7f 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_policy.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_policy.py @@ -27,10 +27,23 @@ class NetworkQosPolicyTests(common.NetworkTests): @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) + if cls.haz_network: + opts = cls.get_opts(cls.FIELDS) + raw_output = cls.openstack( + 'network qos policy create ' + + cls.NAME + + opts + ) + cls.assertOutput(cls.NAME + "\n", raw_output) + + @classmethod + def tearDownClass(cls): + if cls.haz_network: + raw_output = cls.openstack( + 'network qos policy delete ' + + cls.NAME + ) + cls.assertOutput('', raw_output) def setUp(self): super(NetworkQosPolicyTests, self).setUp() @@ -38,11 +51,6 @@ class NetworkQosPolicyTests(common.NetworkTests): 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) - cls.assertOutput('', raw_output) - def test_qos_policy_list(self): opts = self.get_opts(self.HEADERS) raw_output = self.openstack('network qos policy list' + opts) 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 f050635668..c6437d9c0e 100644 --- a/openstackclient/tests/functional/network/v2/test_network_qos_rule.py +++ b/openstackclient/tests/functional/network/v2/test_network_qos_rule.py @@ -19,7 +19,7 @@ from openstackclient.tests.functional.network.v2 import common class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests): - """Functional tests for QoS minimum bandwidth rule.""" + """Functional tests for QoS minimum bandwidth rule""" RULE_ID = None QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex MIN_KBPS = 2800 @@ -32,20 +32,35 @@ class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests): @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 ' + - cls.TYPE + ' --min-kbps ' + - str(cls.MIN_KBPS) + ' ' + cls.DIRECTION + - ' ' + cls.QOS_POLICY_NAME + opts) - cls.assertsOutputNotNone(cls.RULE_ID) + if cls.haz_network: + 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 ' + cls.TYPE + ' ' + + '--min-kbps ' + str(cls.MIN_KBPS) + ' ' + + cls.DIRECTION + ' ' + + cls.QOS_POLICY_NAME + + opts + ) + cls.assertsOutputNotNone(cls.RULE_ID) @classmethod def tearDownClass(cls): - 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) + 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) def setUp(self): super(NetworkQosRuleTestsMinimumBandwidth, self).setUp() @@ -78,7 +93,7 @@ class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests): class NetworkQosRuleTestsDSCPMarking(common.NetworkTests): - """Functional tests for QoS DSCP marking rule.""" + """Functional tests for QoS DSCP marking rule""" RULE_ID = None QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex DSCP_MARK = 8 @@ -90,20 +105,31 @@ class NetworkQosRuleTestsDSCPMarking(common.NetworkTests): @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 ' + - cls.TYPE + ' --dscp-mark ' + - str(cls.DSCP_MARK) + ' ' + - cls.QOS_POLICY_NAME + opts) - cls.assertsOutputNotNone(cls.RULE_ID) + if cls.haz_network: + 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 ' + cls.TYPE + ' ' + + '--dscp-mark ' + str(cls.DSCP_MARK) + ' ' + + cls.QOS_POLICY_NAME + + opts + ) + cls.assertsOutputNotNone(cls.RULE_ID) @classmethod def tearDownClass(cls): - 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) + 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) def setUp(self): super(NetworkQosRuleTestsDSCPMarking, self).setUp() @@ -136,7 +162,7 @@ class NetworkQosRuleTestsDSCPMarking(common.NetworkTests): class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests): - """Functional tests for QoS bandwidth limit rule.""" + """Functional tests for QoS bandwidth limit rule""" RULE_ID = None QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex MAX_KBPS = 10000 @@ -150,21 +176,32 @@ class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests): @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 ' + - cls.TYPE + ' --max-kbps ' + - str(cls.MAX_KBPS) + ' --max-burst-kbits ' + - str(cls.MAX_BURST_KBITS) + ' ' + - cls.QOS_POLICY_NAME + opts) - cls.assertsOutputNotNone(cls.RULE_ID) + if cls.haz_network: + 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 ' + cls.TYPE + ' ' + + '--max-kbps ' + str(cls.MAX_KBPS) + ' ' + + '--max-burst-kbits ' + str(cls.MAX_BURST_KBITS) + ' ' + + cls.QOS_POLICY_NAME + + opts + ) + cls.assertsOutputNotNone(cls.RULE_ID) @classmethod def tearDownClass(cls): - 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) + 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) def setUp(self): super(NetworkQosRuleTestsBandwidthLimit, 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 b6f19ac4bf..de150d3106 100644 --- a/openstackclient/tests/functional/network/v2/test_network_segment.py +++ b/openstackclient/tests/functional/network/v2/test_network_segment.py @@ -12,11 +12,11 @@ import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class NetworkSegmentTests(base.TestCase): - """Functional tests for network segment. """ +class NetworkSegmentTests(common.NetworkTests): + """Functional tests for network segment""" NETWORK_NAME = uuid.uuid4().hex PHYSICAL_NETWORK_NAME = uuid.uuid4().hex NETWORK_SEGMENT_ID = None @@ -25,30 +25,46 @@ class NetworkSegmentTests(base.TestCase): @classmethod def setUpClass(cls): - # Create a network for the segment. - opts = cls.get_opts(['id']) - raw_output = cls.openstack('network create ' + cls.NETWORK_NAME + opts) - cls.NETWORK_ID = raw_output.strip('\n') + common.NetworkTests.setUpClass() + if cls.haz_network: + # Create a network for the segment. + opts = cls.get_opts(['id']) + raw_output = cls.openstack( + 'network create ' + cls.NETWORK_NAME + opts + ) + cls.NETWORK_ID = raw_output.strip('\n') - # NOTE(rtheis): The segment extension is not yet enabled by default. - # Skip the tests if not enabled. - extensions = cls.get_openstack_extention_names() - if 'Segment' in extensions: - cls.NETWORK_SEGMENT_EXTENSION = 'Segment' + # NOTE(rtheis): The segment extension is not yet enabled + # by default. + # Skip the tests if not enabled. + extensions = cls.get_openstack_extention_names() + if 'Segment' in extensions: + cls.NETWORK_SEGMENT_EXTENSION = 'Segment' - if cls.NETWORK_SEGMENT_EXTENSION: - # Get the segment for the network. - opts = cls.get_opts(['ID', 'Network']) - raw_output = cls.openstack('network segment list ' - ' --network ' + cls.NETWORK_NAME + - ' ' + opts) - raw_output_row = raw_output.split('\n')[0] - cls.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0] + if cls.NETWORK_SEGMENT_EXTENSION: + # Get the segment for the network. + opts = cls.get_opts(['ID', 'Network']) + raw_output = cls.openstack( + 'network segment list ' + '--network ' + cls.NETWORK_NAME + ' ' + + opts + ) + raw_output_row = raw_output.split('\n')[0] + cls.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0] @classmethod def tearDownClass(cls): - raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME) - cls.assertOutput('', raw_output) + if cls.haz_network: + raw_output = cls.openstack( + 'network delete ' + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_output) + + def setUp(self): + super(NetworkSegmentTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_network_segment_create_delete(self): if self.NETWORK_SEGMENT_EXTENSION: diff --git a/openstackclient/tests/functional/network/v2/test_network_service_provider.py b/openstackclient/tests/functional/network/v2/test_network_service_provider.py index 6fbff6c8d4..8ed44dd909 100644 --- a/openstackclient/tests/functional/network/v2/test_network_service_provider.py +++ b/openstackclient/tests/functional/network/v2/test_network_service_provider.py @@ -13,14 +13,20 @@ # 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 TestNetworkServiceProvider(base.TestCase): +class TestNetworkServiceProvider(common.NetworkTests): """Functional tests for network service provider""" SERVICE_TYPE = 'L3_ROUTER_NAT' + def setUp(self): + super(TestNetworkServiceProvider, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_network_service_provider_list(self): raw_output = self.openstack('network service provider list') self.assertIn(self.SERVICE_TYPE, raw_output) diff --git a/openstackclient/tests/functional/network/v2/test_port.py b/openstackclient/tests/functional/network/v2/test_port.py index 62c0cbe51b..6659e3e0a9 100644 --- a/openstackclient/tests/functional/network/v2/test_port.py +++ b/openstackclient/tests/functional/network/v2/test_port.py @@ -13,23 +13,36 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class PortTests(base.TestCase): - """Functional tests for port. """ +class PortTests(common.NetworkTests): + """Functional tests for port""" NAME = uuid.uuid4().hex NETWORK_NAME = uuid.uuid4().hex @classmethod def setUpClass(cls): - # Create a network for the port - cls.openstack('network create ' + cls.NETWORK_NAME) + common.NetworkTests.setUpClass() + if cls.haz_network: + # Create a network for the port + cls.openstack( + 'network create ' + cls.NETWORK_NAME + ) @classmethod def tearDownClass(cls): - raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME) - cls.assertOutput('', raw_output) + if cls.haz_network: + raw_output = cls.openstack( + 'network delete ' + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_output) + + def setUp(self): + super(PortTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_port_delete(self): """Test create, delete multiple""" diff --git a/openstackclient/tests/functional/network/v2/test_router.py b/openstackclient/tests/functional/network/v2/test_router.py index aa708e0a6f..313feefc01 100644 --- a/openstackclient/tests/functional/network/v2/test_router.py +++ b/openstackclient/tests/functional/network/v2/test_router.py @@ -13,11 +13,17 @@ import json import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class RouterTests(base.TestCase): - """Functional tests for router. """ +class RouterTests(common.NetworkTests): + """Functional tests for router""" + + def setUp(self): + super(RouterTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_router_create_and_delete(self): """Test create options, delete multiple""" diff --git a/openstackclient/tests/functional/network/v2/test_security_group.py b/openstackclient/tests/functional/network/v2/test_security_group.py index debd81df6e..2a9c0b0ad4 100644 --- a/openstackclient/tests/functional/network/v2/test_security_group.py +++ b/openstackclient/tests/functional/network/v2/test_security_group.py @@ -12,11 +12,11 @@ import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class SecurityGroupTests(base.TestCase): - """Functional tests for security group. """ +class SecurityGroupTests(common.NetworkTests): + """Functional tests for security group""" NAME = uuid.uuid4().hex OTHER_NAME = uuid.uuid4().hex HEADERS = ['Name'] @@ -24,20 +24,39 @@ class SecurityGroupTests(base.TestCase): @classmethod def setUpClass(cls): - opts = cls.get_opts(cls.FIELDS) - raw_output = cls.openstack('security group create ' + cls.NAME + opts) - expected = cls.NAME + '\n' - cls.assertOutput(expected, raw_output) + common.NetworkTests.setUpClass() + if cls.haz_network: + opts = cls.get_opts(cls.FIELDS) + raw_output = cls.openstack( + 'security group create ' + + cls.NAME + + opts + ) + expected = cls.NAME + '\n' + cls.assertOutput(expected, raw_output) @classmethod def tearDownClass(cls): - # 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) + 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) + + def setUp(self): + super(SecurityGroupTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_security_group_list(self): opts = self.get_opts(self.HEADERS) 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 c91de1a570..93f98642f9 100644 --- a/openstackclient/tests/functional/network/v2/test_security_group_rule.py +++ b/openstackclient/tests/functional/network/v2/test_security_group_rule.py @@ -12,11 +12,11 @@ import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class SecurityGroupRuleTests(base.TestCase): - """Functional tests for security group rule. """ +class SecurityGroupRuleTests(common.NetworkTests): + """Functional tests for security group rule""" SECURITY_GROUP_NAME = uuid.uuid4().hex SECURITY_GROUP_RULE_ID = None NAME_FIELD = ['name'] @@ -25,32 +25,49 @@ class SecurityGroupRuleTests(base.TestCase): @classmethod def setUpClass(cls): - # Create the security group to hold the rule. - opts = cls.get_opts(cls.NAME_FIELD) - raw_output = cls.openstack('security group create ' + - cls.SECURITY_GROUP_NAME + - opts) - expected = cls.SECURITY_GROUP_NAME + '\n' - cls.assertOutput(expected, raw_output) + common.NetworkTests.setUpClass() + if cls.haz_network: + # Create the security group to hold the rule. + opts = cls.get_opts(cls.NAME_FIELD) + raw_output = cls.openstack( + 'security group create ' + + cls.SECURITY_GROUP_NAME + + opts + ) + expected = cls.SECURITY_GROUP_NAME + '\n' + cls.assertOutput(expected, raw_output) - # Create the security group rule. - opts = cls.get_opts(cls.ID_FIELD) - raw_output = cls.openstack('security group rule create ' + - cls.SECURITY_GROUP_NAME + - ' --protocol tcp --dst-port 80:80' + - ' --ingress --ethertype IPv4' + - opts) - cls.SECURITY_GROUP_RULE_ID = raw_output.strip('\n') + # Create the security group rule. + opts = cls.get_opts(cls.ID_FIELD) + raw_output = cls.openstack( + 'security group rule create ' + + cls.SECURITY_GROUP_NAME + ' ' + + '--protocol tcp --dst-port 80:80 ' + + '--ingress --ethertype IPv4 ' + + opts + ) + cls.SECURITY_GROUP_RULE_ID = raw_output.strip('\n') @classmethod def tearDownClass(cls): - raw_output = cls.openstack('security group rule delete ' + - cls.SECURITY_GROUP_RULE_ID) - cls.assertOutput('', raw_output) + 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) + raw_output = cls.openstack( + 'security group delete ' + + cls.SECURITY_GROUP_NAME + ) + cls.assertOutput('', raw_output) + + def setUp(self): + super(SecurityGroupRuleTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_security_group_rule_list(self): opts = self.get_opts(self.ID_HEADER) diff --git a/openstackclient/tests/functional/network/v2/test_subnet.py b/openstackclient/tests/functional/network/v2/test_subnet.py index 61cffcde4d..5160042cda 100644 --- a/openstackclient/tests/functional/network/v2/test_subnet.py +++ b/openstackclient/tests/functional/network/v2/test_subnet.py @@ -14,27 +14,39 @@ import json import random import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class SubnetTests(base.TestCase): - """Functional tests for subnet. """ +class SubnetTests(common.NetworkTests): + """Functional tests for subnet""" @classmethod def setUpClass(cls): - # Create a network for the all subnet tests. - cls.NETWORK_NAME = uuid.uuid4().hex - cmd_output = json.loads(cls.openstack( - 'network create -f json ' + - cls.NETWORK_NAME - )) - # Get network_id for assertEqual - cls.NETWORK_ID = cmd_output["id"] + common.NetworkTests.setUpClass() + if cls.haz_network: + # Create a network for the all subnet tests + cls.NETWORK_NAME = uuid.uuid4().hex + cmd_output = json.loads(cls.openstack( + 'network create -f json ' + + cls.NETWORK_NAME + )) + # Get network_id for assertEqual + cls.NETWORK_ID = cmd_output["id"] @classmethod def tearDownClass(cls): - raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME) - cls.assertOutput('', raw_output) + if cls.haz_network: + raw_output = cls.openstack( + 'network delete ' + + cls.NETWORK_NAME + ) + cls.assertOutput('', raw_output) + + def setUp(self): + super(SubnetTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") def test_subnet_create_and_delete(self): """Test create, delete multiple""" diff --git a/openstackclient/tests/functional/network/v2/test_subnet_pool.py b/openstackclient/tests/functional/network/v2/test_subnet_pool.py index d68ca01cf4..640f68b708 100644 --- a/openstackclient/tests/functional/network/v2/test_subnet_pool.py +++ b/openstackclient/tests/functional/network/v2/test_subnet_pool.py @@ -14,12 +14,18 @@ import json import random import uuid -from openstackclient.tests.functional import base +from openstackclient.tests.functional.network.v2 import common -class SubnetPoolTests(base.TestCase): +class SubnetPoolTests(common.NetworkTests): """Functional tests for subnet pool""" + def setUp(self): + super(SubnetPoolTests, self).setUp() + # Nothing in this class works with Nova Network + if not self.haz_network: + self.skipTest("No Network service present") + def test_subnet_pool_create_delete(self): """Test create, delete""" name1 = uuid.uuid4().hex