-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from CDOT-CV/Feature/firmware-manager-update
Firmware Manager Upgrade Scheduler and Runner
- Loading branch information
Showing
30 changed files
with
913 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: '3' | ||
services: | ||
cvmanager_api: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
version: '3' | ||
|
||
include: | ||
- docker-compose.yml | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version: '3.9' | ||
services: | ||
cvmanager_api: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.12.2-slim | ||
|
||
WORKDIR /home | ||
|
||
ADD addons/images/firmware_manager/requirements.txt . | ||
ADD addons/images/firmware_manager/upgrade_scheduler/*.py . | ||
ADD common/*.py ./common/ | ||
|
||
RUN pip3 install -r requirements.txt | ||
RUN apt-get update | ||
|
||
CMD ["/home/upgrade_scheduler.py"] | ||
ENTRYPOINT ["python3"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
7 changes: 0 additions & 7 deletions
7
...addons/images/firmware_manager/sample.env → ...irmware_manager/upgrade_runner/sample.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
services/addons/images/firmware_manager/upgrade_runner/upgrade_runner.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
from flask import Flask, jsonify, request, abort | ||
from subprocess import Popen, DEVNULL | ||
from waitress import serve | ||
from marshmallow import Schema, fields | ||
import json | ||
import logging | ||
import os | ||
|
||
app = Flask(__name__) | ||
|
||
log_level = os.environ.get("LOGGING_LEVEL", "INFO") | ||
logging.basicConfig(format="%(levelname)s:%(message)s", level=log_level) | ||
|
||
manufacturer_upgrade_scripts = { | ||
"Commsignia": "commsignia_upgrader.py", | ||
"Yunex": "yunex_upgrader.py", | ||
} | ||
|
||
|
||
def start_upgrade_task(rsu_upgrade_data): | ||
try: | ||
Popen( | ||
[ | ||
"python3", | ||
f'/home/{manufacturer_upgrade_scripts[rsu_upgrade_data["manufacturer"]]}', | ||
f"'{json.dumps(rsu_upgrade_data)}'", | ||
], | ||
stdout=DEVNULL, | ||
) | ||
|
||
return ( | ||
jsonify( | ||
{ | ||
"message": f"Firmware upgrade started successfully for '{rsu_upgrade_data['ipv4_address']}'" | ||
} | ||
), | ||
201, | ||
) | ||
except Exception as err: | ||
# If this case occurs, only log it since there may not be a listener. | ||
# Since the upgrade_queue and upgrade_queue_info will no longer have the RSU present, | ||
# the hourly check_for_upgrades() will pick up the firmware upgrade again to retry the upgrade. | ||
logging.error( | ||
f"Encountered error of type {type(err)} while starting automatic upgrade process for {rsu_upgrade_data['ipv4_address']}: {err}" | ||
) | ||
|
||
return ( | ||
jsonify( | ||
{ | ||
"message": f"Firmware upgrade failed to start for '{rsu_upgrade_data['ipv4_address']}'" | ||
} | ||
), | ||
500, | ||
) | ||
|
||
|
||
class RunFirmwareUpgradeSchema(Schema): | ||
ipv4_address = fields.IPv4(required=True) | ||
manufacturer = fields.Str(required=True) | ||
model = fields.Str(required=True) | ||
ssh_username = fields.Str(required=True) | ||
ssh_password = fields.Str(required=True) | ||
target_firmware_id = fields.Int(required=True) | ||
target_firmware_version = fields.Str(required=True) | ||
install_package = fields.Str(required=True) | ||
|
||
|
||
# REST endpoint to manually start firmware upgrades for a single targeted RSU | ||
# Required request body values: | ||
# - ipv4_address | ||
# - manufacturer | ||
# - model | ||
# - ssh_username | ||
# - ssh_password | ||
# - target_firmware_id | ||
# - target_firmware_version | ||
# - install_package | ||
@app.route("/run_firmware_upgrade", methods=["POST"]) | ||
def run_firmware_upgrade(): | ||
# Verify HTTP body JSON object | ||
request_args = request.get_json() | ||
schema = RunFirmwareUpgradeSchema() | ||
errors = schema.validate(request_args) | ||
if errors: | ||
logging.error(str(errors)) | ||
abort(400, str(errors)) | ||
|
||
# Start the RSU upgrade task | ||
return start_upgrade_task(request_args) | ||
|
||
|
||
def serve_rest_api(): | ||
# Run Flask app | ||
logging.info("Initiating the Firmware Manager Upgrade Runner REST API...") | ||
serve(app, host="0.0.0.0", port=8080) | ||
|
||
|
||
if __name__ == "__main__": | ||
serve_rest_api() |
File renamed without changes.
Oops, something went wrong.