Merge "Add support for root-disable"

This commit is contained in:
Jenkins 2016-03-30 22:42:24 +00:00 committed by Gerrit Code Review
commit 78e9f78dfc
3 changed files with 33 additions and 26 deletions

View File

@ -231,6 +231,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)

View File

@ -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):

View File

@ -498,16 +498,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'}
@ -521,18 +520,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'}
@ -546,7 +545,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',