[minigraph.py]: Add peer switch hostname to device metadata (#6405)

To make the peer switch hostname easily accessible from config DB. Add peer_switch field to DEVICE_METADATA table

Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
This commit is contained in:
Lawrence Lee 2021-01-11 10:18:39 -08:00 committed by Danny Allen
parent 9da8b0faf9
commit 264ecb181c
2 changed files with 9 additions and 0 deletions

View File

@ -1178,6 +1178,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
if bool(results['PEER_SWITCH']):
results['DEVICE_METADATA']['localhost']['subtype'] = 'DualToR'
if len(results['PEER_SWITCH'].keys()) > 1:
print("Warning: more than one peer switch was found. Only the first will be parsed: {}".format(results['PEER_SWITCH'].keys()[0]))
results['DEVICE_METADATA']['localhost']['peer_switch'] = list(results['PEER_SWITCH'].keys())[0]
if is_storage_device:
results['DEVICE_METADATA']['localhost']['storage_device'] = "true"

View File

@ -57,6 +57,11 @@ class TestCfgGenCaseInsensitive(TestCase):
output = self.run_script(argument)
self.assertEqual(output.strip(), 'DualToR')
def test_minigraph_peer_switch_hostname(self):
argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'peer_switch\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), 'switch2-t0')
def test_additional_json_data(self):
argument = '-a \'{"key1":"value1"}\' -v key1'
output = self.run_script(argument)