Skip to content

Commit 30a2281

Browse files
authoredFeb 7, 2023
[pre-commit] Fix style issues in test scripts under tests/common folder (sonic-net#7360)
* [pre-commit] Fix style issues in test scripts under `tests/common` folder What is the motivation for this PR? pre-commit is a static analysis tool introduced recently. This tool is not able to do diff-only check. It checks the whole files touched by PR. We can't blame PR author for legacy issues. That's why currently the pre-commit check is only optional. To ensure that we can make pre-commit a mandatory check for PRs submitted to this repository, we need to fix all the legacy issues complained by pre-commit. How did you do it? This change fixes the style issues of test scripts under `tests/common` folder How did you verify/test it? Any platform specific information? Supported testbed topology if it's a new test case?
1 parent e037194 commit 30a2281

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+462
-393
lines changed
 

‎tests/common/cisco_data.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import json
2+
import re
23
from tests.common.reboot import reboot
34

5+
46
def is_cisco_device(dut):
57
return dut.facts["asic_type"] == "cisco-8000"
68

9+
710
def get_markings_config_file(duthost):
811
"""
912
Get the config file where the ECN markings are enabled or disabled.
@@ -13,31 +16,32 @@ def get_markings_config_file(duthost):
1316
raise RuntimeError("This is applicable only to cisco platforms.")
1417

1518
hwsku = duthost.facts['hwsku']
16-
match = re.search("\-([^-_]+)_", platform)
19+
match = re.search(r"\-([^-_]+)_", platform)
1720
if match:
18-
model = match.group(1)
21+
model = match.group(1)
1922
else:
20-
raise RuntimeError("Couldn't get the model from platform:{}".format(platform))
23+
raise RuntimeError("Couldn't get the model from platform:{}".format(platform))
2124
config_file = "/usr/share/sonic/device/{}/{}/{}.json".format(platform, hwsku, model)
2225
return config_file
2326

27+
2428
def get_markings_dut(duthost, key_list=['ecn_dequeue_marking', 'ecn_latency_marking', 'voq_allocation_mode']):
2529
"""
2630
Get the ecn marking values from the duthost.
2731
"""
2832
config_file = get_markings_config_file(duthost)
2933
dest_file = "/tmp/"
30-
contents = duthost.fetch(src=config_file, dest = dest_file)
34+
contents = duthost.fetch(src=config_file, dest=dest_file)
3135
local_file = contents['dest']
3236
with open(local_file) as fd:
3337
json_contents = json.load(fd)
3438
required_entry = None
3539
for i in range(len(json_contents['devices'])):
3640
try:
37-
json_contents['devices'][i].get('id')
38-
required_entry = i
41+
json_contents['devices'][i].get('id')
42+
required_entry = i
3943
except KeyError:
40-
continue
44+
continue
4145

4246
if required_entry is None:
4347
raise RuntimeError("Couldnot find the required entry(id) in the config file:{}".format(config_file))
@@ -46,29 +50,30 @@ def get_markings_dut(duthost, key_list=['ecn_dequeue_marking', 'ecn_latency_mark
4650
original_values[key] = json_contents['devices'][i][key]
4751
return original_values
4852

53+
4954
def setup_markings_dut(duthost, localhost, **kwargs):
5055
"""
5156
Setup dequeue or latency depending on arguments.
5257
Applicable to cisco-8000 Platforms only.
5358
"""
5459
config_file = get_markings_config_file(duthost)
5560
dest_file = "/tmp/"
56-
contents = duthost.fetch(src=config_file, dest = dest_file)
61+
contents = duthost.fetch(src=config_file, dest=dest_file)
5762
local_file = contents['dest']
5863
with open(local_file) as fd:
5964
json_contents = json.load(fd)
6065
required_entry = None
6166
for i in range(len(json_contents['devices'])):
6267
try:
63-
json_contents['devices'][i].get('id')
64-
required_entry = i
68+
json_contents['devices'][i].get('id')
69+
required_entry = i
6570
except KeyError:
66-
continue
71+
continue
6772

6873
if required_entry is None:
6974
raise RuntimeError("Couldnot find the required entry(id) in the config file:{}".format(config_file))
7075
reboot_required = False
71-
for k,v in kwargs.iteritems():
76+
for k, v in kwargs.iteritems():
7277
if json_contents['devices'][required_entry][k] != v:
7378
reboot_required = True
7479
json_contents['devices'][required_entry][k] = v

‎tests/common/errors.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def __init__(self, msg, results=None):
2626
self.results = results
2727

2828
def _to_string(self):
29-
return "{}, Ansible Results =>\n{}".format(self.message, dump_ansible_results(self.results)).encode().decode("utf-8")
29+
return "{}, Ansible Results =>\n{}".format(self.message,
30+
dump_ansible_results(self.results)).encode().decode("utf-8")
3031

3132
def __str__(self):
3233
return self._to_string()

0 commit comments

Comments
 (0)