Skip to content

Commit

Permalink
adding a test to make sure we run pio as pioreactor in update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed May 5, 2024
1 parent d16efef commit ef7a44b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Upcoming
- Chart legend's will support more than 8 Pioreactors.
- UI performance improvements.

### 24.5.1

#### Highlights
Expand Down
1 change: 1 addition & 0 deletions pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def log(message: str, level: str, name: str, local_only: bool):
to_mqtt=not local_only,
)
getattr(logger, level)(message)
sleep(0.5) # sleep for a moment to let the message hit mqtt

except Exception as e:
# don't let a logging error bring down a script...
Expand Down
30 changes: 30 additions & 0 deletions pioreactor/tests/test_update_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from __future__ import annotations

import os


def find_shell_scripts(directory):
"""Recursively find all shell script files in the specified directory."""
types = {"update.sh", "pre_update.sh", "post_update.sh"}
for root, dirs, files in os.walk(directory):
for file in files:
if file in types:
yield os.path.join(root, file)


def test_pio_commands():
script_directory = "update_scripts"
scripts = find_shell_scripts(script_directory)
error_msgs = []

for script in scripts:
with open(script, "r") as file:
for line_number, line in enumerate(file, start=1):
# Checking for 'pio' not preceded by 'su -u pioreactor'
if " pio " in line and "su -u pioreactor" not in line:
error_msgs.append(
f"Error in {script} at line {line_number}: 'pio' command must be prefixed with 'su -u pioreactor'."
)

assert not error_msgs, "\n".join(error_msgs)
2 changes: 1 addition & 1 deletion pioreactor/whoami.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_pioreactor_version() -> tuple[int, int]:

from pioreactor.config import config

return version_text_to_tuple(config.get("pioreactor", "version")) # type: ignore
return version_text_to_tuple(config.get("pioreactor", "version", fallback="0.0")) # type: ignore


@cache
Expand Down
2 changes: 1 addition & 1 deletion update_scripts/24.4.3/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ if [ "$HOSTNAME" = "$LEADER_HOSTNAME" ]; then



### update add_new_pioreactor_worker_from_leader to use pio workers discover
### update add_new_pioreactor_worker_from_leader to use `pio workers discover``

FILE_PATH="/usr/local/bin/add_new_pioreactor_worker_from_leader.sh"
sudo sed -i 's/pio discover-workers/pio workers discover/g' "$FILE_PATH"
Expand Down
24 changes: 24 additions & 0 deletions update_scripts/24.5.1/pre_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -xeu


export LC_ALL=C


# Lower bound version
min_version="24.4.11"

# Get the current version of pio
current_version=$(su -u pioreactor pio version)

# Use sorting to determine if the current version is less than the minimum version
is_valid=$(printf "%s\n%s" "$current_version" "$min_version" | sort -V | head -n1)

# If the smallest version isn't the minimum version, then current version is too low
if [ "$is_valid" != "$min_version" ]; then
su -u pioreactor pio log -l ERROR -m "Version error: installed version $current_version is lower than the minimum required version $min_version."
exit 1
fi

echo "Version check passed: $current_version"
2 changes: 0 additions & 2 deletions update_scripts/24.5.1/update.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash

# this runs at startup on every boot.

set -xeu


Expand Down

0 comments on commit ef7a44b

Please sign in to comment.