Skip to content

Commit

Permalink
[dump] [copp] Fixed the NameError Exception for copp dump module (#1911)
Browse files Browse the repository at this point in the history
* Fixed the NameError issur for CONFIG_FILE
Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
  • Loading branch information
vivekrnv authored Nov 9, 2021
1 parent 84be8b4 commit 8a8577b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dump/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
49 changes: 49 additions & 0 deletions tests/dump_tests/dump_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8a8577b

Please sign in to comment.