Merge "Refactor admin password related actions code for better maintenance"

This commit is contained in:
Zuul 2022-05-16 10:24:44 +00:00 committed by Gerrit Code Review
commit 9b2f7e545d
6 changed files with 28 additions and 25 deletions

View File

@ -9,6 +9,9 @@ resume:
Resume keystone services.
If the keystone deployment is clustered using the hacluster charm, the
corresponding hacluster unit on the node must be resumed as well.
get-admin-password:
description: |
Retrieve the admin password for the Keystone service.
rotate-admin-password:
description: |
Rotate the admin user's password.
@ -22,5 +25,3 @@ security-checklist:
description: |
Validate the running configuration against the OpenStack security guides
checklist.
get-admin-password:
description: Retrieve the admin password for the Keystone service.

View File

@ -33,21 +33,12 @@ _add_path(_root)
from charmhelpers.core.hookenv import action_fail
from keystone_utils import (
rotate_admin_passwd,
pause_unit_helper,
resume_unit_helper,
register_configs,
)
def rotate_admin_password(args):
"""Rotate the admin user's password.
@raises Exception if keystone client cannot update the password
"""
rotate_admin_passwd()
def pause(args):
"""Pause all the Keystone services.
@ -67,7 +58,6 @@ def resume(args):
# A dictionary of all the defined actions to callables (which take
# parsed arguments).
ACTIONS = {
"rotate-admin-password": rotate_admin_password,
"pause": pause,
"resume": resume,
}

View File

@ -18,6 +18,7 @@ import os
import sys
sys.path.append('.')
sys.path.append('./hooks')
from charmhelpers.core.hookenv import (
function_set,
@ -25,14 +26,25 @@ from charmhelpers.core.hookenv import (
leader_get,
)
from keystone_utils import rotate_admin_passwd
def get_admin_password(arg):
"""Implementation of 'get-admin-password' action."""
function_set({'admin-password': leader_get("admin_passwd")})
def rotate_admin_password(args):
"""Rotate the admin user's password.
@raises Exception if keystone client cannot update the password
"""
rotate_admin_passwd()
ACTIONS = {
"get-admin-password": get_admin_password
"get-admin-password": get_admin_password,
"rotate-admin-password": rotate_admin_password,
}

View File

@ -1 +1 @@
actions.py
admin_password.py

View File

@ -25,17 +25,6 @@ with patch('charmhelpers.contrib.openstack.utils.'
import actions.actions
class ChangeAdminPasswordTestCase(CharmTestCase):
def setUp(self):
super(ChangeAdminPasswordTestCase, self).setUp(
actions.actions, ["rotate_admin_passwd"])
def test_rotate_admin_password(self):
actions.actions.rotate_admin_password([])
self.rotate_admin_passwd.assert_called_once()
class PauseTestCase(CharmTestCase):
def setUp(self):

View File

@ -35,6 +35,17 @@ class GetAdminPasswordTestCase(CharmTestCase):
self.leader_get("admin_passwd")})
class RotateAdminPasswordTestCase(CharmTestCase):
def setUp(self):
super(RotateAdminPasswordTestCase, self).setUp(
admin_password, ["rotate_admin_passwd"])
def test_rotate_admin_password(self):
admin_password.rotate_admin_password([])
self.rotate_admin_passwd.assert_called_once()
class MainTestCase(CharmTestCase):
def setUp(self):