Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_drop_counters.py exits with error "Failed to parse output of 'portstat -j -n {}' #13780

Closed
kartik-arista opened this issue Feb 10, 2023 · 5 comments
Assignees
Labels
Triaged this issue has been triaged

Comments

@kartik-arista
Copy link

Steps to reproduce the issue:

run test_drop_counters.py

This should fail on any platform.

Additional information you deem important:

    def get_pkt_drops(duthost, cli_cmd, asic_index):
        """
        @summary: Parse output of "portstat" or "intfstat" commands and convert it to the dictionary.
        @param module: The AnsibleModule object
        @param cli_cmd: one of supported CLI commands - "portstat -j" or "intfstat -j"
        @return: Return dictionary of parsed counters
        """
        # Get namespace from asic_index.
        namespace = duthost.get_namespace_from_asic_id(asic_index)

        # Frame the correct cli command
        # the L2 commands need _SUFFIX and L3 commands need _PREFIX
        if cli_cmd == GET_L3_COUNTERS:
            CMD_PREFIX = NAMESPACE_PREFIX if (namespace is not None and duthost.is_multi_asic) else ''
            cli_cmd = CMD_PREFIX + cli_cmd
        elif cli_cmd == GET_L2_COUNTERS:
            CMD_SUFFIX = NAMESPACE_SUFFIX if (namespace is not None and duthost.is_multi_asic) else ''
            cli_cmd = cli_cmd + CMD_SUFFIX

        stdout = duthost.command(cli_cmd.format(namespace))
        stdout = stdout["stdout"]
        match = re.search("Last cached time was.*\n", stdout)
        if match:
            stdout = re.sub("Last cached time was.*\n", "", stdout)

        try:
            return json.loads(stdout)
        except Exception as err:
>           raise Exception("Failed to parse output of '{}', err={}".format(cli_cmd, str(err)))
E           Exception: Failed to parse output of 'portstat -j -n {} ', err=Extra data: line 274 column 1 - line 274 column 84 (char 6315 - 6398)

is the relevant code block.

Running the command on a device:

sudo portstat -j -n asic0
{
    "Ethernet0": {
        "RX_BPS": "1.52 B/s",
        "RX_DRP": "2",
        "RX_ERR": "0",
        "RX_OK": "77",
...

}

**Reminder: Please execute 'show interface counters -d all' to include internal links**

The above string is the issue because it is not properly parseable in JSON.

This change appears to have been introduced with

sonic-net/sonic-utilities#2466

@kartik-arista
Copy link
Author

@wenyiz2021 for viz.

@wenyiz2021
Copy link
Contributor

CLI change here: sonic-net/sonic-utilities#2670

@wenyiz2021 wenyiz2021 self-assigned this Feb 10, 2023
@rlhui
Copy link
Contributor

rlhui commented Feb 11, 2023

Thanks @kartik-arista , then the issue shoudl be open against sonic-buildimage then?

@rlhui rlhui transferred this issue from sonic-net/sonic-mgmt Feb 11, 2023
@rlhui rlhui added the Triaged this issue has been triaged label Feb 11, 2023
@kartik-arista
Copy link
Author

Hi Rita, I initiall

Thanks @kartik-arista , then the issue shoudl be open against sonic-buildimage then?

I initially filed under sonic-mgmt because I wasn't sure if the change needed to be made in sonic-mgmt to adjust for the new output or fixing the original CLI.

@wenyiz2021
Copy link
Contributor

closing as PR sonic-net/sonic-utilities#2670 merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Triaged this issue has been triaged
Projects
Status: Done
Development

No branches or pull requests

3 participants