Implement host detail

Implemented host detail functionality.
Also Added test case for host detail.

Change-Id: I7e62e4a2b1e15ddeb2a592670518d8358f4a6b1c
This commit is contained in:
nirajsingh 2018-01-30 17:46:17 +05:30
parent 702d16efd5
commit 46c6479961
7 changed files with 144 additions and 2 deletions

View File

@ -149,3 +149,8 @@ def get_host_list(request, segment_id):
"""Returns host list"""
query = {}
return masakariclient(request).hosts(segment_id, **query)
def get_host(request, segment_id, host_id):
"""return single host """
return masakariclient(request).get_host(segment_id, host_id)

View File

@ -18,8 +18,10 @@ from horizon import tables
class HostTable(tables.DataTable):
name = tables.Column('name', verbose_name=_("Name"))
uuid = tables.Column('uuid', verbose_name=_("UUID"))
name = tables.Column('name', verbose_name=_("Name"),
link="horizon:masakaridashboard:hosts:detail")
uuid = tables.Column('uuid', verbose_name=_("UUID"),
link="horizon:masakaridashboard:hosts:detail")
reserved = tables.Column(
'reserved', verbose_name=_("Reserved"))
type = tables.Column(

View File

@ -0,0 +1,32 @@
<span class="masakari-wrapper detail-screen">
{% extends 'masakaridashboard/default/base.html' %}
{% load i18n %}
{% block title %}{% trans "Host Detail" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Host Detail") %}
{% endblock page_header %}
{% block main %}
{% load i18n sizeformat parse_date %}
<div class="detail">
<h4>{% trans "Host Detail" %}</h4>
<hr class="header_rule">
<dl class="dl-horizontal">
<dt>{% trans "UUID" %}</dt>
<dd>{{ host.uuid }}</dd>
<dt>{% trans "Name" %}</dt>
<dd>{{ host.name }}</dd>
<dt>{% trans "Reserved" %}</dt>
<dd>{{ host.reserved }}</dd>
<dt>{% trans "Type" %}</dt>
<dd>{{ host.type }}</dd>
<dt>{% trans "Control Attribute" %}</dt>
<dd>{{ host.control_attributes }}</dd>
<dt>{% trans "On Maintenance" %}</dt>
<dd>{{ host.on_maintenance }}</dd>
<dt>{% trans "Failover Segment" %}</dt>
<dd>{{ host.failover_segment_id }}</dd>
</dl>
</div>
{% endblock %}
</span>

View File

@ -17,6 +17,8 @@ from django.conf.urls import url
from masakaridashboard.hosts import views
HOST = r'^(?P<host_id>[^/]+)/%s$'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(HOST % 'detail', views.DetailView.as_view(), name='detail'),
]

View File

@ -12,6 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.views import generic
from horizon import exceptions
from horizon import tables
from masakaridashboard.api import api
@ -38,3 +43,34 @@ class IndexView(tables.DataTableView):
pass
return host_list
class DetailView(generic.TemplateView):
template_name = 'masakaridashboard/hosts/detail.html'
page_title = _("Host Detail")
def get_context_data(self, **kwargs):
context = super(DetailView, self).get_context_data(**kwargs)
host = self.get_data(self.request, **kwargs)
breadcrumb = [(host.uuid, reverse(
'horizon:masakaridashboard:hosts:detail',
args=[host.uuid]
))]
context["custom_breadcrumb"] = breadcrumb
context['host'] = host
return context
def get_data(self, request, **kwargs):
try:
row_data = eval(kwargs['host_id'])
segment_id = row_data[1]
host_id = row_data[0]
host = api.get_host(request, segment_id, host_id)
except Exception:
msg = _('Unable to get host "%s".') % ""
redirect = reverse('horizon:masakaridashboard:hosts:index')
exceptions.handle(self.request, msg, redirect=redirect)
return host

View File

@ -0,0 +1,46 @@
# Copyright (c) 2018 NTT DATA
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.utils.translation import ugettext_lazy as _
from horizon import tabs
from masakaridashboard.api import api
from masakaridashboard.hosts import tables as host_table
class HostTab(tabs.TableTab):
table_classes = (host_table.HostTable,)
name = _("Host")
slug = "host_tab"
template_name = "horizon/common/_detail_table.html"
preload = False
def get_host_data(self):
segment_id = self.tab_group.kwargs['segment_id']
host_list = []
host_gen = api.get_host_list(self.request, segment_id)
try:
for item in host_gen:
host_list.append(item)
except StopIteration:
pass
return host_list
class segmentDetailTabs(tabs.DetailTabsGroup):
slug = "segment_details"
tabs = (HostTab,)

View File

@ -39,10 +39,14 @@ HYPERVISOR_LIST = [
Hypervisor(HypervisorManager, {'id': '1',
'hypervisor_hostname': "test"})]
id_to_update = HOST_LIST[0].uuid+','+HOST_LIST[0].failover_segment_id
INDEX_URL = reverse('horizon:masakaridashboard:hosts:index')
INDEX_URL_SEGMENT = reverse('horizon:masakaridashboard:segment:index')
CREATE_URL = reverse('horizon:masakaridashboard:segment:addhost',
args=[SEGMENT_LIST[0].uuid])
DETAIL_URL = reverse('horizon:masakaridashboard:hosts:detail',
args=[id_to_update])
class HostTest(test.TestCase):
@ -121,3 +125,18 @@ class HostTest(test.TestCase):
result = api.get_host_list(self.request, SEGMENT_LIST[0].uuid)
self.assertEqual(HOST_LIST, result)
mock_hosts.assert_called_once_with(SEGMENT_LIST[0].uuid)
def test_detail(self):
with mock.patch('masakaridashboard.api.api.get_host',
return_value=HOST_LIST[0]):
res = self.client.get(DETAIL_URL)
self.assertTemplateUsed(res, 'masakaridashboard/hosts/detail.html')
@mock.patch.object(proxy_obj.Proxy, 'get_host')
def test_get_host(self, mock_get_host):
mock_get_host.return_value = HOST_LIST[0]
result = api.get_host(self.request, SEGMENT_LIST[0].uuid,
HOST_LIST[0].uuid)
self.assertEqual(HOST_LIST[0], result)
mock_get_host.assert_called_once_with(SEGMENT_LIST[0].uuid,
HOST_LIST[0].uuid)