jetstan-ev-software 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/PKG-INFO +1 -1
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/PKG-INFO +1 -1
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/SOURCES.txt +4 -1
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/pyproject.toml +1 -1
- jetstan_ev_software-0.0.2/software/handlers.py +75 -0
- jetstan_ev_software-0.0.2/software/updater.py +87 -0
- jetstan_ev_software-0.0.2/tests/test_handlers.py +103 -0
- jetstan_ev_software-0.0.2/tests/test_updater.py +73 -0
- jetstan_ev_software-0.0.1/software/handlers.py +0 -28
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/dependency_links.txt +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/requires.txt +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/top_level.txt +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/setup.cfg +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/compiler.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/config.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/discovery.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/exceptions.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/firmware.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/flasher.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/sample_firmware/README.md +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/sample_firmware/motor_test/motor_test.ino +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/state_store.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/verifier.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/deployment/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/deployment/dag.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/deployment/dependencies.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/deployment/pipeline.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/frontend/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/frontend/index.html +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/gen_sample/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/gen_sample/simulator.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/logic/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/logic/calculations.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/sensors/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/sensors/motor_control.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/sensors/serial_telemetry.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/sensors/telemetry_store.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/api.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/config.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/exceptions.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/features.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/model.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/predictor.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/schemas.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/service.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/soc_dashboard.html +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/telemetry.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/soc/xgboost_soc.onnx +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/test/README.md +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/test/__init__.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/test/jetstan-dashboard.service +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/test/server.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_compiler.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_config.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_discovery.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_exceptions.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_firmware.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_flasher.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_sync.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_arduino_verifier.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_deployment_dag.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_deployment_dependencies.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_deployment_pipeline.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_deployment_run.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_gen_sample.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_logic.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_motor_control.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_serial_telemetry.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_api.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_config.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_features.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_model.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_predictor.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_service.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_soc_telemetry.py +0 -0
- {jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_telemetry_store.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jetstan_ev_software
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Jetstan vehicle software - the OTA-deployable application payload that runs on the vehicle's Raspberry Pi (import package: software).
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Requires-Dist: python-dotenv==1.2.2
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: jetstan_ev_software
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Jetstan vehicle software - the OTA-deployable application payload that runs on the vehicle's Raspberry Pi (import package: software).
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Requires-Dist: python-dotenv==1.2.2
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/SOURCES.txt
RENAMED
|
@@ -6,6 +6,7 @@ jetstan_ev_software.egg-info/requires.txt
|
|
|
6
6
|
jetstan_ev_software.egg-info/top_level.txt
|
|
7
7
|
software/__init__.py
|
|
8
8
|
software/handlers.py
|
|
9
|
+
software/updater.py
|
|
9
10
|
software/arduino_updates/__init__.py
|
|
10
11
|
software/arduino_updates/compiler.py
|
|
11
12
|
software/arduino_updates/config.py
|
|
@@ -60,6 +61,7 @@ tests/test_deployment_dependencies.py
|
|
|
60
61
|
tests/test_deployment_pipeline.py
|
|
61
62
|
tests/test_deployment_run.py
|
|
62
63
|
tests/test_gen_sample.py
|
|
64
|
+
tests/test_handlers.py
|
|
63
65
|
tests/test_logic.py
|
|
64
66
|
tests/test_motor_control.py
|
|
65
67
|
tests/test_serial_telemetry.py
|
|
@@ -70,4 +72,5 @@ tests/test_soc_model.py
|
|
|
70
72
|
tests/test_soc_predictor.py
|
|
71
73
|
tests/test_soc_service.py
|
|
72
74
|
tests/test_soc_telemetry.py
|
|
73
|
-
tests/test_telemetry_store.py
|
|
75
|
+
tests/test_telemetry_store.py
|
|
76
|
+
tests/test_updater.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jetstan_ev_software"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.2"
|
|
8
8
|
description = "Jetstan vehicle software - the OTA-deployable application payload that runs on the vehicle's Raspberry Pi (import package: software)."
|
|
9
9
|
requires-python = ">=3.11"
|
|
10
10
|
dependencies = [
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""Your application's own MQTT command handlers.
|
|
2
|
+
|
|
3
|
+
``jetstan_agent.message_router`` automatically picks up ``CUSTOM_HANDLERS``
|
|
4
|
+
from this file and merges it in alongside its built-in commands
|
|
5
|
+
(hello/restart/heartbeat/ota.available) — no changes to ``jetstan_agent``
|
|
6
|
+
needed. Add a function per command, then list it below.
|
|
7
|
+
|
|
8
|
+
Example: sending {"type": "example.ping"} over MQTT will call
|
|
9
|
+
_handle_example_ping and log "Pong from /software!".
|
|
10
|
+
|
|
11
|
+
``software.available`` is the vehicle-software counterpart to
|
|
12
|
+
jetstan_agent's own built-in ``ota.available`` - published by
|
|
13
|
+
cloud-logics's ``POST /deploy`` (see
|
|
14
|
+
``cloud_logics/deployment_engine/adapters/mqtt_deployment_publisher.py``),
|
|
15
|
+
never by the agent's own release/self-update path. Handled entirely
|
|
16
|
+
here, not in ``jetstan_agent``, so the agent never needs to know
|
|
17
|
+
``jetstan_ev_software`` exists.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import logging
|
|
23
|
+
import threading
|
|
24
|
+
from typing import Any, Callable
|
|
25
|
+
|
|
26
|
+
from software import updater
|
|
27
|
+
from software.deployment import run_deployment_dag
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
CommandHandler = Callable[[dict[str, Any]], None]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _handle_example_ping(command: dict[str, Any]) -> None:
|
|
35
|
+
logger.info("Pong from /software!")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _handle_software_available(command: dict[str, Any]) -> None:
|
|
39
|
+
logger.info("Vehicle software update available")
|
|
40
|
+
target_version = command.get("version")
|
|
41
|
+
logger.info("Version: %s", target_version)
|
|
42
|
+
|
|
43
|
+
# apply_update() can take a while (pip install, possibly retried by
|
|
44
|
+
# the caller); running it on its own thread keeps the MQTT network
|
|
45
|
+
# loop (and its keepalive) unaffected while that plays out - same
|
|
46
|
+
# reasoning as jetstan_agent/message_router.py's own
|
|
47
|
+
# _handle_ota_available.
|
|
48
|
+
threading.Thread(
|
|
49
|
+
target=_apply_update_and_activate, args=(target_version,), daemon=True
|
|
50
|
+
).start()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _apply_update_and_activate(target_version: str | None) -> None:
|
|
54
|
+
if not updater.apply_update(target_version):
|
|
55
|
+
return
|
|
56
|
+
|
|
57
|
+
# Reuse the existing deployment DAG as "activation" - the same one
|
|
58
|
+
# jetstan_agent/cli.py already runs after every OTA-triggered restart
|
|
59
|
+
# (see software/deployment/pipeline.py). Never raises (run_deployment_dag's
|
|
60
|
+
# own contract); a failed activation is reported, not crashed on.
|
|
61
|
+
result = run_deployment_dag()
|
|
62
|
+
if result.all_succeeded:
|
|
63
|
+
logger.info("Vehicle software %s installed and activated.", target_version)
|
|
64
|
+
else:
|
|
65
|
+
logger.warning(
|
|
66
|
+
"Vehicle software %s installed, but activation reported failures: %s",
|
|
67
|
+
target_version,
|
|
68
|
+
[o for o in result.outcomes if o.status != "success"],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
CUSTOM_HANDLERS: dict[str, CommandHandler] = {
|
|
73
|
+
"example.ping": _handle_example_ping,
|
|
74
|
+
"software.available": _handle_software_available,
|
|
75
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Self-update: pull a new vehicle-software release from PyPI.
|
|
2
|
+
|
|
3
|
+
Mirrors ``jetstan_agent/updater.py``'s own pip-based upgrade pattern
|
|
4
|
+
(same ``--no-deps`` reasoning: a push must only ever change this
|
|
5
|
+
package's own code, never silently re-resolve numpy/onnxruntime/fastapi
|
|
6
|
+
on every push) - but scoped to ``jetstan_ev_software``, entirely
|
|
7
|
+
independent of jetstan-agent's own version and update cycle. Deliberately
|
|
8
|
+
no restart/rollback marker here: unlike jetstan_agent (which replaces its
|
|
9
|
+
own running process and must recover from a release that breaks at
|
|
10
|
+
import time), vehicle software has no long-running process of its own to
|
|
11
|
+
restart into - the existing deployment DAG
|
|
12
|
+
(``software/deployment/pipeline.py``, via ``run_deployment_dag()``) is
|
|
13
|
+
what "activates" a freshly installed version, run immediately after a
|
|
14
|
+
successful install (see ``handlers.py``'s ``_handle_software_available``).
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import logging
|
|
20
|
+
import subprocess
|
|
21
|
+
import sys
|
|
22
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
23
|
+
|
|
24
|
+
logger = logging.getLogger(__name__)
|
|
25
|
+
|
|
26
|
+
_PACKAGE_NAME = "jetstan_ev_software"
|
|
27
|
+
_PIP_TIMEOUT_SECONDS = 300
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def current_version() -> str | None:
|
|
31
|
+
"""Return the installed jetstan_ev_software version, or None if it can't be found."""
|
|
32
|
+
try:
|
|
33
|
+
return version(_PACKAGE_NAME)
|
|
34
|
+
except PackageNotFoundError:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def apply_update(target_version: str | None) -> bool:
|
|
39
|
+
"""Install ``target_version`` via pip. Returns True if an install actually ran and succeeded.
|
|
40
|
+
|
|
41
|
+
Idempotent against retained/duplicate MQTT messages: a no-op if the
|
|
42
|
+
requested version is already installed - same contract as
|
|
43
|
+
``jetstan_agent.updater.apply_update``, for the same reason.
|
|
44
|
+
"""
|
|
45
|
+
installed = current_version()
|
|
46
|
+
if target_version and target_version == installed:
|
|
47
|
+
logger.info("jetstan_ev_software already at %s; nothing to do.", target_version)
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
package_spec = f"{_PACKAGE_NAME}=={target_version}" if target_version else _PACKAGE_NAME
|
|
51
|
+
logger.info("Installing %s (currently %s)...", package_spec, installed)
|
|
52
|
+
return _run_pip_install(package_spec)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _run_pip_install(package_spec: str) -> bool:
|
|
56
|
+
"""Run a single pip install attempt. Returns True on success.
|
|
57
|
+
|
|
58
|
+
``--no-deps``: see this module's own docstring.
|
|
59
|
+
"""
|
|
60
|
+
command = [
|
|
61
|
+
sys.executable,
|
|
62
|
+
"-m",
|
|
63
|
+
"pip",
|
|
64
|
+
"install",
|
|
65
|
+
"--no-input",
|
|
66
|
+
"--no-deps",
|
|
67
|
+
"--upgrade",
|
|
68
|
+
package_spec,
|
|
69
|
+
]
|
|
70
|
+
try:
|
|
71
|
+
result = subprocess.run(
|
|
72
|
+
command,
|
|
73
|
+
capture_output=True,
|
|
74
|
+
text=True,
|
|
75
|
+
timeout=_PIP_TIMEOUT_SECONDS,
|
|
76
|
+
check=False,
|
|
77
|
+
)
|
|
78
|
+
except subprocess.TimeoutExpired:
|
|
79
|
+
logger.error("Install attempt timed out after %ds.", _PIP_TIMEOUT_SECONDS)
|
|
80
|
+
return False
|
|
81
|
+
|
|
82
|
+
logger.debug("pip stdout: %s", result.stdout)
|
|
83
|
+
if result.returncode != 0:
|
|
84
|
+
logger.error("pip failed (exit %d): %s", result.returncode, result.stderr)
|
|
85
|
+
return False
|
|
86
|
+
|
|
87
|
+
return True
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""Tests for software.handlers - the software.available update path."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
from software.deployment.dag import DagResult, TaskOutcome
|
|
8
|
+
from software.handlers import (
|
|
9
|
+
CUSTOM_HANDLERS,
|
|
10
|
+
_apply_update_and_activate,
|
|
11
|
+
_handle_software_available,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _ImmediateThread:
|
|
16
|
+
"""Stand-in for threading.Thread that runs the target synchronously -
|
|
17
|
+
same pattern jetstan-agent/tests/test_message_router.py already uses
|
|
18
|
+
for its own background-thread handler."""
|
|
19
|
+
|
|
20
|
+
def __init__(self, target, args=(), daemon=None) -> None:
|
|
21
|
+
self._target = target
|
|
22
|
+
self._args = args
|
|
23
|
+
|
|
24
|
+
def start(self) -> None:
|
|
25
|
+
self._target(*self._args)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def test_software_available_is_registered() -> None:
|
|
29
|
+
assert CUSTOM_HANDLERS["software.available"] is _handle_software_available
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_software_available_logs_update_and_version(caplog, mocker) -> None:
|
|
33
|
+
mocker.patch("software.handlers.updater.apply_update", return_value=False)
|
|
34
|
+
|
|
35
|
+
with caplog.at_level(logging.INFO):
|
|
36
|
+
_handle_software_available({"type": "software.available", "version": "0.0.2"})
|
|
37
|
+
|
|
38
|
+
assert "Vehicle software update available" in caplog.text
|
|
39
|
+
assert "Version: 0.0.2" in caplog.text
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def test_software_available_spawns_a_background_thread(mocker) -> None:
|
|
43
|
+
thread_cls = mocker.patch("software.handlers.threading.Thread")
|
|
44
|
+
|
|
45
|
+
_handle_software_available({"type": "software.available", "version": "0.0.2"})
|
|
46
|
+
|
|
47
|
+
thread_cls.assert_called_once_with(
|
|
48
|
+
target=_apply_update_and_activate, args=("0.0.2",), daemon=True
|
|
49
|
+
)
|
|
50
|
+
thread_cls.return_value.start.assert_called_once()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_apply_update_and_activate_runs_dag_on_successful_install(mocker) -> None:
|
|
54
|
+
apply_update = mocker.patch("software.handlers.updater.apply_update", return_value=True)
|
|
55
|
+
run_dag = mocker.patch(
|
|
56
|
+
"software.handlers.run_deployment_dag",
|
|
57
|
+
return_value=DagResult(outcomes=[TaskOutcome("t", "success")]),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
_apply_update_and_activate("0.0.2")
|
|
61
|
+
|
|
62
|
+
apply_update.assert_called_once_with("0.0.2")
|
|
63
|
+
run_dag.assert_called_once()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_apply_update_and_activate_skips_dag_when_install_not_applied(mocker) -> None:
|
|
67
|
+
mocker.patch("software.handlers.updater.apply_update", return_value=False)
|
|
68
|
+
run_dag = mocker.patch("software.handlers.run_deployment_dag")
|
|
69
|
+
|
|
70
|
+
_apply_update_and_activate("0.0.2")
|
|
71
|
+
|
|
72
|
+
run_dag.assert_not_called()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_apply_update_and_activate_logs_warning_when_activation_fails(caplog, mocker) -> None:
|
|
76
|
+
mocker.patch("software.handlers.updater.apply_update", return_value=True)
|
|
77
|
+
mocker.patch(
|
|
78
|
+
"software.handlers.run_deployment_dag",
|
|
79
|
+
return_value=DagResult(outcomes=[TaskOutcome("t", "failed", "boom")]),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
with caplog.at_level(logging.WARNING):
|
|
83
|
+
_apply_update_and_activate("0.0.2")
|
|
84
|
+
|
|
85
|
+
assert "activation reported failures" in caplog.text
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_software_available_end_to_end_installs_and_activates(mocker) -> None:
|
|
89
|
+
"""Full path through the real (synchronous-for-testing) thread:
|
|
90
|
+
receiving the MQTT command results in an install attempt followed by
|
|
91
|
+
the existing deployment DAG running - the DAG is the reused
|
|
92
|
+
'activation' mechanism, not a new one invented for this feature."""
|
|
93
|
+
mocker.patch("software.handlers.threading.Thread", _ImmediateThread)
|
|
94
|
+
apply_update = mocker.patch("software.handlers.updater.apply_update", return_value=True)
|
|
95
|
+
run_dag = mocker.patch(
|
|
96
|
+
"software.handlers.run_deployment_dag",
|
|
97
|
+
return_value=DagResult(outcomes=[TaskOutcome("t", "success")]),
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
_handle_software_available({"type": "software.available", "version": "0.0.2"})
|
|
101
|
+
|
|
102
|
+
apply_update.assert_called_once_with("0.0.2")
|
|
103
|
+
run_dag.assert_called_once()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Tests for software.updater."""
|
|
2
|
+
|
|
3
|
+
import subprocess
|
|
4
|
+
|
|
5
|
+
from software import updater
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _completed(returncode: int = 0, stderr: str = "") -> subprocess.CompletedProcess:
|
|
9
|
+
return subprocess.CompletedProcess(args=[], returncode=returncode, stdout="", stderr=stderr)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_apply_update_skips_when_version_matches(mocker) -> None:
|
|
13
|
+
mocker.patch("software.updater.current_version", return_value="0.0.1")
|
|
14
|
+
run = mocker.patch("software.updater.subprocess.run")
|
|
15
|
+
|
|
16
|
+
result = updater.apply_update("0.0.1")
|
|
17
|
+
|
|
18
|
+
assert result is False
|
|
19
|
+
run.assert_not_called()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_apply_update_runs_pip_install_for_pinned_version(mocker) -> None:
|
|
23
|
+
mocker.patch("software.updater.current_version", return_value="0.0.1")
|
|
24
|
+
run = mocker.patch("software.updater.subprocess.run", return_value=_completed(0))
|
|
25
|
+
|
|
26
|
+
result = updater.apply_update("0.0.2")
|
|
27
|
+
|
|
28
|
+
assert result is True
|
|
29
|
+
command = run.call_args.args[0]
|
|
30
|
+
assert command[-1] == "jetstan_ev_software==0.0.2"
|
|
31
|
+
assert "install" in command
|
|
32
|
+
assert "--upgrade" in command
|
|
33
|
+
# A software push must only ever change jetstan_ev_software's own
|
|
34
|
+
# code - never silently re-resolve numpy/onnxruntime/fastapi.
|
|
35
|
+
assert "--no-deps" in command
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_apply_update_without_version_uses_unpinned_install(mocker) -> None:
|
|
39
|
+
mocker.patch("software.updater.current_version", return_value="0.0.1")
|
|
40
|
+
run = mocker.patch("software.updater.subprocess.run", return_value=_completed(0))
|
|
41
|
+
|
|
42
|
+
result = updater.apply_update(None)
|
|
43
|
+
|
|
44
|
+
assert result is True
|
|
45
|
+
assert run.call_args.args[0][-1] == "jetstan_ev_software"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_apply_update_returns_false_when_pip_fails(mocker) -> None:
|
|
49
|
+
mocker.patch("software.updater.current_version", return_value="0.0.1")
|
|
50
|
+
mocker.patch(
|
|
51
|
+
"software.updater.subprocess.run",
|
|
52
|
+
return_value=_completed(1, "version not found"),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
assert updater.apply_update("9.9.9") is False
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_apply_update_treats_timeout_as_failure(mocker) -> None:
|
|
59
|
+
mocker.patch("software.updater.current_version", return_value="0.0.1")
|
|
60
|
+
mocker.patch(
|
|
61
|
+
"software.updater.subprocess.run",
|
|
62
|
+
side_effect=subprocess.TimeoutExpired(cmd="pip", timeout=300),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
assert updater.apply_update("0.0.2") is False
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_current_version_returns_none_when_not_installed(mocker) -> None:
|
|
69
|
+
from importlib.metadata import PackageNotFoundError
|
|
70
|
+
|
|
71
|
+
mocker.patch("software.updater.version", side_effect=PackageNotFoundError())
|
|
72
|
+
|
|
73
|
+
assert updater.current_version() is None
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"""Your application's own MQTT command handlers.
|
|
2
|
-
|
|
3
|
-
``jetstan_agent.message_router`` automatically picks up ``CUSTOM_HANDLERS``
|
|
4
|
-
from this file and merges it in alongside its built-in commands
|
|
5
|
-
(hello/restart/heartbeat/ota.available) — no changes to ``jetstan_agent``
|
|
6
|
-
needed. Add a function per command, then list it below.
|
|
7
|
-
|
|
8
|
-
Example: sending {"type": "example.ping"} over MQTT will call
|
|
9
|
-
_handle_example_ping and log "Pong from /software!".
|
|
10
|
-
"""
|
|
11
|
-
|
|
12
|
-
from __future__ import annotations
|
|
13
|
-
|
|
14
|
-
import logging
|
|
15
|
-
from typing import Any, Callable
|
|
16
|
-
|
|
17
|
-
logger = logging.getLogger(__name__)
|
|
18
|
-
|
|
19
|
-
CommandHandler = Callable[[dict[str, Any]], None]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def _handle_example_ping(command: dict[str, Any]) -> None:
|
|
23
|
-
logger.info("Pong from /software!")
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
CUSTOM_HANDLERS: dict[str, CommandHandler] = {
|
|
27
|
-
"example.ping": _handle_example_ping,
|
|
28
|
-
}
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/requires.txt
RENAMED
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/jetstan_ev_software.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/__init__.py
RENAMED
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/compiler.py
RENAMED
|
File without changes
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/discovery.py
RENAMED
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/exceptions.py
RENAMED
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/firmware.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/state_store.py
RENAMED
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/arduino_updates/verifier.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/sensors/serial_telemetry.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/software/test/jetstan-dashboard.service
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{jetstan_ev_software-0.0.1 → jetstan_ev_software-0.0.2}/tests/test_deployment_dependencies.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|