mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-21 23:29:39 +00:00
Fix test failures in low-voltage PR (#1207)
* fix lint checks in web python * fix lint checks in common python * rework to pass tests in docker * fix css style lint * fix css style syntax
This commit is contained in:
parent
74eef6f9cc
commit
b514440957
@ -3,13 +3,18 @@ Module with methods that interact with the Pi system
|
|||||||
"""
|
"""
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
from subprocess import run, CalledProcessError
|
from subprocess import run, CalledProcessError
|
||||||
from shutil import disk_usage
|
from shutil import disk_usage
|
||||||
from re import findall, match
|
from re import findall, match
|
||||||
from socket import socket, gethostname, AF_INET, SOCK_DGRAM
|
from socket import socket, gethostname, AF_INET, SOCK_DGRAM
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from platform import uname
|
from platform import uname
|
||||||
from vcgencmd import Vcgencmd
|
|
||||||
|
try:
|
||||||
|
from vcgencmd import Vcgencmd
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
|
||||||
from piscsi.return_codes import ReturnCodes
|
from piscsi.return_codes import ReturnCodes
|
||||||
from piscsi.common_settings import SHELL_ERROR
|
from piscsi.common_settings import SHELL_ERROR
|
||||||
@ -276,26 +281,29 @@ class SysCmds:
|
|||||||
they're triggered. test_modes works similarly to enabled_mode but will
|
they're triggered. test_modes works similarly to enabled_mode but will
|
||||||
ALWAYS display the modes listed for troubleshooting styling.
|
ALWAYS display the modes listed for troubleshooting styling.
|
||||||
"""
|
"""
|
||||||
vcgcmd = Vcgencmd()
|
if "vcgencmd" in sys.modules:
|
||||||
t_states = vcgcmd.get_throttled()['breakdown']
|
vcgcmd = Vcgencmd()
|
||||||
matched_states = []
|
t_states = vcgcmd.get_throttled()["breakdown"]
|
||||||
|
matched_states = []
|
||||||
|
|
||||||
state_msgs = {
|
state_msgs = {
|
||||||
"0": ("error", ReturnCodes.UNDER_VOLTAGE_DETECTED),
|
"0": ("error", ReturnCodes.UNDER_VOLTAGE_DETECTED),
|
||||||
"1": ("warning", ReturnCodes.ARM_FREQUENCY_CAPPED),
|
"1": ("warning", ReturnCodes.ARM_FREQUENCY_CAPPED),
|
||||||
"2": ("error", ReturnCodes.CURRENTLY_THROTTLED),
|
"2": ("error", ReturnCodes.CURRENTLY_THROTTLED),
|
||||||
"3": ("warning", ReturnCodes.SOFT_TEMPERATURE_LIMIT_ACTIVE),
|
"3": ("warning", ReturnCodes.SOFT_TEMPERATURE_LIMIT_ACTIVE),
|
||||||
"16": ("warning", ReturnCodes.UNDER_VOLTAGE_HAS_OCCURRED),
|
"16": ("warning", ReturnCodes.UNDER_VOLTAGE_HAS_OCCURRED),
|
||||||
"17": ("warning", ReturnCodes.ARM_FREQUENCY_CAPPING_HAS_OCCURRED),
|
"17": ("warning", ReturnCodes.ARM_FREQUENCY_CAPPING_HAS_OCCURRED),
|
||||||
"18": ("warning", ReturnCodes.THROTTLING_HAS_OCCURRED),
|
"18": ("warning", ReturnCodes.THROTTLING_HAS_OCCURRED),
|
||||||
"19": ("warning", ReturnCodes.SOFT_TEMPERATURE_LIMIT_HAS_OCCURRED),
|
"19": ("warning", ReturnCodes.SOFT_TEMPERATURE_LIMIT_HAS_OCCURRED),
|
||||||
}
|
}
|
||||||
|
|
||||||
for k in t_states:
|
for k in t_states:
|
||||||
if t_states[k] and k in enabled_modes:
|
if t_states[k] and k in enabled_modes:
|
||||||
matched_states.append(state_msgs[k])
|
matched_states.append(state_msgs[k])
|
||||||
|
|
||||||
for t in test_modes:
|
for t in test_modes:
|
||||||
matched_states.append(state_msgs[t])
|
matched_states.append(state_msgs[t])
|
||||||
|
|
||||||
return matched_states
|
return matched_states
|
||||||
|
else:
|
||||||
|
return []
|
||||||
|
@ -4,3 +4,4 @@ black==22.8.0
|
|||||||
flake8==5.0.4
|
flake8==5.0.4
|
||||||
watchdog==2.1.9
|
watchdog==2.1.9
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
|
vcgencmd==0.1.1
|
||||||
|
@ -51,21 +51,28 @@ class ReturnCodeMapper:
|
|||||||
ReturnCodes.EXTRACTIMAGE_COMMAND_ERROR:
|
ReturnCodes.EXTRACTIMAGE_COMMAND_ERROR:
|
||||||
_("Unable to extract archive: %(error)s"),
|
_("Unable to extract archive: %(error)s"),
|
||||||
ReturnCodes.UNDER_VOLTAGE_DETECTED:
|
ReturnCodes.UNDER_VOLTAGE_DETECTED:
|
||||||
_("Under voltage detected - Make sure to use a proper power source (2.5+ amps)."),
|
_("Potential instability - Under voltage detected - Make sure to use a sufficient "
|
||||||
|
"power source (2.5+ amps)."),
|
||||||
ReturnCodes.ARM_FREQUENCY_CAPPED:
|
ReturnCodes.ARM_FREQUENCY_CAPPED:
|
||||||
_("ARM frequency capped - Ensure proper airflow/cooling."),
|
_("Potential instability - ARM frequency capped - Ensure sufficient airflow/cooling."),
|
||||||
ReturnCodes.CURRENTLY_THROTTLED:
|
ReturnCodes.CURRENTLY_THROTTLED:
|
||||||
_("Currently throttled - Make sure to use a proper power source (2.5+ amps)."),
|
_("Potential instability - Currently throttled - Make sure to use a sufficient power "
|
||||||
|
"source (2.5+ amps)."),
|
||||||
ReturnCodes.SOFT_TEMPERATURE_LIMIT_ACTIVE:
|
ReturnCodes.SOFT_TEMPERATURE_LIMIT_ACTIVE:
|
||||||
_("Soft-temperature limit active - Ensure proper airflow/cooling."),
|
_("Potential instability - Soft-temperature limit active - Ensure sufficient "
|
||||||
|
"airflow/cooling."),
|
||||||
ReturnCodes.UNDER_VOLTAGE_HAS_OCCURRED:
|
ReturnCodes.UNDER_VOLTAGE_HAS_OCCURRED:
|
||||||
_("Under voltage has occurred since last reboot. Make sure to use a proper power source (2.5+ amps)."),
|
_("Potential instability - Under voltage has occurred since last reboot. Make sure "
|
||||||
|
"to use a sufficient power source (2.5+ amps)."),
|
||||||
ReturnCodes.ARM_FREQUENCY_CAPPING_HAS_OCCURRED:
|
ReturnCodes.ARM_FREQUENCY_CAPPING_HAS_OCCURRED:
|
||||||
_("ARM frequency capping has occurred since last reboot. Ensure proper airflow/cooling."),
|
_("Potential instability - ARM frequency capping has occurred since last reboot. "
|
||||||
|
"Ensure sufficient airflow/cooling."),
|
||||||
ReturnCodes.THROTTLING_HAS_OCCURRED:
|
ReturnCodes.THROTTLING_HAS_OCCURRED:
|
||||||
_("Throttling has occurred since the last reboot. Make sure to use a proper power source (2.5+ amps)."),
|
_("Potential instability - Throttling has occurred since the last reboot. Make sure "
|
||||||
|
"to use a sufficient power source (2.5+ amps)."),
|
||||||
ReturnCodes.SOFT_TEMPERATURE_LIMIT_HAS_OCCURRED:
|
ReturnCodes.SOFT_TEMPERATURE_LIMIT_HAS_OCCURRED:
|
||||||
_("Soft temperature limit has occurred since last reboot. Ensure proper airflow/cooling."),
|
_("Potential instability - Soft temperature limit has occurred since last reboot. "
|
||||||
|
"Ensure sufficient airflow/cooling."),
|
||||||
}
|
}
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ TEMPLATE_THEME_DEFAULT = "modern"
|
|||||||
TEMPLATE_THEME_LEGACY = "classic"
|
TEMPLATE_THEME_LEGACY = "classic"
|
||||||
|
|
||||||
# Enable throttle notifications
|
# Enable throttle notifications
|
||||||
#
|
#
|
||||||
# Available modes:
|
# Available modes:
|
||||||
# "0": "Under-voltage detected"
|
# "0": "Under-voltage detected"
|
||||||
# "1": "Arm frequency capped"
|
# "1": "Arm frequency capped"
|
||||||
|
@ -173,7 +173,7 @@ summary.filename {
|
|||||||
margin-left: -27px;
|
margin-left: -27px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div {
|
div.throttle-notice > div {
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: #efefef;
|
background-color: #efefef;
|
||||||
@ -185,23 +185,21 @@ div.throttle_notice > div {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div.error {
|
div.throttle-notice > div.error {
|
||||||
background-color: #dc3545;
|
background-color: #dc3545;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div.warning {
|
div.throttle-notice > div.warning {
|
||||||
background-color: #ffc107;
|
background-color: #ffc107;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div a {
|
div.throttle-notice > div a {
|
||||||
color: black;
|
color: black;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div a:hover {
|
div.throttle-notice > div a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -476,7 +476,7 @@ div.footer div.theme-change-hint a {
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
div.throttle_notice > div {
|
div.throttle-notice > div {
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background-color: #efefef;
|
background-color: #efefef;
|
||||||
@ -487,29 +487,29 @@ div.throttle_notice > div {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div.error {
|
div.throttle-notice > div.error {
|
||||||
background-color: var(--danger);
|
background-color: var(--danger);
|
||||||
background-image: url("icons/error.svg");
|
background-image: url("icons/error.svg");
|
||||||
color: #fff;
|
color: #fff;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div.warning {
|
div.throttle-notice > div.warning {
|
||||||
background-color: var(--warning);
|
background-color: var(--warning);
|
||||||
background-image: url("icons/warning.svg");
|
background-image: url("icons/warning.svg");
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div > span.message {
|
div.throttle-notice > div > span.message {
|
||||||
padding-left: 3rem;
|
padding-left: 3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div a {
|
div.throttle-notice > div a {
|
||||||
color: black;
|
color: black;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.throttle_notice > div a:hover {
|
div.throttle-notice > div a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,13 +73,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="throttle_notice">
|
<div class="throttle-notice">
|
||||||
{% if (env["throttle_status"]|length > 0) %}
|
{% if (env["throttle_status"]|length > 0) %}
|
||||||
{% for category, response in env["throttle_status"] %}
|
{% for category, response in env["throttle_status"] %}
|
||||||
<div class="{{ category }}">
|
<div class="{{ category }}">
|
||||||
<span class="message" title="{{ response['msg'] }}"><a
|
<span class="message" title="{{ response['msg'] }}"><a
|
||||||
href="https://www.raspberrypi.com/documentation/computers/configuration.html#undervoltage-warning">Potential
|
href="https://www.raspberrypi.com/documentation/computers/configuration.html#undervoltage-warning">{{ response['msg'] }}</a></span>
|
||||||
instability due to: {{ response['msg'] }}</a></span>
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -90,8 +90,7 @@ def get_env_info():
|
|||||||
else:
|
else:
|
||||||
username = None
|
username = None
|
||||||
|
|
||||||
throttled_statuses = sys_cmd.get_throttled(
|
throttled_statuses = sys_cmd.get_throttled(THROTTLE_NOTIFY_MODES, THROTTLE_TEST_MODES)
|
||||||
THROTTLE_NOTIFY_MODES, THROTTLE_TEST_MODES)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"running_env": sys_cmd.running_env(),
|
"running_env": sys_cmd.running_env(),
|
||||||
@ -111,8 +110,9 @@ def get_env_info():
|
|||||||
"cd_suffixes": tuple(server_info["sccd"]),
|
"cd_suffixes": tuple(server_info["sccd"]),
|
||||||
"rm_suffixes": tuple(server_info["scrm"]),
|
"rm_suffixes": tuple(server_info["scrm"]),
|
||||||
"mo_suffixes": tuple(server_info["scmo"]),
|
"mo_suffixes": tuple(server_info["scmo"]),
|
||||||
"throttle_status":
|
"throttle_status": [
|
||||||
[(s[0], ReturnCodeMapper.add_msg({"return_code":s[1]})) for s in throttled_statuses],
|
(s[0], ReturnCodeMapper.add_msg({"return_code": s[1]})) for s in throttled_statuses
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -286,12 +286,3 @@ def test_rename_system(env, http_client):
|
|||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
|
|
||||||
assert response_data["data"]["system_name"] == old_name
|
assert response_data["data"]["system_name"] == old_name
|
||||||
|
|
||||||
|
|
||||||
def test_throttle_notification(http_client):
|
|
||||||
response = http_client.get("/")
|
|
||||||
response_data = response.json()
|
|
||||||
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response_data["status"] == STATUS_SUCCESS
|
|
||||||
assert "Under voltage detected" in response_data["data"]
|
|
||||||
|
Loading…
Reference in New Issue
Block a user