From 55ae4aad281c5b8267b912528a0079560fc2ecde Mon Sep 17 00:00:00 2001 From: Alex Kavanagh Date: Thu, 19 Sep 2019 16:17:50 +0200 Subject: [PATCH] Add in check to test for removal of file --- zaza/openstack/charm_tests/policyd/tests.py | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/zaza/openstack/charm_tests/policyd/tests.py b/zaza/openstack/charm_tests/policyd/tests.py index d42b4b76e..abf997f05 100644 --- a/zaza/openstack/charm_tests/policyd/tests.py +++ b/zaza/openstack/charm_tests/policyd/tests.py @@ -20,6 +20,8 @@ import tempfile import zipfile +from juju.errors import JujuError + import zaza import zaza.model as zaza_model import zaza.utilities.juju as zaza_juju @@ -112,10 +114,21 @@ def test_policyd_good_yaml(self): logging.info("Disabling policy override ...") self._set_config(False) # check that the status no longer has "PO:" on it. + # we have to do it twice due to async races and that some info lines + # erase the PO: bit prior to actuall getting back to idle. The double + # check verifies that the charms have started, the idle waits until it + # is finiehed, and then the final check really makes sure they got + # switched off. + block_until_wl_status_info_starts_with( + self.application_name, "PO:", negate_match=True) + zaza_model.block_until_all_units_idle() block_until_wl_status_info_starts_with( self.application_name, "PO:", negate_match=True) # verify that the file no longer exists + logging.info("Checking that {} has been removed".format(path)) + block_until_file_missing(self.application_name, path) + logging.info("...done") @@ -152,3 +165,25 @@ async def _unit_status(): block_until_wl_status_info_starts_with = zaza.sync_wrapper( async_block_until_wl_status_info_starts_with) + + +async def async_block_until_file_missing( + app, path, model_name=None, timeout=2700): + async def _check_for_file(model): + units = model.applications[app].units + results = [] + for unit in units: + try: + output = await unit.run('test -e {}; echo $?'.format(path)) + contents = output.data.get('results')['Stdout'] + results.append("1" in contents) + # libjuju throws a generic error for connection failure. So we + # cannot differentiate between a connectivity issue and a + # target file not existing error. For now just assume the + # latter. + except JujuError: + results.append(False) + return all(results) + + +block_until_file_missing = zaza.sync_wrapper(async_block_until_file_missing)