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
This commit is contained in:
parent
08ca61ba07
commit
4a8e7dbe6b
@ -31,25 +31,38 @@ class FloatingIpTests(base.TestCase):
|
|||||||
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
|
cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|")
|
||||||
cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)")
|
cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)")
|
||||||
|
|
||||||
# Make a random subnet
|
|
||||||
cls.subnet = ".".join(map(
|
|
||||||
str,
|
|
||||||
(random.randint(0, 223) for _ in range(3))
|
|
||||||
)) + ".0/26"
|
|
||||||
|
|
||||||
# Create a network for the floating ip
|
# Create a network for the floating ip
|
||||||
raw_output = cls.openstack(
|
raw_output = cls.openstack(
|
||||||
'network create --external ' + cls.NETWORK_NAME
|
'network create --external ' + cls.NETWORK_NAME
|
||||||
)
|
)
|
||||||
cls.network_id = re.search(cls.re_id, raw_output).group(1)
|
cls.network_id = re.search(cls.re_id, raw_output).group(1)
|
||||||
|
|
||||||
# Create a subnet for the network
|
# Try random subnet range for subnet creating
|
||||||
raw_output = cls.openstack(
|
# Because we can not determine ahead of time what subnets are already
|
||||||
'subnet create ' +
|
# in use, possibly by another test running in parallel, try 4 times
|
||||||
'--network ' + cls.NETWORK_NAME + ' ' +
|
for i in range(4):
|
||||||
'--subnet-range ' + cls.subnet + ' ' +
|
# Make a random subnet
|
||||||
cls.SUBNET_NAME
|
cls.subnet = ".".join(map(
|
||||||
)
|
str,
|
||||||
|
(random.randint(0, 223) for _ in range(3))
|
||||||
|
)) + ".0/26"
|
||||||
|
try:
|
||||||
|
# Create a subnet for the network
|
||||||
|
raw_output = cls.openstack(
|
||||||
|
'subnet create ' +
|
||||||
|
'--network ' + cls.NETWORK_NAME + ' ' +
|
||||||
|
'--subnet-range ' + cls.subnet + ' ' +
|
||||||
|
cls.SUBNET_NAME
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
if (i == 3):
|
||||||
|
# raise the exception at the last time
|
||||||
|
raise
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
# break and no longer retry if create sucessfully
|
||||||
|
break
|
||||||
|
|
||||||
cls.subnet_id = re.search(cls.re_id, raw_output).group(1)
|
cls.subnet_id = re.search(cls.re_id, raw_output).group(1)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user