diff --git a/generic_config_updater/gcu_field_operation_validators.conf.json b/generic_config_updater/gcu_field_operation_validators.conf.json index 0f5da34e0..7f7d1b9b0 100644 --- a/generic_config_updater/gcu_field_operation_validators.conf.json +++ b/generic_config_updater/gcu_field_operation_validators.conf.json @@ -17,7 +17,8 @@ "helper_data": { "rdma_config_update_validator": { "mellanox_asics": { - "spc1": [ "ACS-MSN2700", "ACS-MSN2740", "ACS-MSN2100", "ACS-MSN2410", "ACS-MSN2010", "Mellanox-SN2700", "Mellanox-SN2700-D48C8" ], + "spc1": [ "ACS-MSN2700", "ACS-MSN2740", "ACS-MSN2100", "ACS-MSN2410", "ACS-MSN2010", "Mellanox-SN2700", "Mellanox-SN2700-D48C8", + "ACS-MSN2700-A1", "Mellanox-SN2700-A1", "Mellanox-SN2700-A1-C28D8", "Mellanox-SN2700-A1-D40C8S8", "Mellanox-SN2700-A1-D44C10", "Mellanox-SN2700-A1-D48C8" ], "spc2": [ "ACS-MSN3800", "Mellanox-SN3800-D112C8" ], "spc3": [ "ACS-MSN4700", "ACS-MSN4600", "ACS-MSN4600C", "ACS-MSN4410", "Mellanox-SN4600C-D112C8", "Mellanox-SN4600C-C64", "Mellanox-SN4700-O8C48" ], "spc4": [ "ACS-SN5600"] diff --git a/generic_config_updater/services_validator.py b/generic_config_updater/services_validator.py index 497cb4ee7..25501f759 100644 --- a/generic_config_updater/services_validator.py +++ b/generic_config_updater/services_validator.py @@ -49,11 +49,15 @@ def _service_restart(svc_name): def rsyslog_validator(old_config, upd_config, keys): - rc = os.system("/usr/bin/rsyslog-config.sh") - if rc != 0: - return _service_restart("rsyslog") - else: - return True + old_syslog = old_config.get("SYSLOG_SERVER", {}) + upd_syslog = upd_config.get("SYSLOG_SERVER", {}) + + if old_syslog != upd_syslog: + os.system("systemctl reset-failed rsyslog-config rsyslog") + rc = os.system("systemctl restart rsyslog-config") + if rc != 0: + return False + return True def dhcp_validator(old_config, upd_config, keys): diff --git a/scripts/fast-reboot-filter-routes.py b/scripts/fast-reboot-filter-routes.py index c66972bf4..1e0bcbeca 100755 --- a/scripts/fast-reboot-filter-routes.py +++ b/scripts/fast-reboot-filter-routes.py @@ -6,7 +6,6 @@ import utilities_common.cli as clicommon import syslog import traceback -import click from swsscommon.swsscommon import ConfigDBConnector ROUTE_IDX = 1 @@ -14,19 +13,14 @@ def get_connected_routes(): cmd = ['sudo', 'vtysh', '-c', "show ip route connected json"] connected_routes = [] - try: - output, ret = clicommon.run_command(cmd, return_cmd=True) - if ret != 0: - click.echo(output.rstrip('\n')) - sys.exit(ret) - if output is not None: - route_info = json.loads(output) - for route in route_info.keys(): - connected_routes.append(route) - except Exception: - ctx = click.get_current_context() - ctx.fail("Unable to get connected routes from bgp") - + output, ret = clicommon.run_command(cmd, return_cmd=True) + if ret != 0: + raise Exception("Failed to execute {}: {}".format(" ".join(cmd), output.rstrip('\n'))) + if output is not None: + route_info = json.loads(output) + for route in route_info.keys(): + connected_routes.append(route) + return connected_routes def get_route(db, route): @@ -81,6 +75,7 @@ def main(): syslog.syslog(syslog.LOG_NOTICE, "SIGINT received. Quitting") res = 1 except Exception as e: + print(e) syslog.syslog(syslog.LOG_ERR, "Got an exception %s: Traceback: %s" % (str(e), traceback.format_exc())) res = 2 finally: diff --git a/scripts/generate_dump b/scripts/generate_dump index 544704a3b..552854bec 100755 --- a/scripts/generate_dump +++ b/scripts/generate_dump @@ -50,6 +50,7 @@ SKIP_BCMCMD=0 SAVE_STDERR=true RETURN_CODE=$EXT_SUCCESS DEBUG_DUMP=false +ROUTE_TAB_LIMIT_DIRECT_ITERATION=24000 # lock dirs/files LOCKDIR="/tmp/techsupport-lock" @@ -863,24 +864,114 @@ save_redis() { } ############################################################################### -# SAI DUMP from syncd +# GET ROUTE table size by ASIC id and ip version +# Globals: +# TIMEOUT_MIN +# TIMEOUT_EXIT_CODE +# Arguments: +# asic id +# IP version +# Returns: +# Status: 0 success, otherwise failure +############################################################################### +get_route_table_size_by_asic_id_and_ipver() { + local asic_id="$1" + local ip_ver="$2" + local filepath="/tmp/route_summary.txt" + local ns="" + RC=0 + + if [[ $NUM_ASICS -gt 1 ]] ; then + ns="-n ${asic_id}" + fi + + if [ $ip_ver = "ipv4" ]; then + cmd="vtysh ${ns} -c 'show ip route summary json'" + elif [ $ip_ver = "ipv6" ]; then + cmd="vtysh ${ns} -c 'show ipv6 route summary json'" + else + echo "Wrong argument $ip_ver." + return 255 + fi + + local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m" + local cmds="$cmd > '$filepath'" + + eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$? + + if [ $RC -eq $TIMEOUT_EXIT_CODE ]; then + echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes." + return $RC + elif [ $RC -ne 0 ]; then + echo "Command: $cmds failed with RC $RC" + return $RC + fi + + local route_tab_size=$(python3 -c "\ +import json +with open('$filepath') as json_file: + data = json.load(json_file) + print(data['routesTotal'])") + rm $filepath + echo "$route_tab_size" +} + +############################################################################### +# SAI DUMP based on the route table size +# if the route table has more than ROUTE_TAB_LIMIT_DIRECT_ITERATION +# then dump by Redis Save command, +# otherwize, dump it by directly iteration the Redis +# # Globals: # NUM_ASICS +# ROUTE_TAB_LIMIT_DIRECT_ITERATION # Arguments: # None # Returns: # None ############################################################################### -save_saidump() { +save_saidump_by_route_size() { trap 'handle_error $? $LINENO' ERR - if [[ ( "$NUM_ASICS" == 1 ) ]] ; then - save_cmd "docker exec syncd saidump" "saidump" - else - for (( i=0; i<$NUM_ASICS; i++ )) - do - save_cmd "docker exec syncd$i saidump" "saidump$i" - done - fi + + for (( i=0; i<$NUM_ASICS; i++ )) + do + route_size_ipv4=`get_route_table_size_by_asic_id_and_ipver $i ipv4` + ret=$? + + if [ $ret -ne 0 ]; then + echo "Get route table's size by asicid $i and ipv4 failed." + return $ret + fi + + route_size_ipv6=`get_route_table_size_by_asic_id_and_ipver $i ipv6` + ret=$? + + if [ $ret -ne 0 ]; then + echo "Get route table's size by asicid $i and ipv6 failed." + return $ret + fi + + route_size=`expr $route_size_ipv4 + $route_size_ipv6` + echo "The route table's size is $route_size(ipv4 $route_size_ipv4, ipv6 $route_size_ipv6)" + + if [[ $route_size -gt $ROUTE_TAB_LIMIT_DIRECT_ITERATION ]]; then + echo "Dump by using Redis SAVE." + + if [[ ( "$NUM_ASICS" == 1 ) ]] ; then + save_cmd "docker exec syncd saidump.sh" "saidump" + else + save_cmd "docker exec syncd$i saidump.sh" "saidump$i" + fi + else + echo "Dump by using direct iteration of Redis DB." + + if [[ ( "$NUM_ASICS" == 1 ) ]] ; then + save_cmd "docker exec syncd saidump" "saidump" + else + save_cmd "docker exec syncd$i saidump" "saidump$i" + fi + fi + done } ############################################################################### @@ -1579,6 +1670,22 @@ save_dump_state_all_ns() { done } +############################################################################### +# Save important files that are present in container storage for better debugging +# Files will be saved under dump// +# Types of Files Saved: +# 1) rsyslogd.conf +############################################################################### +save_container_files() { + trap 'handle_error $? $LINENO' ERR + local CONTAINER_FDUMP="container_dumps" + # Get the running container names + container_names=$(docker ps --format '{{.Names}}' --filter status=running) + for name in $container_names; do + $MKDIR $V -p $LOGDIR/$CONTAINER_FDUMP/$name + copy_from_docker $name "/etc/rsyslog.conf" $LOGDIR/$CONTAINER_FDUMP/$name/rsyslog.conf + done +} ############################################################################### # Main generate_dump routine @@ -1706,6 +1813,8 @@ main() { wait save_redis_info & + save_container_files & + if $DEBUG_DUMP then save_dump_state_all_ns & @@ -1732,9 +1841,7 @@ main() { save_cmd "ps -AwwL -o user,pid,lwp,ppid,nlwp,pcpu,pri,nice,vsize,rss,tty,stat,wchan:12,start,bsdtime,command" "ps.extended" & wait - if [[ "$device_type" != "SpineRouter" ]]; then - save_saidump - fi + save_saidump_by_route_size if [ "$asic" = "barefoot" ]; then collect_barefoot diff --git a/scripts/queuestat b/scripts/queuestat index d82e7e4a6..8f9555448 100755 --- a/scripts/queuestat +++ b/scripts/queuestat @@ -198,7 +198,7 @@ class Queuestat(object): cnstat_dict[queue] = get_counters(queue_map[queue]) return cnstat_dict - def cnstat_print(self, port, cnstat_dict, json_opt): + def cnstat_print(self, port, cnstat_dict, json_opt, non_zero): """ Print the cnstat. If JSON option is True, return data in JSON format. @@ -211,19 +211,22 @@ class Queuestat(object): if json_opt: json_output[port][key] = data continue - table.append((port, data['queuetype'] + str(data['queueindex']), - data['totalpacket'], data['totalbytes'], - data['droppacket'], data['dropbytes'])) + if not non_zero or data['totalpacket'] != '0' or data['totalbytes'] != '0' or \ + data['droppacket'] != '0' or data['dropbytes'] != '0': + table.append((port, data['queuetype'] + str(data['queueindex']), + data['totalpacket'], data['totalbytes'], + data['droppacket'], data['dropbytes'])) if json_opt: json_output[port].update(build_json(port, table)) return json_output else: hdr = voq_header if self.voq else header - print(tabulate(table, hdr, tablefmt='simple', stralign='right')) - print() + if table: + print(tabulate(table, hdr, tablefmt='simple', stralign='right')) + print() - def cnstat_diff_print(self, port, cnstat_new_dict, cnstat_old_dict, json_opt): + def cnstat_diff_print(self, port, cnstat_new_dict, cnstat_old_dict, json_opt, non_zero): """ Print the difference between two cnstat results. If JSON option is True, return data in JSON format. @@ -241,25 +244,32 @@ class Queuestat(object): old_cntr = cnstat_old_dict.get(key) if old_cntr is not None: - table.append((port, cntr['queuetype'] + str(cntr['queueindex']), - ns_diff(cntr['totalpacket'], old_cntr['totalpacket']), - ns_diff(cntr['totalbytes'], old_cntr['totalbytes']), - ns_diff(cntr['droppacket'], old_cntr['droppacket']), - ns_diff(cntr['dropbytes'], old_cntr['dropbytes']))) - else: - table.append((port, cntr['queuetype'] + str(cntr['queueindex']), - cntr['totalpacket'], cntr['totalbytes'], - cntr['droppacket'], cntr['dropbytes'])) + if not non_zero or ns_diff(cntr['totalpacket'], old_cntr['totalpacket']) != '0' or \ + ns_diff(cntr['totalbytes'], old_cntr['totalbytes']) != '0' or \ + ns_diff(cntr['droppacket'], old_cntr['droppacket']) != '0' or \ + ns_diff(cntr['dropbytes'], old_cntr['dropbytes']) != '0': + table.append((port, cntr['queuetype'] + str(cntr['queueindex']), + ns_diff(cntr['totalpacket'], old_cntr['totalpacket']), + ns_diff(cntr['totalbytes'], old_cntr['totalbytes']), + ns_diff(cntr['droppacket'], old_cntr['droppacket']), + ns_diff(cntr['dropbytes'], old_cntr['dropbytes']))) + elif not non_zero or cntr['totalpacket'] != '0' or cntr['totalbytes'] != '0' or \ + cntr['droppacket'] != '0' or cntr['dropbytes'] != '0': + table.append((port, cntr['queuetype'] + str(cntr['queueindex']), + cntr['totalpacket'], cntr['totalbytes'], + cntr['droppacket'], cntr['dropbytes'])) if json_opt: json_output[port].update(build_json(port, table)) return json_output else: hdr = voq_header if self.voq else header - print(tabulate(table, hdr, tablefmt='simple', stralign='right')) - print() + if table: + print(port + " Last cached time was " + str(cnstat_old_dict.get('time'))) + print(tabulate(table, hdr, tablefmt='simple', stralign='right')) + print() - def get_print_all_stat(self, json_opt): + def get_print_all_stat(self, json_opt, non_zero): """ Get stat for each port If JSON option is True, collect data for each port and @@ -276,22 +286,21 @@ class Queuestat(object): cnstat_cached_dict = json.load(open(cnstat_fqn_file_name, 'r')) if json_opt: json_output[port].update({"cached_time":cnstat_cached_dict.get('time')}) - json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt)) + json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero)) else: - print(port + " Last cached time was " + str(cnstat_cached_dict.get('time'))) - self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt) + self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero) except IOError as e: print(e.errno, e) else: if json_opt: - json_output.update(self.cnstat_print(port, cnstat_dict, json_opt)) + json_output.update(self.cnstat_print(port, cnstat_dict, json_opt, non_zero)) else: - self.cnstat_print(port, cnstat_dict, json_opt) + self.cnstat_print(port, cnstat_dict, json_opt, non_zero) if json_opt: print(json_dump(json_output)) - def get_print_port_stat(self, port, json_opt): + def get_print_port_stat(self, port, json_opt, non_zero): """ Get stat for the port If JSON option is True print data in JSON format @@ -310,17 +319,17 @@ class Queuestat(object): cnstat_cached_dict = json.load(open(cnstat_fqn_file_name, 'r')) if json_opt: json_output[port].update({"cached_time":cnstat_cached_dict.get('time')}) - json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt)) + json_output.update(self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero)) else: print("Last cached time was " + str(cnstat_cached_dict.get('time'))) - self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt) + self.cnstat_diff_print(port, cnstat_dict, cnstat_cached_dict, json_opt, non_zero) except IOError as e: print(e.errno, e) else: if json_opt: - json_output.update(self.cnstat_print(port, cnstat_dict, json_opt)) + json_output.update(self.cnstat_print(port, cnstat_dict, json_opt, non_zero)) else: - self.cnstat_print(port, cnstat_dict, json_opt) + self.cnstat_print(port, cnstat_dict, json_opt, non_zero) if json_opt: print(json_dump(json_output)) @@ -358,6 +367,7 @@ Examples: parser.add_argument('-j', '--json_opt', action='store_true', help='Print in JSON format') parser.add_argument('-V', '--voq', action='store_true', help='display voq stats') parser.add_argument('-n','--namespace', default=None, help='Display queue counters for specific namespace') + parser.add_argument('-nz','--non_zero', action='store_true', help='Display non-zero queue counters') args = parser.parse_args() save_fresh_stats = args.clear @@ -365,6 +375,7 @@ Examples: voq = args.voq json_opt = args.json_opt namespace = args.namespace + non_zero = args.non_zero port_to_show_stats = args.port @@ -383,9 +394,9 @@ Examples: sys.exit(0) if port_to_show_stats!=None: - queuestat.get_print_port_stat(port_to_show_stats, json_opt) + queuestat.get_print_port_stat(port_to_show_stats, json_opt, non_zero) else: - queuestat.get_print_all_stat(json_opt) + queuestat.get_print_all_stat(json_opt, non_zero) sys.exit(0) diff --git a/show/main.py b/show/main.py index b4a7e4054..f14bf41dd 100755 --- a/show/main.py +++ b/show/main.py @@ -714,7 +714,8 @@ def queue(): @click.option('--verbose', is_flag=True, help="Enable verbose output") @click.option('--json', is_flag=True, help="JSON output") @click.option('--voq', is_flag=True, help="VOQ counters") -def counters(interfacename, namespace, display, verbose, json, voq): +@click.option('--nonzero', is_flag=True, help="Non Zero Counters") +def counters(interfacename, namespace, display, verbose, json, voq, nonzero): """Show queue counters""" cmd = ["queuestat"] @@ -735,6 +736,9 @@ def counters(interfacename, namespace, display, verbose, json, voq): if voq: cmd += ["-V"] + if nonzero: + cmd += ["-nz"] + run_command(cmd, display_cmd=verbose) # diff --git a/tests/fast_reboot_filter_routes_test.py b/tests/fast_reboot_filter_routes_test.py index 5da086288..3227fa831 100644 --- a/tests/fast_reboot_filter_routes_test.py +++ b/tests/fast_reboot_filter_routes_test.py @@ -10,10 +10,17 @@ def setup(self): @patch('utilities_common.cli.run_command') def test_get_connected_routes(self, mock_run_command): - mock_run_command.return_value = (None, 0) + mock_run_command.return_value = ('{"1.1.0.0/16": {}}', 0) output = fast_reboot_filter_routes.get_connected_routes() mock_run_command.assert_called_with(['sudo', 'vtysh', '-c', "show ip route connected json"], return_cmd=True) - assert output == [] + assert output == ['1.1.0.0/16'] + + @patch('utilities_common.cli.run_command') + def test_get_connected_routes_command_failed(self, mock_run_command): + mock_run_command.return_value = ('{"1.1.0.0/16": {}}', 1) + with pytest.raises(Exception): + fast_reboot_filter_routes.get_connected_routes() + mock_run_command.assert_called_with(['sudo', 'vtysh', '-c', "show ip route connected json"], return_cmd=True) def teardown(self): print("TEAR DOWN") diff --git a/tests/generic_config_updater/field_operation_validator_test.py b/tests/generic_config_updater/field_operation_validator_test.py index 938305889..08a56dcf7 100644 --- a/tests/generic_config_updater/field_operation_validator_test.py +++ b/tests/generic_config_updater/field_operation_validator_test.py @@ -143,6 +143,14 @@ def test_get_asic_spc4(self, mock_popen, mock_get_sonic_version_info): mock_popen.return_value.communicate.return_value = ["ACS-SN5600", 0] self.assertEqual(fov.get_asic_name(), "spc4") + @patch('sonic_py_common.device_info.get_sonic_version_info') + @patch('subprocess.Popen') + def test_get_asic_spc4(self, mock_popen, mock_get_sonic_version_info): + mock_get_sonic_version_info.return_value = {'asic_type': 'mellanox'} + mock_popen.return_value = mock.Mock() + mock_popen.return_value.communicate.return_value = ["Mellanox-SN2700-A1", 0] + self.assertEqual(fov.get_asic_name(), "spc1") + @patch('sonic_py_common.device_info.get_sonic_version_info') @patch('subprocess.Popen') def test_get_asic_th(self, mock_popen, mock_get_sonic_version_info): diff --git a/tests/generic_config_updater/service_validator_test.py b/tests/generic_config_updater/service_validator_test.py index f14a3ad7b..fff7fa20b 100644 --- a/tests/generic_config_updater/service_validator_test.py +++ b/tests/generic_config_updater/service_validator_test.py @@ -142,14 +142,39 @@ def mock_time_sleep_call(sleep_time): }, ] -test_rsyslog_fail = [ - # Fail the calls, to get the entire fail path calls invoked - # - { "cmd": "/usr/bin/rsyslog-config.sh", "rc": 1 }, # config update; fails - { "cmd": "systemctl restart rsyslog", "rc": 1 }, # rsyslog restart; fails - { "cmd": "systemctl reset-failed rsyslog", "rc": 1 }, # reset; failure here just logs - { "cmd": "systemctl restart rsyslog", "rc": 1 }, # restart again; fails - { "cmd": "systemctl restart rsyslog", "rc": 1 }, # restart again; fails + +test_rsyslog_data = [ + { "old": {}, "upd": {}, "cmd": "" }, + { + "old": { "SYSLOG_SERVER": { + "10.13.14.17": {}, + "2001:aa:aa::aa": {} } }, + "upd": { "SYSLOG_SERVER": { + "10.13.14.17": {}, + "2001:aa:aa::aa": {} } }, + "cmd": "" + }, + { + "old": { "SYSLOG_SERVER": { + "10.13.14.17": {} } }, + "upd": { "SYSLOG_SERVER": { + "10.13.14.18": {} } }, + "cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config" + }, + { + "old": { "SYSLOG_SERVER": { + "10.13.14.17": {} } }, + "upd": { "SYSLOG_SERVER": { + "10.13.14.17": {}, + "2001:aa:aa::aa": {} } }, + "cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config" + }, + { + "old": { "SYSLOG_SERVER": { + "10.13.14.17": {} } }, + "upd": {}, + "cmd": "systemctl reset-failed rsyslog-config rsyslog,systemctl restart rsyslog-config" + } ] test_vlanintf_data = [ @@ -208,14 +233,16 @@ def test_change_apply_os_system(self, mock_os_sys): vlan_validator(entry["old"], entry["upd"], None) - - # Test failure case - # - os_system_calls = test_rsyslog_fail + os_system_calls = [] os_system_call_index = 0 + for entry in test_rsyslog_data: + if entry["cmd"]: + for c in entry["cmd"].split(","): + os_system_calls.append({"cmd": c, "rc": 0}) + msg = "case failed: {}".format(str(entry)) + + rsyslog_validator(entry["old"], entry["upd"], None) - rc = rsyslog_validator("", "", "") - assert not rc, "rsyslog_validator expected to fail" os_system_calls = [] os_system_call_index = 0 diff --git a/tests/mock_tables/counters_db.json b/tests/mock_tables/counters_db.json index f2caba244..0e563e107 100644 --- a/tests/mock_tables/counters_db.json +++ b/tests/mock_tables/counters_db.json @@ -1,9 +1,9 @@ { "COUNTERS:oid:0x15000000000357": { - "SAI_QUEUE_STAT_BYTES": "30", - "SAI_QUEUE_STAT_DROPPED_BYTES": "74", - "SAI_QUEUE_STAT_DROPPED_PACKETS": "56", - "SAI_QUEUE_STAT_PACKETS": "68", + "SAI_QUEUE_STAT_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "0", + "SAI_QUEUE_STAT_PACKETS": "0", "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "61" }, "COUNTERS:oid:0x15000000000358": { @@ -266,10 +266,10 @@ "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "49" }, "COUNTERS:oid:0x150000000003a7": { - "SAI_QUEUE_STAT_BYTES": "5", - "SAI_QUEUE_STAT_DROPPED_BYTES": "56", - "SAI_QUEUE_STAT_DROPPED_PACKETS": "36", - "SAI_QUEUE_STAT_PACKETS": "19", + "SAI_QUEUE_STAT_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "0", + "SAI_QUEUE_STAT_PACKETS": "0", "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "65" }, "COUNTERS:oid:0x150000000003a8": { @@ -399,10 +399,10 @@ "SAI_QUEUE_STAT_SHARED_WATERMARK_BYTES": "81" }, "COUNTERS:oid:0x15000000000657": { - "SAI_QUEUE_STAT_BYTES": "30", - "SAI_QUEUE_STAT_DROPPED_BYTES": "74", - "SAI_QUEUE_STAT_DROPPED_PACKETS": "56", - "SAI_QUEUE_STAT_PACKETS": "68" + "SAI_QUEUE_STAT_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_BYTES": "0", + "SAI_QUEUE_STAT_DROPPED_PACKETS": "0", + "SAI_QUEUE_STAT_PACKETS": "0" }, "COUNTERS:oid:0x15000000000658": { "SAI_QUEUE_STAT_BYTES": "43", diff --git a/tests/queue_counter_test.py b/tests/queue_counter_test.py index 1a78b3eeb..d5f632ff4 100644 --- a/tests/queue_counter_test.py +++ b/tests/queue_counter_test.py @@ -24,7 +24,107 @@ show_queue_counters = """\ Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet0 UC0 68 30 56 74 +Ethernet0 UC0 0 0 0 0 +Ethernet0 UC1 60 43 39 1 +Ethernet0 UC2 82 7 39 21 +Ethernet0 UC3 52 70 19 76 +Ethernet0 UC4 11 59 12 94 +Ethernet0 UC5 36 62 35 40 +Ethernet0 UC6 49 91 2 88 +Ethernet0 UC7 33 17 94 74 +Ethernet0 UC8 40 71 95 33 +Ethernet0 UC9 54 8 93 78 +Ethernet0 MC10 83 96 74 9 +Ethernet0 MC11 15 60 61 31 +Ethernet0 MC12 45 52 82 94 +Ethernet0 MC13 55 88 89 52 +Ethernet0 MC14 14 70 95 79 +Ethernet0 MC15 68 60 66 81 +Ethernet0 MC16 63 4 48 76 +Ethernet0 MC17 41 73 77 74 +Ethernet0 MC18 60 21 56 54 +Ethernet0 MC19 57 31 12 39 +Ethernet0 ALL20 N/A N/A N/A N/A +Ethernet0 ALL21 N/A N/A N/A N/A +Ethernet0 ALL22 N/A N/A N/A N/A +Ethernet0 ALL23 N/A N/A N/A N/A +Ethernet0 ALL24 N/A N/A N/A N/A +Ethernet0 ALL25 N/A N/A N/A N/A +Ethernet0 ALL26 N/A N/A N/A N/A +Ethernet0 ALL27 N/A N/A N/A N/A +Ethernet0 ALL28 N/A N/A N/A N/A +Ethernet0 ALL29 N/A N/A N/A N/A + + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ +Ethernet4 UC0 41 96 70 98 +Ethernet4 UC1 18 49 63 36 +Ethernet4 UC2 99 90 3 15 +Ethernet4 UC3 60 89 48 41 +Ethernet4 UC4 8 84 82 94 +Ethernet4 UC5 83 15 75 92 +Ethernet4 UC6 84 26 50 71 +Ethernet4 UC7 27 19 49 80 +Ethernet4 UC8 13 89 13 33 +Ethernet4 UC9 43 48 86 31 +Ethernet4 MC10 50 1 57 82 +Ethernet4 MC11 67 99 84 59 +Ethernet4 MC12 4 58 27 5 +Ethernet4 MC13 74 5 57 39 +Ethernet4 MC14 21 59 4 14 +Ethernet4 MC15 24 61 19 53 +Ethernet4 MC16 51 15 15 32 +Ethernet4 MC17 98 18 23 15 +Ethernet4 MC18 41 34 9 57 +Ethernet4 MC19 57 7 18 99 +Ethernet4 ALL20 N/A N/A N/A N/A +Ethernet4 ALL21 N/A N/A N/A N/A +Ethernet4 ALL22 N/A N/A N/A N/A +Ethernet4 ALL23 N/A N/A N/A N/A +Ethernet4 ALL24 N/A N/A N/A N/A +Ethernet4 ALL25 N/A N/A N/A N/A +Ethernet4 ALL26 N/A N/A N/A N/A +Ethernet4 ALL27 N/A N/A N/A N/A +Ethernet4 ALL28 N/A N/A N/A N/A +Ethernet4 ALL29 N/A N/A N/A N/A + + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ +Ethernet8 UC0 0 0 0 0 +Ethernet8 UC1 38 17 68 91 +Ethernet8 UC2 16 65 79 51 +Ethernet8 UC3 11 97 63 72 +Ethernet8 UC4 54 89 62 62 +Ethernet8 UC5 13 84 30 59 +Ethernet8 UC6 49 67 99 85 +Ethernet8 UC7 2 63 38 88 +Ethernet8 UC8 0 82 93 43 +Ethernet8 UC9 80 17 91 61 +Ethernet8 MC10 81 63 76 73 +Ethernet8 MC11 29 16 29 66 +Ethernet8 MC12 32 12 61 35 +Ethernet8 MC13 79 17 72 93 +Ethernet8 MC14 23 21 67 50 +Ethernet8 MC15 37 10 97 14 +Ethernet8 MC16 30 17 74 43 +Ethernet8 MC17 0 63 54 84 +Ethernet8 MC18 69 88 24 79 +Ethernet8 MC19 20 12 84 3 +Ethernet8 ALL20 N/A N/A N/A N/A +Ethernet8 ALL21 N/A N/A N/A N/A +Ethernet8 ALL22 N/A N/A N/A N/A +Ethernet8 ALL23 N/A N/A N/A N/A +Ethernet8 ALL24 N/A N/A N/A N/A +Ethernet8 ALL25 N/A N/A N/A N/A +Ethernet8 ALL26 N/A N/A N/A N/A +Ethernet8 ALL27 N/A N/A N/A N/A +Ethernet8 ALL28 N/A N/A N/A N/A +Ethernet8 ALL29 N/A N/A N/A N/A + +""" +show_queue_counters_nz = """\ + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ Ethernet0 UC1 60 43 39 1 Ethernet0 UC2 82 7 39 21 Ethernet0 UC3 52 70 19 76 @@ -90,7 +190,6 @@ Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet8 UC0 19 5 36 56 Ethernet8 UC1 38 17 68 91 Ethernet8 UC2 16 65 79 51 Ethernet8 UC3 11 97 63 72 @@ -227,7 +326,41 @@ show_queue_counters_port = """\ Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet8 UC0 19 5 36 56 +Ethernet8 UC0 0 0 0 0 +Ethernet8 UC1 38 17 68 91 +Ethernet8 UC2 16 65 79 51 +Ethernet8 UC3 11 97 63 72 +Ethernet8 UC4 54 89 62 62 +Ethernet8 UC5 13 84 30 59 +Ethernet8 UC6 49 67 99 85 +Ethernet8 UC7 2 63 38 88 +Ethernet8 UC8 0 82 93 43 +Ethernet8 UC9 80 17 91 61 +Ethernet8 MC10 81 63 76 73 +Ethernet8 MC11 29 16 29 66 +Ethernet8 MC12 32 12 61 35 +Ethernet8 MC13 79 17 72 93 +Ethernet8 MC14 23 21 67 50 +Ethernet8 MC15 37 10 97 14 +Ethernet8 MC16 30 17 74 43 +Ethernet8 MC17 0 63 54 84 +Ethernet8 MC18 69 88 24 79 +Ethernet8 MC19 20 12 84 3 +Ethernet8 ALL20 N/A N/A N/A N/A +Ethernet8 ALL21 N/A N/A N/A N/A +Ethernet8 ALL22 N/A N/A N/A N/A +Ethernet8 ALL23 N/A N/A N/A N/A +Ethernet8 ALL24 N/A N/A N/A N/A +Ethernet8 ALL25 N/A N/A N/A N/A +Ethernet8 ALL26 N/A N/A N/A N/A +Ethernet8 ALL27 N/A N/A N/A N/A +Ethernet8 ALL28 N/A N/A N/A N/A +Ethernet8 ALL29 N/A N/A N/A N/A + +""" +show_queue_counters_port_nz = """\ + Port TxQ Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ Ethernet8 UC1 38 17 68 91 Ethernet8 UC2 16 65 79 51 Ethernet8 UC3 11 97 63 72 @@ -384,10 +517,10 @@ "totalpacket": "57" }, "UC0": { - "dropbytes": "74", - "droppacket": "56", - "totalbytes": "30", - "totalpacket": "68" + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" }, "UC1": { "dropbytes": "1", @@ -748,10 +881,10 @@ "totalpacket": "20" }, "UC0": { - "dropbytes": "56", - "droppacket": "36", - "totalbytes": "5", - "totalpacket": "19" + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" }, "UC1": { "dropbytes": "91", @@ -810,9 +943,9 @@ } }""" -show_queue_counters_port_json = """\ +show_queue_counters_json_nz = """\ { - "Ethernet8": { + "Ethernet0": { "ALL20": { "dropbytes": "N/A", "droppacket": "N/A", @@ -874,96 +1007,816 @@ "totalpacket": "N/A" }, "MC10": { - "dropbytes": "73", - "droppacket": "76", - "totalbytes": "63", - "totalpacket": "81" + "dropbytes": "9", + "droppacket": "74", + "totalbytes": "96", + "totalpacket": "83" }, "MC11": { - "dropbytes": "66", - "droppacket": "29", - "totalbytes": "16", - "totalpacket": "29" + "dropbytes": "31", + "droppacket": "61", + "totalbytes": "60", + "totalpacket": "15" }, "MC12": { - "dropbytes": "35", - "droppacket": "61", - "totalbytes": "12", - "totalpacket": "32" + "dropbytes": "94", + "droppacket": "82", + "totalbytes": "52", + "totalpacket": "45" }, "MC13": { - "dropbytes": "93", - "droppacket": "72", - "totalbytes": "17", - "totalpacket": "79" + "dropbytes": "52", + "droppacket": "89", + "totalbytes": "88", + "totalpacket": "55" }, "MC14": { - "dropbytes": "50", - "droppacket": "67", - "totalbytes": "21", - "totalpacket": "23" + "dropbytes": "79", + "droppacket": "95", + "totalbytes": "70", + "totalpacket": "14" }, "MC15": { - "dropbytes": "14", - "droppacket": "97", - "totalbytes": "10", - "totalpacket": "37" + "dropbytes": "81", + "droppacket": "66", + "totalbytes": "60", + "totalpacket": "68" }, "MC16": { - "dropbytes": "43", - "droppacket": "74", - "totalbytes": "17", - "totalpacket": "30" + "dropbytes": "76", + "droppacket": "48", + "totalbytes": "4", + "totalpacket": "63" }, "MC17": { - "dropbytes": "84", - "droppacket": "54", - "totalbytes": "63", - "totalpacket": "0" + "dropbytes": "74", + "droppacket": "77", + "totalbytes": "73", + "totalpacket": "41" }, "MC18": { - "dropbytes": "79", - "droppacket": "24", - "totalbytes": "88", - "totalpacket": "69" + "dropbytes": "54", + "droppacket": "56", + "totalbytes": "21", + "totalpacket": "60" }, "MC19": { - "dropbytes": "3", - "droppacket": "84", - "totalbytes": "12", - "totalpacket": "20" - }, - "UC0": { - "dropbytes": "56", - "droppacket": "36", - "totalbytes": "5", - "totalpacket": "19" + "dropbytes": "39", + "droppacket": "12", + "totalbytes": "31", + "totalpacket": "57" }, "UC1": { - "dropbytes": "91", - "droppacket": "68", - "totalbytes": "17", - "totalpacket": "38" + "dropbytes": "1", + "droppacket": "39", + "totalbytes": "43", + "totalpacket": "60" }, "UC2": { - "dropbytes": "51", - "droppacket": "79", - "totalbytes": "65", - "totalpacket": "16" + "dropbytes": "21", + "droppacket": "39", + "totalbytes": "7", + "totalpacket": "82" }, "UC3": { - "dropbytes": "72", - "droppacket": "63", - "totalbytes": "97", - "totalpacket": "11" + "dropbytes": "76", + "droppacket": "19", + "totalbytes": "70", + "totalpacket": "52" }, "UC4": { - "dropbytes": "62", - "droppacket": "62", - "totalbytes": "89", - "totalpacket": "54" - }, - "UC5": { + "dropbytes": "94", + "droppacket": "12", + "totalbytes": "59", + "totalpacket": "11" + }, + "UC5": { + "dropbytes": "40", + "droppacket": "35", + "totalbytes": "62", + "totalpacket": "36" + }, + "UC6": { + "dropbytes": "88", + "droppacket": "2", + "totalbytes": "91", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "74", + "droppacket": "94", + "totalbytes": "17", + "totalpacket": "33" + }, + "UC8": { + "dropbytes": "33", + "droppacket": "95", + "totalbytes": "71", + "totalpacket": "40" + }, + "UC9": { + "dropbytes": "78", + "droppacket": "93", + "totalbytes": "8", + "totalpacket": "54" + } + }, + "Ethernet4": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "82", + "droppacket": "57", + "totalbytes": "1", + "totalpacket": "50" + }, + "MC11": { + "dropbytes": "59", + "droppacket": "84", + "totalbytes": "99", + "totalpacket": "67" + }, + "MC12": { + "dropbytes": "5", + "droppacket": "27", + "totalbytes": "58", + "totalpacket": "4" + }, + "MC13": { + "dropbytes": "39", + "droppacket": "57", + "totalbytes": "5", + "totalpacket": "74" + }, + "MC14": { + "dropbytes": "14", + "droppacket": "4", + "totalbytes": "59", + "totalpacket": "21" + }, + "MC15": { + "dropbytes": "53", + "droppacket": "19", + "totalbytes": "61", + "totalpacket": "24" + }, + "MC16": { + "dropbytes": "32", + "droppacket": "15", + "totalbytes": "15", + "totalpacket": "51" + }, + "MC17": { + "dropbytes": "15", + "droppacket": "23", + "totalbytes": "18", + "totalpacket": "98" + }, + "MC18": { + "dropbytes": "57", + "droppacket": "9", + "totalbytes": "34", + "totalpacket": "41" + }, + "MC19": { + "dropbytes": "99", + "droppacket": "18", + "totalbytes": "7", + "totalpacket": "57" + }, + "UC0": { + "dropbytes": "98", + "droppacket": "70", + "totalbytes": "96", + "totalpacket": "41" + }, + "UC1": { + "dropbytes": "36", + "droppacket": "63", + "totalbytes": "49", + "totalpacket": "18" + }, + "UC2": { + "dropbytes": "15", + "droppacket": "3", + "totalbytes": "90", + "totalpacket": "99" + }, + "UC3": { + "dropbytes": "41", + "droppacket": "48", + "totalbytes": "89", + "totalpacket": "60" + }, + "UC4": { + "dropbytes": "94", + "droppacket": "82", + "totalbytes": "84", + "totalpacket": "8" + }, + "UC5": { + "dropbytes": "92", + "droppacket": "75", + "totalbytes": "15", + "totalpacket": "83" + }, + "UC6": { + "dropbytes": "71", + "droppacket": "50", + "totalbytes": "26", + "totalpacket": "84" + }, + "UC7": { + "dropbytes": "80", + "droppacket": "49", + "totalbytes": "19", + "totalpacket": "27" + }, + "UC8": { + "dropbytes": "33", + "droppacket": "13", + "totalbytes": "89", + "totalpacket": "13" + }, + "UC9": { + "dropbytes": "31", + "droppacket": "86", + "totalbytes": "48", + "totalpacket": "43" + } + }, + "Ethernet8": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "73", + "droppacket": "76", + "totalbytes": "63", + "totalpacket": "81" + }, + "MC11": { + "dropbytes": "66", + "droppacket": "29", + "totalbytes": "16", + "totalpacket": "29" + }, + "MC12": { + "dropbytes": "35", + "droppacket": "61", + "totalbytes": "12", + "totalpacket": "32" + }, + "MC13": { + "dropbytes": "93", + "droppacket": "72", + "totalbytes": "17", + "totalpacket": "79" + }, + "MC14": { + "dropbytes": "50", + "droppacket": "67", + "totalbytes": "21", + "totalpacket": "23" + }, + "MC15": { + "dropbytes": "14", + "droppacket": "97", + "totalbytes": "10", + "totalpacket": "37" + }, + "MC16": { + "dropbytes": "43", + "droppacket": "74", + "totalbytes": "17", + "totalpacket": "30" + }, + "MC17": { + "dropbytes": "84", + "droppacket": "54", + "totalbytes": "63", + "totalpacket": "0" + }, + "MC18": { + "dropbytes": "79", + "droppacket": "24", + "totalbytes": "88", + "totalpacket": "69" + }, + "MC19": { + "dropbytes": "3", + "droppacket": "84", + "totalbytes": "12", + "totalpacket": "20" + }, + "UC1": { + "dropbytes": "91", + "droppacket": "68", + "totalbytes": "17", + "totalpacket": "38" + }, + "UC2": { + "dropbytes": "51", + "droppacket": "79", + "totalbytes": "65", + "totalpacket": "16" + }, + "UC3": { + "dropbytes": "72", + "droppacket": "63", + "totalbytes": "97", + "totalpacket": "11" + }, + "UC4": { + "dropbytes": "62", + "droppacket": "62", + "totalbytes": "89", + "totalpacket": "54" + }, + "UC5": { + "dropbytes": "59", + "droppacket": "30", + "totalbytes": "84", + "totalpacket": "13" + }, + "UC6": { + "dropbytes": "85", + "droppacket": "99", + "totalbytes": "67", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "88", + "droppacket": "38", + "totalbytes": "63", + "totalpacket": "2" + }, + "UC8": { + "dropbytes": "43", + "droppacket": "93", + "totalbytes": "82", + "totalpacket": "0" + }, + "UC9": { + "dropbytes": "61", + "droppacket": "91", + "totalbytes": "17", + "totalpacket": "80" + } + } +}""" + + +show_queue_counters_port_json = """\ +{ + "Ethernet8": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "73", + "droppacket": "76", + "totalbytes": "63", + "totalpacket": "81" + }, + "MC11": { + "dropbytes": "66", + "droppacket": "29", + "totalbytes": "16", + "totalpacket": "29" + }, + "MC12": { + "dropbytes": "35", + "droppacket": "61", + "totalbytes": "12", + "totalpacket": "32" + }, + "MC13": { + "dropbytes": "93", + "droppacket": "72", + "totalbytes": "17", + "totalpacket": "79" + }, + "MC14": { + "dropbytes": "50", + "droppacket": "67", + "totalbytes": "21", + "totalpacket": "23" + }, + "MC15": { + "dropbytes": "14", + "droppacket": "97", + "totalbytes": "10", + "totalpacket": "37" + }, + "MC16": { + "dropbytes": "43", + "droppacket": "74", + "totalbytes": "17", + "totalpacket": "30" + }, + "MC17": { + "dropbytes": "84", + "droppacket": "54", + "totalbytes": "63", + "totalpacket": "0" + }, + "MC18": { + "dropbytes": "79", + "droppacket": "24", + "totalbytes": "88", + "totalpacket": "69" + }, + "MC19": { + "dropbytes": "3", + "droppacket": "84", + "totalbytes": "12", + "totalpacket": "20" + }, + "UC0": { + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" + }, + "UC1": { + "dropbytes": "91", + "droppacket": "68", + "totalbytes": "17", + "totalpacket": "38" + }, + "UC2": { + "dropbytes": "51", + "droppacket": "79", + "totalbytes": "65", + "totalpacket": "16" + }, + "UC3": { + "dropbytes": "72", + "droppacket": "63", + "totalbytes": "97", + "totalpacket": "11" + }, + "UC4": { + "dropbytes": "62", + "droppacket": "62", + "totalbytes": "89", + "totalpacket": "54" + }, + "UC5": { + "dropbytes": "59", + "droppacket": "30", + "totalbytes": "84", + "totalpacket": "13" + }, + "UC6": { + "dropbytes": "85", + "droppacket": "99", + "totalbytes": "67", + "totalpacket": "49" + }, + "UC7": { + "dropbytes": "88", + "droppacket": "38", + "totalbytes": "63", + "totalpacket": "2" + }, + "UC8": { + "dropbytes": "43", + "droppacket": "93", + "totalbytes": "82", + "totalpacket": "0" + }, + "UC9": { + "dropbytes": "61", + "droppacket": "91", + "totalbytes": "17", + "totalpacket": "80" + } + } +}""" + + +show_queue_counters_port_json_nz = """\ +{ + "Ethernet8": { + "ALL20": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL21": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL22": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL23": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL24": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL25": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL26": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL27": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL28": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "ALL29": { + "dropbytes": "N/A", + "droppacket": "N/A", + "totalbytes": "N/A", + "totalpacket": "N/A" + }, + "MC10": { + "dropbytes": "73", + "droppacket": "76", + "totalbytes": "63", + "totalpacket": "81" + }, + "MC11": { + "dropbytes": "66", + "droppacket": "29", + "totalbytes": "16", + "totalpacket": "29" + }, + "MC12": { + "dropbytes": "35", + "droppacket": "61", + "totalbytes": "12", + "totalpacket": "32" + }, + "MC13": { + "dropbytes": "93", + "droppacket": "72", + "totalbytes": "17", + "totalpacket": "79" + }, + "MC14": { + "dropbytes": "50", + "droppacket": "67", + "totalbytes": "21", + "totalpacket": "23" + }, + "MC15": { + "dropbytes": "14", + "droppacket": "97", + "totalbytes": "10", + "totalpacket": "37" + }, + "MC16": { + "dropbytes": "43", + "droppacket": "74", + "totalbytes": "17", + "totalpacket": "30" + }, + "MC17": { + "dropbytes": "84", + "droppacket": "54", + "totalbytes": "63", + "totalpacket": "0" + }, + "MC18": { + "dropbytes": "79", + "droppacket": "24", + "totalbytes": "88", + "totalpacket": "69" + }, + "MC19": { + "dropbytes": "3", + "droppacket": "84", + "totalbytes": "12", + "totalpacket": "20" + }, + "UC1": { + "dropbytes": "91", + "droppacket": "68", + "totalbytes": "17", + "totalpacket": "38" + }, + "UC2": { + "dropbytes": "51", + "droppacket": "79", + "totalbytes": "65", + "totalpacket": "16" + }, + "UC3": { + "dropbytes": "72", + "droppacket": "63", + "totalbytes": "97", + "totalpacket": "11" + }, + "UC4": { + "dropbytes": "62", + "droppacket": "62", + "totalbytes": "89", + "totalpacket": "54" + }, + "UC5": { "dropbytes": "59", "droppacket": "30", "totalbytes": "84", @@ -996,10 +1849,46 @@ } }""" + show_queue_voq_counters = """\ Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet0 VOQ0 68 30 56 74 +Ethernet0 VOQ0 0 0 0 0 +Ethernet0 VOQ1 60 43 39 1 +Ethernet0 VOQ2 82 7 39 21 +Ethernet0 VOQ3 11 59 12 94 +Ethernet0 VOQ4 36 62 35 40 +Ethernet0 VOQ5 49 91 2 88 +Ethernet0 VOQ6 33 17 94 74 +Ethernet0 VOQ7 40 71 95 33 + + Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ +Ethernet4 VOQ0 54 8 93 78 +Ethernet4 VOQ1 83 96 74 9 +Ethernet4 VOQ2 15 60 61 31 +Ethernet4 VOQ3 45 52 82 94 +Ethernet4 VOQ4 55 88 89 52 +Ethernet4 VOQ5 14 70 95 79 +Ethernet4 VOQ6 68 60 66 81 +Ethernet4 VOQ7 63 4 48 76 + + Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ +Ethernet8 VOQ0 41 73 77 74 +Ethernet8 VOQ1 60 21 56 54 +Ethernet8 VOQ2 57 31 12 39 +Ethernet8 VOQ3 41 96 70 98 +Ethernet8 VOQ4 18 49 63 36 +Ethernet8 VOQ5 99 90 3 15 +Ethernet8 VOQ6 8 84 82 94 +Ethernet8 VOQ7 83 15 75 92 + +""" + +show_queue_voq_counters_nz = """\ + Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ Ethernet0 VOQ1 60 43 39 1 Ethernet0 VOQ2 82 7 39 21 Ethernet0 VOQ3 11 59 12 94 @@ -1035,7 +1924,20 @@ show_queue_port_voq_counters = """\ Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes --------- ----- -------------- --------------- ----------- ------------ -Ethernet0 VOQ0 68 30 56 74 +Ethernet0 VOQ0 0 0 0 0 +Ethernet0 VOQ1 60 43 39 1 +Ethernet0 VOQ2 82 7 39 21 +Ethernet0 VOQ3 11 59 12 94 +Ethernet0 VOQ4 36 62 35 40 +Ethernet0 VOQ5 49 91 2 88 +Ethernet0 VOQ6 33 17 94 74 +Ethernet0 VOQ7 40 71 95 33 + +""" + +show_queue_port_voq_counters_nz = """\ + Port Voq Counter/pkts Counter/bytes Drop/pkts Drop/bytes +--------- ----- -------------- --------------- ----------- ------------ Ethernet0 VOQ1 60 43 39 1 Ethernet0 VOQ2 82 7 39 21 Ethernet0 VOQ3 11 59 12 94 @@ -1050,10 +1952,10 @@ { "Ethernet0": { "VOQ0": { - "dropbytes": "74", - "droppacket": "56", - "totalbytes": "30", - "totalpacket": "68" + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" }, "VOQ1": { "dropbytes": "1", @@ -1204,10 +2106,10 @@ { "Ethernet0": { "VOQ0": { - "dropbytes": "74", - "droppacket": "56", - "totalbytes": "30", - "totalpacket": "68" + "dropbytes": "0", + "droppacket": "0", + "totalbytes": "0", + "totalpacket": "0" }, "VOQ1": { "dropbytes": "1", @@ -1271,6 +2173,16 @@ def test_queue_counters(self): assert result.exit_code == 0 assert result.output == show_queue_counters + def test_queue_counters_nonzero(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["--nonzero"] + ) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_queue_counters_nz + def test_queue_counters_with_clear(self): runner = CliRunner() result = runner.invoke(clear.cli.commands['queuecounters'], []) @@ -1299,6 +2211,16 @@ def test_queue_counters_port(self): assert result.exit_code == 0 assert result.output == show_queue_counters_port + def test_queue_counters_port_nz(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["Ethernet8", "--nonzero"] + ) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_queue_counters_port_nz + def test_queue_counters_json(self): runner = CliRunner() result = runner.invoke( @@ -1312,7 +2234,22 @@ def test_queue_counters_json(self): # remove "time" from the output for _, v in json_output.items(): del v["time"] - assert json_dump(json_output) == show_queue_counters_json + assert json_dump(json_output) == show_queue_counters_json + + def test_queue_counters_json_nz(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["--json", "--nonzero"] + ) + assert result.exit_code == 0 + print(result.output) + json_output = json.loads(result.output) + + # remove "time" from the output + for _, v in json_output.items(): + del v["time"] + assert json_dump(json_output) == show_queue_counters_json_nz def test_queue_counters_port_json(self): runner = CliRunner() @@ -1327,7 +2264,22 @@ def test_queue_counters_port_json(self): # remove "time" from the output for _, v in json_output.items(): del v["time"] - assert json_dump(json_output) == show_queue_counters_port_json + assert json_dump(json_output) == show_queue_counters_port_json + + def test_queue_counters_port_json_nz(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["Ethernet8", "--json", "--nonzero"] + ) + assert result.exit_code == 0 + print(result.output) + json_output = json.loads(result.output) + + # remove "time" from the output + for _, v in json_output.items(): + del v["time"] + assert json_dump(json_output) == show_queue_counters_port_json_nz def test_queue_voq_counters(self): runner = CliRunner() @@ -1338,6 +2290,16 @@ def test_queue_voq_counters(self): print(result.output) assert result.exit_code == 0 assert result.output == show_queue_voq_counters + + def test_queue_voq_counters_nz(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["--voq", "--nonzero"] + ) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_queue_voq_counters_nz def test_queue_port_voq_counters(self): runner = CliRunner() @@ -1349,6 +2311,16 @@ def test_queue_port_voq_counters(self): assert result.exit_code == 0 assert result.output == show_queue_port_voq_counters + def test_queue_port_voq_counters_nz(self): + runner = CliRunner() + result = runner.invoke( + show.cli.commands["queue"].commands["counters"], + ["Ethernet0", "--voq", "--nonzero"] + ) + print(result.output) + assert result.exit_code == 0 + assert result.output == show_queue_port_voq_counters_nz + def test_queue_voq_counters_json(self): runner = CliRunner() result = runner.invoke(