Skip to content

Commit 291c354

Browse files
committed
wip
Signed-off-by: Maciej Pijanowski <[email protected]>
1 parent a949b95 commit 291c354

38 files changed

+242
-56
lines changed

osfv_cli/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build:
88
poetry build
99

1010
install: build
11-
pip install dist/$(PACKAGE_NAME)-$(VERSION)-py3-none-any.whl
11+
pip install --force-reinstall dist/$(PACKAGE_NAME)-$(VERSION)-py3-none-any.whl
1212
test -f $(SNIPEIT_CONFIG_FILE) || install -D -m 644 snipeit.yml $(SNIPEIT_CONFIG_FILE)
1313
test -f $(ZABBIX_CONFIG_FILE) || install -D -m 644 zabbix.yml $(ZABBIX_CONFIG_FILE)
1414

osfv_cli/osfv_cli/rte_robot.py

-27
This file was deleted.

osfv_cli/pyproject.toml

+9-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ requires = ["poetry-core>=1.0.0"]
33
build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry.scripts]
6-
osfv_cli = "osfv_cli.osfv_cli:main"
6+
osfv_cli = "osfv.cli.cli:main"
77

88
[tool.poetry]
9-
name = "osfv_cli"
10-
version = "0.4.1"
9+
name = "osfv"
10+
version = "0.4.4"
1111
description = "Open Source Firmware Validation Command Line Interface Tool"
1212
authors = ["Maciej Pijanowski <[email protected]>"]
13-
include = ["osfv_cli/models/*.yml"]
13+
include = ["src/models/*.yml"]
1414

1515
[tool.poetry.dependencies]
1616
python = "^3.8"
@@ -21,3 +21,8 @@ requests = "^2.31.0"
2121
unidecode = "^1.3.6"
2222
importlib-resources = "^6.1.1"
2323
voluptuous = "^0.14.2"
24+
25+
# # Include your packages here
26+
# osfv_cli = {path = "./src/osfv_cli"}
27+
# osfv_libs = {path = "./src/osfv_libs"}
28+
# osfv_rf = {path = "./src/osfv_rf"}
File renamed without changes.

osfv_cli/src/osfv/__main__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
4+
if __name__ == "__main__":
5+
from osfv.osfv_cli.osfv_cli import main
6+
7+
sys.exit(main())

osfv_cli/src/osfv/cli/__init__.py

Whitespace-only changes.

osfv_cli/osfv_cli/osfv_cli.py osfv_cli/src/osfv/cli/cli.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import pexpect
99
import requests
1010

11-
from .rte import RTE
12-
from .snipeit_api import SnipeIT
13-
from .sonoff_api import SonoffDevice
14-
from .zabbix import Zabbix
11+
from osfv.libs.rte import RTE
12+
from osfv.libs.snipeit_api import SnipeIT
13+
from osfv.libs.sonoff_api import SonoffDevice
14+
from osfv.libs.zabbix import Zabbix
1515

1616

1717
# Check out an asset
@@ -155,10 +155,10 @@ def print_asset_details_for_zabbix(asset):
155155

156156
def relay_toggle(rte, args):
157157
state_str = rte.relay_get()
158-
if state_str == "low":
159-
new_state_str = "high"
158+
if state_str == "off":
159+
new_state_str = "on"
160160
else:
161-
new_state_str = "low"
161+
new_state_str = "off"
162162
rte.relay_set(new_state_str)
163163
state = rte.relay_get()
164164
print(f"Relay state toggled. New state: {state}")
@@ -466,7 +466,7 @@ def update_zabbix_assets(snipeit_api):
466466
def main():
467467
parser = argparse.ArgumentParser(description="Open Source Firmware Validation CLI")
468468
parser.add_argument(
469-
"-v", "--version", action="version", version=metadata.version("osfv_cli")
469+
"-v", "--version", action="version", version=metadata.version("osfv")
470470
)
471471

472472
parser.add_argument(
@@ -622,8 +622,8 @@ def main():
622622
set_rel_parser.add_argument(
623623
"state",
624624
choices=[
625-
"high",
626-
"low",
625+
"on",
626+
"off",
627627
],
628628
help="Relay state",
629629
)

osfv_cli/src/osfv/libs/__init__.py

Whitespace-only changes.

osfv_cli/osfv_cli/rte.py osfv_cli/src/osfv/libs/rte.py

+22-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from importlib_resources import files
77
from voluptuous import Any, Optional, Required, Schema
88

9-
from .rtectrl_api import rtectrl
10-
from .sonoff_api import SonoffDevice
9+
from osfv.libs.rtectrl_api import rtectrl
10+
from osfv.libs.sonoff_api import SonoffDevice
1111

1212

1313
class RTE(rtectrl):
@@ -38,7 +38,7 @@ def __init__(self, rte_ip, dut_model, snipeit_api):
3838
self.sonoff, self.sonoff_ip = self.init_sonoff()
3939

4040
def load_model_data(self):
41-
file_path = os.path.join(files("osfv_cli"), "models", f"{self.dut_model}.yml")
41+
file_path = os.path.join(files("osfv"), "models", f"{self.dut_model}.yml")
4242

4343
# Check if the file exists
4444
if not os.path.isfile(file_path):
@@ -125,10 +125,21 @@ def reset(self, sleep=1):
125125
time.sleep(sleep)
126126

127127
def relay_get(self):
128-
return self.gpio_get(self.GPIO_RELAY)
129-
130-
def relay_set(self, state):
131-
self.gpio_set(self.GPIO_RELAY, state)
128+
gpio_state = self.gpio_get(self.GPIO_RELAY)
129+
relay_state = None
130+
if gpio_state == 'high':
131+
relay_state = 'on'
132+
if gpio_state == 'low':
133+
relay_state = 'off'
134+
return relay_state
135+
136+
def relay_set(self, relay_state):
137+
gpio_state = None
138+
if relay_state == 'on':
139+
gpio_state = 'high'
140+
if relay_state == 'low':
141+
gpio_state = 'off'
142+
self.gpio_set(self.GPIO_RELAY, gpio_state)
132143

133144
def reset_cmos(self):
134145
self.gpio_set(self.GPIO_CMOS, "low")
@@ -163,9 +174,9 @@ def pwr_ctrl_on(self):
163174
if state != "ON":
164175
raise Exception("Failed to power control ON")
165176
elif self.dut_data["pwr_ctrl"]["relay"] is True:
166-
self.relay_set("high")
177+
self.relay_set("on")
167178
state = self.relay_get()
168-
if state != "high":
179+
if state != "on":
169180
raise Exception("Failed to power control ON")
170181
time.sleep(5)
171182

@@ -176,9 +187,9 @@ def pwr_ctrl_off(self):
176187
if state != "OFF":
177188
raise Exception("Failed to power control OFF")
178189
elif self.dut_data["pwr_ctrl"]["relay"] is True:
179-
self.relay_set("low")
190+
self.relay_set("off")
180191
state = self.relay_get()
181-
if state != "low":
192+
if state != "off":
182193
raise Exception("Failed to power control OFF")
183194
time.sleep(2)
184195

File renamed without changes.

osfv_cli/osfv_cli/snipeit_api.py osfv_cli/src/osfv/libs/snipeit_api.py

+23
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ def get_sonoff_ip_by_rte_ip(self, rte_ip):
117117
# No asset found with matching RTE IP
118118
return None
119119

120+
def get_pikvm_ip_by_rte_ip(self, rte_ip):
121+
# Retrieve all assets
122+
all_assets = self.get_all_assets()
123+
124+
# Search for asset with matching RTE IP
125+
for asset in all_assets:
126+
custom_fields = asset.get("custom_fields", {})
127+
if custom_fields:
128+
rte_ip_field = next(
129+
(
130+
field_data["value"]
131+
for field_name, field_data in custom_fields.items()
132+
if field_name == "RTE IP"
133+
),
134+
None,
135+
)
136+
if rte_ip_field == rte_ip:
137+
if custom_fields["PiKVM IP"]:
138+
return custom_fields["PiKVM IP"]["value"]
139+
140+
# No asset found with matching PiKVM IP
141+
return None
142+
120143
# Check out an asset
121144
def check_out_asset(self, asset_id):
122145
status, asset_data = self.get_asset(asset_id)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

osfv_cli/src/osfv/rf/__init__.py

Whitespace-only changes.

osfv_cli/src/osfv/rf/rte_robot.py

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import robot.api.logger
2+
from robot.api.deco import keyword
3+
from osfv.libs.rte import RTE
4+
from osfv.libs.snipeit_api import SnipeIT
5+
6+
7+
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}")
14+
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)
19+
20+
@keyword(types=None)
21+
def rte_flash_read(self, fw_file):
22+
"""Reads DUT flash chip content into ``fw_file`` path
23+
"""
24+
robot.api.logger.info(f"Reading from flash...")
25+
self.rte.flash_read(fw_file)
26+
robot.api.logger.info(f"Read flash content saved to {fw_file}")
27+
28+
@keyword(types=None)
29+
def rte_flash_write(self, fw_file):
30+
"""Writes file from ``fw_file`` path into DUT flash chip
31+
"""
32+
robot.api.logger.info(f"Writing {fw_file} to flash...")
33+
self.rte.flash_write(fw_file)
34+
robot.api.logger.info(f"Flash written")
35+
36+
@keyword(types=None)
37+
def rte_flash_probe(self):
38+
robot.api.logger.info(f"Probing flash...")
39+
self.rte.flash_probe()
40+
41+
@keyword(types=None)
42+
def rte_flash_erase(self):
43+
robot.api.logger.info(f"Erasing DUT flash...")
44+
self.rte.flash_erase()
45+
robot.api.logger.info(f"Flash erased")
46+
47+
@keyword(types=None)
48+
def rte_relay_toggle(self):
49+
state_str = self.rte.relay_get()
50+
if state_str == "low":
51+
new_state_str = "high"
52+
else:
53+
new_state_str = "low"
54+
self.rte.relay_set(new_state_str)
55+
state = self.rte.relay_get()
56+
robot.api.logger.info(f"Relay state toggled. New state: {state}")
57+
58+
@keyword(types=None)
59+
def rte_relay_set(self, state):
60+
self.rte.relay_set(state)
61+
state = self.rte.relay_get()
62+
robot.api.logger.info(f"Relay state set to {state}")
63+
return state
64+
65+
@keyword(types=None)
66+
def rte_relay_get(self):
67+
state = self.rte.relay_get()
68+
robot.api.logger.info(f"Relay state: {state}")
69+
return state
70+
71+
@keyword(types=None)
72+
def rte_power_on(self, time=1):
73+
robot.api.logger.info(f"Powering on...")
74+
self.rte.power_on(time)
75+
76+
@keyword(types=None)
77+
def rte_power_off(self, time=6):
78+
robot.api.logger.info(f"Powering off...")
79+
self.rte.power_off(time)
80+
81+
@keyword(types=None)
82+
def rte_reset(self, time=1):
83+
robot.api.logger.info(f"Pressing reset button...")
84+
self.rte.reset(time)
85+
86+
@keyword(types=None)
87+
def rte_gpio_get(self, gpio_no):
88+
state = self.rte.gpio_get(gpio_no)
89+
robot.api.logger.info(f"GPIO {gpio_no} state: {state}")
90+
return state
91+
92+
@keyword(types=None)
93+
def rte_gpio_set(self, gpio_no, state):
94+
self.rte.gpio_set(gpio_no, state)
95+
state = self.rte.gpio_get(gpio_no)
96+
robot.api.logger.info(f"GPIO {gpio_no} state set to {state}")

osfv_cli/osfv_cli/snipeit_robot.py osfv_cli/src/osfv/rf/snipeit_robot.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import robot.api.logger
2-
from snipeit_api import SnipeIT
2+
from osfv.libs.snipeit_api import SnipeIT
33

44
snipeit_api = SnipeIT()
55

6-
76
def snipeit_checkout(rte_ip):
87
asset_id = snipeit_api.get_asset_id_by_rte_ip(rte_ip)
98
success, data = snipeit_api.check_out_asset(asset_id)
@@ -15,7 +14,6 @@ def snipeit_checkout(rte_ip):
1514
f"Error checking out asset {asset_id}. Response data: {data}"
1615
)
1716

18-
1917
def snipeit_checkin(rte_ip):
2018
asset_id = snipeit_api.get_asset_id_by_rte_ip(rte_ip)
2119
success, data = snipeit_api.check_in_asset(asset_id)
@@ -26,3 +24,20 @@ def snipeit_checkin(rte_ip):
2624
raise AssertionError(
2725
f"Error checking in asset {asset_id}. Response data: {data}"
2826
)
27+
28+
def snipeit_get_sonoff_ip(rte_ip):
29+
return snipeit_api.get_sonoff_ip_by_rte_ip(rte_ip)
30+
31+
def snipeit_get_pikvm_ip(rte_ip):
32+
return snipeit_api.get_pikvm_ip_by_rte_ip(rte_ip)
33+
34+
def snipeit_get_asset_model(rte_ip):
35+
asset_id = snipeit_api.get_asset_id_by_rte_ip(rte_ip)
36+
success, data = snipeit_api.get_asset_model_name(asset_id)
37+
if success:
38+
robot.api.logger.info(f"Asset {asset_id} model is: {data} in.")
39+
return data
40+
else:
41+
raise AssertionError(
42+
f"Error getting model name of asset: {asset_id}. Response data: {data}"
43+
)

0 commit comments

Comments
 (0)