From 6ee5fff0389fd3626cb2258e68fc452c2f22d4b4 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 7 Jul 2023 12:42:17 +0000 Subject: [PATCH] Add tests for rabbit on k8s --- .../charm_tests/rabbitmq_server/tests_k8s.py | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 zaza/openstack/charm_tests/rabbitmq_server/tests_k8s.py diff --git a/zaza/openstack/charm_tests/rabbitmq_server/tests_k8s.py b/zaza/openstack/charm_tests/rabbitmq_server/tests_k8s.py new file mode 100644 index 0000000..b8776e3 --- /dev/null +++ b/zaza/openstack/charm_tests/rabbitmq_server/tests_k8s.py @@ -0,0 +1,63 @@ +# Copyright 2023 Canonical Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""RabbitMQ K8S Testing.""" + +import tenacity +import rabbitmq_admin + +import zaza.model +import zaza.openstack.charm_tests.test_utils as test_utils +import zaza.utilities.juju as juju_utils + + +class RabbitMQK8STest(test_utils.BaseCharmTest): + """Tests for rabbit on K8s.""" + + def get_service_account(self): + """Get service account details.""" + result = zaza.model.run_action_on_leader( + 'rabbitmq', + 'get-operator-info', + raise_on_failure=False).data['results'] + return (result['operator-user'], result['operator-password']) + + def get_mgr_endpoint(self): + """Get url for management api.""" + public_address = juju_utils.get_application_status( + 'rabbitmq').public_address + return "http://{}:{}".format(public_address, 15672) + + def get_connection(self): + """Return an api connection.""" + username, password = self.get_service_account() + mgmt_url = self.get_mgr_endpoint() + connection = rabbitmq_admin.AdminAPI( + url=mgmt_url, auth=(username, password) + ) + return connection + + def test_get_operator_info_action(self): + """Test running get-operator-info action.""" + user, password = self.get_service_account() + self.assertEqual(user, "operator") + + @tenacity.retry( + reraise=True, + wait=tenacity.wait_fixed(30), + stop=tenacity.stop_after_attempt(2)) + def test_query_api(self): + """Test querying managment api.""" + conn = self.get_connection() + self.assertEqual(conn.overview()['product_name'], "RabbitMQ")