From e85e9661e0694d83e88439abd0ae0666f6b0a384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 30 Oct 2019 13:01:42 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=B7=E2=80=8D=E2=99=80=EF=B8=8F=20PMGR/?= =?UTF-8?q?SWU:=20Flag=20to=20ignore=20throttle=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Will allow people to circumvent the shoot-yourself-in-the-foot-countermeasures by editing config.yaml. If they do that and stuff then fails due to platform instability it's their problem. --- src/octoprint/plugins/pi_support/__init__.py | 38 ++++++++++++------- .../plugins/pluginmanager/__init__.py | 7 +++- .../pluginmanager/static/js/pluginmanager.js | 2 +- .../plugins/softwareupdate/__init__.py | 8 +++- .../static/js/softwareupdate.js | 4 +- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/octoprint/plugins/pi_support/__init__.py b/src/octoprint/plugins/pi_support/__init__.py index 7983c97c8..cc18136b5 100644 --- a/src/octoprint/plugins/pi_support/__init__.py +++ b/src/octoprint/plugins/pi_support/__init__.py @@ -18,14 +18,23 @@ _PROC_DT_MODEL_PATH = "/proc/device-tree/model" _OCTOPI_VERSION_PATH = "/etc/octopi_version" _VCGENCMD_THROTTLE = "/usr/bin/vcgencmd get_throttled" -### uncomment for local debugging -#import sys -#base = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "tests", "plugins", "pi_support", "fakes")) -#_PROC_DT_MODEL_PATH = os.path.join(base, "fake_model.txt") -#_OCTOPI_VERSION_PATH = os.path.join(base, "fake_octopi.txt") -#_VCGENCMD_THROTTLE = "{} {}".format(sys.executable, os.path.join(base, "fake_vcgencmd.py")) -#import itertools -#_VCGENCMD_OUTPUT = itertools.chain(iter(("0x0", "0x0", "0x50005", "0x50000", "0x70007")), itertools.repeat("0x70000")) +_CHECK_INTERVAL_OK = 300 +_CHECK_INTERVAL_THROTTLED = 30 + +__LOCAL_DEBUG = False + +if __LOCAL_DEBUG: + ### mocks & settings for local debugging + import sys + base = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "tests", "plugins", "pi_support", "fakes")) + _PROC_DT_MODEL_PATH = os.path.join(base, "fake_model.txt") + _OCTOPI_VERSION_PATH = os.path.join(base, "fake_octopi.txt") + _VCGENCMD_THROTTLE = "{} {}".format(sys.executable, os.path.join(base, "fake_vcgencmd.py")) + import itertools + _VCGENCMD_OUTPUT = itertools.chain(iter(("0x0", "0x0", "0x50005", "0x50000", "0x70007")), itertools.repeat("0x70005")) + + _CHECK_INTERVAL_OK = 10 + _CHECK_INTERVAL_THROTTLED = 5 # see https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=147781&start=50#p972790 @@ -134,8 +143,11 @@ def get_proc_dt_model(): def get_vcgencmd_throttled_state(command): - output = sarge.get_stdout(command) - #output = "throttled={}".format(next(_VCGENCMD_OUTPUT)) # for local debugging + if __LOCAL_DEBUG: + output = "throttled={}".format(next(_VCGENCMD_OUTPUT)) # mock for local debugging + else: + output = sarge.get_stdout(command) + if not "throttled=0x" in output: raise ValueError("cannot parse \"{}\" output: {}".format(command, output)) @@ -236,11 +248,9 @@ class PiSupportPlugin(octoprint.plugin.EnvironmentDetectionPlugin, def _check_throttled_state_interval(self): if self._throttle_state.current_issue: - # check state every 30s if something's currently amiss - return 30 + return _CHECK_INTERVAL_THROTTLED else: - # check state every 5min if nothing's currently amiss - return 300 + return _CHECK_INTERVAL_OK def _check_throttled_state_condition(self): return self._throttle_functional diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 221007443..d7f2e0b59 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -153,6 +153,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, helpers = self._plugin_manager.get_helpers("pi_support", "get_throttled") if helpers and "get_throttled" in helpers: self._get_throttled = helpers["get_throttled"] + if self._settings.get_boolean(["ignore_throttled"]): + self._logger.warn("!!! THROTTLE STATE IGNORED !!! You have configured the Plugin Manager plugin to ignore an active throttle state of the underlying system. You might run into stability issues or outright corrupt your install. Consider fixing the throttling issue instead of suppressing it.") # decouple repository fetching from server startup self._fetch_all_data(do_async=True) @@ -170,7 +172,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, confirm_uninstall=True, confirm_disable=False, dependency_links=False, - hidden=[] + hidden=[], + ignore_throttled=False ) def on_settings_save(self, data): @@ -359,7 +362,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin, def command_install(self, url=None, path=None, force=False, reinstall=None, dependency_links=False): throttled = self._get_throttled() - if throttled and isinstance(throttled, dict) and throttled.get("current_issue", False): + if throttled and isinstance(throttled, dict) and throttled.get("current_issue", False) and not self._settings.get_boolean(["ignore_throttled"]): # currently throttled, we refuse to run return make_response("System is currently throttled, refusing to install " "anything due to possible stability issues", 409) diff --git a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js index ed5d7c4d9..c1450e5bf 100644 --- a/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js +++ b/src/octoprint/plugins/pluginmanager/static/js/pluginmanager.js @@ -190,7 +190,7 @@ $(function() { }; self.throttled = ko.pureComputed(function() { - return self.piSupport && self.piSupport.currentIssue(); + return self.piSupport && self.piSupport.currentIssue() && !self.settingsViewModel.settings.plugins.pluginmanager.ignore_throttled(); }); self.invalidUrl = ko.pureComputed(function() { diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 61149ecb0..597a53c2b 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -104,6 +104,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, helpers = self._plugin_manager.get_helpers("pi_support", "get_throttled") if helpers and "get_throttled" in helpers: self._get_throttled = helpers["get_throttled"] + if self._settings.get_boolean(["ignore_throttled"]): + self._logger.warn("!!! THROTTLE STATE IGNORED !!! You have configured the Software Update plugin to ignore an active throttle state of the underlying system. You might run into stability issues or outright corrupt your install. Consider fixing the throttling issue instead of suppressing it.") def on_after_startup(self): self._check_environment() @@ -281,7 +283,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, "cache_ttl": 24 * 60, - "notify_users": True + "notify_users": True, + + "ignore_throttled": False } def on_settings_load(self): @@ -575,7 +579,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, @admin_permission.require(403) def perform_update(self): throttled = self._get_throttled() - if throttled and isinstance(throttled, dict) and throttled.get("current_issue", False): + if throttled and isinstance(throttled, dict) and throttled.get("current_issue", False) and not self._settings.get_boolean(["ignore_throttled"]): # currently throttled, we refuse to run return flask.make_response("System is currently throttled, refusing to update " "anything due to possible stability issues", 409) diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js index 76b2ec4e7..e53ebf516 100644 --- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js +++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js @@ -97,7 +97,7 @@ $(function() { }); self.throttled = ko.pureComputed(function() { - return self.piSupport && self.piSupport.currentIssue(); + return self.piSupport && self.piSupport.currentIssue() && !self.settings.settings.plugins.pluginmanager.ignore_throttled(); }); self.onUserLoggedIn = function() { @@ -496,7 +496,7 @@ $(function() { return; } - if (self.piSupport && self.piSupport.currentIssue()) { + if (self.throttled()) { self._showPopup({ title: gettext("Can't update while throttled"), text: gettext("Your system is currently throttled. OctoPrint refuses to run updates while in this state due to possible stability issues."),