Skip to content

Commit 64d6809

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Convert network segment functional tests to JSON"
2 parents d0b0b90 + b30f0f3 commit 64d6809

1 file changed

Lines changed: 99 additions & 45 deletions

File tree

openstackclient/tests/functional/network/v2/test_network_segment.py

Lines changed: 99 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import json
1314
import uuid
1415

1516
from openstackclient.tests.functional.network.v2 import common
@@ -18,64 +19,117 @@
1819
class NetworkSegmentTests(common.NetworkTests):
1920
"""Functional tests for network segment"""
2021

22+
@classmethod
23+
def setUpClass(cls):
24+
common.NetworkTests.setUpClass()
25+
if cls.haz_network:
26+
cls.NETWORK_NAME = uuid.uuid4().hex
27+
cls.PHYSICAL_NETWORK_NAME = uuid.uuid4().hex
28+
29+
# Create a network for the all subnet tests
30+
cmd_output = json.loads(cls.openstack(
31+
'network create -f json ' +
32+
cls.NETWORK_NAME
33+
))
34+
# Get network_id for assertEqual
35+
cls.NETWORK_ID = cmd_output["id"]
36+
37+
@classmethod
38+
def tearDownClass(cls):
39+
try:
40+
if cls.haz_network:
41+
raw_output = cls.openstack(
42+
'network delete ' +
43+
cls.NETWORK_NAME
44+
)
45+
cls.assertOutput('', raw_output)
46+
finally:
47+
super(NetworkSegmentTests, cls).tearDownClass()
48+
2149
def setUp(self):
2250
super(NetworkSegmentTests, self).setUp()
2351
# Nothing in this class works with Nova Network
2452
if not self.haz_network:
2553
self.skipTest("No Network service present")
2654

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
55+
def test_network_segment_create_delete(self):
56+
name = uuid.uuid4().hex
57+
json_output = json.loads(self.openstack(
58+
' network segment create -f json ' +
59+
'--network ' + self.NETWORK_ID + ' ' +
60+
'--network-type geneve ' +
61+
'--segment 2055 ' +
62+
name
63+
))
64+
self.assertEqual(
65+
name,
66+
json_output["name"],
4567
)
46-
raw_output_row = raw_output.split('\n')[0]
47-
self.NETWORK_SEGMENT_ID = raw_output_row.split(' ')[0]
4868

49-
def test_network_segment_create_delete(self):
50-
opts = self.get_opts(['id'])
5169
raw_output = self.openstack(
52-
' network segment create --network ' + self.NETWORK_ID +
53-
' --network-type geneve ' +
54-
' --segment 2055 test_segment ' + opts
70+
'network segment delete ' + name,
5571
)
56-
network_segment_id = raw_output.strip('\n')
57-
raw_output = self.openstack('network segment delete ' +
58-
network_segment_id)
5972
self.assertOutput('', raw_output)
6073

6174
def test_network_segment_list(self):
62-
opts = self.get_opts(['ID'])
63-
raw_output = self.openstack('network segment list' + opts)
64-
self.assertIn(self.NETWORK_SEGMENT_ID, raw_output)
75+
name = uuid.uuid4().hex
76+
json_output = json.loads(self.openstack(
77+
' network segment create -f json ' +
78+
'--network ' + self.NETWORK_ID + ' ' +
79+
'--network-type geneve ' +
80+
'--segment 2055 ' +
81+
name
82+
))
83+
network_segment_id = json_output.get('id')
84+
network_segment_name = json_output.get('name')
85+
self.addCleanup(
86+
self.openstack,
87+
'network segment delete ' + network_segment_id
88+
)
89+
self.assertEqual(
90+
name,
91+
json_output["name"],
92+
)
93+
94+
json_output = json.loads(self.openstack(
95+
'network segment list -f json'
96+
))
97+
item_map = {
98+
item.get('ID'): item.get('Name') for item in json_output
99+
}
100+
self.assertIn(network_segment_id, item_map.keys())
101+
self.assertIn(network_segment_name, item_map.values())
102+
103+
def test_network_segment_set_show(self):
104+
name = uuid.uuid4().hex
105+
json_output = json.loads(self.openstack(
106+
' network segment create -f json ' +
107+
'--network ' + self.NETWORK_ID + ' ' +
108+
'--network-type geneve ' +
109+
'--segment 2055 ' +
110+
name
111+
))
112+
self.addCleanup(
113+
self.openstack,
114+
'network segment delete ' + name
115+
)
116+
self.assertIsNone(
117+
json_output["description"],
118+
)
65119

66-
def test_network_segment_set(self):
67120
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)
121+
cmd_output = self.openstack(
122+
'network segment set ' +
123+
'--description ' + new_description + ' ' +
124+
name
125+
)
126+
self.assertOutput('', cmd_output)
76127

77-
def test_network_segment_show(self):
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)
128+
json_output = json.loads(self.openstack(
129+
'network segment show -f json ' +
130+
name
131+
))
132+
self.assertEqual(
133+
new_description,
134+
json_output["description"],
135+
)

0 commit comments

Comments
 (0)