From 198a486413738148eb0de2a25749daac289a496e Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Sun, 23 Jul 2017 23:41:33 +0000 Subject: [PATCH] network functest: Remove condition for segment test Previously fucntional tests for network segment feature are skipped as neutron 'segment' API extension was disabled in the gate. We now enable neutron 'segment' API extension, so we can safely drop the check for the segment extension from the test code. Also setup code in test_network_segment is moved from setUpClass to setUp. There is no good reason to do them in setUpClass and having them in setUp simplifies the test code. no user once this commit is applied. Change-Id: I183310b94d9b6d7f4311a3859b59dc22d36440db --- openstackclient/tests/functional/base.py | 5 - .../network/v2/test_network_segment.py | 132 +++++++----------- 2 files changed, 48 insertions(+), 89 deletions(-) diff --git a/openstackclient/tests/functional/base.py b/openstackclient/tests/functional/base.py index d95f7f8465..4c88b13e93 100644 --- a/openstackclient/tests/functional/base.py +++ b/openstackclient/tests/functional/base.py @@ -68,11 +68,6 @@ class TestCase(testtools.TestCase): opts = cls.get_opts([configuration]) return cls.openstack('configuration show ' + opts) - @classmethod - def get_openstack_extension_names(cls): - opts = cls.get_opts(['Name']) - return cls.openstack('extension list ' + opts) - @classmethod def get_opts(cls, fields, output_format='value'): return ' -f {0} {1}'.format(output_format, diff --git a/openstackclient/tests/functional/network/v2/test_network_segment.py b/openstackclient/tests/functional/network/v2/test_network_segment.py index b34515fa41..e1dbc7a0c5 100644 --- a/openstackclient/tests/functional/network/v2/test_network_segment.py +++ b/openstackclient/tests/functional/network/v2/test_network_segment.py @@ -17,52 +17,6 @@ from openstackclient.tests.functional.network.v2 import common class NetworkSegmentTests(common.NetworkTests): """Functional tests for network segment""" - NETWORK_SEGMENT_ID = None - NETWORK_ID = None - NETWORK_SEGMENT_EXTENSION = None - - @classmethod - def setUpClass(cls): - common.NetworkTests.setUpClass() - if cls.haz_network: - cls.NETWORK_NAME = uuid.uuid4().hex - cls.PHYSICAL_NETWORK_NAME = uuid.uuid4().hex - - # 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_extension_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] - - @classmethod - def tearDownClass(cls): - 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() @@ -70,48 +24,58 @@ class NetworkSegmentTests(common.NetworkTests): if not self.haz_network: self.skipTest("No Network service present") + self.NETWORK_NAME = uuid.uuid4().hex + self.PHYSICAL_NETWORK_NAME = uuid.uuid4().hex + + # Create a network for the segment + opts = self.get_opts(['id']) + raw_output = self.openstack( + 'network create ' + self.NETWORK_NAME + opts + ) + self.addCleanup(self.openstack, + 'network delete ' + self.NETWORK_NAME) + self.NETWORK_ID = raw_output.strip('\n') + + # Get the segment for the network. + opts = self.get_opts(['ID', 'Network']) + raw_output = self.openstack( + 'network segment list ' + '--network ' + self.NETWORK_NAME + ' ' + + opts + ) + raw_output_row = raw_output.split('\n')[0] + self.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0] + def test_network_segment_create_delete(self): - if self.NETWORK_SEGMENT_EXTENSION: - opts = self.get_opts(['id']) - raw_output = self.openstack( - ' network segment create --network ' + self.NETWORK_ID + - ' --network-type geneve ' + - ' --segment 2055 test_segment ' + opts - ) - network_segment_id = raw_output.strip('\n') - raw_output = self.openstack('network segment delete ' + - network_segment_id) - self.assertOutput('', raw_output) - else: - self.skipTest('Segment extension disabled') + opts = self.get_opts(['id']) + raw_output = self.openstack( + ' network segment create --network ' + self.NETWORK_ID + + ' --network-type geneve ' + + ' --segment 2055 test_segment ' + opts + ) + network_segment_id = raw_output.strip('\n') + raw_output = self.openstack('network segment delete ' + + network_segment_id) + self.assertOutput('', raw_output) def test_network_segment_list(self): - if self.NETWORK_SEGMENT_EXTENSION: - opts = self.get_opts(['ID']) - raw_output = self.openstack('network segment list' + opts) - self.assertIn(self.NETWORK_SEGMENT_ID, raw_output) - else: - self.skipTest('Segment extension disabled') + opts = self.get_opts(['ID']) + raw_output = self.openstack('network segment list' + opts) + self.assertIn(self.NETWORK_SEGMENT_ID, raw_output) def test_network_segment_set(self): - if self.NETWORK_SEGMENT_EXTENSION: - new_description = 'new_description' - raw_output = self.openstack('network segment set ' + - '--description ' + new_description + - ' ' + self.NETWORK_SEGMENT_ID) - self.assertOutput('', raw_output) - opts = self.get_opts(['description']) - raw_output = self.openstack('network segment show ' + - self.NETWORK_SEGMENT_ID + opts) - self.assertEqual(new_description + "\n", raw_output) - else: - self.skipTest('Segment extension disabled') + new_description = 'new_description' + raw_output = self.openstack('network segment set ' + + '--description ' + new_description + + ' ' + self.NETWORK_SEGMENT_ID) + self.assertOutput('', raw_output) + opts = self.get_opts(['description']) + raw_output = self.openstack('network segment show ' + + self.NETWORK_SEGMENT_ID + opts) + self.assertEqual(new_description + "\n", raw_output) def test_network_segment_show(self): - if self.NETWORK_SEGMENT_EXTENSION: - opts = self.get_opts(['network_id']) - raw_output = self.openstack('network segment show ' + - self.NETWORK_SEGMENT_ID + opts) - self.assertEqual(self.NETWORK_ID + "\n", raw_output) - else: - self.skipTest('Segment extension disabled') + opts = self.get_opts(['network_id']) + raw_output = self.openstack('network segment show ' + + self.NETWORK_SEGMENT_ID + opts) + self.assertEqual(self.NETWORK_ID + "\n", raw_output)