Add delete user action

Change-Id: Iff88333ecdbdc3ece3a9053470d239e260030612
This commit is contained in:
Liam Young 2021-09-09 12:31:29 +00:00
parent 07a66d1945
commit de2bc7fbac
3 changed files with 31 additions and 0 deletions

View File

@ -12,3 +12,10 @@ add-user:
description: Role to give user
type: string
default: ""
delete-user:
description: delete a dashboard user
params:
username:
description: Name of user to delete
type: string
default: ""

View File

@ -179,6 +179,9 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
self.radosgw_user.on.gw_user_ready,
self._configure_dashboard)
self.framework.observe(self.on.add_user_action, self._add_user_action)
self.framework.observe(
self.on.delete_user_action,
self._delete_user_action)
self.ingress = interface_api_endpoints.APIEndpointsRequires(
self,
'loadbalancer',
@ -518,5 +521,15 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
else:
event.set_results({"password": password})
def _delete_user_action(self, event: ActionEvent) -> None:
"""Delete a user"""
username = event.params["username"]
try:
self._run_cmd(['ceph', 'dashboard', 'ac-user-delete', username])
event.set_results({"message": "User {} deleted".format(username)})
except subprocess.CalledProcessError as exc:
event.fail(exc.output)
if __name__ == "__main__":
main(CephDashboardCharm)

View File

@ -630,3 +630,14 @@ class TestCephDashboardCharmBase(CharmTestCase):
self.subprocess.check_output.assert_called_once_with(
['ceph', 'dashboard', 'ac-user-create', '--enabled',
'-i', 'tempfilename', 'auser', 'administrator'])
def test__delete_user_action(self):
self.subprocess.check_output.return_value = b''
self.harness.begin()
action_event = MagicMock()
action_event.params = {
'username': 'auser'}
self.harness.charm._delete_user_action(action_event)
self.subprocess.check_output.assert_called_once_with(
['ceph', 'dashboard', 'ac-user-delete', 'auser'],
stderr=self.subprocess.STDOUT)