Skip to content

Commit d9a2ef3

Browse files
committed
fix missing sysinfo in config override
1 parent 479181c commit d9a2ef3

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

config/main.py

+29
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,33 @@ def override_config_by(golden_config_path):
18751875
return
18761876

18771877

1878+
def generate_sysinfo(config_input, ns=None):
1879+
# Generate required sysinfo for Golden Config.
1880+
device_metadata = config_input.get('DEVICE_METADATA')
1881+
1882+
if not device_metadata or 'localhost' not in device_metadata:
1883+
return
1884+
1885+
if ns:
1886+
asic_role = device_metadata.get('localhost', {}).get('sub_role')
1887+
switch_type = device_metadata.get('localhost', {}).get('switch_type')
1888+
1889+
if ((switch_type is not None and switch_type.lower() == "chassis-packet") or
1890+
(asic_role is not None and asic_role.lower() == "backend")):
1891+
mac = device_info.get_system_mac(namespace=ns)
1892+
else:
1893+
mac = device_info.get_system_mac()
1894+
else:
1895+
mac = device_info.get_system_mac()
1896+
1897+
platform = device_info.get_platform()
1898+
1899+
device_metadata['localhost']['mac'] = mac
1900+
device_metadata['localhost']['platform'] = platform
1901+
1902+
return
1903+
1904+
18781905
#
18791906
# 'override-config-table' command ('config override-config-table ...')
18801907
#
@@ -1912,8 +1939,10 @@ def override_config_table(db, input_config_db, dry_run):
19121939

19131940
if multi_asic.is_multi_asic():
19141941
ns_config_input = config_input[ns]
1942+
generate_sysinfo(ns_config_input, ns)
19151943
else:
19161944
ns_config_input = config_input
1945+
generate_sysinfo(ns_config_input)
19171946
updated_config = update_config(current_config, ns_config_input)
19181947

19191948
yang_enabled = device_info.is_yang_config_validation_enabled(config_db)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"": {
3+
"DEVICE_METADATA": {
4+
"localhost": {
5+
"default_bgp_status": "down",
6+
"default_pfcwd_status": "enable",
7+
"deployment_id": "1",
8+
"docker_routing_config_mode": "separated",
9+
"hostname": "sonic-switch",
10+
"hwsku": "Mellanox-SN3800-D112C8",
11+
"peer_switch": "sonic-switch",
12+
"type": "ToRRouter",
13+
"suppress-fib-pending": "enabled"
14+
}
15+
}
16+
},
17+
"asic0": {
18+
"DEVICE_METADATA": {
19+
"localhost": {
20+
"asic_id": "01.00.0",
21+
"asic_name": "asic0",
22+
"bgp_asn": "65100",
23+
"cloudtype": "None",
24+
"default_bgp_status": "down",
25+
"default_pfcwd_status": "enable",
26+
"deployment_id": "None",
27+
"docker_routing_config_mode": "separated",
28+
"hostname": "sonic",
29+
"hwsku": "multi_asic",
30+
"region": "None",
31+
"sub_role": "FrontEnd",
32+
"type": "LeafRouter"
33+
}
34+
}
35+
},
36+
"asic1": {
37+
"DEVICE_METADATA": {
38+
"localhost": {
39+
"asic_id": "08:00.0",
40+
"asic_name": "asic1",
41+
"bgp_asn": "65100",
42+
"cloudtype": "None",
43+
"default_bgp_status": "down",
44+
"default_pfcwd_status": "enable",
45+
"deployment_id": "None",
46+
"docker_routing_config_mode": "separated",
47+
"hostname": "sonic",
48+
"hwsku": "multi_asic",
49+
"region": "None",
50+
"sub_role": "BackEnd",
51+
"type": "LeafRouter"
52+
}
53+
}
54+
}
55+
}

tests/config_override_test.py

+26
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
FINAL_CONFIG_YANG_FAILURE = os.path.join(DATA_DIR, "final_config_yang_failure.json")
2424
MULTI_ASIC_MACSEC_OV = os.path.join(DATA_DIR, "multi_asic_macsec_ov.json")
2525
MULTI_ASIC_DEVICE_METADATA_RM = os.path.join(DATA_DIR, "multi_asic_dm_rm.json")
26+
MULTI_ASIC_DEVICE_METADATA_GEN_SYSINFO = os.path.join(DATA_DIR, "multi_asic_dm_gen_sysinfo.json")
2627

2728
# Load sonic-cfggen from source since /usr/local/bin/sonic-cfggen does not have .py extension.
2829
sonic_cfggen = load_module_from_source('sonic_cfggen', '/usr/local/bin/sonic-cfggen')
@@ -318,6 +319,31 @@ def read_json_file_side_effect(filename):
318319
for ns, config_db in cfgdb_clients.items():
319320
assert 'DEVICE_METADATA' not in config_db.get_config()
320321

322+
def test_device_metadata_gen_sysinfo(self):
323+
def read_json_file_side_effect(filename):
324+
with open(MULTI_ASIC_DEVICE_METADATA_GEN_SYSINFO, "r") as f:
325+
device_metadata = json.load(f)
326+
return device_metadata
327+
db = Db()
328+
cfgdb_clients = db.cfgdb_clients
329+
330+
with mock.patch('config.main.read_json_file',
331+
mock.MagicMock(side_effect=read_json_file_side_effect)),\
332+
mock.patch('sonic_py_common.device_info.get_platform',
333+
return_value="multi_asic"),\
334+
mock.patch('sonic_py_common.device_info.get_system_mac',
335+
return_value="11:22:33:44:55:66"):
336+
runner = CliRunner()
337+
result = runner.invoke(config.config.commands["override-config-table"],
338+
['golden_config_db.json'], obj=db)
339+
assert result.exit_code == 0
340+
341+
for ns, config_db in cfgdb_clients.items():
342+
platform = config_db.get_config()['DEVICE_METADATA']['localhost'].get('platform')
343+
mac = config_db.get_config()['DEVICE_METADATA']['localhost'].get('mac')
344+
assert platform == "multi_asic"
345+
assert mac == "11:22:33:44:55:66"
346+
321347

322348
@classmethod
323349
def teardown_class(cls):

0 commit comments

Comments
 (0)