Skip to content

Commit

Permalink
server error messages; try not using REF for this self-test
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed May 27, 2024
1 parent 9d6f659 commit 065e498
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 22 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### Upcoming

- Fix for Pioreactors page when _no workers are added to the cluster_.
- Fix for UI labels when trying to remove multiple labels from Pioreactors.
- Added groupings on the Experiment dropdown to organize "Active" and "Inactive" experiments. An active experiment has >= 1 Pioreactor assigned to it.
- UI now supports changing the MQTT broker. This configuration lives in the config.ini, under `[mqtt]`.
-


### 24.5.22

#### Enhancements
Expand Down
6 changes: 5 additions & 1 deletion config.dev.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ console_log_level=DEBUG

[cluster.topology]
leader_hostname=localhost
leader_address=localhost:4999
leader_address=localhost


[cluster.inventory]
Expand All @@ -90,6 +90,10 @@ raw_od_lookback_minutes=240
log_display_count=65
time_display_mode=hours

[ui]
port=4999
proto=http


[dosing_automation.pid_morbidostat]
Kp=5
Expand Down
19 changes: 11 additions & 8 deletions pioreactor/actions/self_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,21 @@ def test_PD_is_near_0_volts_for_blank(
) -> None:
assert is_HAT_present()
reference_channel = cast(PdChannel, config["od_config.photodiode_channel_reverse"][REF_keyword])
signal_channel = cast(PdChannel, "2" if reference_channel == "1" else "1")
assert config.get("od_config.photodiode_channel", signal_channel, fallback=None) in [
"90",
"45",
"135",
]

if reference_channel == "1":
signal_channel = cast(PdChannel, "2")
else:
signal_channel = cast(PdChannel, "1")

angle = config.get("od_config.photodiode_channel", signal_channel, fallback=None)

assert angle in ["90", "45", "135"]

signals = []

with start_od_reading(
od_angle_channel1=config.get("od_config.photodiode_channel", "1", fallback=None),
od_angle_channel2=config.get("od_config.photodiode_channel", "2", fallback=None),
od_angle_channel1=angle if signal_channel == "1" else None, # don't use REF
od_angle_channel2=angle if signal_channel == "2" else None, # don't use REF
interval=1.15,
unit=unit,
fake_data=is_testing_env(),
Expand Down
8 changes: 5 additions & 3 deletions pioreactor/cli/pio.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def update_app(
"""
import subprocess

logger = create_logger("update-app", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT)
logger = create_logger("update_app", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT)

commands_and_priority: list[tuple[str, float]] = []

Expand Down Expand Up @@ -556,7 +556,9 @@ def update_firmware(version: Optional[str]) -> None:
"""
import subprocess

logger = create_logger("update-app", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT)
logger = create_logger(
"update_firmware", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT
)
commands_and_priority: list[tuple[str, int]] = []

if version is None:
Expand Down Expand Up @@ -635,7 +637,7 @@ def update_ui(branch: Optional[str], repo: str, source: Optional[str], version:
import subprocess

logger = create_logger(
"update-ui", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT
"update_ui", unit=whoami.get_unit_name(), experiment=whoami.UNIVERSAL_EXPERIMENT
)
commands = []

Expand Down
21 changes: 15 additions & 6 deletions pioreactor/cluster_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ def add_worker(hostname: str, password: str, version: str, model: str) -> None:
raise BashScriptError(res.stderr)

try:
result = put_into_leader(
r = put_into_leader(
"/api/workers",
json={"pioreactor_unit": hostname},
)
result.raise_for_status()
r.raise_for_status()
except HTTPErrorStatus:
logger.error("Did not add Pioreactor to backend")
raise HTTPException("Did not add Pioreactor to backend")
if r.status_code >= 500:
click.echo("Server error. Could not complete.")
else:
logger.error("Did not add worker to backend")
raise HTTPException("Did not add worker to backend")
except HTTPException:
logger.error("Could not connect to leader's webserver")
raise HTTPException("Could not connect to leader's webserver")
Expand All @@ -125,7 +128,10 @@ def remove_worker(hostname: str) -> None:
r = delete_from_leader(f"/api/workers/{hostname}")
r.raise_for_status()
except HTTPErrorStatus:
click.echo(f"Worker {hostname} not present to be removed. Check hostname.")
if r.status_code >= 500:
click.echo("Server error. Could not complete.")
else:
click.echo(f"Worker {hostname} not present to be removed. Check hostname.")
click.Abort()
except HTTPException:
click.echo("Not able to connect to leader's backend.")
Expand All @@ -145,7 +151,10 @@ def assign_worker_to_experiment(hostname: str, experiment: str) -> None:
)
r.raise_for_status()
except HTTPErrorStatus:
click.echo("Not valid data. Check hostname or experiment.")
if r.status_code >= 500:
click.echo("Server error. Could not complete.")
else:
click.echo("Not valid data. Check hostname or experiment.")
click.Abort()
except HTTPException:
click.echo("Not able to connect to leader's backend.")
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def update_service(self, *args, **kwargs):

def __next__(self) -> str:
try:
return self.hostnames.get(timeout=2 if terminate else None)
return self.hostnames.get(timeout=3 if terminate else None)
except Empty:
raise StopIteration

Expand Down
2 changes: 1 addition & 1 deletion pioreactor/utils/pwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
try:
from rpi_hardware_pwm import HardwarePWM # type: ignore
except ImportError:
pass
from pioreactor.utils.mock import MockHardwarePWM as HardwarePWM


class HardwarePWMOutputDevice(HardwarePWM):
Expand Down
2 changes: 1 addition & 1 deletion pioreactor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Append ".dev0" if a dev version
# Append "rc0" if a rc version
# No zero padding!
__version__ = "24.5.22"
__version__ = "24.5.22.dev0"


def get_hardware_version() -> tuple[int, int] | tuple[int, int, str]:
Expand Down
2 changes: 1 addition & 1 deletion update_scripts/24.5.22/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ echo "force_turbo=1" | sudo tee -a /boot/config.txt
nmcli con add type ethernet con-name eth0 ifname eth0 autoconnect yes ipv4.method auto ipv6.method auto ipv6.addr-gen-mode default connection.id eth0 connection.autoconnect-priority 1 || :
nmcli con modify PioreactorLocalLink connection.autoconnect-priority 0 connection.autoconnect no || :

echo "max_inflight_messages 1000" | sudo tee /etc/mosquitto/mosquitto.conf -a
echo "max_inflight_messages 1000" | sudo tee /etc/mosquitto/mosquitto.conf -a || :

0 comments on commit 065e498

Please sign in to comment.