Allow setting the description of switches and ports

Change-Id: If81f8eed647f69d88c299bfdcf83e88a5f3fa662
This commit is contained in:
Adit Sarfaty 2017-08-17 14:43:04 +03:00
parent 0d5da8224c
commit fc48ac0be0
4 changed files with 34 additions and 14 deletions

View File

@ -275,14 +275,15 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
fake_port['address_bindings'] = binding_repr fake_port['address_bindings'] = binding_repr
mocked_resource = self._mocked_lport() mocked_resource = self._mocked_lport()
description = 'dummy'
switch_profile = resources.SwitchingProfile switch_profile = resources.SwitchingProfile
mocked_resource.create( mocked_resource.create(
fake_port['logical_switch_id'], fake_port['logical_switch_id'],
fake_port['attachment']['id'], fake_port['attachment']['id'],
address_bindings=pkt_classifiers, address_bindings=pkt_classifiers,
switch_profile_ids=switch_profile.build_switch_profile_ids( switch_profile_ids=switch_profile.build_switch_profile_ids(
mock.Mock(), *profile_dicts)) mock.Mock(), *profile_dicts),
description=description)
resp_body = { resp_body = {
'logical_switch_id': fake_port['logical_switch_id'], 'logical_switch_id': fake_port['logical_switch_id'],
@ -292,7 +293,8 @@ class LogicalPortTestCase(nsxlib_testcase.NsxClientTestCase):
'id': fake_port['attachment']['id'] 'id': fake_port['attachment']['id']
}, },
'admin_state': 'UP', 'admin_state': 'UP',
'address_bindings': fake_port['address_bindings'] 'address_bindings': fake_port['address_bindings'],
'description': description
} }
test_client.assert_json_call( test_client.assert_json_call(

View File

@ -29,7 +29,7 @@ class NsxLibSwitchTestCase(nsxlib_testcase.NsxClientTestCase):
_tz_id = "8f602f97-ee3e-46b0-9d9f-358955f03608" _tz_id = "8f602f97-ee3e-46b0-9d9f-358955f03608"
def _create_body(self, admin_state=nsx_constants.ADMIN_STATE_UP, def _create_body(self, admin_state=nsx_constants.ADMIN_STATE_UP,
vlan_id=None): vlan_id=None, description=None):
body = { body = {
"transport_zone_id": NsxLibSwitchTestCase._tz_id, "transport_zone_id": NsxLibSwitchTestCase._tz_id,
"replication_mode": "MTEP", "replication_mode": "MTEP",
@ -39,16 +39,21 @@ class NsxLibSwitchTestCase(nsxlib_testcase.NsxClientTestCase):
} }
if vlan_id: if vlan_id:
body['vlan'] = vlan_id body['vlan'] = vlan_id
if description is not None:
body['description'] = description
return body return body
def test_create_logical_switch(self): def test_create_logical_switch(self):
"""Test creating a switch returns the correct response and 200 status """Test creating a switch returns the correct response and 200 status
""" """
desc = 'dummy'
with mock.patch.object(self.nsxlib.client, 'create') as create: with mock.patch.object(self.nsxlib.client, 'create') as create:
self.nsxlib.logical_switch.create( self.nsxlib.logical_switch.create(
nsx_v3_mocks.FAKE_NAME, NsxLibSwitchTestCase._tz_id, []) nsx_v3_mocks.FAKE_NAME, NsxLibSwitchTestCase._tz_id, [],
create.assert_called_with('logical-switches', self._create_body()) description=desc)
create.assert_called_with('logical-switches',
self._create_body(description=desc))
def test_create_logical_switch_admin_down(self): def test_create_logical_switch_admin_down(self):
"""Test creating switch with admin_state down""" """Test creating switch with admin_state down"""

View File

@ -121,7 +121,7 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
def create(self, display_name, transport_zone_id, tags, def create(self, display_name, transport_zone_id, tags,
replication_mode=nsx_constants.MTEP, replication_mode=nsx_constants.MTEP,
admin_state=True, vlan_id=None, ip_pool_id=None, admin_state=True, vlan_id=None, ip_pool_id=None,
mac_pool_id=None): mac_pool_id=None, description=None):
# TODO(salv-orlando): Validate Replication mode and admin_state # TODO(salv-orlando): Validate Replication mode and admin_state
# NOTE: These checks might be moved to the API client library if one # NOTE: These checks might be moved to the API client library if one
# that performs such checks in the client is available # that performs such checks in the client is available
@ -144,6 +144,9 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
if mac_pool_id: if mac_pool_id:
body['mac_pool_id'] = mac_pool_id body['mac_pool_id'] = mac_pool_id
if description is not None:
body['description'] = description
return self.client.create(self.get_path(), body) return self.client.create(self.get_path(), body)
def delete(self, lswitch_id): def delete(self, lswitch_id):
@ -157,7 +160,8 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
_do_delete() _do_delete()
def update(self, lswitch_id, name=None, admin_state=None, tags=None): def update(self, lswitch_id, name=None, admin_state=None, tags=None,
description=None):
# Using internal method so we can access max_attempts in the decorator # Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception( @utils.retry_upon_exception(
exceptions.StaleRevision, exceptions.StaleRevision,
@ -174,6 +178,8 @@ class NsxLibLogicalSwitch(utils.NsxLibApiBase):
lswitch['admin_state'] = nsx_constants.ADMIN_STATE_DOWN lswitch['admin_state'] = nsx_constants.ADMIN_STATE_DOWN
if tags is not None: if tags is not None:
lswitch['tags'] = tags lswitch['tags'] = tags
if description is not None:
lswitch['description'] = description
return self.client.update(self.get_path(lswitch_id), lswitch) return self.client.update(self.get_path(lswitch_id), lswitch)
return _do_update() return _do_update()

View File

@ -80,7 +80,8 @@ class LogicalPort(utils.NsxLibApiBase):
admin_state=True, tags=None, admin_state=True, tags=None,
address_bindings=None, address_bindings=None,
switch_profile_ids=None, switch_profile_ids=None,
attachment=None): attachment=None,
description=None):
tags = tags or [] tags = tags or []
address_bindings = address_bindings or [] address_bindings = address_bindings or []
switch_profile_ids = switch_profile_ids or [] switch_profile_ids = switch_profile_ids or []
@ -124,6 +125,9 @@ class LogicalPort(utils.NsxLibApiBase):
if attachment is not False: if attachment is not False:
body['attachment'] = attachment body['attachment'] = attachment
if description is not None:
body['description'] = description
return body return body
def _prepare_attachment(self, attachment_type, vif_uuid, def _prepare_attachment(self, attachment_type, vif_uuid,
@ -160,9 +164,9 @@ class LogicalPort(utils.NsxLibApiBase):
admin_state=True, name=None, address_bindings=None, admin_state=True, name=None, address_bindings=None,
parent_vif_id=None, traffic_tag=None, parent_vif_id=None, traffic_tag=None,
switch_profile_ids=None, vif_type=None, app_id=None, switch_profile_ids=None, vif_type=None, app_id=None,
allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE): allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE,
description=None):
tags = tags or [] tags = tags or []
body = {'logical_switch_id': lswitch_id} body = {'logical_switch_id': lswitch_id}
# NOTE(arosen): If parent_vif_id is specified we need to use # NOTE(arosen): If parent_vif_id is specified we need to use
# CIF attachment type. # CIF attachment type.
@ -175,7 +179,8 @@ class LogicalPort(utils.NsxLibApiBase):
admin_state=admin_state, tags=tags, admin_state=admin_state, tags=tags,
address_bindings=address_bindings, address_bindings=address_bindings,
switch_profile_ids=switch_profile_ids, switch_profile_ids=switch_profile_ids,
attachment=attachment)) attachment=attachment,
description=description))
return self.client.create(self.get_path(), body=body) return self.client.create(self.get_path(), body=body)
def delete(self, lport_id): def delete(self, lport_id):
@ -196,7 +201,8 @@ class LogicalPort(utils.NsxLibApiBase):
attachment_type=nsx_constants.ATTACHMENT_VIF, attachment_type=nsx_constants.ATTACHMENT_VIF,
parent_vif_id=None, traffic_tag=None, parent_vif_id=None, traffic_tag=None,
vif_type=None, app_id=None, vif_type=None, app_id=None,
allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE): allocate_addresses=nsx_constants.ALLOCATE_ADDRESS_NONE,
description=None):
# Using internal method so we can access max_attempts in the decorator # Using internal method so we can access max_attempts in the decorator
@utils.retry_upon_exception( @utils.retry_upon_exception(
exceptions.StaleRevision, exceptions.StaleRevision,
@ -220,7 +226,8 @@ class LogicalPort(utils.NsxLibApiBase):
admin_state=admin_state, tags=tags, admin_state=admin_state, tags=tags,
address_bindings=addr_bindings, address_bindings=addr_bindings,
switch_profile_ids=switch_profile_ids, switch_profile_ids=switch_profile_ids,
attachment=attachment)) attachment=attachment,
description=description))
# If revision_id of the payload that we send is older than what # If revision_id of the payload that we send is older than what
# NSX has, we will get a 412: Precondition Failed. # NSX has, we will get a 412: Precondition Failed.