Implement delete host
Implemented delete host functionality. Also added test case for delete host. Change-Id: I8265b4f1af7bb61d15d005ee3785895f678f7d10
This commit is contained in:
parent
702d16efd5
commit
4d261dedbf
|
@ -149,3 +149,9 @@ def get_host_list(request, segment_id):
|
|||
"""Returns host list"""
|
||||
query = {}
|
||||
return masakariclient(request).hosts(segment_id, **query)
|
||||
|
||||
|
||||
def delete_host(request, segment_id, host_id):
|
||||
"""delete host"""
|
||||
return masakariclient(request).delete_host(
|
||||
segment_id, host_id, True)
|
||||
|
|
|
@ -13,8 +13,35 @@
|
|||
# limitations under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
from horizon import tables
|
||||
|
||||
from masakaridashboard.api import api
|
||||
|
||||
|
||||
class DeleteHost(tables.DeleteAction):
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Delete Host",
|
||||
u"Delete Host",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Deleted Host",
|
||||
u"Deleted Host",
|
||||
count
|
||||
)
|
||||
|
||||
def delete(self, request, host_id):
|
||||
row_data = eval(host_id)
|
||||
segment_uuid = row_data[1]
|
||||
host_uuid = row_data[0]
|
||||
api.delete_host(request, segment_uuid, host_uuid)
|
||||
|
||||
|
||||
class HostTable(tables.DataTable):
|
||||
|
||||
|
@ -39,3 +66,4 @@ class HostTable(tables.DataTable):
|
|||
class Meta(object):
|
||||
name = "host"
|
||||
verbose_name = _("Host")
|
||||
table_actions = (tables.FilterAction, DeleteHost)
|
||||
|
|
|
@ -121,3 +121,35 @@ 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_delete_ok(self):
|
||||
|
||||
segment = SEGMENT_LIST[0]
|
||||
host = HOST_LIST[0]
|
||||
data = {'object_ids': [(segment.uuid, host.uuid)],
|
||||
'action': 'host__delete'}
|
||||
with mock.patch('masakaridashboard.api.api.segment_list',
|
||||
return_value=SEGMENT_LIST), mock.patch(
|
||||
'masakaridashboard.api.api.get_host_list',
|
||||
return_value=HOST_LIST), mock.patch(
|
||||
'masakaridashboard.api.api.delete_host',
|
||||
return_value=None
|
||||
) as mocked_delete:
|
||||
res = self.client.post(INDEX_URL, data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
mocked_delete.assert_called_once_with(
|
||||
mock.ANY,
|
||||
segment.uuid,
|
||||
host.uuid
|
||||
)
|
||||
|
||||
@mock.patch.object(proxy_obj.Proxy, 'delete_host')
|
||||
def test_delete_host(self, mock_delete_host):
|
||||
mock_delete_host.return_value = None
|
||||
result = api.delete_host(self.request, SEGMENT_LIST[0].uuid,
|
||||
HOST_LIST[0].uuid)
|
||||
self.assertEqual(None, result)
|
||||
mock_delete_host.assert_called_once_with(SEGMENT_LIST[0].uuid,
|
||||
HOST_LIST[0].uuid, True)
|
||||
|
|
Loading…
Reference in New Issue