Skip to content

Commit 623e8ff

Browse files
committed
osfv_cli: Allow not using snipeit
Signed-off-by: Pawel Langowski <[email protected]>
1 parent 7585f4d commit 623e8ff

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

osfv_cli/src/osfv/libs/rte.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class RTE(rtectrl):
3030
PROGRAMMER_CH341A = "ch341a_spi"
3131
FLASHROM_CMD = "flashrom -p {programmer} {args}"
3232

33-
def __init__(self, rte_ip, dut_model, snipeit_api):
33+
def __init__(self, rte_ip, dut_model, snipeit_api=None, sonoff_ip= None):
3434
self.rte_ip = rte_ip
3535
self.dut_model = dut_model
3636
self.dut_data = self.load_model_data()
3737
self.snipeit_api = snipeit_api
38-
self.sonoff, self.sonoff_ip = self.init_sonoff()
38+
self.sonoff, self.sonoff_ip = self.init_sonoff(sonoff_ip)
3939

4040
def load_model_data(self):
4141
file_path = os.path.join(files("osfv"), "models", f"{self.dut_model}.yml")
@@ -98,11 +98,15 @@ def load_model_data(self):
9898
# Return the loaded data
9999
return data
100100

101-
def init_sonoff(self):
101+
def init_sonoff(self, init_sonoff_ip):
102102
sonoff_ip = ""
103103
sonoff = None
104104

105105
if self.dut_data["pwr_ctrl"]["sonoff"] is True:
106+
if not self.snipeit_api:
107+
if not init_sonoff_ip:
108+
raise TypeError(f"Expected a value for 'sonoff_ip', but got {init_sonoff_ip}")
109+
return SonoffDevice(init_sonoff_ip), init_sonoff_ip
106110
sonoff_ip = self.snipeit_api.get_sonoff_ip_by_rte_ip(self.rte_ip)
107111
if not sonoff_ip:
108112
raise SonoffNotFound(

osfv_cli/src/osfv/rf/rte_robot.py

+54-18
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,57 @@
11
import robot.api.logger
22
from robot.api.deco import keyword
3-
from osfv.libs.rte import RTE
3+
from osfv.libs.rte import RTE, UnsupportedDUTModel
44
from osfv.libs.snipeit_api import SnipeIT
55

66

7+
model_dict = {
8+
"minnowboard_turbot": "MinnowBoard Turbot B41",
9+
"msi-pro-z690-a-ddr4": "MSI PRO Z690-A DDR4",
10+
"msi-pro-z690-a-ddr5": "MSI PRO Z690-A DDR5",
11+
"pcengines-apu2": "APU2",
12+
"pcengines-apu3": "APU3",
13+
"pcengines-apu4": "APU4",
14+
"pcengines-apu6": "APU6",
15+
"protectli-v1210": "V1210",
16+
"protectli-v1410": "V1410",
17+
"protectli-v1610": "V1610",
18+
"protectli-vp2410": "VP2410",
19+
"protectli-vp2420": "VP2420",
20+
"protectli-vp4630": "VP4630",
21+
"protectli-vp4650": "VP4650",
22+
"protectli-vp4670": "VP4670",
23+
"protectli-vp6650": "VP6650",
24+
"protectli-vp6670": "VP6670"
25+
}
26+
27+
728
class RobotRTE:
8-
def __init__(self, rte_ip):
9-
snipeit_api = SnipeIT()
10-
asset_id = snipeit_api.get_asset_id_by_rte_ip(rte_ip)
11-
status, dut_model_name = snipeit_api.get_asset_model_name(asset_id)
12-
if status:
13-
robot.api.logger.info(f"DUT model retrieved from snipeit: {dut_model_name}")
29+
def __init__(self, rte_ip, snipeit: bool, sonoff_ip=None, config=None):
30+
if snipeit:
31+
snipeit_api = SnipeIT()
32+
asset_id = snipeit_api.get_asset_id_by_rte_ip(rte_ip)
33+
status, dut_model_name = snipeit_api.get_asset_model_name(asset_id)
34+
if status:
35+
robot.api.logger.info(
36+
f"DUT model retrieved from snipeit: {dut_model_name}")
37+
else:
38+
raise AssertionError(
39+
f"Failed to retrieve model name from Snipe-IT. Check again arguments, or try providing model manually."
40+
)
41+
self.rte = RTE(rte_ip, dut_model_name, snipeit_api)
1442
else:
15-
raise AssertionError(
16-
f"Failed to retrieve model name from Snipe-IT. Check again arguments, or try providing model manually."
17-
)
18-
self.rte = RTE(rte_ip, dut_model_name, snipeit_api)
43+
self.rte = RTE(rte_ip, self.cli_model_from_osfv(config), sonoff_ip=sonoff_ip)
44+
45+
def cli_model_from_osfv(self, osfv_model):
46+
"""
47+
Get osfv_cli model name from OSFV repo config name
48+
"""
49+
if not osfv_model:
50+
raise TypeError(f"Expected a value for 'config', but got {osfv_model}")
51+
cli_model = model_dict.get(osfv_model)
52+
if not cli_model:
53+
raise UnsupportedDUTModel(f"The {osfv_model} model has no counterpart in osfv_cli")
54+
return cli_model
1955

2056
@keyword(types=None)
2157
def rte_flash_read(self, fw_file):
@@ -37,7 +73,7 @@ def rte_flash_write(self, fw_file):
3773
def rte_flash_probe(self):
3874
robot.api.logger.info(f"Probing flash...")
3975
self.rte.flash_probe()
40-
76+
4177
@keyword(types=None)
4278
def rte_flash_erase(self):
4379
robot.api.logger.info(f"Erasing DUT flash...")
@@ -54,14 +90,14 @@ def rte_relay_toggle(self):
5490
self.rte.relay_set(new_state_str)
5591
state = self.rte.relay_get()
5692
robot.api.logger.info(f"Relay state toggled. New state: {state}")
57-
93+
5894
@keyword(types=None)
5995
def rte_relay_set(self, state):
6096
self.rte.relay_set(state)
6197
state = self.rte.relay_get()
6298
robot.api.logger.info(f"Relay state set to {state}")
6399
return state
64-
100+
65101
@keyword(types=None)
66102
def rte_relay_get(self):
67103
state = self.rte.relay_get()
@@ -72,23 +108,23 @@ def rte_relay_get(self):
72108
def rte_power_on(self, time=1):
73109
robot.api.logger.info(f"Powering on...")
74110
self.rte.power_on(time)
75-
111+
76112
@keyword(types=None)
77113
def rte_power_off(self, time=6):
78114
robot.api.logger.info(f"Powering off...")
79115
self.rte.power_off(time)
80-
116+
81117
@keyword(types=None)
82118
def rte_reset(self, time=1):
83119
robot.api.logger.info(f"Pressing reset button...")
84120
self.rte.reset(time)
85-
121+
86122
@keyword(types=None)
87123
def rte_gpio_get(self, gpio_no):
88124
state = self.rte.gpio_get(int(gpio_no))
89125
robot.api.logger.info(f"GPIO {gpio_no} state: {state}")
90126
return state
91-
127+
92128
@keyword(types=None)
93129
def rte_gpio_set(self, gpio_no, state):
94130
self.rte.gpio_set(int(gpio_no), state)

0 commit comments

Comments
 (0)