Skip to content

Commit

Permalink
Add fix instructions to Tilt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thorrak authored Apr 11, 2020
2 parents 4fc3038 + 754b449 commit 6b21f8f
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 10 deletions.
6 changes: 6 additions & 0 deletions app/templates/github_trigger_upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ <h4>Remote Commit Info:</h4>

{% endif %}

<p>Need to manually refresh the Python packages without upgrading? Click the below to trigger a refresh without pulling
new code from GitHub</p>
<p>
<a href="{% url "trigger_requirements_reload" %}" class="btn btn-primary">Update/Install Missing Python Packages</a>
</p>

{% if allow_git_branch_switching %}

<h3>Switch Branch</h3>
Expand Down
30 changes: 30 additions & 0 deletions app/templates/trigger_requirements_reload.html
Original file line number Diff line number Diff line change
@@ -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 %}
<h1>Reload Python Requirements</h1>

<p>
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.
</p>

<p>
Once complete, you can view the <a href="{% url "get_app_log" "text" "upgrade" "stderr" %}">upgrade log</a> to see
what was installed/updated.
</p>


{% endblock %}



{% block scripts %}
{% endblock %}
14 changes: 14 additions & 0 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion docs/source/gravitysensors/tilt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 'Update/Install Missing Python Packages' button


1 change: 1 addition & 0 deletions fermentrack_django/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
6 changes: 5 additions & 1 deletion gravity/templates/gravity/gravity_manage_tilt.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ <h2>Extra Data from Device</h2>

<h2>Troubleshoot Tilt Connection</h2>

<p>If you are having difficulty getting/keeping your Tilt connected, <a href="{% url "gravity_tilt_test" %}">click here</a> to debug the connection.</p>
<p>If you are having difficulty getting/keeping your Bluetooth Tilt connected, click the button below to launch the Tilt test script.</p>

<p>
<a href="{% url "gravity_tilt_test" %}" class="btn btn-primary">Troubleshoot Tilt Connection</a>
</p>

{% endif %}

Expand Down
57 changes: 49 additions & 8 deletions gravity/templates/gravity/gravity_tilt_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ <h4 style="color: darkred">Several system packages are missing. </h4>

<table class="table table-hover">
<tr>
<td>Package Name</td>
<td>OK?</td>
<th>Package Name</th>
<th>OK?</th>
</tr>

{% for test_result in apt_test_results %}
Expand All @@ -37,6 +37,19 @@ <h4 style="color: darkred">Several system packages are missing. </h4>
{% endfor %}

</table>

{% if not has_apt_packages %}
<h5 style="color: darkred">NOTE - Fix the above errors first and then re-run the tests before proceeding</h5>

<p>
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 <a href="http://docs.fermentrack.com/en/dev/gravitysensors/tilt.html#fixing-missing-system-packages">Fermentrack documentation.</a>
</p>
{% endif %}{# has_apt_packages #}


{% else %}
<h4>Unable to locate the software necessary to check system packages</h4>
<p>
Expand All @@ -46,6 +59,8 @@ <h4>Unable to locate the software necessary to check system packages</h4>
{% endif %}{# has_apt #}




<h3>Python Packages</h3>

<p>
Expand All @@ -72,10 +87,10 @@ <h4 style="color: darkred">Several python packages are missing. </h4>

<table class="table table-hover">
<tr>
<td>Package Name</td>
<td>Required Version</td>
<td>Installed Version</td>
<td>OK?</td>
<th>Package Name</th>
<th>Required Version</th>
<th>Installed Version</th>
<th>OK?</th>
</tr>

{% for test_result in python_test_results %}
Expand All @@ -87,11 +102,37 @@ <h4 style="color: darkred">Several python packages are missing. </h4>
</tr>
{% endfor %}
</table>

{% if not has_python_packages %}

<p>
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
<a href="{% url "get_app_log" "text" "upgrade" "stderr" %}">upgrade log</a> to see what is happening.
</p>

<p>
<a href="{% url "trigger_requirements_reload" %}" class="btn btn-primary">Update/Install Missing Python Packages</a>
</p>
{% endif %}

{% else %}
<h4>Python 'packaging' module is not available - Test cannot run!</h4>
<h4 style="color: darkred">Python 'packaging' module is not available - Test cannot run!</h4>
<p>
This is a fairly serious error, as it implies that your python packages are not being kept up-to-date.
Check the <a href="{% url "get_app_log" "text" "upgrade" "stderr" %}">upgrade log</a> 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
<a href="{% url "get_app_log" "text" "upgrade" "stderr" %}">upgrade log</a> to see what is happening.
</p>
<p>
<a href="{% url "trigger_requirements_reload" %}" class="btn btn-primary">Update/Install Missing Python Packages</a>
</p>

{% endif %}
Expand Down
73 changes: 73 additions & 0 deletions utils/fix_python_requirements.sh
Original file line number Diff line number Diff line change
@@ -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!"

0 comments on commit 6b21f8f

Please sign in to comment.