Allow skipping subnet CIDRs reservation when creating subnet.
This implements a special parameter to be passed to
create_subnet method to specify subnet CIDR will not be
reserved after its assigment to a new subnet.
It also reserve subnet CIDR only after subnet has been
sucessefully created.
Reserved CIDRs are still not released when subnets are
deleted. This is is left for future improvements.
Change-Id: I421dd28999086ee0af9246121f4f033291e341b4
Related-Bug: #1766702
diff --git a/neutron_tempest_plugin/api/base.py b/neutron_tempest_plugin/api/base.py
index 6700131..6246eb7 100644
--- a/neutron_tempest_plugin/api/base.py
+++ b/neutron_tempest_plugin/api/base.py
@@ -285,7 +285,8 @@
@classmethod
def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None,
- ip_version=None, client=None, **kwargs):
+ ip_version=None, client=None, reserve_cidr=True,
+ **kwargs):
"""Wrapper utility that returns a test subnet.
Convenient wrapper for client.create_subnet method. It reserves and
@@ -319,6 +320,10 @@
:param client: client to be used to connect to network service
+ :param reserve_cidr: if True then it reserves assigned CIDR to avoid
+ using the same CIDR for further subnets in the scope of the same
+ test case class
+
:param **kwargs: optional parameters to be forwarded to wrapped method
[1] http://netaddr.readthedocs.io/en/latest/tutorial_01.html#supernets-and-subnets # noqa
@@ -341,19 +346,18 @@
for subnet_cidr in cls.get_subnet_cidrs(
ip_version=ip_version, cidr=cidr, mask_bits=mask_bits):
- if cls.try_reserve_subnet_cidr(subnet_cidr):
- if gateway is not None:
- kwargs['gateway_ip'] = str(gateway or (subnet_cidr.ip + 1))
- try:
- body = client.create_subnet(
- network_id=network['id'],
- cidr=str(subnet_cidr),
- ip_version=subnet_cidr.version,
- **kwargs)
- break
- except lib_exc.BadRequest as e:
- if 'overlaps with another subnet' not in str(e):
- raise
+ if gateway is not None:
+ kwargs['gateway_ip'] = str(gateway or (subnet_cidr.ip + 1))
+ try:
+ body = client.create_subnet(
+ network_id=network['id'],
+ cidr=str(subnet_cidr),
+ ip_version=subnet_cidr.version,
+ **kwargs)
+ break
+ except lib_exc.BadRequest as e:
+ if 'overlaps with another subnet' not in str(e):
+ raise
else:
message = 'Available CIDR for subnet creation could not be found'
raise ValueError(message)
@@ -362,6 +366,8 @@
cls.subnets.append(subnet)
else:
cls.admin_subnets.append(subnet)
+ if reserve_cidr:
+ cls.reserve_subnet_cidr(subnet_cidr)
return subnet
@classmethod