Skip to content

Decode bytes before running string operations on the same#85

Open
rohit-mundra wants to merge 2 commits into
Mellanox:mlnx_ofedfrom
rohit-mundra:py3_tc_wrap_issue84
Open

Decode bytes before running string operations on the same#85
rohit-mundra wants to merge 2 commits into
Mellanox:mlnx_ofedfrom
rohit-mundra:py3_tc_wrap_issue84

Conversation

@rohit-mundra
Copy link
Copy Markdown

@rohit-mundra rohit-mundra commented Mar 5, 2024

Post execution of grep on vlan information for interface and when tc tool is executed get qdisc information for the device, the bytes must be converted to string to run split and regex.

resolve: #84

Copy link
Copy Markdown

@ntnx-alay ntnx-alay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. This would uncover in certain conditions where vlan is enabled. Otherwise code path is not exercised.

Copy link
Copy Markdown

@prasheshpatel prasheshpatel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change resolves #84 impacting Socket Priority to User Priority mapping for a parent PF device of the VLAN device.

@rohit-mundra rohit-mundra force-pushed the py3_tc_wrap_issue84 branch from c71b0d1 to fb4c658 Compare March 7, 2024 23:31
@tzafrir-mellanox
Copy link
Copy Markdown
Collaborator

When removing spaces, you also removed useful spaces. Please fix that.

@rohit-mundra
Copy link
Copy Markdown
Author

rohit-mundra commented Mar 20, 2024

When removing spaces, you also removed useful spaces. Please fix that.

Not able to find which space I have removed, as I have added just the decode calls to line variable.

[rohit.mundra@rohit-mundra mlnx-tools]$ git diff HEAD~2

diff --git a/python/tc_wrap.py b/python/tc_wrap.py
index b6fbe5e..54180bc 100755
--- a/python/tc_wrap.py
+++ b/python/tc_wrap.py
@@ -53,7 +53,7 @@ class skprio2up:
                                "* 2> /dev/null", shell=True, bufsize=4096,
                                stdout=PIPE).stdout
                for line in output:
-                       param, val=line.strip().split(":", 1)
+                       param, val=line.decode("utf-8").strip().split(":", 1)
                        vlan = param.split('.')[-1]
                        for item in val.split(":", 1)[1].split():
                                skprio, up = item.split(':')
@@ -150,7 +150,7 @@ class tcnum_mqprio(tcnum):

                for line in output:
                        empty=False
-                       m = re.search(r'tc (\d)', line)
+                       m = re.search(r'tc (\d)', line.decode("utf-8"))
                        if m:
                                self.tc_num = m.group(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tc_wrap.py is failing due to use of string operation on bytes object

4 participants