diff --git a/actions.yaml b/actions.yaml index c76df64..df585b5 100644 --- a/actions.yaml +++ b/actions.yaml @@ -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: "" diff --git a/src/charm.py b/src/charm.py index d4597f3..75ea0db 100755 --- a/src/charm.py +++ b/src/charm.py @@ -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) diff --git a/unit_tests/test_ceph_dashboard_charm.py b/unit_tests/test_ceph_dashboard_charm.py index 77c47d6..1332ea1 100644 --- a/unit_tests/test_ceph_dashboard_charm.py +++ b/unit_tests/test_ceph_dashboard_charm.py @@ -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)