Files
zaza-openstack-tests/zaza/charm_lifecycle/utils.py
Liam Young 9d06bb890f Move call to get_juju_model() down to run_in_model
Currently interacting with functions in zaza.model requires the
model to be passed in. This has resulted in multiple calls to
get_juju_model(). It is cleaner to push these calls down into
the model wrapper and make the model_name an optional
argument. In addition, the current model name is now cached
without having to check the os.env each time.

Unfortunately this has resulted in the signature changing on a
great many function so this diff is bigger than would normally
be desirable.
2018-06-14 06:19:26 +01:00

38 lines
1.0 KiB
Python

"""Utilities to support running lifecycle phases."""
import importlib
import yaml
BUNDLE_DIR = "./tests/bundles/"
DEFAULT_TEST_CONFIG = "./tests/tests.yaml"
def get_charm_config(yaml_file=None):
"""Read the yaml test config file and return the resulting config.
:param yaml_file: File to be read
:type yaml_file: str
:returns: Config dictionary
:rtype: dict
"""
if not yaml_file:
yaml_file = DEFAULT_TEST_CONFIG
with open(yaml_file, 'r') as stream:
return yaml.load(stream)
def get_class(class_str):
"""Get the class represented by the given string.
For example, get_class('zaza.charms_tests.svc.TestSVCClass1')
returns zaza.charms_tests.svc.TestSVCClass1
:param class_str: Class to be returned
:type class_str: str
:returns: Test class
:rtype: class
"""
module_name = '.'.join(class_str.split('.')[:-1])
class_name = class_str.split('.')[-1]
module = importlib.import_module(module_name)
return getattr(module, class_name)