diff --git a/zaza/openstack/charm_tests/test_utils.py b/zaza/openstack/charm_tests/test_utils.py index d94ded7..2a22ab1 100644 --- a/zaza/openstack/charm_tests/test_utils.py +++ b/zaza/openstack/charm_tests/test_utils.py @@ -89,51 +89,7 @@ def audit_assertions(action, assert value == "PASS", "Unexpected failure: {}".format(key) -class CharmTestAssertions: - """Custom assertions to support zaza testings.""" - - def assertActionRanOK(self, action): - """Assert that the remote action ran successfully. - - Example usage:: - - self.assertActionRanOK(model.run_action( - unit, - 'pause', - model_name=self.model_name)) - - self.assertActionRanOK(model.run_action_on_leader( - unit, - 'pause', - model_name=self.model_name)) - - :param action: Action object to check. - :type action: juju.action.Action - :raises: AssertionError if the assertion fails. - """ - if action.status != 'completed': - msg = ("Action '{name}' exited with status '{status}': " - "'{message}'").format(**action.data) - raise AssertionError(msg) - - def assertRemoteRunOK(self, run_output): - """Use with zaza.model.run_on_unit. - - Example usage:: - - self.assertRemoteRunOK(zaza.model.run_on_unit( - unit, - 'ls /tmp/')) - - :param action: Dict returned from remote run. - :type action: dict - :raises: AssertionError if the assertion fails. - """ - if int(run_output['Code']) != 0: - raise AssertionError("Command failed: {}".format(run_output)) - - -class BaseCharmTest(unittest.TestCase, CharmTestAssertions): +class BaseCharmTest(unittest.TestCase): """Generic helpers for testing charms.""" run_resource_cleanup = False @@ -394,7 +350,7 @@ class BaseCharmTest(unittest.TestCase, CharmTestAssertions): self.lead_unit, 'active', model_name=self.model_name) - self.assertActionRanOK(model.run_action( + generic_utils.assertActionRanOK(model.run_action( self.lead_unit, 'pause', model_name=self.model_name)) @@ -410,7 +366,7 @@ class BaseCharmTest(unittest.TestCase, CharmTestAssertions): model_name=self.model_name, pgrep_full=pgrep_full) yield - self.assertActionRanOK(model.run_action( + generic_utils.assertActionRanOK(model.run_action( self.lead_unit, 'resume', model_name=self.model_name)) diff --git a/zaza/openstack/utilities/generic.py b/zaza/openstack/utilities/generic.py index 3a22404..e342369 100644 --- a/zaza/openstack/utilities/generic.py +++ b/zaza/openstack/utilities/generic.py @@ -28,6 +28,48 @@ from zaza.openstack.utilities import exceptions as zaza_exceptions from zaza.openstack.utilities.os_versions import UBUNTU_OPENSTACK_RELEASE +def assertActionRanOK(action): + """Assert that the remote action ran successfully. + + Example usage:: + + self.assertActionRanOK(model.run_action( + unit, + 'pause', + model_name=self.model_name)) + + self.assertActionRanOK(model.run_action_on_leader( + unit, + 'pause', + model_name=self.model_name)) + + :param action: Action object to check. + :type action: juju.action.Action + :raises: AssertionError if the assertion fails. + """ + if action.status != 'completed': + msg = ("Action '{name}' exited with status '{status}': " + "'{message}'").format(**action.data) + raise AssertionError(msg) + + +def assertRemoteRunOK(run_output): + """Use with zaza.model.run_on_unit. + + Example usage:: + + self.assertRemoteRunOK(zaza.model.run_on_unit( + unit, + 'ls /tmp/')) + + :param action: Dict returned from remote run. + :type action: dict + :raises: AssertionError if the assertion fails. + """ + if int(run_output['Code']) != 0: + raise AssertionError("Command failed: {}".format(run_output)) + + def dict_to_yaml(dict_data): """Return YAML from dictionary.