Implement delete host
Implemented delete host functionality. Also added test case for delete host. Partial-Implements: blueprint masakari-dashboard Change-Id: I8265b4f1af7bb61d15d005ee3785895f678f7d10
This commit is contained in:
parent
a83abbd2b5
commit
9ae3efef6b
|
@ -146,3 +146,8 @@ def create_host(request, data):
|
|||
def get_host_list(request, segment_id, filters):
|
||||
"""Returns host list."""
|
||||
return openstack_connection(request).hosts(segment_id, **filters)
|
||||
|
||||
|
||||
def delete_host(request, host_id, segment_id):
|
||||
return openstack_connection(request).delete_host(
|
||||
host_id, segment_id, False)
|
||||
|
|
|
@ -12,9 +12,16 @@
|
|||
# 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.utils.translation import ungettext_lazy
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
||||
from masakaridashboard.api import api
|
||||
|
||||
|
||||
HOST_FILTER_CHOICES = (
|
||||
('failover_segment_id', _("Segment Id ="), True),
|
||||
('type', _("Type ="), True),
|
||||
|
@ -28,6 +35,35 @@ class HostFilterAction(tables.FilterAction):
|
|||
filter_choices = HOST_FILTER_CHOICES
|
||||
|
||||
|
||||
class DeleteHost(tables.DeleteAction):
|
||||
@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, data):
|
||||
row_data = data.split(',')
|
||||
segment_uuid = row_data[1]
|
||||
host_uuid = row_data[0]
|
||||
try:
|
||||
api.delete_host(request, host_uuid, segment_uuid)
|
||||
except Exception:
|
||||
msg = _('Unable to delete host.')
|
||||
redirect = reverse('horizon:masakaridashboard:hosts:index')
|
||||
exceptions.handle(self.request, msg, redirect=redirect)
|
||||
|
||||
|
||||
class HostTable(tables.DataTable):
|
||||
|
||||
name = tables.Column('name', verbose_name=_("Name"))
|
||||
|
@ -50,4 +86,4 @@ class HostTable(tables.DataTable):
|
|||
class Meta(object):
|
||||
name = "host"
|
||||
verbose_name = _("Host")
|
||||
table_actions = (HostFilterAction,)
|
||||
table_actions = (HostFilterAction, DeleteHost)
|
||||
|
|
|
@ -70,3 +70,26 @@ class HostTest(test.TestCase):
|
|||
mock.ANY,
|
||||
form_data
|
||||
)
|
||||
|
||||
def test_delete_ok(self):
|
||||
host = self.masakari_host.list()[0]
|
||||
data = {'object_ids': host.uuid + ',' + host.failover_segment_id,
|
||||
'action': 'host__delete'}
|
||||
with mock.patch(
|
||||
'masakaridashboard.api.api.segment_list',
|
||||
return_value=[self.masakari_segment.first(
|
||||
)]), mock.patch(
|
||||
'masakaridashboard.api.api.get_host_list',
|
||||
return_value=self.masakari_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,
|
||||
host.uuid,
|
||||
host.failover_segment_id,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue