Merge "Populate switch_info with lldp system name"
This commit is contained in:
@@ -26,6 +26,7 @@ import ironic.objects.port as ironic_port
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
PORT_ID_ITEM_NAME = "port_id"
|
PORT_ID_ITEM_NAME = "port_id"
|
||||||
SWITCH_ID_ITEM_NAME = "switch_id"
|
SWITCH_ID_ITEM_NAME = "switch_id"
|
||||||
|
SWITCH_INFO_ITEM_NAME = "switch_info"
|
||||||
|
|
||||||
|
|
||||||
class LocalLinkConnectionHook(base.InspectionHook):
|
class LocalLinkConnectionHook(base.InspectionHook):
|
||||||
@@ -69,6 +70,16 @@ class LocalLinkConnectionHook(base.InspectionHook):
|
|||||||
if 'mac_address' in chassis_id.subtype:
|
if 'mac_address' in chassis_id.subtype:
|
||||||
item = SWITCH_ID_ITEM_NAME
|
item = SWITCH_ID_ITEM_NAME
|
||||||
value = chassis_id.value.value
|
value = chassis_id.value.value
|
||||||
|
elif tlv_type == tlv.LLDP_TLV_SYS_NAME:
|
||||||
|
try:
|
||||||
|
switch_info = tlv.SysName.parse(data)
|
||||||
|
except (core.MappingError, netaddr.AddrFormatError) as e:
|
||||||
|
LOG.warning('TLV parse error for Sys Name for node %s: '
|
||||||
|
'%s', node_uuid, e)
|
||||||
|
return
|
||||||
|
|
||||||
|
item = SWITCH_INFO_ITEM_NAME
|
||||||
|
value = switch_info.value
|
||||||
|
|
||||||
if item is None or value is None:
|
if item is None or value is None:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -176,3 +176,19 @@ class LocalLinkConnectionTestCase(db_base.DbTestCase):
|
|||||||
self.assertTrue(mock_port_save.called)
|
self.assertTrue(mock_port_save.called)
|
||||||
self.assertEqual({'port_id': 'Ethernet1/18'},
|
self.assertEqual({'port_id': 'Ethernet1/18'},
|
||||||
self.port.local_link_connection)
|
self.port.local_link_connection)
|
||||||
|
|
||||||
|
@mock.patch.object(port.Port, 'save', autospec=True)
|
||||||
|
@mock.patch.object(port.Port, 'get_by_address', autospec=True)
|
||||||
|
def test_valid_system_info(self, mock_get_port, mock_port_save):
|
||||||
|
# Add a system name to the LLDP data
|
||||||
|
self.inventory['interfaces'][0]['lldp'].append(
|
||||||
|
(5, "737730312d646973742d31622d623132"))
|
||||||
|
mock_get_port.return_value = self.port
|
||||||
|
with task_manager.acquire(self.context, self.node.id) as task:
|
||||||
|
hook.LocalLinkConnectionHook().__call__(task, self.inventory,
|
||||||
|
self.plugin_data)
|
||||||
|
self.assertTrue(mock_port_save.called)
|
||||||
|
self.assertEqual(self.port.local_link_connection,
|
||||||
|
{'port_id': 'Ethernet1/18',
|
||||||
|
'switch_id': '88:5a:92:ec:54:59',
|
||||||
|
'switch_info': 'sw01-dist-1b-b12'})
|
||||||
|
|||||||
Reference in New Issue
Block a user