Skip to content

Commit 385b87c

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Beef up floating IP functional tests"
2 parents 0948aa6 + 3da71c8 commit 385b87c

1 file changed

Lines changed: 121 additions & 22 deletions

File tree

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

Lines changed: 121 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,148 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import random
14+
import re
1315
import uuid
1416

1517
from openstackclient.tests.functional import base
1618

1719

1820
class FloatingIpTests(base.TestCase):
19-
"""Functional tests for floating ip. """
21+
"""Functional tests for floating ip"""
2022
SUBNET_NAME = uuid.uuid4().hex
2123
NETWORK_NAME = uuid.uuid4().hex
22-
ID = None
23-
HEADERS = ['ID']
24-
FIELDS = ['id']
2524

2625
@classmethod
2726
def setUpClass(cls):
28-
# Create a network for the floating ip.
29-
cls.openstack('network create --external ' + cls.NETWORK_NAME)
30-
# Create a subnet for the network.
31-
cls.openstack(
32-
'subnet create --network ' + cls.NETWORK_NAME +
33-
' --subnet-range 10.10.10.0/24 ' +
34-
cls.SUBNET_NAME
27+
# Set up some regex for matching below
28+
cls.re_id = re.compile("id\s+\|\s+(\S+)")
29+
cls.re_floating_ip = re.compile("floating_ip_address\s+\|\s+(\S+)")
30+
cls.re_fixed_ip = re.compile("fixed_ip_address\s+\|\s+(\S+)")
31+
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
32+
cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)")
33+
34+
# Make a random subnet
35+
cls.subnet = ".".join(map(
36+
str,
37+
(random.randint(0, 255) for _ in range(3))
38+
)) + ".0/26"
39+
40+
# Create a network for the floating ip
41+
raw_output = cls.openstack(
42+
'network create --external ' + cls.NETWORK_NAME
3543
)
36-
opts = cls.get_opts(cls.FIELDS)
44+
cls.network_id = re.search(cls.re_id, raw_output).group(1)
45+
46+
# Create a subnet for the network
3747
raw_output = cls.openstack(
38-
'floating ip create ' + cls.NETWORK_NAME + opts)
39-
cls.ID = raw_output.strip('\n')
48+
'subnet create ' +
49+
'--network ' + cls.NETWORK_NAME + ' ' +
50+
'--subnet-range ' + cls.subnet + ' ' +
51+
cls.SUBNET_NAME
52+
)
53+
cls.subnet_id = re.search(cls.re_id, raw_output).group(1)
4054

4155
@classmethod
4256
def tearDownClass(cls):
43-
raw_output = cls.openstack('floating ip delete ' + cls.ID)
44-
cls.assertOutput('', raw_output)
4557
raw_output = cls.openstack('subnet delete ' + cls.SUBNET_NAME)
4658
cls.assertOutput('', raw_output)
4759
raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME)
4860
cls.assertOutput('', raw_output)
4961

62+
def test_floating_ip_delete(self):
63+
"""Test create, delete multiple"""
64+
raw_output = self.openstack(
65+
'floating ip create ' +
66+
'--description aaaa ' +
67+
self.NETWORK_NAME
68+
)
69+
re_ip = re.search(self.re_floating_ip, raw_output)
70+
self.assertIsNotNone(re_ip)
71+
ip1 = re_ip.group(1)
72+
self.assertEqual(
73+
'aaaa',
74+
re.search(self.re_description, raw_output).group(1),
75+
)
76+
77+
raw_output = self.openstack(
78+
'floating ip create ' +
79+
'--description bbbb ' +
80+
self.NETWORK_NAME
81+
)
82+
ip2 = re.search(self.re_floating_ip, raw_output).group(1)
83+
self.assertEqual(
84+
'bbbb',
85+
re.search(self.re_description, raw_output).group(1),
86+
)
87+
88+
# Clean up after ourselves
89+
raw_output = self.openstack('floating ip delete ' + ip1 + ' ' + ip2)
90+
self.assertOutput('', raw_output)
91+
5092
def test_floating_ip_list(self):
51-
opts = self.get_opts(self.HEADERS)
52-
raw_output = self.openstack('floating ip list' + opts)
53-
self.assertIn(self.ID, raw_output)
93+
"""Test create defaults, list filters, delete"""
94+
raw_output = self.openstack(
95+
'floating ip create ' +
96+
'--description aaaa ' +
97+
self.NETWORK_NAME
98+
)
99+
re_ip = re.search(self.re_floating_ip, raw_output)
100+
self.assertIsNotNone(re_ip)
101+
ip1 = re_ip.group(1)
102+
self.addCleanup(self.openstack, 'floating ip delete ' + ip1)
103+
self.assertEqual(
104+
'aaaa',
105+
re.search(self.re_description, raw_output).group(1),
106+
)
107+
self.assertIsNotNone(re.search(self.re_network_id, raw_output))
108+
109+
raw_output = self.openstack(
110+
'floating ip create ' +
111+
'--description bbbb ' +
112+
self.NETWORK_NAME
113+
)
114+
ip2 = re.search(self.re_floating_ip, raw_output).group(1)
115+
self.addCleanup(self.openstack, 'floating ip delete ' + ip2)
116+
self.assertEqual(
117+
'bbbb',
118+
re.search(self.re_description, raw_output).group(1),
119+
)
120+
121+
# Test list
122+
raw_output = self.openstack('floating ip list')
123+
self.assertIsNotNone(re.search("\|\s+" + ip1 + "\s+\|", raw_output))
124+
self.assertIsNotNone(re.search("\|\s+" + ip2 + "\s+\|", raw_output))
125+
126+
# Test list --long
127+
raw_output = self.openstack('floating ip list --long')
128+
self.assertIsNotNone(re.search("\|\s+" + ip1 + "\s+\|", raw_output))
129+
self.assertIsNotNone(re.search("\|\s+" + ip2 + "\s+\|", raw_output))
130+
131+
# TODO(dtroyer): add more filter tests
54132

55133
def test_floating_ip_show(self):
56-
opts = self.get_opts(self.FIELDS)
57-
raw_output = self.openstack('floating ip show ' + self.ID + opts)
58-
self.assertEqual(self.ID + "\n", raw_output)
134+
"""Test show"""
135+
raw_output = self.openstack(
136+
'floating ip create ' +
137+
'--description shosho ' +
138+
# '--fixed-ip-address 1.2.3.4 ' +
139+
self.NETWORK_NAME
140+
)
141+
re_ip = re.search(self.re_floating_ip, raw_output)
142+
self.assertIsNotNone(re_ip)
143+
ip = re_ip.group(1)
144+
145+
raw_output = self.openstack('floating ip show ' + ip)
146+
self.addCleanup(self.openstack, 'floating ip delete ' + ip)
147+
148+
self.assertEqual(
149+
'shosho',
150+
re.search(self.re_description, raw_output).group(1),
151+
)
152+
# TODO(dtroyer): not working???
153+
# self.assertEqual(
154+
# '1.2.3.4',
155+
# re.search(self.re_floating_ip, raw_output).group(1),
156+
# )
157+
self.assertIsNotNone(re.search(self.re_network_id, raw_output))

0 commit comments

Comments
 (0)