Merge "Support a host delete operation"
This commit is contained in:
commit
2783ed798f
|
@ -116,3 +116,8 @@ def host_get(request, host_id):
|
|||
"""Get a host."""
|
||||
host = blazarclient(request).host.get(host_id)
|
||||
return Host(host)
|
||||
|
||||
|
||||
def host_delete(request, host_id):
|
||||
"""Delete a host."""
|
||||
blazarclient(request).host.delete(host_id)
|
||||
|
|
|
@ -11,9 +11,38 @@
|
|||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
from horizon import tables
|
||||
from horizon.templatetags import sizeformat
|
||||
|
||||
from blazar_dashboard import api
|
||||
|
||||
|
||||
class DeleteHost(tables.DeleteAction):
|
||||
name = "delete"
|
||||
data_type_singular = _("Host")
|
||||
data_type_plural = _("Hosts")
|
||||
classes = ('btn-danger', 'btn-terminate')
|
||||
|
||||
@staticmethod
|
||||
def action_present(count):
|
||||
return ungettext_lazy(
|
||||
u"Delete Host",
|
||||
u"Delete Hosts",
|
||||
count
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def action_past(count):
|
||||
return ungettext_lazy(
|
||||
u"Deleted Host",
|
||||
u"Deleted Hosts",
|
||||
count
|
||||
)
|
||||
|
||||
def delete(self, request, host_id):
|
||||
api.client.host_delete(request, host_id)
|
||||
|
||||
|
||||
class HostsTable(tables.DataTable):
|
||||
name = tables.Column("hypervisor_hostname", verbose_name=_("Host name"),
|
||||
|
@ -28,3 +57,5 @@ class HostsTable(tables.DataTable):
|
|||
class Meta(object):
|
||||
name = "hosts"
|
||||
verbose_name = _("Hosts")
|
||||
table_actions = (DeleteHost,)
|
||||
row_actions = (DeleteHost,)
|
||||
|
|
|
@ -82,3 +82,32 @@ class HostsTests(test.BaseAdminViewTests):
|
|||
self.assertTemplateNotUsed(res, DETAIL_TEMPLATE)
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.client: ('host_list', 'host_delete')})
|
||||
def test_delete_host(self):
|
||||
hosts = self.hosts.list()
|
||||
host = self.hosts.get(hypervisor_hostname='compute-1')
|
||||
api.client.host_list(IsA(http.HttpRequest)).AndReturn(hosts)
|
||||
api.client.host_delete(IsA(http.HttpRequest), host['id'])
|
||||
self.mox.ReplayAll()
|
||||
|
||||
action = 'hosts__delete__%s' % host['id']
|
||||
form_data = {'action': action}
|
||||
res = self.client.post(INDEX_URL, form_data)
|
||||
self.assertMessageCount(success=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
||||
@test.create_stubs({api.client: ('host_list', 'host_delete')})
|
||||
def test_delete_host_error(self):
|
||||
hosts = self.hosts.list()
|
||||
host = self.hosts.get(hypervisor_hostname='compute-1')
|
||||
api.client.host_list(IsA(http.HttpRequest)).AndReturn(hosts)
|
||||
api.client.host_delete(IsA(http.HttpRequest),
|
||||
host['id']).AndRaise(self.exceptions.blazar)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
action = 'hosts__delete__%s' % host['id']
|
||||
form_data = {'action': action}
|
||||
res = self.client.post(INDEX_URL, form_data)
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, INDEX_URL)
|
||||
|
|
Loading…
Reference in New Issue