-
Notifications
You must be signed in to change notification settings - Fork 111
Some changes to enable proto/ptf test to pass on system using Python3 #543
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
f988cfd
7391c5a
4ec8fe9
57f5ae6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/bin/env python | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Copyright 2013-present Barefoot Networks, Inc. | ||
| # | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/bin/env python | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Copyright 2013-present Barefoot Networks, Inc. | ||
| # | ||
|
|
@@ -53,7 +53,7 @@ def check_ifaces(ifaces): | |
| ''' | ||
| Checks that required interfaces exist. | ||
| ''' | ||
| ip_out = subprocess.check_output(['ip', 'link']) | ||
| ip_out = subprocess.check_output(['ip', 'link'], text=True) | ||
| # 'ip link' returns a list of interfaces as | ||
| # <idx>: <iface>: ... | ||
| # <idx>: <veth>@<peer veth>: ... | ||
|
|
@@ -105,7 +105,7 @@ def run_test(config_path, p4info_path, grpc_addr, device_id, | |
| iface_name = entry["iface_name"] | ||
| port_map[p4_port] = iface_name | ||
|
|
||
| if not check_ifaces(port_map.values()): | ||
| if not check_ifaces(list(port_map.values())): | ||
| error("Some interfaces are missing") | ||
| return False | ||
|
|
||
|
|
@@ -117,7 +117,7 @@ def run_test(config_path, p4info_path, grpc_addr, device_id, | |
| os.environ['PYTHONPATH'] += ":" + pypath | ||
| else: | ||
| os.environ['PYTHONPATH'] = pypath | ||
| for iface_idx, iface_name in port_map.items(): | ||
| for iface_idx, iface_name in list(port_map.items()): | ||
|
||
| ifaces.extend(['-i', '{}@{}'.format(iface_idx, iface_name)]) | ||
| cmd = ['ptf'] | ||
| cmd.extend(['--test-dir', ptfdir]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As indicated in the comment, this code was equivalent to the
int.to_bytesPython3 function, so I think we should just use that (and forget about Python2 support)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My 2nd commit has another variation of stringify() for your consideration. It doesn't behave exactly as int.to_bytes does alone, because I believe the Python2 version would take a parameter n that did not fit into the given number of bytes, and return a longer string with no exception. int.to_bytes would throw an exception in that scenario.