From 6780945d4d0cc5fda6c6ab2b9759437422136ccf Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Tue, 22 Sep 2020 15:30:18 -0700 Subject: [PATCH 1/4] CRM show/config commands changes for multi-asic --- crm/main.py | 122 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 38 deletions(-) diff --git a/crm/main.py b/crm/main.py index 33fbfb5de5..83c22e21f6 100644 --- a/crm/main.py +++ b/crm/main.py @@ -3,27 +3,34 @@ import click import swsssdk from tabulate import tabulate +from utilities_common import multi_asic as multi_asic_util +from sonic_py_common import multi_asic class Crm: def __init__(self): self.cli_mode = None self.addr_family = None self.res_type = None + self.db = None + self.config_db = None + self.multi_asic = multi_asic_util.MultiAsic() + @multi_asic_util.run_on_multi_asic def config(self, attr, val): """ CRM handler for 'config' CLI commands. """ - configdb = swsssdk.ConfigDBConnector() - configdb.connect() - - configdb.mod_entry("CRM", 'Config', {attr: val}) + self.config_db.mod_entry("CRM", 'Config', {attr: val}) def show_summary(self): """ CRM Handler to display general information. """ - configdb = swsssdk.ConfigDBConnector() + + # Get the namespace list + namespaces = multi_asic.get_namespace_list() + + configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') @@ -37,7 +44,11 @@ def show_thresholds(self, resource): """ CRM Handler to display thresholds information. """ - configdb = swsssdk.ConfigDBConnector() + + # Get the namespace list + namespaces = multi_asic.get_namespace_list() + + configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') @@ -60,16 +71,11 @@ def show_thresholds(self, resource): click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) click.echo() - def show_resources(self, resource): + def get_resources(self, resource): """ - CRM Handler to display resources information. + CRM Handler to get resources information. """ - countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') - countersdb.connect(countersdb.COUNTERS_DB) - - crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, 'CRM:STATS') - - header = ("Resource Name", "Used Count", "Available Count") + crm_stats = self.db.get_all(self.db.COUNTERS_DB, 'CRM:STATS') data = [] if crm_stats: @@ -79,26 +85,18 @@ def show_resources(self, resource): data.append([res, crm_stats['crm_stats_' + res + "_used"], crm_stats['crm_stats_' + res + "_available"]]) else: data.append([resource, crm_stats['crm_stats_' + resource + "_used"], crm_stats['crm_stats_' + resource + "_available"]]) - else: - click.echo('\nCRM counters are not ready. They would be populated after the polling interval.') - click.echo() - click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) - click.echo() + return data - def show_acl_resources(self): + def get_acl_resources(self): """ - CRM Handler to display ACL recources information. + CRM Handler to get ACL recources information. """ - countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') - countersdb.connect(countersdb.COUNTERS_DB) - - header = ("Stage", "Bind Point", "Resource Name", "Used Count", "Available Count") data = [] for stage in ["INGRESS", "EGRESS"]: for bind_point in ["PORT", "LAG", "VLAN", "RIF", "SWITCH"]: - crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, 'CRM:ACL_STATS:{0}:{1}'.format(stage, bind_point)) + crm_stats = self.db.get_all(self.db.COUNTERS_DB, 'CRM:ACL_STATS:{0}:{1}'.format(stage, bind_point)) if crm_stats: for res in ["acl_group", "acl_table"]: @@ -108,21 +106,13 @@ def show_acl_resources(self): crm_stats['crm_stats_' + res + "_available"] ]) - click.echo() - click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) - click.echo() - - def show_acl_table_resources(self): + return data + def get_acl_table_resources(self): """ CRM Handler to display ACL table information. """ - countersdb = swsssdk.SonicV2Connector(host='127.0.0.1') - countersdb.connect(countersdb.COUNTERS_DB) - - header = ("Table ID", "Resource Name", "Used Count", "Available Count") - # Retrieve all ACL table keys from CRM:ACL_TABLE_STATS - crm_acl_keys = countersdb.keys(countersdb.COUNTERS_DB, 'CRM:ACL_TABLE_STATS*') + crm_acl_keys = self.db.keys(self.db.COUNTERS_DB, 'CRM:ACL_TABLE_STATS*') for key in crm_acl_keys or [None]: data = [] @@ -130,16 +120,69 @@ def show_acl_table_resources(self): if key: id = key.replace('CRM:ACL_TABLE_STATS:', '') - crm_stats = countersdb.get_all(countersdb.COUNTERS_DB, key) + crm_stats = self.db.get_all(self.db.COUNTERS_DB, key) for res in ['acl_entry', 'acl_counter']: if ('crm_stats_' + res + '_used' in crm_stats) and ('crm_stats_' + res + '_available' in crm_stats): data.append([id, res, crm_stats['crm_stats_' + res + '_used'], crm_stats['crm_stats_' + res + '_available']]) + return data + @multi_asic_util.run_on_multi_asic + def show_resources(self, resource): + """ + CRM Handler to display resources information. + """ + if multi_asic.is_multi_asic(): + header = (self.multi_asic.current_namespace.upper() + "\n\nResource Name", "\n\nUsed Count", "\n\nAvailable Count") + err_msg = '\nCRM counters are not ready for '+ self.multi_asic.current_namespace.upper() + '. They would be populated after the polling interval.' + else: + header = ("Resource Name", "Used Count", "Available Count") + err_msg = '\nCRM counters are not ready. They would be populated after the polling interval.' + + data = [] + data = self.get_resources(resource) + + if data: click.echo() click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) click.echo() + else: + click.echo(err_msg) + @multi_asic_util.run_on_multi_asic + def show_acl_resources(self): + """ + CRM Handler to display ACL recources information. + """ + + if multi_asic.is_multi_asic(): + header = (self.multi_asic.current_namespace.upper() + "\n\nStage", "\n\nBind Point", "\n\nResource Name", "\n\nUsed Count", "\n\nAvailable Count") + else: + header = ("Stage", "Bind Point", "Resource Name", "Used Count", "Available Count") + + data = [] + data = self.get_acl_resources() + + click.echo() + click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) + click.echo() + + @multi_asic_util.run_on_multi_asic + def show_acl_table_resources(self): + """ + CRM Handler to display ACL table information. + """ + if multi_asic.is_multi_asic(): + header = (self.multi_asic.current_namespace.upper() + "\n\nTable ID", "\n\nResource Name", "\n\nUsed Count", "\n\nAvailable Count") + else: + header = ("Table ID", "Resource Name", "Used Count", "Available Count") + + data = [] + data = self.get_acl_table_resources() + + click.echo() + click.echo(tabulate(data, headers=header, tablefmt="simple", missingval="")) + click.echo() @click.group() @click.pass_context @@ -153,6 +196,9 @@ def cli(ctx): ctx.obj = context + # Load the global config file database_global.json once. + swsssdk.SonicDBConfig.load_sonic_global_db_config() + @cli.group() @click.pass_context def config(ctx): From b0d190e2c0bc73d83f2418008550cac2a63d2e9a Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Tue, 27 Oct 2020 11:35:25 -0700 Subject: [PATCH 2/4] Unit tests added to cover for single/multi-asic. --- crm/main.py | 4 +- tests/crm_test.py | 902 +++++++++++++++++++++++ tests/mock_tables/asic0/config_db.json | 42 ++ tests/mock_tables/asic0/counters_db.json | 92 +++ tests/mock_tables/asic1/config_db.json | 42 ++ tests/mock_tables/asic1/counters_db.json | 86 +++ tests/mock_tables/config_db.json | 42 ++ tests/mock_tables/counters_db.json | 88 ++- 8 files changed, 1295 insertions(+), 3 deletions(-) create mode 100644 tests/crm_test.py diff --git a/crm/main.py b/crm/main.py index 83c22e21f6..03e2441b49 100644 --- a/crm/main.py +++ b/crm/main.py @@ -113,10 +113,9 @@ def get_acl_table_resources(self): """ # Retrieve all ACL table keys from CRM:ACL_TABLE_STATS crm_acl_keys = self.db.keys(self.db.COUNTERS_DB, 'CRM:ACL_TABLE_STATS*') + data = [] for key in crm_acl_keys or [None]: - data = [] - if key: id = key.replace('CRM:ACL_TABLE_STATS:', '') @@ -127,6 +126,7 @@ def get_acl_table_resources(self): data.append([id, res, crm_stats['crm_stats_' + res + '_used'], crm_stats['crm_stats_' + res + '_available']]) return data + @multi_asic_util.run_on_multi_asic def show_resources(self, resource): """ diff --git a/tests/crm_test.py b/tests/crm_test.py new file mode 100644 index 0000000000..4f07cf6384 --- /dev/null +++ b/tests/crm_test.py @@ -0,0 +1,902 @@ +import os +import sys + +from click.testing import CliRunner +import crm.main as crm + +# Expected output for CRM + +crm_show_summary = """\ + +Polling Interval: 300 second(s) + +""" + +crm_show_thresholds_acl_group = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +acl_group percentage 70 85 + +""" + +crm_show_thresholds_acl_table = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +acl_table percentage 70 85 + +""" + +crm_show_thresholds_all = """\ + +Resource Name Threshold Type Low Threshold High Threshold +-------------------- ---------------- --------------- ---------------- +ipv4_route percentage 70 85 +ipv6_route percentage 70 85 +ipv4_nexthop percentage 70 85 +ipv6_nexthop percentage 70 85 +ipv4_neighbor percentage 70 85 +ipv6_neighbor percentage 70 85 +nexthop_group_member percentage 70 85 +nexthop_group percentage 70 85 +acl_table percentage 70 85 +acl_group percentage 70 85 +acl_entry percentage 70 85 +acl_counter percentage 70 85 +fdb_entry percentage 70 85 + +""" + +crm_show_thresholds_fdb = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +fdb_entry percentage 70 85 + +""" + +crm_show_thresholds_ipv4_neighbor = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv4_neighbor percentage 70 85 + +""" + +crm_show_thresholds_ipv4_nexthop = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv4_nexthop percentage 70 85 + +""" + +crm_show_thresholds_ipv4_route = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv4_route percentage 70 85 + +""" + +crm_show_thresholds_ipv6_neighbor = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv6_neighbor percentage 70 85 + +""" + +crm_show_thresholds_ipv6_nexthop = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv6_nexthop percentage 70 85 + +""" + +crm_show_thresholds_ipv6_route= """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv6_route percentage 70 85 + +""" + +crm_show_thresholds_nexthop_group_member = """\ + +Resource Name Threshold Type Low Threshold High Threshold +-------------------- ---------------- --------------- ---------------- +nexthop_group_member percentage 70 85 + +""" + +crm_show_thresholds_nexthop_group_object = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +nexthop_group percentage 70 85 + +""" + +crm_show_resources_acl_group = """\ + +Stage Bind Point Resource Name Used Count Available Count +------- ------------ --------------- ------------ ----------------- +INGRESS PORT acl_group 16 232 +INGRESS PORT acl_table 2 3 +INGRESS LAG acl_group 8 232 +INGRESS LAG acl_table 0 3 +INGRESS VLAN acl_group 0 232 +INGRESS VLAN acl_table 0 6 +INGRESS RIF acl_group 0 232 +INGRESS RIF acl_table 0 6 +INGRESS SWITCH acl_group 0 232 +INGRESS SWITCH acl_table 0 6 +EGRESS PORT acl_group 0 232 +EGRESS PORT acl_table 0 2 +EGRESS LAG acl_group 0 232 +EGRESS LAG acl_table 0 2 +EGRESS VLAN acl_group 0 232 +EGRESS VLAN acl_table 0 2 +EGRESS RIF acl_group 0 232 +EGRESS RIF acl_table 0 2 +EGRESS SWITCH acl_group 0 232 +EGRESS SWITCH acl_table 0 2 + +""" + +crm_show_resources_acl_table = """\ + +Table ID Resource Name Used Count Available Count +--------------- --------------- ------------ ----------------- +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 +0x7000000000670 acl_entry 0 1024 +0x7000000000670 acl_counter 0 1280 + +""" + +crm_show_resources_all = """\ + +Resource Name Used Count Available Count +-------------------- ------------ ----------------- +ipv4_route 58 98246 +ipv6_route 60 16324 +ipv4_nexthop 8 49086 +ipv6_nexthop 8 49086 +ipv4_neighbor 8 8168 +ipv6_neighbor 8 4084 +nexthop_group_member 0 16384 +nexthop_group 0 512 +fdb_entry 0 32767 + + +Stage Bind Point Resource Name Used Count Available Count +------- ------------ --------------- ------------ ----------------- +INGRESS PORT acl_group 16 232 +INGRESS PORT acl_table 2 3 +INGRESS LAG acl_group 8 232 +INGRESS LAG acl_table 0 3 +INGRESS VLAN acl_group 0 232 +INGRESS VLAN acl_table 0 6 +INGRESS RIF acl_group 0 232 +INGRESS RIF acl_table 0 6 +INGRESS SWITCH acl_group 0 232 +INGRESS SWITCH acl_table 0 6 +EGRESS PORT acl_group 0 232 +EGRESS PORT acl_table 0 2 +EGRESS LAG acl_group 0 232 +EGRESS LAG acl_table 0 2 +EGRESS VLAN acl_group 0 232 +EGRESS VLAN acl_table 0 2 +EGRESS RIF acl_group 0 232 +EGRESS RIF acl_table 0 2 +EGRESS SWITCH acl_group 0 232 +EGRESS SWITCH acl_table 0 2 + + +Table ID Resource Name Used Count Available Count +--------------- --------------- ------------ ----------------- +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 +0x7000000000670 acl_entry 0 1024 +0x7000000000670 acl_counter 0 1280 + +""" + +crm_show_resources_fdb = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +fdb_entry 0 32767 + +""" + +crm_show_resources_ipv4_neighbor = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_neighbor 8 8168 + +""" + +crm_show_resources_ipv4_nexthop = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_nexthop 8 49086 + +""" + +crm_show_resources_ipv4_route = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_route 58 98246 + +""" + +crm_show_resources_ipv6_route = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_route 60 16324 + +""" + +crm_show_resources_ipv6_neighbor = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_neighbor 8 4084 + +""" + +crm_show_resources_ipv6_nexthop = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_nexthop 8 49086 + +""" + +crm_show_resources_nexthop_group_member = """\ + +Resource Name Used Count Available Count +-------------------- ------------ ----------------- +nexthop_group_member 0 16384 + +""" + +crm_show_resources_nexthop_group_object = """\ + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +nexthop_group 0 512 + +""" + +crm_multi_asic_show_resources_acl_group = """\ + +ASIC0 + +Stage Bind Point Resource Name Used Count Available Count +------- ------------ --------------- ------------ ----------------- +INGRESS PORT acl_group 16 232 +INGRESS PORT acl_table 2 3 +INGRESS LAG acl_group 8 232 +INGRESS LAG acl_table 0 3 +INGRESS VLAN acl_group 0 232 +INGRESS VLAN acl_table 0 6 +INGRESS RIF acl_group 0 232 +INGRESS RIF acl_table 0 6 +INGRESS SWITCH acl_group 0 232 +INGRESS SWITCH acl_table 0 6 +EGRESS PORT acl_group 0 232 +EGRESS PORT acl_table 0 2 +EGRESS LAG acl_group 0 232 +EGRESS LAG acl_table 0 2 +EGRESS VLAN acl_group 0 232 +EGRESS VLAN acl_table 0 2 +EGRESS RIF acl_group 0 232 +EGRESS RIF acl_table 0 2 +EGRESS SWITCH acl_group 0 232 +EGRESS SWITCH acl_table 0 2 + + +ASIC1 + +Stage Bind Point Resource Name Used Count Available Count +------- ------------ --------------- ------------ ----------------- +INGRESS PORT acl_group 16 232 +INGRESS PORT acl_table 2 3 +INGRESS LAG acl_group 8 232 +INGRESS LAG acl_table 0 3 +INGRESS VLAN acl_group 0 232 +INGRESS VLAN acl_table 0 6 +INGRESS RIF acl_group 0 232 +INGRESS RIF acl_table 0 6 +INGRESS SWITCH acl_group 0 232 +INGRESS SWITCH acl_table 0 6 +EGRESS PORT acl_group 0 232 +EGRESS PORT acl_table 0 2 +EGRESS LAG acl_group 0 232 +EGRESS LAG acl_table 0 2 +EGRESS VLAN acl_group 0 232 +EGRESS VLAN acl_table 0 2 +EGRESS RIF acl_group 0 232 +EGRESS RIF acl_table 0 2 +EGRESS SWITCH acl_group 0 232 +EGRESS SWITCH acl_table 0 2 + +""" + +crm_multi_asic_show_resources_acl_table = """\ + +ASIC0 + +Table ID Resource Name Used Count Available Count +--------------- --------------- ------------ ----------------- +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 +0x7000000000670 acl_entry 0 1024 +0x7000000000670 acl_counter 0 1280 + + +ASIC1 + +Table ID Resource Name Used Count Available Count +--------------- --------------- ------------ ----------------- +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 +0x7000000000670 acl_entry 0 1024 +0x7000000000670 acl_counter 0 1280 + +""" + +crm_multi_asic_show_resources_all = """\ + +ASIC0 + +Resource Name Used Count Available Count +-------------------- ------------ ----------------- +ipv4_route 58 98246 +ipv6_route 60 16324 +ipv4_nexthop 8 49086 +ipv6_nexthop 8 49086 +ipv4_neighbor 8 8168 +ipv6_neighbor 8 4084 +nexthop_group_member 0 16384 +nexthop_group 0 512 +fdb_entry 0 32767 + + +ASIC1 + +Resource Name Used Count Available Count +-------------------- ------------ ----------------- +ipv4_route 58 98246 +ipv6_route 60 16324 +ipv4_nexthop 8 49086 +ipv6_nexthop 8 49086 +ipv4_neighbor 8 8168 +ipv6_neighbor 8 4084 +nexthop_group_member 0 16384 +nexthop_group 0 512 +fdb_entry 0 32767 + + +ASIC0 + +Stage Bind Point Resource Name Used Count Available Count +------- ------------ --------------- ------------ ----------------- +INGRESS PORT acl_group 16 232 +INGRESS PORT acl_table 2 3 +INGRESS LAG acl_group 8 232 +INGRESS LAG acl_table 0 3 +INGRESS VLAN acl_group 0 232 +INGRESS VLAN acl_table 0 6 +INGRESS RIF acl_group 0 232 +INGRESS RIF acl_table 0 6 +INGRESS SWITCH acl_group 0 232 +INGRESS SWITCH acl_table 0 6 +EGRESS PORT acl_group 0 232 +EGRESS PORT acl_table 0 2 +EGRESS LAG acl_group 0 232 +EGRESS LAG acl_table 0 2 +EGRESS VLAN acl_group 0 232 +EGRESS VLAN acl_table 0 2 +EGRESS RIF acl_group 0 232 +EGRESS RIF acl_table 0 2 +EGRESS SWITCH acl_group 0 232 +EGRESS SWITCH acl_table 0 2 + + +ASIC1 + +Stage Bind Point Resource Name Used Count Available Count +------- ------------ --------------- ------------ ----------------- +INGRESS PORT acl_group 16 232 +INGRESS PORT acl_table 2 3 +INGRESS LAG acl_group 8 232 +INGRESS LAG acl_table 0 3 +INGRESS VLAN acl_group 0 232 +INGRESS VLAN acl_table 0 6 +INGRESS RIF acl_group 0 232 +INGRESS RIF acl_table 0 6 +INGRESS SWITCH acl_group 0 232 +INGRESS SWITCH acl_table 0 6 +EGRESS PORT acl_group 0 232 +EGRESS PORT acl_table 0 2 +EGRESS LAG acl_group 0 232 +EGRESS LAG acl_table 0 2 +EGRESS VLAN acl_group 0 232 +EGRESS VLAN acl_table 0 2 +EGRESS RIF acl_group 0 232 +EGRESS RIF acl_table 0 2 +EGRESS SWITCH acl_group 0 232 +EGRESS SWITCH acl_table 0 2 + + +ASIC0 + +Table ID Resource Name Used Count Available Count +--------------- --------------- ------------ ----------------- +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 +0x7000000000670 acl_entry 0 1024 +0x7000000000670 acl_counter 0 1280 + + +ASIC1 + +Table ID Resource Name Used Count Available Count +--------------- --------------- ------------ ----------------- +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 +0x7000000000670 acl_entry 0 1024 +0x7000000000670 acl_counter 0 1280 + +""" + +crm_multi_asic_show_resources_fdb = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +fdb_entry 0 32767 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +fdb_entry 0 32767 + +""" + +crm_multi_asic_show_resources_ipv4_neighbor = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_neighbor 8 8168 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_neighbor 8 8168 + +""" + +crm_multi_asic_show_resources_ipv4_nexthop = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_nexthop 8 49086 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_nexthop 8 49086 + +""" + +crm_multi_asic_show_resources_ipv4_route = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_route 58 98246 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv4_route 58 98246 + +""" + +crm_multi_asic_show_resources_ipv6_route = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_route 60 16324 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_route 60 16324 + +""" + +crm_multi_asic_show_resources_ipv6_neighbor = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_neighbor 8 4084 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_neighbor 8 4084 + +""" + +crm_multi_asic_show_resources_ipv6_nexthop = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_nexthop 8 49086 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +ipv6_nexthop 8 49086 + +""" + +crm_multi_asic_show_resources_nexthop_group_member = """\ + +ASIC0 + +Resource Name Used Count Available Count +-------------------- ------------ ----------------- +nexthop_group_member 0 16384 + + +ASIC1 + +Resource Name Used Count Available Count +-------------------- ------------ ----------------- +nexthop_group_member 0 16384 + +""" + +crm_multi_asic_show_resources_nexthop_group_object = """\ + +ASIC0 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +nexthop_group 0 512 + + +ASIC1 + +Resource Name Used Count Available Count +--------------- ------------ ----------------- +nexthop_group 0 512 + +""" + +class TestCrm(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def test_crm_show_summary(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'summary']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_summary + + def test_crm_show_thresholds_acl_group(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'group']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_acl_group + + def test_crm_show_thresholds_acl_table(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'table']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_acl_table + + def test_crm_show_thresholds_all(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'all']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_all + + def test_crm_show_thresholds_fdb(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'fdb']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_fdb + + def test_crm_show_thresholds_ipv4_neighbor(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'neighbor']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv4_neighbor + + def test_crm_show_thresholds_ipv4_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'nexthop']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv4_nexthop + + def test_crm_show_thresholds_ipv4_route(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'route']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv4_route + + def test_crm_show_thresholds_ipv6_neighbor(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'neighbor']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv6_neighbor + + def test_crm_show_thresholds_ipv6_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'nexthop']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv6_nexthop + + def test_crm_show_thresholds_ipv6_route(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'route']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv6_route + + def test_crm_show_thresholds_nexthop_group_member(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'member']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_nexthop_group_member + + def test_crm_show_thresholds_nexthop_group_object(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'object']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_nexthop_group_object + + def test_crm_show_resources_acl_group(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'group']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_acl_group + + def test_crm_show_resources_acl_table(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'table']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_acl_table + + def test_crm_show_resources_all(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'all']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_all + + def test_crm_show_resources_fdb(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'fdb']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_fdb + + def test_crm_show_resources_ipv4_neighbor(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv4', 'neighbor']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_ipv4_neighbor + + def test_crm_show_resources_ipv4_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv4', 'nexthop']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_ipv4_nexthop + + def test_crm_show_resources_ipv4_route(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv4', 'route']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_ipv4_route + + def test_crm_show_resources_ipv6_route(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv6', 'route']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_ipv6_route + + def test_crm_show_resources_ipv6_neighbor(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv6', 'neighbor']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_ipv6_neighbor + + def test_crm_show_resources_ipv6_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv6', 'nexthop']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_ipv6_nexthop + + def test_crm_show_resources_nexthop_group_member(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'nexthop', 'group', 'member']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_nexthop_group_member + + def test_crm_show_resources_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'nexthop', 'group', 'object']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_resources_nexthop_group_object + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" + +class TestCrmMultiAsic(object): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["UTILITIES_UNIT_TESTING"] = "2" + os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "multi_asic" + import mock_tables.mock_multi_asic + mock_tables.dbconnector.load_namespace_config() + + def test_crm_multi_asic_show_resources_acl_group(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'group']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_acl_group + + def test_crm_multi_asic_show_resources_acl_table(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'table']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_acl_table + + def test_crm_multi_asic_show_resources_all(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'all']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_all + + def test_crm_multi_asic_show_resources_fdb(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'fdb']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_fdb + + def test_crm_multi_asic_show_resources_ipv4_neighbor(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv4', 'neighbor']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_ipv4_neighbor + + def test_crm_multi_asic_show_resources_ipv4_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv4', 'nexthop']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_ipv4_nexthop + + def test_crm_multi_asic_show_resources_ipv4_route(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv4', 'route']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_ipv4_route + + def test_crm_multi_asic_show_resources_ipv6_route(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv6', 'route']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_ipv6_route + + def test_crm_multi_asic_show_resources_ipv6_neighbor(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv6', 'neighbor']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_ipv6_neighbor + + def test_crm_multi_asic_show_resources_ipv6_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'ipv6', 'nexthop']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_ipv6_nexthop + + def test_crm_multi_asic_show_resources_nexthop_group_member(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'nexthop', 'group', 'member']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_nexthop_group_member + + def test_crm_multi_asic_show_resources_nexthop(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'resources', 'nexthop', 'group', 'object']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_multi_asic_show_resources_nexthop_group_object + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" + os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" diff --git a/tests/mock_tables/asic0/config_db.json b/tests/mock_tables/asic0/config_db.json index fb6169bfc7..f4d4383b72 100644 --- a/tests/mock_tables/asic0/config_db.json +++ b/tests/mock_tables/asic0/config_db.json @@ -107,5 +107,47 @@ "PFC_WD|GLOBAL": { "BIG_RED_SWITCH": "enable", "POLL_INTERVAL": "199" + }, + "CRM|Config": { + "acl_table_threshold_type": "percentage", + "nexthop_group_threshold_type": "percentage", + "fdb_entry_high_threshold": "85", + "acl_entry_threshold_type": "percentage", + "ipv6_neighbor_low_threshold": "70", + "nexthop_group_member_low_threshold": "70", + "acl_group_high_threshold": "85", + "ipv4_route_high_threshold": "85", + "acl_counter_high_threshold": "85", + "ipv4_route_low_threshold": "70", + "ipv4_route_threshold_type": "percentage", + "ipv4_neighbor_low_threshold": "70", + "acl_group_threshold_type": "percentage", + "ipv4_nexthop_high_threshold": "85", + "ipv6_route_threshold_type": "percentage", + "nexthop_group_low_threshold": "70", + "ipv4_neighbor_high_threshold": "85", + "ipv6_route_high_threshold": "85", + "ipv6_nexthop_threshold_type": "percentage", + "polling_interval": "300", + "ipv4_nexthop_threshold_type": "percentage", + "acl_group_low_threshold": "70", + "acl_entry_low_threshold": "70", + "nexthop_group_member_threshold_type": "percentage", + "ipv4_nexthop_low_threshold": "70", + "acl_counter_threshold_type": "percentage", + "ipv6_neighbor_high_threshold": "85", + "nexthop_group_member_high_threshold": "85", + "acl_table_low_threshold": "70", + "fdb_entry_threshold_type": "percentage", + "ipv6_neighbor_threshold_type": "percentage", + "acl_table_high_threshold": "85", + "ipv6_nexthop_low_threshold": "70", + "acl_counter_low_threshold": "70", + "ipv4_neighbor_threshold_type": "percentage", + "nexthop_group_high_threshold": "85", + "ipv6_route_low_threshold": "70", + "acl_entry_high_threshold": "85", + "fdb_entry_low_threshold": "70", + "ipv6_nexthop_high_threshold": "85" } } diff --git a/tests/mock_tables/asic0/counters_db.json b/tests/mock_tables/asic0/counters_db.json index 3286a0a752..488915a79c 100644 --- a/tests/mock_tables/asic0/counters_db.json +++ b/tests/mock_tables/asic0/counters_db.json @@ -1662,5 +1662,97 @@ }, "COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": { "DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE" + }, + "CRM:ACL_STATS:INGRESS:VLAN":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:STATS":{ + "crm_stats_ipv4_neighbor_used":"8", + "crm_stats_ipv4_route_available":"98246", + "crm_stats_nexthop_group_used":"0", + "crm_stats_ipv6_neighbor_used":"8", + "crm_stats_ipv6_nexthop_available":"49086", + "crm_stats_ipv4_nexthop_used":"8", + "crm_stats_ipv4_nexthop_available":"49086", + "crm_stats_nexthop_group_available":"512", + "crm_stats_nexthop_group_member_used":"0", + "crm_stats_nexthop_group_member_available":"16384", + "crm_stats_fdb_entry_used":"0", + "crm_stats_fdb_entry_available":"32767", + "crm_stats_ipv4_route_used":"58", + "crm_stats_ipv4_neighbor_available":"8168", + "crm_stats_ipv6_route_used":"60", + "crm_stats_ipv6_route_available":"16324", + "crm_stats_ipv6_nexthop_used":"8", + "crm_stats_ipv6_neighbor_available":"4084" + }, + "CRM:ACL_STATS:EGRESS:PORT":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:RIF":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:PORT":{ + "crm_stats_acl_table_used":"2", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"3", + "crm_stats_acl_group_used":"16" + }, + "CRM:ACL_STATS:INGRESS:LAG":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"3", + "crm_stats_acl_group_used":"8" + }, + "CRM:ACL_STATS:EGRESS:LAG":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:SWITCH":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:SWITCH":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:VLAN":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:RIF":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_TABLE_STATS:0x700000000063f":{ + "crm_stats_acl_counter_used":"0", + "crm_stats_acl_entry_used":"0", + "crm_stats_acl_counter_available":"2048", + "crm_stats_acl_entry_available":"2048" + }, + "CRM:ACL_TABLE_STATS:0x7000000000670":{ + "crm_stats_acl_counter_used":"0", + "crm_stats_acl_entry_used":"0", + "crm_stats_acl_counter_available":"1280", + "crm_stats_acl_entry_available":"1024" } } diff --git a/tests/mock_tables/asic1/config_db.json b/tests/mock_tables/asic1/config_db.json index 1ae3cff40b..691f7df7c9 100644 --- a/tests/mock_tables/asic1/config_db.json +++ b/tests/mock_tables/asic1/config_db.json @@ -76,5 +76,47 @@ "PFC_WD|GLOBAL": { "BIG_RED_SWITCH": "enable", "POLL_INTERVAL": "199" + }, + "CRM|Config": { + "acl_table_threshold_type": "percentage", + "nexthop_group_threshold_type": "percentage", + "fdb_entry_high_threshold": "85", + "acl_entry_threshold_type": "percentage", + "ipv6_neighbor_low_threshold": "70", + "nexthop_group_member_low_threshold": "70", + "acl_group_high_threshold": "85", + "ipv4_route_high_threshold": "85", + "acl_counter_high_threshold": "85", + "ipv4_route_low_threshold": "70", + "ipv4_route_threshold_type": "percentage", + "ipv4_neighbor_low_threshold": "70", + "acl_group_threshold_type": "percentage", + "ipv4_nexthop_high_threshold": "85", + "ipv6_route_threshold_type": "percentage", + "nexthop_group_low_threshold": "70", + "ipv4_neighbor_high_threshold": "85", + "ipv6_route_high_threshold": "85", + "ipv6_nexthop_threshold_type": "percentage", + "polling_interval": "300", + "ipv4_nexthop_threshold_type": "percentage", + "acl_group_low_threshold": "70", + "acl_entry_low_threshold": "70", + "nexthop_group_member_threshold_type": "percentage", + "ipv4_nexthop_low_threshold": "70", + "acl_counter_threshold_type": "percentage", + "ipv6_neighbor_high_threshold": "85", + "nexthop_group_member_high_threshold": "85", + "acl_table_low_threshold": "70", + "fdb_entry_threshold_type": "percentage", + "ipv6_neighbor_threshold_type": "percentage", + "acl_table_high_threshold": "85", + "ipv6_nexthop_low_threshold": "70", + "acl_counter_low_threshold": "70", + "ipv4_neighbor_threshold_type": "percentage", + "nexthop_group_high_threshold": "85", + "ipv6_route_low_threshold": "70", + "acl_entry_high_threshold": "85", + "fdb_entry_low_threshold": "70", + "ipv6_nexthop_high_threshold": "85" } } diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index 111912867f..b3c806cf17 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -869,5 +869,91 @@ }, "COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": { "DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE" + }, + "CRM:STATS":{ + "crm_stats_ipv4_neighbor_used":"8", + "crm_stats_ipv4_route_available":"98246", + "crm_stats_nexthop_group_used":"0", + "crm_stats_ipv6_neighbor_used":"8", + "crm_stats_ipv6_nexthop_available":"49086", + "crm_stats_ipv4_nexthop_used":"8", + "crm_stats_ipv4_nexthop_available":"49086", + "crm_stats_nexthop_group_available":"512", + "crm_stats_nexthop_group_member_used":"0", + "crm_stats_nexthop_group_member_available":"16384", + "crm_stats_fdb_entry_used":"0", + "crm_stats_fdb_entry_available":"32767", + "crm_stats_ipv4_route_used":"58", + "crm_stats_ipv4_neighbor_available":"8168", + "crm_stats_ipv6_route_used":"60", + "crm_stats_ipv6_route_available":"16324", + "crm_stats_ipv6_nexthop_used":"8", + "crm_stats_ipv6_neighbor_available":"4084" + }, + "CRM:ACL_STATS:EGRESS:PORT":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:RIF":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:PORT":{ + "crm_stats_acl_table_used":"2", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"3", + "crm_stats_acl_group_used":"16" + }, + "CRM:ACL_STATS:INGRESS:LAG":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"3", + "crm_stats_acl_group_used":"8" + }, + "CRM:ACL_STATS:EGRESS:LAG":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:SWITCH":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:SWITCH":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:VLAN":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:RIF":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_TABLE_STATS:0x700000000063f":{ + "crm_stats_acl_counter_used":"0", + "crm_stats_acl_entry_used":"0", + "crm_stats_acl_counter_available":"2048", + "crm_stats_acl_entry_available":"2048" + }, + "CRM:ACL_TABLE_STATS:0x7000000000670":{ + "crm_stats_acl_counter_used":"0", + "crm_stats_acl_entry_used":"0", + "crm_stats_acl_counter_available":"1280", + "crm_stats_acl_entry_available":"1024" } } diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index a7e8041fbf..eeb72f74f6 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -1257,5 +1257,47 @@ }, "PFC_WD|GLOBAL": { "POLL_INTERVAL": "600" + }, + "CRM|Config": { + "acl_table_threshold_type": "percentage", + "nexthop_group_threshold_type": "percentage", + "fdb_entry_high_threshold": "85", + "acl_entry_threshold_type": "percentage", + "ipv6_neighbor_low_threshold": "70", + "nexthop_group_member_low_threshold": "70", + "acl_group_high_threshold": "85", + "ipv4_route_high_threshold": "85", + "acl_counter_high_threshold": "85", + "ipv4_route_low_threshold": "70", + "ipv4_route_threshold_type": "percentage", + "ipv4_neighbor_low_threshold": "70", + "acl_group_threshold_type": "percentage", + "ipv4_nexthop_high_threshold": "85", + "ipv6_route_threshold_type": "percentage", + "nexthop_group_low_threshold": "70", + "ipv4_neighbor_high_threshold": "85", + "ipv6_route_high_threshold": "85", + "ipv6_nexthop_threshold_type": "percentage", + "polling_interval": "300", + "ipv4_nexthop_threshold_type": "percentage", + "acl_group_low_threshold": "70", + "acl_entry_low_threshold": "70", + "nexthop_group_member_threshold_type": "percentage", + "ipv4_nexthop_low_threshold": "70", + "acl_counter_threshold_type": "percentage", + "ipv6_neighbor_high_threshold": "85", + "nexthop_group_member_high_threshold": "85", + "acl_table_low_threshold": "70", + "fdb_entry_threshold_type": "percentage", + "ipv6_neighbor_threshold_type": "percentage", + "acl_table_high_threshold": "85", + "ipv6_nexthop_low_threshold": "70", + "acl_counter_low_threshold": "70", + "ipv4_neighbor_threshold_type": "percentage", + "nexthop_group_high_threshold": "85", + "ipv6_route_low_threshold": "70", + "acl_entry_high_threshold": "85", + "fdb_entry_low_threshold": "70", + "ipv6_nexthop_high_threshold": "85" } } diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index 5636f27c1c..23e746a39d 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -1000,5 +1000,91 @@ }, "PERSISTENT_WATERMARKS:oid:0x18000000000b66": { "SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "4000" - } + }, + "CRM:STATS":{ + "crm_stats_ipv4_neighbor_used":"8", + "crm_stats_ipv4_route_available":"98246", + "crm_stats_nexthop_group_used":"0", + "crm_stats_ipv6_neighbor_used":"8", + "crm_stats_ipv6_nexthop_available":"49086", + "crm_stats_ipv4_nexthop_used":"8", + "crm_stats_ipv4_nexthop_available":"49086", + "crm_stats_nexthop_group_available":"512", + "crm_stats_nexthop_group_member_used":"0", + "crm_stats_nexthop_group_member_available":"16384", + "crm_stats_fdb_entry_used":"0", + "crm_stats_fdb_entry_available":"32767", + "crm_stats_ipv4_route_used":"58", + "crm_stats_ipv4_neighbor_available":"8168", + "crm_stats_ipv6_route_used":"60", + "crm_stats_ipv6_route_available":"16324", + "crm_stats_ipv6_nexthop_used":"8", + "crm_stats_ipv6_neighbor_available":"4084" + }, + "CRM:ACL_STATS:EGRESS:PORT":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:RIF":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:PORT":{ + "crm_stats_acl_table_used":"2", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"3", + "crm_stats_acl_group_used":"16" + }, + "CRM:ACL_STATS:INGRESS:LAG":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"3", + "crm_stats_acl_group_used":"8" + }, + "CRM:ACL_STATS:EGRESS:LAG":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:INGRESS:SWITCH":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:SWITCH":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:VLAN":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_STATS:EGRESS:RIF":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"2", + "crm_stats_acl_group_used":"0" + }, + "CRM:ACL_TABLE_STATS:0x700000000063f":{ + "crm_stats_acl_counter_used":"0", + "crm_stats_acl_entry_used":"0", + "crm_stats_acl_counter_available":"2048", + "crm_stats_acl_entry_available":"2048" + }, + "CRM:ACL_TABLE_STATS:0x7000000000670":{ + "crm_stats_acl_counter_used":"0", + "crm_stats_acl_entry_used":"0", + "crm_stats_acl_counter_available":"1280", + "crm_stats_acl_entry_available":"1024" + } } From 98000a4f9644fa52888dd7fa174678328f231acd Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 28 Oct 2020 23:56:19 -0700 Subject: [PATCH 3/4] Fix unit test errors --- tests/crm_test.py | 9 +++++---- tests/mock_tables/asic1/counters_db.json | 6 ++++++ tests/mock_tables/counters_db.json | 8 +++++++- tests/mock_tables/mock_single_asic.py | 16 ++++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 tests/mock_tables/mock_single_asic.py diff --git a/tests/crm_test.py b/tests/crm_test.py index 4f07cf6384..005940f24c 100644 --- a/tests/crm_test.py +++ b/tests/crm_test.py @@ -349,10 +349,10 @@ Table ID Resource Name Used Count Available Count --------------- --------------- ------------ ----------------- -0x700000000063f acl_entry 0 2048 -0x700000000063f acl_counter 0 2048 0x7000000000670 acl_entry 0 1024 0x7000000000670 acl_counter 0 1280 +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 """ @@ -454,10 +454,10 @@ Table ID Resource Name Used Count Available Count --------------- --------------- ------------ ----------------- -0x700000000063f acl_entry 0 2048 -0x700000000063f acl_counter 0 2048 0x7000000000670 acl_entry 0 1024 0x7000000000670 acl_counter 0 1280 +0x700000000063f acl_entry 0 2048 +0x700000000063f acl_counter 0 2048 """ @@ -900,3 +900,4 @@ def teardown_class(cls): os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1]) os.environ["UTILITIES_UNIT_TESTING"] = "0" os.environ["UTILITIES_UNIT_TESTING_TOPOLOGY"] = "" + import mock_tables.mock_single_asic diff --git a/tests/mock_tables/asic1/counters_db.json b/tests/mock_tables/asic1/counters_db.json index b3c806cf17..a323ecde3e 100644 --- a/tests/mock_tables/asic1/counters_db.json +++ b/tests/mock_tables/asic1/counters_db.json @@ -870,6 +870,12 @@ "COUNTERS_DEBUG_NAME_SWITCH_STAT_MAP": { "DEBUG_1": "SAI_SWITCH_STAT_IN_DROP_REASON_RANGE_BASE" }, + "CRM:ACL_STATS:INGRESS:VLAN":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, "CRM:STATS":{ "crm_stats_ipv4_neighbor_used":"8", "crm_stats_ipv4_route_available":"98246", diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index 23e746a39d..96be3b5fc5 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -1000,7 +1000,13 @@ }, "PERSISTENT_WATERMARKS:oid:0x18000000000b66": { "SAI_BUFFER_POOL_STAT_WATERMARK_BYTES": "4000" - }, + }, + "CRM:ACL_STATS:INGRESS:VLAN":{ + "crm_stats_acl_table_used":"0", + "crm_stats_acl_group_available":"232", + "crm_stats_acl_table_available":"6", + "crm_stats_acl_group_used":"0" + }, "CRM:STATS":{ "crm_stats_ipv4_neighbor_used":"8", "crm_stats_ipv4_route_available":"98246", diff --git a/tests/mock_tables/mock_single_asic.py b/tests/mock_tables/mock_single_asic.py new file mode 100644 index 0000000000..418b7f63fa --- /dev/null +++ b/tests/mock_tables/mock_single_asic.py @@ -0,0 +1,16 @@ +# MONKEY PATCH!!! +import mock +from sonic_py_common import multi_asic + +def mock_get_num_asics(): + return 1 + +def mock_is_multi_asic(): + return False + +def mock_get_namespace_list(namespace=None): + return [''] + +multi_asic.is_multi_asic = mock_is_multi_asic +multi_asic.get_num_asics = mock_get_num_asics +multi_asic.get_namespace_list = mock_get_namespace_list From 8729283e5c451e57a9421eec94639e8afe92c9e8 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Sat, 7 Nov 2020 23:18:29 -0800 Subject: [PATCH 4/4] Add more tests + introduce the option to pass the DB to crm main --- crm/main.py | 31 ++-- tests/crm_test.py | 422 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 430 insertions(+), 23 deletions(-) diff --git a/crm/main.py b/crm/main.py index 03e2441b49..f3b59b3288 100644 --- a/crm/main.py +++ b/crm/main.py @@ -7,12 +7,12 @@ from sonic_py_common import multi_asic class Crm: - def __init__(self): + def __init__(self, db=None): self.cli_mode = None self.addr_family = None self.res_type = None self.db = None - self.config_db = None + self.cfgdb = db self.multi_asic = multi_asic_util.MultiAsic() @multi_asic_util.run_on_multi_asic @@ -20,6 +20,8 @@ def config(self, attr, val): """ CRM handler for 'config' CLI commands. """ + if self.cfgdb: + self.config_db = self.cfgdb self.config_db.mod_entry("CRM", 'Config', {attr: val}) def show_summary(self): @@ -27,11 +29,13 @@ def show_summary(self): CRM Handler to display general information. """ - # Get the namespace list - namespaces = multi_asic.get_namespace_list() + configdb = self.cfgdb + if configdb is None: + # Get the namespace list + namespaces = multi_asic.get_namespace_list() - configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) - configdb.connect() + configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) + configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') @@ -45,11 +49,13 @@ def show_thresholds(self, resource): CRM Handler to display thresholds information. """ - # Get the namespace list - namespaces = multi_asic.get_namespace_list() + configdb = self.cfgdb + if configdb is None: + # Get the namespace list + namespaces = multi_asic.get_namespace_list() - configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) - configdb.connect() + configdb = swsssdk.ConfigDBConnector(namespace=namespaces[0]) + configdb.connect() crm_info = configdb.get_entry('CRM', 'Config') @@ -190,8 +196,11 @@ def cli(ctx): """ Utility entry point. """ + # Use the db object if given as input. + db = None if ctx.obj is None else ctx.obj.cfgdb + context = { - "crm": Crm() + "crm": Crm(db) } ctx.obj = context diff --git a/tests/crm_test.py b/tests/crm_test.py index 005940f24c..f6fe980bd5 100644 --- a/tests/crm_test.py +++ b/tests/crm_test.py @@ -3,6 +3,7 @@ from click.testing import CliRunner import crm.main as crm +from utilities_common.db import Db # Expected output for CRM @@ -120,6 +121,100 @@ """ +crm_new_show_summary = """\ + +Polling Interval: 30 second(s) + +""" + +crm_new_show_thresholds_acl_group = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +acl_group percentage 60 90 + +""" + +crm_new_show_thresholds_acl_table = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +acl_table percentage 60 90 + +""" + +crm_new_show_thresholds_fdb = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +fdb_entry percentage 60 90 + +""" + +crm_new_show_thresholds_ipv4_neighbor = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv4_neighbor percentage 60 90 + +""" + +crm_new_show_thresholds_ipv4_nexthop = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv4_nexthop percentage 60 90 + +""" + +crm_new_show_thresholds_ipv4_route = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv4_route percentage 60 90 + +""" + +crm_new_show_thresholds_ipv6_neighbor = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv6_neighbor percentage 60 90 + +""" + +crm_new_show_thresholds_ipv6_nexthop = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv6_nexthop percentage 60 90 + +""" + +crm_new_show_thresholds_ipv6_route= """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +ipv6_route percentage 60 90 + +""" + +crm_new_show_thresholds_nexthop_group_member = """\ + +Resource Name Threshold Type Low Threshold High Threshold +-------------------- ---------------- --------------- ---------------- +nexthop_group_member percentage 60 90 + +""" + +crm_new_show_thresholds_nexthop_group_object = """\ + +Resource Name Threshold Type Low Threshold High Threshold +--------------- ---------------- --------------- ---------------- +nexthop_group percentage 60 90 + +""" + crm_show_resources_acl_group = """\ Stage Bind Point Resource Name Used Count Available Count @@ -622,24 +717,49 @@ def setup_class(cls): def test_crm_show_summary(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'summary']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'summary'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_summary + result = runner.invoke(crm.cli, ['config', 'polling', 'interval', '30'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'summary'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_summary def test_crm_show_thresholds_acl_group(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'group']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'group'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_acl_group + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'group', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'group', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'group'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_acl_group def test_crm_show_thresholds_acl_table(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'table']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'table'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_acl_table + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'table', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'table', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'table'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_acl_table def test_crm_show_thresholds_all(self): runner = CliRunner() @@ -650,66 +770,147 @@ def test_crm_show_thresholds_all(self): def test_crm_show_thresholds_fdb(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'fdb']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'fdb'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_fdb + result = runner.invoke(crm.cli, ['config', 'thresholds', 'fdb', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'fdb', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'fdb'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_fdb def test_crm_show_thresholds_ipv4_neighbor(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'neighbor']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'neighbor'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_ipv4_neighbor + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'neighbor', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'neighbor', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'neighbor'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv4_neighbor def test_crm_show_thresholds_ipv4_nexthop(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'nexthop']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'nexthop'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_ipv4_nexthop + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'nexthop', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'nexthop', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'nexthop'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv4_nexthop def test_crm_show_thresholds_ipv4_route(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'route']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'route'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_ipv4_route + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'route', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'route', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'route'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv4_route def test_crm_show_thresholds_ipv6_neighbor(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'neighbor']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'neighbor'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_ipv6_neighbor + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'neighbor', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'neighbor', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'neighbor'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv6_neighbor def test_crm_show_thresholds_ipv6_nexthop(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'nexthop']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'nexthop'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_ipv6_nexthop + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'nexthop', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'nexthop', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'nexthop'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv6_nexthop def test_crm_show_thresholds_ipv6_route(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'route']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'route'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_ipv6_route + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'route', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'route', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'route'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv6_route def test_crm_show_thresholds_nexthop_group_member(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'member']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'member'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_nexthop_group_member + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'member', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'member', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'member'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_nexthop_group_member def test_crm_show_thresholds_nexthop_group_object(self): runner = CliRunner() - result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'object']) + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'object'], obj=db) print(sys.stderr, result.output) assert result.exit_code == 0 assert result.output == crm_show_thresholds_nexthop_group_object + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'object', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'object', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'object'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_nexthop_group_object def test_crm_show_resources_acl_group(self): runner = CliRunner() @@ -810,6 +1011,203 @@ def setup_class(cls): import mock_tables.mock_multi_asic mock_tables.dbconnector.load_namespace_config() + def test_crm_show_summary(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'summary'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_summary + result = runner.invoke(crm.cli, ['config', 'polling', 'interval', '30'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'summary'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_summary + + def test_crm_show_thresholds_acl_group(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'group'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_acl_group + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'group', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'group', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'group'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_acl_group + + def test_crm_show_thresholds_acl_table(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'table'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_acl_table + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'table', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'acl', 'table', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'acl', 'table'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_acl_table + + def test_crm_show_thresholds_all(self): + runner = CliRunner() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'all']) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_all + + def test_crm_show_thresholds_fdb(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'fdb'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_fdb + result = runner.invoke(crm.cli, ['config', 'thresholds', 'fdb', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'fdb', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'fdb'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_fdb + + def test_crm_show_thresholds_ipv4_neighbor(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'neighbor'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv4_neighbor + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'neighbor', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'neighbor', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'neighbor'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv4_neighbor + + def test_crm_show_thresholds_ipv4_nexthop(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'nexthop'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv4_nexthop + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'nexthop', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'nexthop', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'nexthop'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv4_nexthop + + def test_crm_show_thresholds_ipv4_route(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'route'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv4_route + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'route', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv4', 'route', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv4', 'route'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv4_route + + def test_crm_show_thresholds_ipv6_neighbor(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'neighbor'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv6_neighbor + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'neighbor', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'neighbor', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'neighbor'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv6_neighbor + + def test_crm_show_thresholds_ipv6_nexthop(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'nexthop'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv6_nexthop + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'nexthop', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'nexthop', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'nexthop'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv6_nexthop + + def test_crm_show_thresholds_ipv6_route(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'route'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_ipv6_route + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'route', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'ipv6', 'route', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'ipv6', 'route'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_ipv6_route + + def test_crm_show_thresholds_nexthop_group_member(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'member'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_nexthop_group_member + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'member', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'member', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'member'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_nexthop_group_member + + def test_crm_show_thresholds_nexthop_group_object(self): + runner = CliRunner() + db = Db() + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'object'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_show_thresholds_nexthop_group_object + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'object', 'high', '90'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['config', 'thresholds', 'nexthop', 'group', 'object', 'low', '60'], obj=db) + print(sys.stderr, result.output) + result = runner.invoke(crm.cli, ['show', 'thresholds', 'nexthop', 'group', 'object'], obj=db) + print(sys.stderr, result.output) + assert result.exit_code == 0 + assert result.output == crm_new_show_thresholds_nexthop_group_object + def test_crm_multi_asic_show_resources_acl_group(self): runner = CliRunner() result = runner.invoke(crm.cli, ['show', 'resources', 'acl', 'group'])