diff --git a/dump/main.py b/dump/main.py index 3a183520c3e8..c5878b2787d1 100644 --- a/dump/main.py +++ b/dump/main.py @@ -165,7 +165,7 @@ def populate_fv(info, module, namespace): final_info[id][db_name]["tables_not_found"] = info[id][db_name]["tables_not_found"] for key in info[id][db_name]["keys"]: if db_name is "CONFIG_FILE": - fv = db_dict[db_name].get(db_name, key) + fv = db_cfg_file.get(db_name, key) else: fv = db_conn.get_all(db_name, key) final_info[id][db_name]["keys"].append({key: fv}) diff --git a/tests/dump_tests/dump_state_test.py b/tests/dump_tests/dump_state_test.py index 49217b8cf8c9..4eb948ad7232 100644 --- a/tests/dump_tests/dump_state_test.py +++ b/tests/dump_tests/dump_state_test.py @@ -10,6 +10,7 @@ from utilities_common.db import Db import traceback from utilities_common.constants import DEFAULT_NAMESPACE +from pyfakefs.fake_filesystem_unittest import Patcher def compare_json_output(exp_json, rec, exclude_paths=None): @@ -79,6 +80,30 @@ def compare_json_output(exp_json, rec, exclude_paths=None): +-------------+-----------+-----------------------------------------------------------+ ''' +table_config_file_copp='''\ ++-----------+-------------+---------------------------------------------------------------+ +| trap_id | DB_NAME | DUMP | ++===========+=============+===============================================================+ +| bgp | CONFIG_FILE | +--------------------------+--------------------------------+ | +| | | | Keys | field-value pairs | | +| | | +==========================+================================+ | +| | | | COPP_TRAP|bgp | +------------+---------------+ | | +| | | | | | field | value | | | +| | | | | |------------+---------------| | | +| | | | | | trap_ids | bgp,bgpv6 | | | +| | | | | | trap_group | queue4_group1 | | | +| | | | | +------------+---------------+ | | +| | | +--------------------------+--------------------------------+ | +| | | | COPP_GROUP|queue4_group1 | +---------------+---------+ | | +| | | | | | field | value | | | +| | | | | |---------------+---------| | | +| | | | | | trap_action | trap | | | +| | | | | | trap_priority | 4 | | | +| | | | | | queue | 4 | | | +| | | | | +---------------+---------+ | | +| | | +--------------------------+--------------------------------+ | ++-----------+-------------+---------------------------------------------------------------+ +''' class TestDumpState(object): @@ -178,6 +203,30 @@ def test_namespace_single_asic(self): result = runner.invoke(dump.state, ["port", "Ethernet0", "--table", "--key-map", "--namespace", "asic0"]) print(result.output) assert result.output == "Namespace option is not valid for a single-ASIC device\n" + + def test_populate_fv_config_file(self): + test_data = { + "COPP_TRAP": { + "bgp": { + "trap_ids": "bgp,bgpv6", + "trap_group": "queue4_group1" + } + }, + "COPP_GROUP": { + "queue4_group1": { + "trap_action":"trap", + "trap_priority":"4", + "queue": "4" + } + } + } + with Patcher() as patcher: + patcher.fs.create_file("/etc/sonic/copp_cfg.json", contents=json.dumps(test_data)) + runner = CliRunner() + result = runner.invoke(dump.state, ["copp", "bgp", "--table", "--db", "CONFIG_FILE"]) + print(result) + print(result.output) + assert result.output == table_config_file_copp @classmethod def teardown(cls):