From b95f6e6e7ddd552822e92b503a7c140b51d754ab Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Wed, 6 Nov 2019 11:40:20 +0000 Subject: [PATCH] Add heat policy.d functional tests --- zaza/openstack/charm_tests/policyd/tests.py | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/zaza/openstack/charm_tests/policyd/tests.py b/zaza/openstack/charm_tests/policyd/tests.py index 8779149..c359695 100644 --- a/zaza/openstack/charm_tests/policyd/tests.py +++ b/zaza/openstack/charm_tests/policyd/tests.py @@ -41,6 +41,7 @@ import zipfile import keystoneauth1 import glanceclient.common.exceptions import cinderclient.exceptions +import heatclient.exc import zaza.model as zaza_model @@ -559,3 +560,35 @@ class CinderTests(BasePolicydSpecialization): cinder_client.volumes.list() except cinderclient.exceptions.Forbidden: raise PolicydOperationFailedException() + + +class HeatTests(BasePolicydSpecialization): + """Test the policyd override using the heat client.""" + + _rule = "{'stacks:index': '!'}" + + @classmethod + def setUpClass(cls, application_name=None): + """Run class setup for running HeatTests charm operation tests.""" + super(HeatTests, cls).setUpClass(application_name="heat") + cls.application_name = "heat" + + def get_client_and_attempt_operation(self, ip): + """Attempt to list the heat stacks as a policyd override. + + This operation should pass normally, and fail when + the rule has been overriden (see the `rule` class variable). + + :param ip: the IP address to get the session against. + :type ip: str + :raises: PolicydOperationFailedException if operation fails. + """ + heat_client = openstack_utils.get_heat_session_client( + self.get_keystone_session_admin_user(ip)) + try: + # stacks.list() returns a generator (as opposed to a list), so to + # force the client to actually connect, the generator has to be + # iterated. + list(heat_client.stacks.list()) + except heatclient.exc.HTTPForbidden: + raise PolicydOperationFailedException()