From 462f2e602b641f29349172f7f5c0ddc28cba3c9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?=
Date: Thu, 18 Jun 2020 13:50:32 +0200
Subject: [PATCH] =?UTF-8?q?=E2=98=82=20SWU:=20Minimum=20free=20storage=20r?=
=?UTF-8?q?equirement?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We now need to have at least 150MB (configurable) of free disk space on
all of site-packages, plugins and temp folder locations available in
order to enable updates.
Closes #2312
---
.../plugins/softwareupdate/__init__.py | 100 ++++++++++++++++--
.../static/js/softwareupdate.js | 18 +++-
.../templates/softwareupdate_settings.jinja2 | 29 ++++-
3 files changed, 136 insertions(+), 11 deletions(-)
diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py
index eab67039c..debb9bd0d 100644
--- a/src/octoprint/plugins/softwareupdate/__init__.py
+++ b/src/octoprint/plugins/softwareupdate/__init__.py
@@ -29,7 +29,7 @@ from octoprint.server.util.flask import no_firstrun_access, with_revalidation_ch
from octoprint.server import VERSION, REVISION, BRANCH
from octoprint.access import USER_GROUP, ADMIN_GROUP
from octoprint.access.permissions import Permissions
-from octoprint.util import dict_merge, to_unicode
+from octoprint.util import dict_merge, to_unicode, get_formatted_size
from octoprint.util.version import get_comparable_version, get_python_version_string
from octoprint.util.pip import LocalPipCaller
import octoprint.settings
@@ -79,6 +79,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._environment_versions = dict()
self._environment_ready = threading.Event()
+ self._storage_sufficient = True
+ self.storage_info = dict()
+
self._console_logger = None
self._get_throttled = lambda: False
@@ -133,6 +136,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
def on_after_startup(self):
self._check_environment()
+ self._check_storage()
self.get_current_versions()
def _get_configured_checks(self):
@@ -220,6 +224,45 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._environment_versions = versions
self._environment_ready.set()
+ def _check_storage(self):
+ import distutils.sysconfig
+ import tempfile
+ import psutil
+
+ storage_info = dict()
+ paths = dict(python=distutils.sysconfig.get_python_lib(),
+ plugins=self._settings.global_get_basefolder("plugins"),
+ temp=tempfile.gettempdir())
+
+ for key, path in paths.items():
+ info = dict(path=path,
+ free=None)
+
+ try:
+ data = psutil.disk_usage(path)
+ info["free"] = data.free
+ except:
+ self._logger.exception("Error while determining disk usage of {}".format(path))
+ continue
+
+ storage_info[key] = info
+
+ if len(storage_info):
+ free_storage = min(*list(map(lambda x: x["free"], storage_info.values())))
+ else:
+ free_storage = None
+
+ self._storage_sufficient = free_storage is None or free_storage >= self._settings.get_int(["minimum_free_storage"]) * 1024 * 1024
+ self._storage_info = storage_info
+
+ self._logger.info("Minimum free storage across all update relevant locations is {}. "
+ "That is considered {} for updating.".format(get_formatted_size(free_storage)
+ if free_storage is not None
+ else "unknown",
+ "sufficient"
+ if self._storage_sufficient
+ else "insufficient"))
+
def _load_version_cache(self):
if not os.path.isfile(self._version_cache_path):
return
@@ -303,7 +346,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
"notify_users": True,
- "ignore_throttled": False
+ "ignore_throttled": False,
+
+ "minimum_free_storage": 150
}
def on_settings_load(self):
@@ -352,7 +397,8 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
def on_settings_save(self, data):
for key in self.get_settings_defaults():
- if key in ("checks", "cache_ttl", "notify_user", "octoprint_checkout_folder", "octoprint_type", "octoprint_release_channel"):
+ if key in ("checks", "cache_ttl", "notify_user", "minimum_free_storage",
+ "octoprint_checkout_folder", "octoprint_type", "octoprint_release_channel"):
continue
if key in data:
self._settings.set([key], data[key])
@@ -364,6 +410,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
if "notify_users" in data:
self._settings.set_boolean(["notify_users"], data["notify_users"])
+ if "minimum_free_storage" in data:
+ self._settings.set_int(["minimum_free_storage"], data["minimum_free_storage"])
+ self._check_storage()
+
defaults = dict(
plugins=dict(softwareupdate=dict(
checks=dict(
@@ -583,13 +633,42 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
try:
information, update_available, update_possible = self.get_current_versions(check_targets=check_targets, force=force)
- return flask.jsonify(dict(status="inProgress" if self._update_in_progress else "updatePossible" if update_available and update_possible and self._environment_supported else "updateAvailable" if update_available else "current",
+
+ storage = list()
+ for key, name in (("python", gettext("Python package installation folder")),
+ ("plugins", gettext("Plugin folder")),
+ ("temp", gettext("System temporary files"))):
+ data = self._storage_info.get(key)
+ if not data:
+ continue
+
+ s = dict(name=name)
+ s.update(**data)
+ storage.append(s)
+
+ status = "current"
+ if self._update_in_progress:
+ status = "inProgress"
+ elif update_available and update_possible and self._environment_supported and self._storage_sufficient:
+ status = "updatePossible"
+ elif update_available:
+ status = "updateAvailable"
+
+ return flask.jsonify(dict(status=status,
information=information,
timestamp=self._version_cache_timestamp,
environment=dict(supported=self._environment_supported,
- versions=[dict(name=gettext("Python"), current=self._environment_versions.get("python", "unknown"), minimum=MINIMUM_PYTHON),
- dict(name=gettext("pip"), current=self._environment_versions.get("pip", "unknown"), minimum=MINIMUM_PIP),
- dict(name=gettext("setuptools"), current=self._environment_versions.get("setuptools", "unknown"), minimum=MINIMUM_SETUPTOOLS)])))
+ versions=[dict(name=gettext("Python"),
+ current=self._environment_versions.get("python", "unknown"),
+ minimum=MINIMUM_PYTHON),
+ dict(name=gettext("pip"),
+ current=self._environment_versions.get("pip", "unknown"),
+ minimum=MINIMUM_PIP),
+ dict(name=gettext("setuptools"),
+ current=self._environment_versions.get("setuptools", "unknown"),
+ minimum=MINIMUM_SETUPTOOLS)]),
+ storage=dict(sufficient=self._storage_sufficient,
+ free=storage)))
except exceptions.ConfigurationInvalid as e:
return flask.make_response("Update not properly configured, can't proceed: %s" % e.message, 500)
@@ -651,6 +730,9 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
if not self._environment_supported:
return flask.make_response("Direct updates are not supported in this Python environment", 409)
+ if not self._storage_sufficient:
+ return flask.make_response("Not enough free disk space for updating", 409)
+
if not "application/json" in flask.request.headers["Content-Type"]:
return flask.make_response("Expected content-type JSON", 400)
@@ -914,6 +996,10 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
self._logger.error("Direct updates are unsupported in this environment")
return [], dict()
+ if not self._storage_sufficient:
+ self._logger.error("Not enough free disk space for updating")
+ return [], dict()
+
targets = kwargs.get("targets", kwargs.get("check_targets", None))
checks = self._get_configured_checks()
diff --git a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js
index d9057556d..da81c859f 100644
--- a/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js
+++ b/src/octoprint/plugins/softwareupdate/static/js/softwareupdate.js
@@ -41,6 +41,9 @@ $(function() {
self.environmentSupported = ko.observable(true);
self.environmentVersions = ko.observableArray([]);
+ self.storageSufficient = ko.observable(true);
+ self.storageFree = ko.observableArray([]);
+
self.cacheTimestamp = ko.observable();
self.cacheTimestampText = ko.pureComputed(function() {
return formatDate(self.cacheTimestamp());
@@ -54,6 +57,7 @@ $(function() {
self.config_checkType = ko.observable();
self.config_releaseChannel = ko.observable();
self.config_pipEnableCheck = ko.observable();
+ self.config_minimumFreeStorage = ko.observable();
self.error_checkoutFolder = ko.pureComputed(function() {
return self.config_checkType() === "git_commit"
@@ -61,7 +65,7 @@ $(function() {
});
self.enableUpdate = ko.pureComputed(function() {
- return !self.updateInProgress && self.environmentSupported() && !self.printerState.isPrinting() && !self.throttled();
+ return !self.updateInProgress && self.environmentSupported() && self.storageSufficient() && !self.printerState.isPrinting() && !self.throttled();
});
self.enable_configSave = ko.pureComputed(function() {
@@ -166,7 +170,8 @@ $(function() {
octoprint_checkout_folder: self.config_checkoutFolder(),
octoprint_tracked_branch: self.config_trackedBranch(),
octoprint_pip_target: self.config_pipTarget(),
- pip_enable_check: self.config_pipEnableCheck()
+ pip_enable_check: self.config_pipEnableCheck(),
+ minimum_free_storage: self.config_minimumFreeStorage()
}
}
};
@@ -205,6 +210,8 @@ $(function() {
self.config_pipTarget(self.settings.settings.plugins.softwareupdate.octoprint_pip_target());
self.config_pipEnableCheck(self.settings.settings.plugins.softwareupdate.pip_enable_check());
+
+ self.config_minimumFreeStorage(self.settings.settings.plugins.softwareupdate.minimum_free_storage());
};
self._copyConfigBack = function() {
@@ -248,6 +255,9 @@ $(function() {
self.environmentSupported(data.environment.supported);
self.environmentVersions(data.environment.versions);
+ self.storageSufficient(data.storage.sufficient);
+ self.storageFree(data.storage.free);
+
if (data.status === "inProgress") {
self._markWorking(gettext("Updating..."), gettext("Updating, please wait."));
return;
@@ -262,7 +272,7 @@ $(function() {
_.each(self.versions.items(), function(update_info) {
if (update_info.updateAvailable) {
text += ""
- + " "
+ + " "
+ "" + update_info.fullNameRemote + " "
+ (update_info.releaseNotes ? "" + gettext("Release Notes") + " " : "")
+ " ";
@@ -272,6 +282,8 @@ $(function() {
if (!self.environmentSupported()) {
text += "" + gettext("This version of the Python environment is not supported for direct updates.") + "
";
+ } else if (!self.storageSufficient()) {
+ text += "" + gettext("There's currently not enough free disk space available for a direct update.") + "
";
} else {
text += "" + gettext("Those components marked with can be updated directly.") + "
";
}
diff --git a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2 b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2
index f743f749e..63996cb8f 100644
--- a/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2
+++ b/src/octoprint/plugins/softwareupdate/templates/softwareupdate_settings.jinja2
@@ -32,6 +32,23 @@
Please take a look at this FAQ entry on how to proceed .
{% endtrans %}
+{% trans min_free_storage='
' %}
+
+ There is not enough free disk space available to run an update.
+
+
+ To reduce the likelihood of running into update problems due to insuffient disk space, OctoPrint requires
+ a minimum of {{ min_free_storage }} free disk space in various locations:
+
+{% endtrans %}
+
+{% trans %}
+
+ Please take a look at this FAQ entry on how to proceed .
+
+{% endtrans %}
{% trans %}
OctoPrint is running on a throttled system, updates are disabled.
@@ -110,7 +127,7 @@
{{ _('Version cache TTL') }}
@@ -123,6 +140,16 @@
+
+
{{ _('Minimum free disk space') }}
+
+
+
+ MB
+ {{ _('The minimum amount of free disk space that has to be available on various locations for OctoPrint to allow updates. Should not be set to 0.') }}
+
+
+