From e2e504ba40cf1bafee2b5326aa731a0157f82a01 Mon Sep 17 00:00:00 2001 From: Duk Loi Date: Mon, 29 Feb 2016 11:35:43 -0500 Subject: [PATCH] Add support for root-disable Added new root disable row action to the manage root table. Removed the existing reset root action and consolidated it into the enable root action. Added the root disable api call as well. Change-Id: I7ec1bdce5a20d220ed90a51e533bdeeae6d52f57 Closes-Bug: #1548503 --- trove_dashboard/api/trove.py | 4 +++ trove_dashboard/content/databases/tables.py | 34 ++++++++++++--------- trove_dashboard/content/databases/tests.py | 21 ++++++------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/trove_dashboard/api/trove.py b/trove_dashboard/api/trove.py index 44ba17f..909b5ac 100644 --- a/trove_dashboard/api/trove.py +++ b/trove_dashboard/api/trove.py @@ -229,6 +229,10 @@ def root_show(request, instance_id): return troveclient(request).root.is_root_enabled(instance_id) +def root_disable(request, instance_id): + return troveclient(request).root.delete(instance_id) + + def users_list(request, instance_id): return troveclient(request).users.list(instance_id) diff --git a/trove_dashboard/content/databases/tables.py b/trove_dashboard/content/databases/tables.py index 028e43b..9f69e02 100644 --- a/trove_dashboard/content/databases/tables.py +++ b/trove_dashboard/content/databases/tables.py @@ -410,7 +410,10 @@ class ResizeInstance(tables.LinkAction): return urlresolvers.reverse(self.url, args=[instance_id]) -class RootAction(tables.Action): +class EnableRootAction(tables.Action): + name = "enable_root_action" + verbose_name = _("Enable Root") + def handle(self, table, request, obj_ids): try: username, password = api.trove.root_enable(request, obj_ids) @@ -420,23 +423,23 @@ class RootAction(tables.Action): messages.error(request, _('There was a problem enabling root.')) -class EnableRootAction(RootAction): - name = "enable_root_action" - verbose_name = _("Enable Root") - - def allowed(self, request, instance): - enabled = api.trove.root_show(request, instance.id) - return not enabled.rootEnabled - - -class ResetRootAction(RootAction): - name = "reset_root_action" - verbose_name = _("Reset Password") +class DisableRootAction(tables.Action): + name = "disable_root_action" + verbose_name = _("Disable Root") def allowed(self, request, instance): enabled = api.trove.root_show(request, instance.id) return enabled.rootEnabled + def single(self, table, request, object_id): + try: + api.trove.root_disable(request, object_id) + table.data[0].password = None + messages.success(request, _("Successfully disabled root access.")) + except Exception as e: + messages.warning(request, + _("Cannot disable root access: %s") % e.message) + class ManageRoot(tables.LinkAction): name = "manage_root_action" @@ -453,7 +456,8 @@ class ManageRoot(tables.LinkAction): class ManageRootTable(tables.DataTable): name = tables.Column('name', verbose_name=_('Instance Name')) - enabled = tables.Column('enabled', verbose_name=_('Root Enabled'), + enabled = tables.Column('enabled', + verbose_name=_('Has Root Ever Been Enabled'), filters=(d_filters.yesno, d_filters.capfirst), help_text=_("Status if root was ever enabled " "for an instance.")) @@ -465,7 +469,7 @@ class ManageRootTable(tables.DataTable): class Meta(object): name = "manage_root" verbose_name = _("Manage Root") - row_actions = (EnableRootAction, ResetRootAction,) + row_actions = (EnableRootAction, DisableRootAction,) class UpdateRow(tables.Row): diff --git a/trove_dashboard/content/databases/tests.py b/trove_dashboard/content/databases/tests.py index 44f126c..6b82d58 100644 --- a/trove_dashboard/content/databases/tests.py +++ b/trove_dashboard/content/databases/tests.py @@ -485,16 +485,15 @@ class DatabaseTests(test.TestCase): self.assertNotEqual(table.data[0].enabled, True) self.assertNotEqual(table.data[0].password, "password") - @test.create_stubs({api.trove: ('root_enable',)}) - def test_reset_root(self): - api.trove.root_enable(IsA(http.HttpRequest), [u'id']) \ - .AndReturn(("root", "newpassword")) + @test.create_stubs({api.trove: ('root_disable',)}) + def test_disable_root(self): + api.trove.root_disable(IsA(http.HttpRequest), u'id') self.mox.ReplayAll() url = reverse('horizon:project:databases:manage_root', args=['id']) - form_data = {"action": "manage_root__reset_root_action__%s" % 'id'} + form_data = {"action": "manage_root__disable_root_action__%s" % 'id'} req = self.factory.post(url, form_data) kwargs = {'instance_id': 'id'} @@ -508,18 +507,18 @@ class DatabaseTests(test.TestCase): table.maybe_handle() self.assertEqual(table.data[0].enabled, True) - self.assertEqual(table.data[0].password, "newpassword") + self.assertEqual(table.data[0].password, None) - @test.create_stubs({api.trove: ('root_enable',)}) - def test_reset_root_exception(self): - api.trove.root_enable(IsA(http.HttpRequest), [u'id']) \ + @test.create_stubs({api.trove: ('root_disable',)}) + def test_disable_root_exception(self): + api.trove.root_disable(IsA(http.HttpRequest), u'id') \ .AndRaise(self.exceptions.trove) self.mox.ReplayAll() url = reverse('horizon:project:databases:manage_root', args=['id']) - form_data = {"action": "manage_root__reset_root_action__%s" % 'id'} + form_data = {"action": "manage_root__disable_root_action__%s" % 'id'} req = self.factory.post(url, form_data) kwargs = {'instance_id': 'id'} @@ -533,7 +532,7 @@ class DatabaseTests(test.TestCase): table.maybe_handle() self.assertEqual(table.data[0].enabled, True) - self.assertNotEqual(table.data[0].password, "newpassword") + self.assertEqual(table.data[0].password, "password") @test.create_stubs( {api.trove: ('instance_get', 'flavor_get', 'users_list',