Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions osfv_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,34 @@ unset SSH_AUTH_SOCK

You can test local changes by running `poetry shell` first. Then, all
`osfv_cli` calls will use the local files in repository, not installed package.

## Tests

OSFV CLI tests can be found in the `test` directory.
The tests are written in [Robot Framework](https://robotframework.org/),

### Dependencies

Enter development shell with test dependencies:

```shell
poetry install --with test
poetry shell
```

### Required configs

To test some functionalities related to SnipeIT, it is required to
use a configuration of a second SnipeIT user. The configuration
should be located at `~/.osfv-robot/snipeit.yaml`.
The API key and User ID must be valid, and different
from the one at `~/.osfv/snipeit.yaml`.
For details on SnipeIT configuration see [Customize the configuration](#customize-the-configuration).

### Running tests

When all the prerequisites are met, the test can be run:

```shell
robot test
```
2 changes: 1 addition & 1 deletion osfv_cli/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ robotframework = "^7.2"

[tool.poetry]
name = "osfv"
version = "0.5.14"
version = "0.6.0"
description = "Open Source Firmware Validation Command Line Interface Tool"
authors = ["Maciej Pijanowski <Maciej.Pijanowski@3mdeb.com>"]
include = ["src/models/*.yml"]
Expand Down
14 changes: 12 additions & 2 deletions osfv_cli/src/osfv/libs/snipeit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def __init__(self):
"Authorization": f"Bearer {self.cfg_api_token}",
}
self.session = self._init_session()
self.all_assets = None
self.assets_cache = {}

SNIPEIT_CONFIG_FILE_PATH = os.getenv(
"SNIPEIT_CONFIG_FILE_PATH", os.path.expanduser("~/.osfv/snipeit.yml")
Expand Down Expand Up @@ -175,6 +177,8 @@ def get_all_assets(self):
Returns:
list: A list of dictionaries, where each dictionary represents an asset.
"""
if self.all_assets is not None:
return self.all_assets
page = 1
all_assets = []

Expand All @@ -191,7 +195,9 @@ def get_all_assets(self):
else:
print(f"Error retrieving assets: {data}")
break

self.all_assets = all_assets
for asset in all_assets:
self.assets_cache[asset["id"]] = (success, asset)
return all_assets

def __retieve_custom_field_value(self, custom_fields, expected_field_name):
Expand Down Expand Up @@ -484,7 +490,11 @@ def get_asset(self, asset_id):
Returns:
success status with a response object from server.
"""
return self._request_get(f"{self.cfg_api_url}/hardware/{asset_id}")
if asset_id not in self.assets_cache:
self.assets_cache[asset_id] = self._request_get(
f"{self.cfg_api_url}/hardware/{asset_id}"
)
return self.assets_cache[asset_id]

def get_asset_model_name(self, asset_id):
"""
Expand Down
3 changes: 2 additions & 1 deletion osfv_cli/src/osfv/rf/rte_robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from osfv.libs.rte import RTE
from osfv.libs.snipeit_api import SnipeIT
from osfv.libs.sonoff_api import SonoffDevice
from robot.api.deco import keyword
from robot.api.deco import keyword, library

model_dict = {
"odroid-h4-plus": "H4-PLUS",
Expand Down Expand Up @@ -41,6 +41,7 @@
}


@library(scope="GLOBAL")
class RobotRTE:
def __init__(self, rte_ip, snipeit: bool, sonoff_ip=None, config=None):
self.rte_ip = rte_ip
Expand Down
Loading