Merge "Support first_ip for allocate_block_subnet"

This commit is contained in:
Zuul 2019-11-20 10:05:34 +00:00 committed by Gerrit Code Review
commit bfbe3fa101
3 changed files with 50 additions and 6 deletions

View File

@ -3856,14 +3856,41 @@ class TestPolicyIpPool(NsxPolicyLibTestCase):
ip_block_id = 'block-id'
size = 256
ip_subnet_id = 'subnet-id'
start_ip = '192.168.1.0'
with mock.patch.object(self.policy_api,
"create_or_update") as api_call:
with mock.patch.object(
self.policy_api, "create_or_update") as api_call, \
mock.patch.object(self.resourceApi, 'version', '3.0.0'):
self.resourceApi.allocate_block_subnet(
ip_pool_id, ip_block_id, size, ip_subnet_id,
tenant=TEST_TENANT)
tenant=TEST_TENANT, start_ip=start_ip)
expected_def = core_defs.IpPoolBlockSubnetDef(
nsx_version='3.0.0',
ip_pool_id=ip_pool_id,
ip_block_id=ip_block_id,
ip_subnet_id=ip_subnet_id,
size=size,
tenant=TEST_TENANT,
start_ip=start_ip)
self.assert_called_with_def(api_call, expected_def)
def test_allocate_block_subnet_with_unsupported_attribute(self):
ip_pool_id = '111'
ip_block_id = 'block-id'
size = 256
ip_subnet_id = 'subnet-id'
start_ip = '192.168.1.0'
with mock.patch.object(
self.policy_api, "create_or_update") as api_call, \
mock.patch.object(self.resourceApi, 'version', '2.5.0'):
self.resourceApi.allocate_block_subnet(
ip_pool_id, ip_block_id, size, ip_subnet_id,
tenant=TEST_TENANT, start_ip=start_ip)
expected_def = core_defs.IpPoolBlockSubnetDef(
nsx_version='2.5.0',
ip_pool_id=ip_pool_id,
ip_block_id=ip_block_id,
ip_subnet_id=ip_subnet_id,

View File

@ -1199,8 +1199,22 @@ class IpPoolBlockSubnetDef(IpPoolSubnetDef):
self._set_attr_if_specified(
body, 'ip_block_id', body_attr='ip_block_path',
value=ip_block_path)
self._set_attr_if_supported(body, 'start_ip')
return body
def _version_dependant_attr_supported(self, attr):
if (version.LooseVersion(self.nsx_version) >=
version.LooseVersion(nsx_constants.NSX_VERSION_3_0_0)):
if attr == 'start_ip':
return True
LOG.warning(
"Ignoring %s for %s %s: this feature is not supported."
"Current NSX version: %s. Minimum supported version: %s",
attr, self.resource_type, self.attrs.get('name', ''),
self.nsx_version, nsx_constants.NSX_VERSION_3_0_0)
return False
class IpPoolStaticSubnetDef(IpPoolSubnetDef):
'''Infra IpPool static subnet'''

View File

@ -2701,7 +2701,8 @@ class NsxPolicyIpPoolApi(NsxPolicyResourceBase):
def allocate_block_subnet(self, ip_pool_id, ip_block_id, size,
ip_subnet_id=None, auto_assign_gateway=IGNORE,
name=IGNORE, description=IGNORE, tags=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
tenant=constants.POLICY_INFRA_TENANT,
start_ip=IGNORE):
ip_subnet_id = self._init_obj_uuid(ip_subnet_id)
args = self._get_user_args(
ip_pool_id=ip_pool_id,
@ -2712,9 +2713,11 @@ class NsxPolicyIpPoolApi(NsxPolicyResourceBase):
name=name,
description=description,
tags=tags,
tenant=tenant)
tenant=tenant,
start_ip=start_ip)
ip_subnet_def = core_defs.IpPoolBlockSubnetDef(**args)
ip_subnet_def = core_defs.IpPoolBlockSubnetDef(
nsx_version=self.version, **args)
self._create_or_store(ip_subnet_def)
def release_block_subnet(self, ip_pool_id, ip_subnet_id,