Skip to content

Commit dd7da49

Browse files
author
Dean Troyer
committed
Nova net functional tests round 2
* floating ip * ip availability * network qos policy * network qos rule * network qos rule type * network rbac Change-Id: Id3946bdff43bfef3a1d879c058bde4792bd299c6
1 parent e0d1af9 commit dd7da49

6 files changed

Lines changed: 180 additions & 106 deletions

File tree

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

Lines changed: 89 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import re
1515
import uuid
1616

17-
from openstackclient.tests.functional import base
17+
from openstackclient.tests.functional.network.v2 import common
1818

1919

20-
class FloatingIpTests(base.TestCase):
20+
class FloatingIpTests(common.NetworkTests):
2121
"""Functional tests for floating ip"""
2222
SUBNET_NAME = uuid.uuid4().hex
2323
NETWORK_NAME = uuid.uuid4().hex
@@ -28,78 +28,97 @@ class FloatingIpTests(base.TestCase):
2828

2929
@classmethod
3030
def setUpClass(cls):
31-
# Set up some regex for matching below
32-
cls.re_id = re.compile("id\s+\|\s+(\S+)")
33-
cls.re_floating_ip = re.compile("floating_ip_address\s+\|\s+(\S+)")
34-
cls.re_fixed_ip = re.compile("fixed_ip_address\s+\|\s+(\S+)")
35-
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
36-
cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)")
37-
cls.re_port_id = re.compile("\s+id\s+\|\s+(\S+)")
38-
cls.re_fp_port_id = re.compile("\s+port_id\s+\|\s+(\S+)")
39-
40-
# Create a network for the floating ip
41-
raw_output = cls.openstack(
42-
'network create --external ' + cls.NETWORK_NAME
43-
)
44-
cls.network_id = re.search(cls.re_id, raw_output).group(1)
31+
common.NetworkTests.setUpClass()
32+
if cls.haz_network:
33+
# Set up some regex for matching below
34+
cls.re_id = re.compile("id\s+\|\s+(\S+)")
35+
cls.re_floating_ip = re.compile("floating_ip_address\s+\|\s+(\S+)")
36+
cls.re_fixed_ip = re.compile("fixed_ip_address\s+\|\s+(\S+)")
37+
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
38+
cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)")
39+
cls.re_port_id = re.compile("\s+id\s+\|\s+(\S+)")
40+
cls.re_fp_port_id = re.compile("\s+port_id\s+\|\s+(\S+)")
4541

46-
# Create a private network for the port
47-
raw_output = cls.openstack(
48-
'network create ' + cls.PRIVATE_NETWORK_NAME
49-
)
50-
cls.private_network_id = re.search(cls.re_id, raw_output).group(1)
51-
52-
# Try random subnet range for subnet creating
53-
# Because we can not determine ahead of time what subnets are already
54-
# in use, possibly by another test running in parallel, try 4 times
55-
for i in range(4):
56-
# Make a random subnet
57-
cls.subnet = ".".join(map(
58-
str,
59-
(random.randint(0, 223) for _ in range(3))
60-
)) + ".0/26"
61-
cls.private_subnet = ".".join(map(
62-
str,
63-
(random.randint(0, 223) for _ in range(3))
64-
)) + ".0/26"
65-
try:
66-
# Create a subnet for the network
67-
raw_output = cls.openstack(
68-
'subnet create ' +
69-
'--network ' + cls.NETWORK_NAME + ' ' +
70-
'--subnet-range ' + cls.subnet + ' ' +
71-
cls.SUBNET_NAME
72-
)
73-
# Create a subnet for the private network
74-
priv_raw_output = cls.openstack(
75-
'subnet create ' +
76-
'--network ' + cls.PRIVATE_NETWORK_NAME + ' ' +
77-
'--subnet-range ' + cls.private_subnet + ' ' +
78-
cls.PRIVATE_SUBNET_NAME
79-
)
80-
except Exception:
81-
if (i == 3):
82-
# raise the exception at the last time
83-
raise
84-
pass
85-
else:
86-
# break and no longer retry if create sucessfully
87-
break
88-
89-
cls.subnet_id = re.search(cls.re_id, raw_output).group(1)
90-
cls.private_subnet_id = re.search(cls.re_id, priv_raw_output).group(1)
42+
# Create a network for the floating ip
43+
raw_output = cls.openstack(
44+
'network create --external ' + cls.NETWORK_NAME
45+
)
46+
cls.network_id = re.search(cls.re_id, raw_output).group(1)
47+
48+
# Create a private network for the port
49+
raw_output = cls.openstack(
50+
'network create ' + cls.PRIVATE_NETWORK_NAME
51+
)
52+
cls.private_network_id = re.search(cls.re_id, raw_output).group(1)
53+
54+
# Try random subnet range for subnet creating
55+
# Because we can not determine ahead of time what subnets are
56+
# already in use, possibly by another test running in parallel,
57+
# try 4 times
58+
for i in range(4):
59+
# Make a random subnet
60+
cls.subnet = ".".join(map(
61+
str,
62+
(random.randint(0, 223) for _ in range(3))
63+
)) + ".0/26"
64+
cls.private_subnet = ".".join(map(
65+
str,
66+
(random.randint(0, 223) for _ in range(3))
67+
)) + ".0/26"
68+
try:
69+
# Create a subnet for the network
70+
raw_output = cls.openstack(
71+
'subnet create ' +
72+
'--network ' + cls.NETWORK_NAME + ' ' +
73+
'--subnet-range ' + cls.subnet + ' ' +
74+
cls.SUBNET_NAME
75+
)
76+
# Create a subnet for the private network
77+
priv_raw_output = cls.openstack(
78+
'subnet create ' +
79+
'--network ' + cls.PRIVATE_NETWORK_NAME + ' ' +
80+
'--subnet-range ' + cls.private_subnet + ' ' +
81+
cls.PRIVATE_SUBNET_NAME
82+
)
83+
except Exception:
84+
if (i == 3):
85+
# raise the exception at the last time
86+
raise
87+
pass
88+
else:
89+
# break and no longer retry if create sucessfully
90+
break
91+
92+
cls.subnet_id = re.search(cls.re_id, raw_output).group(1)
93+
cls.private_subnet_id = re.search(
94+
cls.re_id, priv_raw_output
95+
).group(1)
9196

9297
@classmethod
9398
def tearDownClass(cls):
94-
raw_output = cls.openstack('subnet delete ' + cls.SUBNET_NAME)
95-
cls.assertOutput('', raw_output)
96-
raw_output = cls.openstack('subnet delete ' + cls.PRIVATE_SUBNET_NAME)
97-
cls.assertOutput('', raw_output)
98-
raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME)
99-
cls.assertOutput('', raw_output)
100-
raw_output = cls.openstack(
101-
'network delete ' + cls.PRIVATE_NETWORK_NAME)
102-
cls.assertOutput('', raw_output)
99+
if cls.haz_network:
100+
raw_output = cls.openstack(
101+
'subnet delete ' + cls.SUBNET_NAME,
102+
)
103+
cls.assertOutput('', raw_output)
104+
raw_output = cls.openstack(
105+
'subnet delete ' + cls.PRIVATE_SUBNET_NAME,
106+
)
107+
cls.assertOutput('', raw_output)
108+
raw_output = cls.openstack(
109+
'network delete ' + cls.NETWORK_NAME,
110+
)
111+
cls.assertOutput('', raw_output)
112+
raw_output = cls.openstack(
113+
'network delete ' + cls.PRIVATE_NETWORK_NAME,
114+
)
115+
cls.assertOutput('', raw_output)
116+
117+
def setUp(self):
118+
super(FloatingIpTests, self).setUp()
119+
# Nothing in this class works with Nova Network
120+
if not self.haz_network:
121+
self.skipTest("No Network service present")
103122

104123
def test_floating_ip_delete(self):
105124
"""Test create, delete multiple"""

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
import json
1414
import uuid
1515

16-
from openstackclient.tests.functional import base
16+
from openstackclient.tests.functional.network.v2 import common
1717

1818

19-
class IPAvailabilityTests(base.TestCase):
19+
class IPAvailabilityTests(common.NetworkTests):
2020
"""Functional tests for IP availability. """
2121

2222
@classmethod
2323
def setUpClass(cls):
24+
common.NetworkTests.setUpClass()
25+
if not cls.haz_network:
26+
common.NetworkTests.skipTest(cls, "No Network service present")
27+
2428
# Create a network for the subnet.
2529
cls.NAME = uuid.uuid4().hex
2630
cls.NETWORK_NAME = uuid.uuid4().hex

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,29 @@
1515

1616
import uuid
1717

18-
from openstackclient.tests.functional import base
18+
from openstackclient.tests.functional.network.v2 import common
1919

2020

21-
class QosPolicyTests(base.TestCase):
21+
class NetworkQosPolicyTests(common.NetworkTests):
2222
"""Functional tests for QoS policy. """
2323
NAME = uuid.uuid4().hex
2424
HEADERS = ['Name']
2525
FIELDS = ['name']
2626

2727
@classmethod
2828
def setUpClass(cls):
29+
common.NetworkTests.setUpClass()
2930
opts = cls.get_opts(cls.FIELDS)
3031
raw_output = cls.openstack('network qos policy create ' + cls.NAME +
3132
opts)
3233
cls.assertOutput(cls.NAME + "\n", raw_output)
3334

35+
def setUp(self):
36+
super(NetworkQosPolicyTests, self).setUp()
37+
# Nothing in this class works with Nova Network
38+
if not self.haz_network:
39+
self.skipTest("No Network service present")
40+
3441
@classmethod
3542
def tearDownClass(cls):
3643
raw_output = cls.openstack('network qos policy delete ' + cls.NAME)

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

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
import uuid
1717

18-
from openstackclient.tests.functional import base
18+
from openstackclient.tests.functional.network.v2 import common
1919

2020

21-
class NetworkQosRuleTestsMinimumBandwidth(base.TestCase):
21+
class NetworkQosRuleTestsMinimumBandwidth(common.NetworkTests):
2222
"""Functional tests for QoS minimum bandwidth rule."""
2323
RULE_ID = None
2424
QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex
@@ -31,6 +31,7 @@ class NetworkQosRuleTestsMinimumBandwidth(base.TestCase):
3131

3232
@classmethod
3333
def setUpClass(cls):
34+
common.NetworkTests.setUpClass()
3435
opts = cls.get_opts(cls.FIELDS)
3536
cls.openstack('network qos policy create ' + cls.QOS_POLICY_NAME)
3637
cls.RULE_ID = cls.openstack('network qos rule create --type ' +
@@ -46,20 +47,26 @@ def tearDownClass(cls):
4647
cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME)
4748
cls.assertOutput('', raw_output)
4849

49-
def test_qos_policy_list(self):
50+
def setUp(self):
51+
super(NetworkQosRuleTestsMinimumBandwidth, self).setUp()
52+
# Nothing in this class works with Nova Network
53+
if not self.haz_network:
54+
self.skipTest("No Network service present")
55+
56+
def test_qos_rule_list(self):
5057
opts = self.get_opts(self.HEADERS)
5158
raw_output = self.openstack('network qos rule list '
5259
+ self.QOS_POLICY_NAME + opts)
5360
self.assertIn(self.RULE_ID, raw_output)
5461

55-
def test_qos_policy_show(self):
62+
def test_qos_rule_show(self):
5663
opts = self.get_opts(self.FIELDS)
5764
raw_output = self.openstack('network qos rule show ' +
5865
self.QOS_POLICY_NAME + ' ' + self.RULE_ID +
5966
opts)
6067
self.assertEqual(self.RULE_ID, raw_output)
6168

62-
def test_qos_policy_set(self):
69+
def test_qos_rule_set(self):
6370
self.openstack('network qos rule set --min-kbps ' +
6471
str(self.MIN_KBPS_MODIFIED) + ' ' +
6572
self.QOS_POLICY_NAME + ' ' + self.RULE_ID)
@@ -70,7 +77,7 @@ def test_qos_policy_set(self):
7077
self.assertEqual(str(self.MIN_KBPS_MODIFIED) + "\n", raw_output)
7178

7279

73-
class NetworkQosRuleTestsDSCPMarking(base.TestCase):
80+
class NetworkQosRuleTestsDSCPMarking(common.NetworkTests):
7481
"""Functional tests for QoS DSCP marking rule."""
7582
RULE_ID = None
7683
QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex
@@ -82,6 +89,7 @@ class NetworkQosRuleTestsDSCPMarking(base.TestCase):
8289

8390
@classmethod
8491
def setUpClass(cls):
92+
common.NetworkTests.setUpClass()
8593
opts = cls.get_opts(cls.FIELDS)
8694
cls.openstack('network qos policy create ' + cls.QOS_POLICY_NAME)
8795
cls.RULE_ID = cls.openstack('network qos rule create --type ' +
@@ -97,20 +105,26 @@ def tearDownClass(cls):
97105
cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME)
98106
cls.assertOutput('', raw_output)
99107

100-
def test_qos_policy_list(self):
108+
def setUp(self):
109+
super(NetworkQosRuleTestsDSCPMarking, self).setUp()
110+
# Nothing in this class works with Nova Network
111+
if not self.haz_network:
112+
self.skipTest("No Network service present")
113+
114+
def test_qos_rule_list(self):
101115
opts = self.get_opts(self.HEADERS)
102116
raw_output = self.openstack('network qos rule list '
103117
+ self.QOS_POLICY_NAME + opts)
104118
self.assertIn(self.RULE_ID, raw_output)
105119

106-
def test_qos_policy_show(self):
120+
def test_qos_rule_show(self):
107121
opts = self.get_opts(self.FIELDS)
108122
raw_output = self.openstack('network qos rule show ' +
109123
self.QOS_POLICY_NAME + ' ' + self.RULE_ID +
110124
opts)
111125
self.assertEqual(self.RULE_ID, raw_output)
112126

113-
def test_qos_policy_set(self):
127+
def test_qos_rule_set(self):
114128
self.openstack('network qos rule set --dscp-mark ' +
115129
str(self.DSCP_MARK_MODIFIED) + ' ' +
116130
self.QOS_POLICY_NAME + ' ' + self.RULE_ID)
@@ -121,7 +135,7 @@ def test_qos_policy_set(self):
121135
self.assertEqual(str(self.DSCP_MARK_MODIFIED) + "\n", raw_output)
122136

123137

124-
class NetworkQosRuleTestsBandwidthLimit(base.TestCase):
138+
class NetworkQosRuleTestsBandwidthLimit(common.NetworkTests):
125139
"""Functional tests for QoS bandwidth limit rule."""
126140
RULE_ID = None
127141
QOS_POLICY_NAME = 'qos_policy_' + uuid.uuid4().hex
@@ -135,6 +149,7 @@ class NetworkQosRuleTestsBandwidthLimit(base.TestCase):
135149

136150
@classmethod
137151
def setUpClass(cls):
152+
common.NetworkTests.setUpClass()
138153
opts = cls.get_opts(cls.FIELDS)
139154
cls.openstack('network qos policy create ' + cls.QOS_POLICY_NAME)
140155
cls.RULE_ID = cls.openstack('network qos rule create --type ' +
@@ -151,20 +166,26 @@ def tearDownClass(cls):
151166
cls.openstack('network qos policy delete ' + cls.QOS_POLICY_NAME)
152167
cls.assertOutput('', raw_output)
153168

154-
def test_qos_policy_list(self):
169+
def setUp(self):
170+
super(NetworkQosRuleTestsBandwidthLimit, self).setUp()
171+
# Nothing in this class works with Nova Network
172+
if not self.haz_network:
173+
self.skipTest("No Network service present")
174+
175+
def test_qos_rule_list(self):
155176
opts = self.get_opts(self.HEADERS)
156177
raw_output = self.openstack('network qos rule list '
157178
+ self.QOS_POLICY_NAME + opts)
158179
self.assertIn(self.RULE_ID, raw_output)
159180

160-
def test_qos_policy_show(self):
181+
def test_qos_rule_show(self):
161182
opts = self.get_opts(self.FIELDS)
162183
raw_output = self.openstack('network qos rule show ' +
163184
self.QOS_POLICY_NAME + ' ' + self.RULE_ID +
164185
opts)
165186
self.assertEqual(self.RULE_ID, raw_output)
166187

167-
def test_qos_policy_set(self):
188+
def test_qos_rule_set(self):
168189
self.openstack('network qos rule set --max-kbps ' +
169190
str(self.MAX_KBPS_MODIFIED) + ' --max-burst-kbits ' +
170191
str(self.MAX_BURST_KBITS_MODIFIED) + ' ' +

0 commit comments

Comments
 (0)