Merge "Add IP POOL ID during port create/update"
This commit is contained in:
commit
fe1816d4c4
|
@ -345,6 +345,55 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
|
|||
'https://1.2.3.4/api/v1/logical-ports',
|
||||
data=jsonutils.dumps(resp_body, sort_keys=True))
|
||||
|
||||
def test_create_logical_port_for_container_with_ip_pool_key_value(self):
|
||||
"""Test creating for container port returns correct response
|
||||
|
||||
"""
|
||||
fake_port = test_constants.FAKE_CONTAINER_PORT.copy()
|
||||
fake_port_ctx = fake_port['attachment']['context']
|
||||
fake_container_host_vif_id = fake_port_ctx['container_host_vif_id']
|
||||
profile_dicts = []
|
||||
for profile_id in fake_port['switching_profile_ids']:
|
||||
profile_dicts.append({'resource_type': profile_id['key'],
|
||||
'id': profile_id['value']})
|
||||
|
||||
key_values = [{'key': 'IP_POOL_ID',
|
||||
'value': test_constants.FAKE_IP_POOL_UUID}]
|
||||
|
||||
mocked_resource = self._mocked_lport()
|
||||
|
||||
switch_profile = resources.SwitchingProfile
|
||||
mocked_resource.create(
|
||||
fake_port['logical_switch_id'],
|
||||
fake_port['attachment']['id'],
|
||||
parent_vif_id=fake_container_host_vif_id,
|
||||
parent_tag=[],
|
||||
switch_profile_ids=switch_profile.build_switch_profile_ids(
|
||||
mock.Mock(), *profile_dicts),
|
||||
key_values=key_values)
|
||||
|
||||
resp_body = {
|
||||
'logical_switch_id': fake_port['logical_switch_id'],
|
||||
'switching_profile_ids': fake_port['switching_profile_ids'],
|
||||
'attachment': {
|
||||
'attachment_type': 'CIF',
|
||||
'id': fake_port['attachment']['id'],
|
||||
'context': {
|
||||
'container_host_vif_id': fake_container_host_vif_id,
|
||||
'resource_type': 'CifAttachmentContext',
|
||||
'vlan_tag': [],
|
||||
'key_values': key_values
|
||||
}
|
||||
},
|
||||
'admin_state': 'UP',
|
||||
'address_bindings': []
|
||||
}
|
||||
|
||||
test_client.assert_json_call(
|
||||
'post', mocked_resource,
|
||||
'https://1.2.3.4/api/v1/logical-ports',
|
||||
data=jsonutils.dumps(resp_body, sort_keys=True))
|
||||
|
||||
def test_create_logical_port_admin_down(self):
|
||||
"""Test creating port with admin_state down."""
|
||||
fake_port = test_constants.FAKE_PORT
|
||||
|
|
|
@ -245,7 +245,7 @@ class LogicalPort(AbstractRESTResource):
|
|||
return body
|
||||
|
||||
def _prepare_attachment(self, vif_uuid, parent_vif_id, parent_tag,
|
||||
address_bindings, attachment_type):
|
||||
address_bindings, attachment_type, key_values):
|
||||
if attachment_type and vif_uuid:
|
||||
attachment = {'attachment_type': attachment_type,
|
||||
'id': vif_uuid}
|
||||
|
@ -253,6 +253,8 @@ class LogicalPort(AbstractRESTResource):
|
|||
context = {'vlan_tag': parent_tag,
|
||||
'container_host_vif_id': parent_vif_id,
|
||||
'resource_type': nsx_constants.CIF_RESOURCE_TYPE}
|
||||
if key_values is not None:
|
||||
context['key_values'] = key_values
|
||||
attachment['context'] = context
|
||||
return attachment
|
||||
elif attachment_type is None and vif_uuid is None:
|
||||
|
@ -264,7 +266,7 @@ class LogicalPort(AbstractRESTResource):
|
|||
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
||||
admin_state=True, name=None, address_bindings=None,
|
||||
parent_vif_id=None, parent_tag=None,
|
||||
switch_profile_ids=None):
|
||||
switch_profile_ids=None, key_values=None):
|
||||
tags = tags or []
|
||||
|
||||
body = {'logical_switch_id': lswitch_id}
|
||||
|
@ -274,7 +276,7 @@ class LogicalPort(AbstractRESTResource):
|
|||
attachment_type = nsx_constants.ATTACHMENT_CIF
|
||||
attachment = self._prepare_attachment(vif_uuid, parent_vif_id,
|
||||
parent_tag, address_bindings,
|
||||
attachment_type)
|
||||
attachment_type, key_values)
|
||||
body.update(self._build_body_attrs(
|
||||
display_name=name,
|
||||
admin_state=admin_state, tags=tags,
|
||||
|
@ -298,7 +300,7 @@ class LogicalPort(AbstractRESTResource):
|
|||
address_bindings=None, switch_profile_ids=None,
|
||||
tags_update=None,
|
||||
attachment_type=nsx_constants.ATTACHMENT_VIF,
|
||||
parent_vif_id=None, parent_tag=None):
|
||||
parent_vif_id=None, parent_tag=None, key_values=None):
|
||||
# Using internal method so we can access max_attempts in the decorator
|
||||
@utils.retry_upon_exception(
|
||||
exceptions.StaleRevision,
|
||||
|
@ -310,7 +312,7 @@ class LogicalPort(AbstractRESTResource):
|
|||
tags = utils.update_v3_tags(tags, tags_update)
|
||||
attachment = self._prepare_attachment(vif_uuid, parent_vif_id,
|
||||
parent_tag, address_bindings,
|
||||
attachment_type)
|
||||
attachment_type, key_values)
|
||||
lport.update(self._build_body_attrs(
|
||||
display_name=name,
|
||||
admin_state=admin_state, tags=tags,
|
||||
|
|
Loading…
Reference in New Issue