|
17 | 17 |
|
18 | 18 | class NetworkSegmentTests(common.NetworkTests): |
19 | 19 | """Functional tests for network segment""" |
20 | | - NETWORK_SEGMENT_ID = None |
21 | | - NETWORK_ID = None |
22 | | - NETWORK_SEGMENT_EXTENSION = None |
23 | | - |
24 | | - @classmethod |
25 | | - def setUpClass(cls): |
26 | | - common.NetworkTests.setUpClass() |
27 | | - if cls.haz_network: |
28 | | - cls.NETWORK_NAME = uuid.uuid4().hex |
29 | | - cls.PHYSICAL_NETWORK_NAME = uuid.uuid4().hex |
30 | | - |
31 | | - # Create a network for the segment |
32 | | - opts = cls.get_opts(['id']) |
33 | | - raw_output = cls.openstack( |
34 | | - 'network create ' + cls.NETWORK_NAME + opts |
35 | | - ) |
36 | | - cls.NETWORK_ID = raw_output.strip('\n') |
37 | | - |
38 | | - # NOTE(rtheis): The segment extension is not yet enabled |
39 | | - # by default. |
40 | | - # Skip the tests if not enabled. |
41 | | - extensions = cls.get_openstack_extension_names() |
42 | | - if 'Segment' in extensions: |
43 | | - cls.NETWORK_SEGMENT_EXTENSION = 'Segment' |
44 | | - |
45 | | - if cls.NETWORK_SEGMENT_EXTENSION: |
46 | | - # Get the segment for the network. |
47 | | - opts = cls.get_opts(['ID', 'Network']) |
48 | | - raw_output = cls.openstack( |
49 | | - 'network segment list ' |
50 | | - '--network ' + cls.NETWORK_NAME + ' ' + |
51 | | - opts |
52 | | - ) |
53 | | - raw_output_row = raw_output.split('\n')[0] |
54 | | - cls.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0] |
55 | | - |
56 | | - @classmethod |
57 | | - def tearDownClass(cls): |
58 | | - try: |
59 | | - if cls.haz_network: |
60 | | - raw_output = cls.openstack( |
61 | | - 'network delete ' + cls.NETWORK_NAME |
62 | | - ) |
63 | | - cls.assertOutput('', raw_output) |
64 | | - finally: |
65 | | - super(NetworkSegmentTests, cls).tearDownClass() |
66 | 20 |
|
67 | 21 | def setUp(self): |
68 | 22 | super(NetworkSegmentTests, self).setUp() |
69 | 23 | # Nothing in this class works with Nova Network |
70 | 24 | if not self.haz_network: |
71 | 25 | self.skipTest("No Network service present") |
72 | 26 |
|
| 27 | + self.NETWORK_NAME = uuid.uuid4().hex |
| 28 | + self.PHYSICAL_NETWORK_NAME = uuid.uuid4().hex |
| 29 | + |
| 30 | + # Create a network for the segment |
| 31 | + opts = self.get_opts(['id']) |
| 32 | + raw_output = self.openstack( |
| 33 | + 'network create ' + self.NETWORK_NAME + opts |
| 34 | + ) |
| 35 | + self.addCleanup(self.openstack, |
| 36 | + 'network delete ' + self.NETWORK_NAME) |
| 37 | + self.NETWORK_ID = raw_output.strip('\n') |
| 38 | + |
| 39 | + # Get the segment for the network. |
| 40 | + opts = self.get_opts(['ID', 'Network']) |
| 41 | + raw_output = self.openstack( |
| 42 | + 'network segment list ' |
| 43 | + '--network ' + self.NETWORK_NAME + ' ' + |
| 44 | + opts |
| 45 | + ) |
| 46 | + raw_output_row = raw_output.split('\n')[0] |
| 47 | + self.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0] |
| 48 | + |
73 | 49 | def test_network_segment_create_delete(self): |
74 | | - if self.NETWORK_SEGMENT_EXTENSION: |
75 | | - opts = self.get_opts(['id']) |
76 | | - raw_output = self.openstack( |
77 | | - ' network segment create --network ' + self.NETWORK_ID + |
78 | | - ' --network-type geneve ' + |
79 | | - ' --segment 2055 test_segment ' + opts |
80 | | - ) |
81 | | - network_segment_id = raw_output.strip('\n') |
82 | | - raw_output = self.openstack('network segment delete ' + |
83 | | - network_segment_id) |
84 | | - self.assertOutput('', raw_output) |
85 | | - else: |
86 | | - self.skipTest('Segment extension disabled') |
| 50 | + opts = self.get_opts(['id']) |
| 51 | + raw_output = self.openstack( |
| 52 | + ' network segment create --network ' + self.NETWORK_ID + |
| 53 | + ' --network-type geneve ' + |
| 54 | + ' --segment 2055 test_segment ' + opts |
| 55 | + ) |
| 56 | + network_segment_id = raw_output.strip('\n') |
| 57 | + raw_output = self.openstack('network segment delete ' + |
| 58 | + network_segment_id) |
| 59 | + self.assertOutput('', raw_output) |
87 | 60 |
|
88 | 61 | def test_network_segment_list(self): |
89 | | - if self.NETWORK_SEGMENT_EXTENSION: |
90 | | - opts = self.get_opts(['ID']) |
91 | | - raw_output = self.openstack('network segment list' + opts) |
92 | | - self.assertIn(self.NETWORK_SEGMENT_ID, raw_output) |
93 | | - else: |
94 | | - self.skipTest('Segment extension disabled') |
| 62 | + opts = self.get_opts(['ID']) |
| 63 | + raw_output = self.openstack('network segment list' + opts) |
| 64 | + self.assertIn(self.NETWORK_SEGMENT_ID, raw_output) |
95 | 65 |
|
96 | 66 | def test_network_segment_set(self): |
97 | | - if self.NETWORK_SEGMENT_EXTENSION: |
98 | | - new_description = 'new_description' |
99 | | - raw_output = self.openstack('network segment set ' + |
100 | | - '--description ' + new_description + |
101 | | - ' ' + self.NETWORK_SEGMENT_ID) |
102 | | - self.assertOutput('', raw_output) |
103 | | - opts = self.get_opts(['description']) |
104 | | - raw_output = self.openstack('network segment show ' + |
105 | | - self.NETWORK_SEGMENT_ID + opts) |
106 | | - self.assertEqual(new_description + "\n", raw_output) |
107 | | - else: |
108 | | - self.skipTest('Segment extension disabled') |
| 67 | + new_description = 'new_description' |
| 68 | + raw_output = self.openstack('network segment set ' + |
| 69 | + '--description ' + new_description + |
| 70 | + ' ' + self.NETWORK_SEGMENT_ID) |
| 71 | + self.assertOutput('', raw_output) |
| 72 | + opts = self.get_opts(['description']) |
| 73 | + raw_output = self.openstack('network segment show ' + |
| 74 | + self.NETWORK_SEGMENT_ID + opts) |
| 75 | + self.assertEqual(new_description + "\n", raw_output) |
109 | 76 |
|
110 | 77 | def test_network_segment_show(self): |
111 | | - if self.NETWORK_SEGMENT_EXTENSION: |
112 | | - opts = self.get_opts(['network_id']) |
113 | | - raw_output = self.openstack('network segment show ' + |
114 | | - self.NETWORK_SEGMENT_ID + opts) |
115 | | - self.assertEqual(self.NETWORK_ID + "\n", raw_output) |
116 | | - else: |
117 | | - self.skipTest('Segment extension disabled') |
| 78 | + opts = self.get_opts(['network_id']) |
| 79 | + raw_output = self.openstack('network segment show ' + |
| 80 | + self.NETWORK_SEGMENT_ID + opts) |
| 81 | + self.assertEqual(self.NETWORK_ID + "\n", raw_output) |
0 commit comments