From 6648aaf0e9f491cfef90afff215dd4f847933aa6 Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Wed, 25 Sep 2019 12:03:21 +0100 Subject: [PATCH] Add negative test for broken yaml --- zaza/openstack/charm_tests/policyd/tests.py | 33 ++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/zaza/openstack/charm_tests/policyd/tests.py b/zaza/openstack/charm_tests/policyd/tests.py index 07f4753..0e0fdce 100644 --- a/zaza/openstack/charm_tests/policyd/tests.py +++ b/zaza/openstack/charm_tests/policyd/tests.py @@ -99,7 +99,7 @@ class PolicydTest(object): 'file1.yaml': "{'rule1': '!'}" } good_zip_path = self._make_zip_file_from('good.zip', good) - logging.info("Attaching a resource.") + logging.info("Attaching good zip file as a resource.") zaza_model.attach_resource(self.application_name, 'policyd-override', good_zip_path) @@ -141,6 +141,37 @@ class PolicydTest(object): logging.info("...done") + def test_002_policyd_bad_yaml(self): + # Test that a bad yaml file in the zip file doesn't not put it in the + # override and puts up a status message that it is bad + bad = { + "file2.yaml": "{'rule': '!}" + } + bad_zip_path = self._make_zip_file_from('bad.zip', bad) + logging.info("Attaching bad zip file as a resource") + zaza_model.attach_resource(self.application_name, + 'policyd-override', + bad_zip_path) + logging.debug("... waiting for idle") + zaza_model.block_until_all_units_idle() + logging.debug("Now setting config to true") + self._set_config(True) + # ensure that the workload status info line starts with PO (broken): + # to show that it didn't work + logging.info("Checking for workload status line starts with PO:") + zaza_model.block_until_wl_status_info_starts_with( + self.application_name, "PO (broken):") + logging.debug("App status is valid for broken yaml file") + zaza_model.block_until_all_units_idle() + # now verify that no file got landed on the machine + path = os.path.join( + "/etc", self._service_name, "policy.d", 'file2.yaml') + logging.info("Now checking that file {} is not present.".format(path)) + zaza_model.block_until_file_missing(self.application_name, path) + self._set_config(True) + zaza_model.block_until_all_units_idle() + logging.info("...done") + class KeystonePolicydTest(PolicydTest, ch_keystone.BaseKeystoneTest,