Skip to content

Commit 226b006

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

File tree

2 files changed

+62
-21
lines changed

2 files changed

+62
-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

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

2057
@keyword(types=None)
2158
def rte_flash_read(self, fw_file):
@@ -37,7 +74,7 @@ def rte_flash_write(self, fw_file):
3774
def rte_flash_probe(self):
3875
robot.api.logger.info(f"Probing flash...")
3976
self.rte.flash_probe()
40-
77+
4178
@keyword(types=None)
4279
def rte_flash_erase(self):
4380
robot.api.logger.info(f"Erasing DUT flash...")
@@ -54,14 +91,14 @@ def rte_relay_toggle(self):
5491
self.rte.relay_set(new_state_str)
5592
state = self.rte.relay_get()
5693
robot.api.logger.info(f"Relay state toggled. New state: {state}")
57-
94+
5895
@keyword(types=None)
5996
def rte_relay_set(self, state):
6097
self.rte.relay_set(state)
6198
state = self.rte.relay_get()
6299
robot.api.logger.info(f"Relay state set to {state}")
63100
return state
64-
101+
65102
@keyword(types=None)
66103
def rte_relay_get(self):
67104
state = self.rte.relay_get()
@@ -72,23 +109,23 @@ def rte_relay_get(self):
72109
def rte_power_on(self, time=1):
73110
robot.api.logger.info(f"Powering on...")
74111
self.rte.power_on(time)
75-
112+
76113
@keyword(types=None)
77114
def rte_power_off(self, time=6):
78115
robot.api.logger.info(f"Powering off...")
79116
self.rte.power_off(time)
80-
117+
81118
@keyword(types=None)
82119
def rte_reset(self, time=1):
83120
robot.api.logger.info(f"Pressing reset button...")
84121
self.rte.reset(time)
85-
122+
86123
@keyword(types=None)
87124
def rte_gpio_get(self, gpio_no):
88125
state = self.rte.gpio_get(int(gpio_no))
89126
robot.api.logger.info(f"GPIO {gpio_no} state: {state}")
90127
return state
91-
128+
92129
@keyword(types=None)
93130
def rte_gpio_set(self, gpio_no, state):
94131
self.rte.gpio_set(int(gpio_no), state)

0 commit comments

Comments
 (0)