Skip to content

Commit 4a8e7db

Browse files
Huanxuan AoDean Troyer
authored andcommitted
Fix functional test for creating subnet
subnet create failed by some bad random subnet range, so retry it with new random range when the test failed. Change-Id: If528ff419b51dd5c5232f81d4b26abae542bd820
1 parent 08ca61b commit 4a8e7db

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,38 @@ def setUpClass(cls):
3131
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
3232
cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)")
3333

34-
# Make a random subnet
35-
cls.subnet = ".".join(map(
36-
str,
37-
(random.randint(0, 223) for _ in range(3))
38-
)) + ".0/26"
39-
4034
# Create a network for the floating ip
4135
raw_output = cls.openstack(
4236
'network create --external ' + cls.NETWORK_NAME
4337
)
4438
cls.network_id = re.search(cls.re_id, raw_output).group(1)
4539

46-
# Create a subnet for the network
47-
raw_output = cls.openstack(
48-
'subnet create ' +
49-
'--network ' + cls.NETWORK_NAME + ' ' +
50-
'--subnet-range ' + cls.subnet + ' ' +
51-
cls.SUBNET_NAME
52-
)
40+
# Try random subnet range for subnet creating
41+
# Because we can not determine ahead of time what subnets are already
42+
# in use, possibly by another test running in parallel, try 4 times
43+
for i in range(4):
44+
# Make a random subnet
45+
cls.subnet = ".".join(map(
46+
str,
47+
(random.randint(0, 223) for _ in range(3))
48+
)) + ".0/26"
49+
try:
50+
# Create a subnet for the network
51+
raw_output = cls.openstack(
52+
'subnet create ' +
53+
'--network ' + cls.NETWORK_NAME + ' ' +
54+
'--subnet-range ' + cls.subnet + ' ' +
55+
cls.SUBNET_NAME
56+
)
57+
except Exception:
58+
if (i == 3):
59+
# raise the exception at the last time
60+
raise
61+
pass
62+
else:
63+
# break and no longer retry if create sucessfully
64+
break
65+
5366
cls.subnet_id = re.search(cls.re_id, raw_output).group(1)
5467

5568
@classmethod

0 commit comments

Comments
 (0)