Skip to content

Commit

Permalink
[minigraph.py]: Add peer switch hostname to device metadata (#6405)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
theasianpianist authored and daall committed Jan 11, 2021
1 parent 9da8b0f commit 264ecb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def test_minigraph_subtype(self):
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)
Expand Down

0 comments on commit 264ecb1

Please sign in to comment.