From 3242594cc689d2c31e97edb06c89e617d2e36c62 Mon Sep 17 00:00:00 2001 From: CamDavidsonPilon Date: Thu, 14 Dec 2023 14:45:01 -0500 Subject: [PATCH] updateS --- pioreactor/background_jobs/stirring.py | 4 ++-- pioreactor/cli/pio.py | 17 +++++++++++------ pioreactor/tests/test_dosing_control.py | 2 +- pioreactor/version.py | 2 +- update_scripts/23.12.11/update.sh | 9 ++++++++- update_scripts/README.md | 1 - 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/pioreactor/background_jobs/stirring.py b/pioreactor/background_jobs/stirring.py index 4b559c41..938394b9 100644 --- a/pioreactor/background_jobs/stirring.py +++ b/pioreactor/background_jobs/stirring.py @@ -309,10 +309,10 @@ def start_stirring(self) -> None: def kick_stirring(self) -> None: self.logger.debug("Kicking stirring") self.set_duty_cycle(100) - sleep(0.20) + sleep(0.10) self.set_duty_cycle( max(1.01 * self._previous_duty_cycle, 60) - ) # DC should never be above 60. We want to avoid the death spiral to 100%. + ) # DC should never need to be above 60 - simply not realistic. We want to avoid the death spiral to 100%. def kick_stirring_but_avoid_od_reading(self) -> None: """ diff --git a/pioreactor/cli/pio.py b/pioreactor/cli/pio.py index d127f94b..f82f16db 100644 --- a/pioreactor/cli/pio.py +++ b/pioreactor/cli/pio.py @@ -499,9 +499,8 @@ def update_app( version_installed = source commands_and_priority.append((f"sudo pip3 install --force-reinstall --no-index {source}", 1)) else: - raise click.Abort( - "Not a valid source file. Should be either a whl or release archive." - ) # TODO: this doesn't print any message on error... + click.echo("Not a valid source file. Should be either a whl or release archive.") + raise click.Abort() elif branch is not None: cleaned_branch = quote(branch) @@ -526,6 +525,12 @@ def update_app( release_metadata = loads(response.body) version_installed = release_metadata["tag_name"] found_whl = False + + # nuke all existing assets in /tmp + # TODO: just make a new tempdir, put all files there, and then nuke that temp dir...... + # BETTER TODO: just download the release archive and run the script above..... + commands_and_priority.append(("rm -f /tmp/*update.sh /tmp/update.sql", -1)) + for asset in release_metadata["assets"]: # add the following files to the release. They should ideally be idempotent! @@ -534,8 +539,6 @@ def update_app( # update.sh runs (if exists) # update.sql to update sqlite schema runs (if exists) # post_update.sh runs (if exists) - - # TODO: potential supply chain attack is to add malicious assets to releases url = asset["browser_download_url"] asset_name = asset["name"] @@ -600,7 +603,9 @@ def update_app( @click.option("-v", "--version", help="install a specific version, default is latest") def update_firmware(version: Optional[str]) -> None: """ - Update the RP2040 firmware + Update the RP2040 firmware. + + # TODO: this needs accept a --source arg """ logger = create_logger("update-app", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT) commands_and_priority: list[tuple[str, int]] = [] diff --git a/pioreactor/tests/test_dosing_control.py b/pioreactor/tests/test_dosing_control.py index e7c65c52..39dc1fef 100644 --- a/pioreactor/tests/test_dosing_control.py +++ b/pioreactor/tests/test_dosing_control.py @@ -1591,7 +1591,7 @@ def test_warning_is_logged_if_under_remove_waste() -> None: experiment = "test_warning_is_logged_if_under_remove_waste" class BadWasteRemoval(DosingAutomationJob): - automation_name = "bad_waste_removal" + automation_name = "_test_bad_waste_removal" def remove_waste_from_bioreactor(self, unit, experiment, ml, source_of_event, mqtt_client): return ml / 2 diff --git a/pioreactor/version.py b/pioreactor/version.py index aec1ed41..982abcb6 100644 --- a/pioreactor/version.py +++ b/pioreactor/version.py @@ -20,7 +20,7 @@ def _get_hardware_version() -> tuple[int, int] | tuple[int, int, str]: text = f.read().rstrip("\x00") return (int(text[-2]), int(text[-1])) except FileNotFoundError: - # no eeprom? Probably dev board with no EEPROM, or testing env, or EEPROM not written. + # no eeprom? Probably dev board with no EEPROM, or testing env, or EEPROM not written, or cable exists between HAT and Pi -> signal degradation. return (0, 0) diff --git a/update_scripts/23.12.11/update.sh b/update_scripts/23.12.11/update.sh index c2667a28..1284b984 100644 --- a/update_scripts/23.12.11/update.sh +++ b/update_scripts/23.12.11/update.sh @@ -1,12 +1,19 @@ #!/bin/bash set -x -set -e export LC_ALL=C # Get the directory where the script is located SCRIPT_DIR=$(dirname "$0") +# Attempt to download update_ui.sh +if ! wget -O "${SCRIPT_DIR}/update_ui.sh" https://github.com/Pioreactor/pioreactor/releases/download/23.12.11/update_ui.sh; then + echo "Failed to download update_ui.sh" +fi + +# Ensure the script is executable +chmod +x "${SCRIPT_DIR}/update_ui.sh" + # Copy update_ui.sh from the script's directory sudo cp "${SCRIPT_DIR}/update_ui.sh" /usr/local/bin/ diff --git a/update_scripts/README.md b/update_scripts/README.md index 522e2b4f..1056846c 100644 --- a/update_scripts/README.md +++ b/update_scripts/README.md @@ -8,7 +8,6 @@ Possible update scripts and their sequence: - `post_update.sh` runs (if exists). Useful for restarting jobs, or rebooting RPis. - It's very important that update scripts are idempotent. Some tips: - Use ChatGPT to assist psuedo-check if a script is idempotent, or making suggestions.