Skip to content

Commit 81c9d7e

Browse files
committed
change to json file for input
1 parent 334433b commit 81c9d7e

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
3+
"": {
4+
"DEVICE_METADATA": {}
5+
},
6+
"asic0": {
7+
"DEVICE_METADATA": {}
8+
},
9+
"asic1": {
10+
"DEVICE_METADATA": {}
11+
},
12+
"asic2": {
13+
"DEVICE_METADATA": {}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
3+
"": {
4+
"MACSEC_PROFILE": {
5+
"profile": {
6+
"key": "value"
7+
}
8+
}
9+
},
10+
"asic0": {
11+
"MACSEC_PROFILE": {
12+
"profile": {
13+
"key": "value"
14+
}
15+
}
16+
},
17+
"asic1": {
18+
"MACSEC_PROFILE": {
19+
"profile": {
20+
"key": "value"
21+
}
22+
}
23+
},
24+
"asic2": {
25+
"MACSEC_PROFILE": {
26+
"profile": {
27+
"key": "value"
28+
}
29+
}
30+
}
31+
}

tests/config_override_test.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
RUNNING_CONFIG_YANG_FAILURE = os.path.join(DATA_DIR, "running_config_yang_failure.json")
2222
GOLDEN_INPUT_YANG_FAILURE = os.path.join(DATA_DIR, "golden_input_yang_failure.json")
2323
FINAL_CONFIG_YANG_FAILURE = os.path.join(DATA_DIR, "final_config_yang_failure.json")
24+
MULTI_ASIC_MACSEC_OV = os.path.join(DATA_DIR, "multi_asic_macsec_ov.json")
25+
MULTI_ASIC_DEVICE_METADATA_RM = os.path.join(DATA_DIR, "multi_asic_dm_rm.json")
2426

2527
# Load sonic-cfggen from source since /usr/local/bin/sonic-cfggen does not have .py extension.
2628
sonic_cfggen = load_module_from_source('sonic_cfggen', '/usr/local/bin/sonic-cfggen')
@@ -275,15 +277,15 @@ def setup_class(cls):
275277

276278
def test_macsec_override(self):
277279
def read_json_file_side_effect(filename):
280+
with open(MULTI_ASIC_MACSEC_OV, "r") as f:
281+
macsec_profile = json.load(f)
278282
return macsec_profile
279283
db = Db()
280284
cfgdb_clients = db.cfgdb_clients
281-
macsec_profile = {}
282-
profile_content = {"profile": {"key": "value"}}
283285

284-
for ns, config_db in cfgdb_clients.items():
285-
macsec_profile[ns] = {}
286-
macsec_profile[ns]['MACSEC_PROFILE'] = profile_content
286+
# The profile_content was copied from MULTI_ASIC_MACSEC_OV, where all
287+
# ns sharing the same content: {"profile": {"key": "value"}}
288+
profile_content = {"profile": {"key": "value"}}
287289

288290
with mock.patch('config.main.read_json_file',
289291
mock.MagicMock(side_effect=read_json_file_side_effect)):
@@ -297,15 +299,14 @@ def read_json_file_side_effect(filename):
297299

298300
def test_device_metadata_table_rm(self):
299301
def read_json_file_side_effect(filename):
302+
with open(MULTI_ASIC_DEVICE_METADATA_RM, "r") as f:
303+
device_metadata = json.load(f)
300304
return device_metadata
301305
db = Db()
302306
cfgdb_clients = db.cfgdb_clients
303-
device_metadata = {}
304307

305308
for ns, config_db in cfgdb_clients.items():
306309
assert 'DEVICE_METADATA' in config_db.get_config()
307-
device_metadata[ns] = {}
308-
device_metadata[ns]['DEVICE_METADATA'] = {}
309310

310311
with mock.patch('config.main.read_json_file',
311312
mock.MagicMock(side_effect=read_json_file_side_effect)):

0 commit comments

Comments
 (0)