Skip to content

Commit be3427e

Browse files
Some code refactoring (#274)
* Remove debug print statement in SaiDpu.__init__ * Use context manager for file operations in SaiPhy.init * Use context managers for file operations in SaiNpu and SaiTestbedMeta * Sort import statements alphabetically in sai_testbed.py * Fix grammar in README.md --------- Signed-off-by: Andriy Kokhan <[email protected]>
1 parent c9d1631 commit be3427e

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ See [Use-Cases README](usecases/README.md) for more details.
4949

5050
## Porting SAI Challenger to new platform
5151

52-
For more information on how port SAI Challenger to new platform, please refer to [Porting Guide](docs/porting_guide.md) document.
52+
For more information on how to port SAI Challenger to new platform, please refer to [Porting Guide](docs/porting_guide.md) document.
5353

5454
## SAI Challenger internals
5555

common/sai_dpu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class SaiDpu(Sai):
1414
def __init__(self, cfg):
1515
cfg["client"]["config"]["asic_type"] = "dpu"
1616
super().__init__(cfg)
17-
print("__INIT__")
1817
self.switch_oid = "oid:0x0"
1918
self.dot1q_br_oid = "oid:0x0"
2019
self.default_vlan_oid = "oid:0x0"

common/sai_npu.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ def init(self, attr):
3737
# Load SKU configuration if any
3838
if self.sku is not None:
3939
try:
40-
f = open(f"{self.asic_dir}/{self.target}/sku/{self.sku}.json")
41-
self.sku_config = json.load(f)
42-
f.close()
40+
with open(f"{self.asic_dir}/{self.target}/sku/{self.sku}.json") as f:
41+
self.sku_config = json.load(f)
4342
except Exception as e:
4443
assert False, f"{e}"
4544

common/sai_phy.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ def init(self, attr):
2323
# Load SKU configuration if any
2424
if self.sku is not None:
2525
try:
26-
f = open(f"{self.asic_dir}/{self.target}/sku/{self.sku}.json")
27-
self.sku_config = json.load(f)
28-
f.close()
26+
with open(f"{self.asic_dir}/{self.target}/sku/{self.sku}.json") as f:
27+
self.sku_config = json.load(f)
2928
except Exception as e:
3029
assert False, f"{e}"
3130

common/sai_testbed.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import glob
12
import importlib
2-
import os
33
import json
4-
import glob
54
import logging
5+
import os
66
import sys
77

88
from saichallenger.common.sai_dut import SaiDut
@@ -24,9 +24,8 @@ def __init__(self, base_dir, name):
2424
self.base_dir = base_dir
2525
try:
2626
testbed_file = name if name.endswith(".json") else f"{base_dir}/testbeds/{name}.json"
27-
f = open(testbed_file)
28-
self.config = json.load(f)
29-
f.close()
27+
with open(testbed_file) as f:
28+
self.config = json.load(f)
3029
except Exception as e:
3130
assert False, f"{e}"
3231

@@ -94,9 +93,8 @@ def get_sku_config(self, alias, asic_type="npu"):
9493
asic_dir = self.get_asic_dir(self.base_dir, cfg["asic"], asic_type)
9594
try:
9695
target = cfg.get("target")
97-
f = open(f"{asic_dir}/{target}/sku/{sku}.json")
98-
sku = json.load(f)
99-
f.close()
96+
with open(f"{asic_dir}/{target}/sku/{sku}.json") as f:
97+
sku = json.load(f)
10098
except Exception as e:
10199
assert False, f"{e}"
102100
return sku

0 commit comments

Comments
 (0)