Skip to content

Commit

Permalink
Add in check to test for removal of file
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkavanagh committed Sep 25, 2019
1 parent 3465dac commit 55ae4aa
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions zaza/openstack/charm_tests/policyd/tests.py
Expand Up @@ -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
Expand Down Expand Up @@ -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")


Expand Down Expand Up @@ -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)

0 comments on commit 55ae4aa

Please sign in to comment.