Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
admin: added healing page.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsmedina committed Oct 31, 2014
1 parent 28c5aec commit 89d226e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
5 changes: 5 additions & 0 deletions abyss/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<span>Deploys</span>
</a>
</li>
<li{% if active == "healing" %} class="active"{% endif %}>
<a href="{% url 'list-healing' %}">
<span>Healing</span>
</a>
</li>
{% endif %}
</div>
</div> <!-- /container-user -->
Expand Down
38 changes: 38 additions & 0 deletions admin/templates/docker/list_healing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "base.html" %}

{% block sidebar %}
{% include "sidebar.html" with active="healing" %}
{% endblock %}

{% block header %}
<h1>Admin/Healing</h1>
{% endblock %}

{% block content %}
<div class="container-fluid">
<div class="row-fluid">
<div class="span11">
<table class="table">
<tr>
<th>Start</th>
<th>Finish</th>
<th>Success</th>
<th>Failing</th>
<th>Created</th>
<th>Error</th>
</tr>
{% for event in events %}
<tr>
<td>{{ event.StartTime }}</td>
<td>{{ event.EndTime }}</td>
<td>{{ event.Succefull }}</td>
<td>{% if event.FailingNode.Address %}{{ event.FailingNode.Address }}{% else %}{{ event.FailingContainer.ID }}{% endif %}</td>
<td>{% if event.CreatedNode.Address %}{{ event.CreatedNode.Address }}{% else %}{{ event.CreatedContainer.ID }}{% endif %}</td>
<td>{{ event.Error }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% endblock %}
27 changes: 27 additions & 0 deletions admin/tests/test_list_healing_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from mock import patch, Mock

from django.conf import settings
from django.test import TestCase
from django.test.client import RequestFactory

from admin.views import ListHealing


class ListHealingViewTest(TestCase):
def setUp(self):
self.request = RequestFactory().get("/")
self.request.session = {"tsuru_token": "admin"}

@patch("requests.get")
def test_should_use_list_template(self, get):
response_mock = Mock()
response_mock.json.return_value = []
get.return_value = response_mock
response = ListHealing.as_view()(self.request)
self.assertEqual("docker/list_healing.html", response.template_name)
expected = []
self.assertListEqual(expected, response.context_data["events"])
get.assert_called_with(
"{0}/docker/healing".format(settings.TSURU_HOST),
headers={"authorization": "admin"}
)
1 change: 1 addition & 0 deletions admin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
urlpatterns = patterns(
'',
url(r'^$', views.ListNode.as_view(), name='list-node'),
url(r'^healing/$', views.ListHealing.as_view(), name='list-healing'),
url(r'^(?P<address>[http://\w.:1-9-]+)/containers/$', views.ListContainer.as_view(),
name='list-container'),
url(r'^deploys/$', views.ListDeploy.as_view(), name='list-deploys'),
Expand Down
12 changes: 12 additions & 0 deletions admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ def get(self, request, *args, **kwargs):
diff_output = highlight(context["deploy"]["Diff"], DiffLexer(), format)
context["deploy"]["Diff"] = diff_output
return TemplateResponse(request, "deploys/deploy_details.html", context)


class ListHealing(LoginRequiredView):
@property
def authorization(self):
return {'authorization': self.request.session.get('tsuru_token')}

def get(self, request):
url = '{}/docker/healing'.format(settings.TSURU_HOST)
response = requests.get(url, headers=self.authorization)
events = response.json()
return TemplateResponse(request, "docker/list_healing.html", {"events": events})

0 comments on commit 89d226e

Please sign in to comment.