Merge remote-tracking branch 'sunil/diagnostics'

This commit is contained in:
James Valleroy 2015-08-10 18:02:33 -04:00
commit 2879c9cedb
7 changed files with 108 additions and 7 deletions

View File

@ -121,6 +121,17 @@ remove_user_from_group()
}
diagnose()
{
result="failed"
if lsldap | grep 'dn: dc=thisbox' > /dev/null; then
result="passed"
fi
echo "[[\"Access LDAP server locally\", \"$result\"]]"
}
setup()
{
# XXX: Password setting on users is disabled as changing passwords
@ -163,6 +174,9 @@ case $command in
remove-user-from-group)
remove_user_from_group "$@"
;;
diagnose)
diagnose "$@"
;;
*)
echo "Invalid sub-command"
exit -1

View File

@ -144,14 +144,14 @@ def get_modules_to_load():
module_directory = os.path.join(cfg.config_dir, 'modules-enabled')
# Omit hidden files
file_names = [file
for file in os.listdir(module_directory)
if not file.startswith('.') and '.dpkg' not in file]
file_names = [file_name
for file_name in os.listdir(module_directory)
if not file_name.startswith('.') and '.dpkg' not in file_name]
for file_name in file_names:
full_file_name = os.path.join(module_directory, file_name)
with open(full_file_name, 'r') as file:
for line in file:
with open(full_file_name, 'r') as file_handle:
for line in file_handle:
line = re.sub('#.*', '', line)
line = line.strip()
if line:

View File

@ -19,11 +19,14 @@
Plinth module for running diagnostics
"""
from django.http import Http404
from django.template.response import TemplateResponse
from gettext import gettext as _
import importlib
from plinth import actions
from plinth import cfg
from plinth import module_loader
from plinth.errors import ActionError
@ -55,3 +58,24 @@ def test(request):
{'title': _('Diagnostic Test'),
'diagnostics_output': output,
'diagnostics_error': error})
def module(request, module_name):
"""Return diagnostics for a particular module."""
found = False
for module_import_path in module_loader.loaded_modules:
if module_name == module_import_path.split('.')[-1]:
found = True
break
if not found:
raise Http404('Module does not exist or not loaded')
loaded_module = importlib.import_module(module_import_path)
results = []
if hasattr(loaded_module, 'diagnose'):
results = loaded_module.diagnose()
return TemplateResponse(request, 'diagnostics_module.html',
{'title': _('Diagnostic Test'),
'module_name': module_name,
'results': results})

View File

@ -0,0 +1,52 @@
{% extends 'base.html' %}
{% comment %}
#
# This file is part of Plinth.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
{% endcomment %}
{% block content %}
<h2>Diagnostic Results</h2>
<h3>Module: {{ module_name }}</h3>
{% if results %}
<div class="row">
<div class="col-sm-3">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Test</th>
<th>Result</th>
</tr>
</thead>
<tbody>
{% for test, result in results %}
<tr>
<td>{{ test }}</td>
<td>{{ result }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% else %}
<p>This module does not support diagnostics</p>
{% endif %}
{% endblock %}

View File

@ -26,4 +26,6 @@ urlpatterns = patterns( # pylint: disable-msg=C0103
'plinth.modules.diagnostics.diagnostics',
url(r'^sys/diagnostics/$', 'index', name='index'),
url(r'^sys/diagnostics/test/$', 'test', name='test'),
url(r'^sys/diagnostics/module/(?P<module_name>[a-z\-]+)/$', 'module',
name='module'),
)

View File

@ -20,10 +20,10 @@ Plinth module to manage users
"""
from gettext import gettext as _
import json
from plinth import cfg
__all__ = ['init']
from plinth import actions
depends = ['plinth.modules.system']
@ -33,3 +33,9 @@ def init():
menu = cfg.main_menu.get('system:index')
menu.add_urlname(_('Users and Groups'), 'glyphicon-user', 'users:index',
15)
def diagnose():
"""Run diagnostics and result the results."""
output = actions.superuser_run('ldap', ['diagnose'])
return json.loads(output)

View File

@ -59,6 +59,9 @@
</div>
{% endfor %}
</div>
<a href="{% url 'diagnostics:module' 'users' %}"
class="btn btn-default">Run Diagnostics</a>
</div>
</div>