☂ SWU: Minimum free storage requirement
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
This commit is contained in:
1 parent
7290a6d350
commit
462f2e602b
3 files changed
+136
-11
No files matched your search
@@ -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()
|
||||
|
||||
@@ -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 += "<li>"
|
||||
+ "<i class='fa fa-li " + (update_info.updatePossible && self.environmentSupported() ? "fa-check" : "fa-remove")+ "'></i>"
|
||||
+ "<i class='fa fa-li " + (update_info.updatePossible && self.environmentSupported() && self.storageSufficient() ? "fa-check" : "fa-remove")+ "'></i>"
|
||||
+ "<span class='name' title='" + update_info.fullNameRemote + "'>" + update_info.fullNameRemote + "</span>"
|
||||
+ (update_info.releaseNotes ? "<a href=\"" + update_info.releaseNotes + "\" target=\"_blank\">" + gettext("Release Notes") + "</a>" : "")
|
||||
+ "</li>";
|
||||
@@ -272,6 +282,8 @@ $(function() {
|
||||
|
||||
if (!self.environmentSupported()) {
|
||||
text += "<p><small>" + gettext("This version of the Python environment is not supported for direct updates.") + "</small></p>";
|
||||
} else if (!self.storageSufficient()) {
|
||||
text += "<p><small>" + gettext("There's currently not enough free disk space available for a direct update.") + "</small></p>";
|
||||
} else {
|
||||
text += "<p><small>" + gettext("Those components marked with <i class=\"fa fa-check\"></i> can be updated directly.") + "</small></p>";
|
||||
}
|
||||
|
||||
@@ -32,6 +32,23 @@
|
||||
Please take a look at <a href="https://faq.octoprint.org/unsupported-python-environment" target="_blank">this FAQ entry on how to proceed</a>.
|
||||
</p>
|
||||
{% endtrans %}</div>
|
||||
<div class="alert" data-bind="visible: !storageSufficient()">{% trans min_free_storage='<strong data-bind="text: formatSize(settings.settings.plugins.softwareupdate.minimum_free_storage() * 1024 * 1024)"></strong>' %}
|
||||
<p>
|
||||
<strong>There is not enough free disk space available to run an update.</strong>
|
||||
</p>
|
||||
<p>
|
||||
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:
|
||||
</p>
|
||||
{% endtrans %}
|
||||
<ul data-bind="foreach: storageFree">
|
||||
<li><span data-bind="text: name"></span> (<span data-bind="text: path"></span>): <span data-bind="text: formatSize($data.free)"></span> free</li>
|
||||
</ul>
|
||||
{% trans %}
|
||||
<p>
|
||||
Please take a look at <a href="https://faq.octoprint.org/insuffienct-disk-space" target="_blank">this FAQ entry on how to proceed</a>.
|
||||
</p>
|
||||
{% endtrans %}</div>
|
||||
<div class="alert" data-bind="visible: throttled()">{% trans %}
|
||||
<p>
|
||||
<strong>OctoPrint is running on a throttled system, updates are disabled.</strong>
|
||||
@@ -110,7 +127,7 @@
|
||||
<label class="control-label">{{ _('Version cache TTL') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" class="input-mini" data-bind="value: config_cacheTtl">
|
||||
<input type="number" class="input-small" data-bind="value: config_cacheTtl">
|
||||
<span class="add-on">min</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -123,6 +140,16 @@
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label">{{ _('Minimum free disk space') }}</label>
|
||||
<div class="controls">
|
||||
<div class="input-append">
|
||||
<input type="number" class="input-small" data-bind="value: config_minimumFreeStorage">
|
||||
<span class="add-on">MB</span>
|
||||
<span class="help-block">{{ _('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.') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
Reference in new issue
Block a user