From 52d2e020dd223caa883e72ac3340e3fbc2c5ab43 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 10 Apr 2020 21:53:21 -0400 Subject: [PATCH 1/2] Create fix_python_requirements script & add links from the Tilt test workflow --- app/templates/github_trigger_upgrade.html | 6 ++ .../trigger_requirements_reload.html | 30 ++++++++ app/views.py | 14 ++++ docs/source/gravitysensors/tilt.rst | 7 +- fermentrack_django/urls.py | 1 + .../templates/gravity/gravity_tilt_test.html | 42 +++++++++-- utils/fix_python_requirements.sh | 73 +++++++++++++++++++ 7 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 app/templates/trigger_requirements_reload.html create mode 100755 utils/fix_python_requirements.sh diff --git a/app/templates/github_trigger_upgrade.html b/app/templates/github_trigger_upgrade.html index f5226ecc..850ddc36 100644 --- a/app/templates/github_trigger_upgrade.html +++ b/app/templates/github_trigger_upgrade.html @@ -74,6 +74,12 @@

Remote Commit Info:

{% endif %} +

Need to manually refresh the Python packages without upgrading? Click the below to trigger a refresh without pulling + new code from GitHub

+

+ Refresh Python Packages +

+ {% if allow_git_branch_switching %}

Switch Branch

diff --git a/app/templates/trigger_requirements_reload.html b/app/templates/trigger_requirements_reload.html new file mode 100644 index 00000000..d91f6f3b --- /dev/null +++ b/app/templates/trigger_requirements_reload.html @@ -0,0 +1,30 @@ +{% extends "sitewide/flat_ui_template.html" %} +{% load custom_tags %} +{% load static %} + +{% block title %}Reload Python Requirements{% endblock %} + +{% block header_scripts %} +{% endblock %} + + +{% block content %} +

Reload Python Requirements

+ +

+ You have triggered a manual reload of the Python packages required by Fermentrack. Please wait several minutes + for this refresh to complete and for Fermentrack to relaunch before proceeding. +

+ +

+ Once complete, you can view the upgrade log to see + what was installed/updated. +

+ + +{% endblock %} + + + +{% block scripts %} +{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index 72a4d797..e5b1460e 100644 --- a/app/views.py +++ b/app/views.py @@ -540,6 +540,20 @@ def github_trigger_force_upgrade(request): +@login_required +@site_is_configured +def trigger_requirements_reload(request): + # TODO - Add permission check here + + # All that this view does is trigger the utils/fix_python_requirements.sh shell script and return a message letting + # the user know that Fermentrack will take a few minutes to restart. + cmd = "nohup utils/fix_python_requirements.sh &" + messages.success(request, "Triggered a reload of your Python packages") + subprocess.call(cmd, shell=True) + + return render(request, template_name="trigger_requirements_reload.html", context={}) + + def login(request, next=None): if not next: if 'next' in request.GET: diff --git a/docs/source/gravitysensors/tilt.rst b/docs/source/gravitysensors/tilt.rst index d811bfd8..e0333c16 100644 --- a/docs/source/gravitysensors/tilt.rst +++ b/docs/source/gravitysensors/tilt.rst @@ -103,7 +103,12 @@ Although all Python packages should be automatically installed as part of the in packages come out of sync for a variety of reasons. If you are missing packages they will need to be installed for Fermentrack to properly interface with your Tilt. -.. todo:: Enrich this with steps for resolving missing Python packages +A manual refresh of the Python packages can be triggered from the GitHub upgrade page without updating Fermentrack from +GitHub. To trigger a refresh: +#. Log into Fermentrack +#. Click the 'gear' icon in the upper right hand corner of the page +#. Click 'Update from GitHub' +#. Click the 'Refresh Python Packages' button diff --git a/fermentrack_django/urls.py b/fermentrack_django/urls.py index 48477ad5..e6fa7ac0 100644 --- a/fermentrack_django/urls.py +++ b/fermentrack_django/urls.py @@ -31,6 +31,7 @@ url(r'^upgrade/$', app.views.github_trigger_upgrade, name='github_trigger_upgrade'), url(r'^upgrade/force/$', app.views.github_trigger_force_upgrade, name='github_trigger_force_upgrade'), + url(r'^upgrade/reload/$', app.views.trigger_requirements_reload, name='trigger_requirements_reload'), ### Device Views url(r'^devices/$', app.views.device_lcd_list, name='device_lcd_list'), diff --git a/gravity/templates/gravity/gravity_tilt_test.html b/gravity/templates/gravity/gravity_tilt_test.html index 394900ab..6e0b5ffa 100644 --- a/gravity/templates/gravity/gravity_tilt_test.html +++ b/gravity/templates/gravity/gravity_tilt_test.html @@ -25,8 +25,8 @@

Several system packages are missing.

- - + + {% for test_result in apt_test_results %} @@ -37,6 +37,19 @@

Several system packages are missing.

{% endfor %}
Package NameOK?Package NameOK?
+ + {% if not has_apt_packages %} +
NOTE - Fix the above errors first and then re-run the tests before proceeding
+ +

+ Several of the system packages listed above are required for all of the Python packages to install. If you + do not first install the missing system packages you may be unable to fix other errors that appear on this + page. Thankfully, installing these missing packages is pretty simple. Information on how to resolve this + can be found in the Fermentrack documentation. +

+ {% endif %}{# has_apt_packages #} + + {% else %}

Unable to locate the software necessary to check system packages

@@ -46,6 +59,8 @@

Unable to locate the software necessary to check system packages

{% endif %}{# has_apt #} + +

Python Packages

@@ -72,10 +87,10 @@

Several python packages are missing.

- - - - + + + + {% for test_result in python_test_results %} @@ -87,11 +102,24 @@

Several python packages are missing.

{% endfor %}
Package NameRequired VersionInstalled VersionOK?Package NameRequired VersionInstalled VersionOK?
+ + {% if not has_python_packages %} +

+ Refresh Python Packages +

+ {% endif %} + {% else %}

Python 'packaging' module is not available - Test cannot run!

This is a fairly serious error, as it implies that your python packages are not being kept up-to-date. - Check the upgrade log to see what is happening. + If there are missing system packages (above) resolve those before proceeding. Next, attempt a + manual refresh (below) of the Python requirements to see if the 'packaging' module can be installed. If + neither of these resolve this issue, check the + upgrade log to see what is happening. +

+

+ Refresh Python Packages

{% endif %} diff --git a/utils/fix_python_requirements.sh b/utils/fix_python_requirements.sh new file mode 100755 index 00000000..51ef6349 --- /dev/null +++ b/utils/fix_python_requirements.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# Defaults +SILENT=0 +CIRCUSCTL="python3 -m circus.circusctl --timeout 10" + +# Colors (for printinfo/error/warn below) +green=$(tput setaf 76) +red=$(tput setaf 1) +tan=$(tput setaf 3) +reset=$(tput sgr0) + + + +printinfo() { + if [ ${SILENT} -eq 0 ] + then + printf "::: ${green}%s${reset}\n" "$@" + fi +} + + +printwarn() { + if [ ${SILENT} -eq 0 ] + then + printf "${tan}*** WARNING: %s${reset}\n" "$@" + fi +} + + +printerror() { + if [ ${SILENT} -eq 0 ] + then + printf "${red}*** ERROR: %s${reset}\n" "$@" + fi +} + + + +exec > >(tee -i log/upgrade.log) + + +printinfo "Re-installing Python packages from requirements.txt" +# First, launch the virtualenv +source ~/venv/bin/activate # Assuming the directory based on a normal install with Fermentrack-tools + +# Given that this script can be called by the webapp proper, give it 2 seconds to finish sending a reply to the +# user if he/she initiated an upgrade through the webapp. +printinfo "Waiting 1 second for Fermentrack to send updates if triggered from the web..." +sleep 1s + +# Next, kill the running Fermentrack instance using circus +printinfo "Stopping circus..." +$CIRCUSCTL stop &>> log/upgrade.log + +# Install everything from requirements.txt +printinfo "Updating requirements via pip3..." +pip3 install -U -r requirements.txt --upgrade &>> log/upgrade.log + +# Migrate to create/adjust anything necessary in the database +printinfo "Running manage.py migrate..." +python3 manage.py migrate &>> log/upgrade.log + +# Migrate to create/adjust anything necessary in the database +printinfo "Running manage.py collectstatic..." +python3 manage.py collectstatic --noinput >> /dev/null + + +# Finally, relaunch the Fermentrack instance using circus +printinfo "Relaunching circus..." +$CIRCUSCTL reloadconfig &>> log/upgrade.log +$CIRCUSCTL start &>> log/upgrade.log +printinfo "Complete!" From 754b4499b7d77d0c6bc275ff67454b2030903604 Mon Sep 17 00:00:00 2001 From: Thorrak Date: Fri, 10 Apr 2020 22:08:01 -0400 Subject: [PATCH 2/2] Update text --- app/templates/github_trigger_upgrade.html | 2 +- docs/source/gravitysensors/tilt.rst | 2 +- .../gravity/gravity_manage_tilt.html | 6 +++++- .../templates/gravity/gravity_tilt_test.html | 19 ++++++++++++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/templates/github_trigger_upgrade.html b/app/templates/github_trigger_upgrade.html index 850ddc36..fc6bbf0d 100644 --- a/app/templates/github_trigger_upgrade.html +++ b/app/templates/github_trigger_upgrade.html @@ -77,7 +77,7 @@

Remote Commit Info:

Need to manually refresh the Python packages without upgrading? Click the below to trigger a refresh without pulling new code from GitHub

- Refresh Python Packages + Update/Install Missing Python Packages

{% if allow_git_branch_switching %} diff --git a/docs/source/gravitysensors/tilt.rst b/docs/source/gravitysensors/tilt.rst index e0333c16..f95fbfc1 100644 --- a/docs/source/gravitysensors/tilt.rst +++ b/docs/source/gravitysensors/tilt.rst @@ -109,6 +109,6 @@ GitHub. To trigger a refresh: #. Log into Fermentrack #. Click the 'gear' icon in the upper right hand corner of the page #. Click 'Update from GitHub' -#. Click the 'Refresh Python Packages' button +#. Click the 'Update/Install Missing Python Packages' button diff --git a/gravity/templates/gravity/gravity_manage_tilt.html b/gravity/templates/gravity/gravity_manage_tilt.html index 6907e050..f0f4a2f1 100644 --- a/gravity/templates/gravity/gravity_manage_tilt.html +++ b/gravity/templates/gravity/gravity_manage_tilt.html @@ -143,7 +143,11 @@

Extra Data from Device

Troubleshoot Tilt Connection

-

If you are having difficulty getting/keeping your Tilt connected, click here to debug the connection.

+

If you are having difficulty getting/keeping your Bluetooth Tilt connected, click the button below to launch the Tilt test script.

+ +

+ Troubleshoot Tilt Connection +

{% endif %} diff --git a/gravity/templates/gravity/gravity_tilt_test.html b/gravity/templates/gravity/gravity_tilt_test.html index 6e0b5ffa..433aca3a 100644 --- a/gravity/templates/gravity/gravity_tilt_test.html +++ b/gravity/templates/gravity/gravity_tilt_test.html @@ -104,13 +104,26 @@

Several python packages are missing.

{% if not has_python_packages %} + +

+ One or more of the Python packages required for Fermentrack's Tilt support to function are either + missing or at an incorrect version. + {% if not has_apt_packages %} + This may be caused by missing system packages. Before proceeding, please ensure that all required + system packages (see the earlier test) are installed. + {% endif %} + The easiest way to resolve this is to trigger a manual refresh of the Python requirements. To do this, + click the button below. If this does not resolve your missing packages check the + upgrade log to see what is happening. +

+

- Refresh Python Packages + Update/Install Missing Python Packages

{% endif %} {% else %} -

Python 'packaging' module is not available - Test cannot run!

+

Python 'packaging' module is not available - Test cannot run!

This is a fairly serious error, as it implies that your python packages are not being kept up-to-date. If there are missing system packages (above) resolve those before proceeding. Next, attempt a @@ -119,7 +132,7 @@

Python 'packaging' module is not available - Test cannot run!

upgrade log to see what is happening.

- Refresh Python Packages + Update/Install Missing Python Packages

{% endif %}