Ejemplo n.º 1
0
def func_test_runner(keep_model=False, smoke=False, dev=False, bundle=None):
    """Deploy the bundles and run the tests as defined by the charms tests.yaml.

    :param keep_model: Whether to destroy model at end of run
    :type keep_model: boolean
    :param smoke: Whether to just run smoke test.
    :param dev: Whether to just run dev test.
    :type smoke: boolean
    :type dev: boolean
    """
    if bundle:
        environment_deploys = [
            utils.EnvironmentDeploy(
                'default',
                [utils.ModelDeploy(
                    utils.DEFAULT_MODEL_ALIAS,
                    utils.generate_model_name(),
                    bundle)],
                True)]
    else:
        if smoke:
            bundle_key = 'smoke_bundles'
        elif dev:
            bundle_key = 'dev_bundles'
        else:
            bundle_key = 'gate_bundles'
        environment_deploys = utils.get_environment_deploys(bundle_key)
    last_test = environment_deploys[-1].name

    for env_deployment in environment_deploys:
        preserve_model = False
        if keep_model and last_test == env_deployment.name:
            preserve_model = True
        run_env_deployment(env_deployment, keep_model=preserve_model)
 def test_get_environment_deploys(self):
     self.patch_object(lc_utils, 'get_charm_config')
     charm_config = {'smoke_bundles': ['map1', 'map2', 'map3']}
     self.patch_object(lc_utils, 'get_environment_deploy')
     env_depl1 = lc_utils.EnvironmentDeploy('ed1', [], True)
     env_depl2 = lc_utils.EnvironmentDeploy('ed2', [], True)
     env_depl3 = lc_utils.EnvironmentDeploy('ed3', [], True)
     env_deploys = {'map1': env_depl1, 'map2': env_depl2, 'map3': env_depl3}
     self.get_charm_config.return_value = charm_config
     self.get_environment_deploy.side_effect = lambda x: env_deploys[x]
     self.assertEqual(lc_utils.get_environment_deploys('smoke_bundles'),
                      [env_depl1, env_depl2, env_depl3])
Ejemplo n.º 3
0
def func_test_runner(keep_model=False,
                     smoke=False,
                     dev=False,
                     bundle=None,
                     force=False,
                     test_directory=None):
    """Deploy the bundles and run the tests as defined by the charms tests.yaml.

    :param keep_model: Whether to destroy model at end of run
    :type keep_model: boolean
    :param smoke: Whether to just run smoke test.
    :param dev: Whether to just run dev test.
    :type smoke: boolean
    :type dev: boolean
    :param force: Pass the force parameter if True to the juju deploy command
    :type force: Boolean
    :param test_directory: Set the directory containing tests.yaml and bundles.
    :type test_directory: str
    """
    utils.set_base_test_dir(test_dir=test_directory)
    if bundle:
        if ':' in bundle:
            model_alias, bundle = bundle.split(':')
        else:
            model_alias = utils.DEFAULT_MODEL_ALIAS
        environment_deploys = [
            utils.EnvironmentDeploy('default', [
                utils.ModelDeploy(model_alias.strip(),
                                  utils.generate_model_name(), bundle.strip())
            ], True)
        ]
    else:
        if smoke:
            bundle_key = 'smoke_bundles'
        elif dev:
            bundle_key = 'dev_bundles'
        else:
            bundle_key = 'gate_bundles'
        environment_deploys = utils.get_environment_deploys(bundle_key)
    last_test = environment_deploys[-1].name

    for env_deployment in environment_deploys:
        preserve_model = False
        if keep_model and last_test == env_deployment.name:
            preserve_model = True
        run_env_deployment(env_deployment,
                           keep_model=preserve_model,
                           force=force,
                           test_directory=test_directory)
Ejemplo n.º 4
0
def func_test_runner(keep_last_model=False, keep_all_models=False,
                     keep_faulty_model=False, smoke=False, dev=False,
                     bundles=None, force=False, test_directory=None):
    """Deploy the bundles and run the tests as defined by the charms tests.yaml.

    :param keep_last_model: Whether to destroy last model at end of run
    :type keep_last_model: boolean
    :param keep_all_models: Whether to keep all models at end of run
    :type keep_all_models: boolean
    :param keep_faulty_model: Whether to destroy a model when tests failed
    :param smoke: Whether to just run smoke test.
    :param dev: Whether to just run dev test.
    :type smoke: boolean
    :type dev: boolean
    :param bundles: Bundles is a list of specific bundles to run, in the format
                    ['bundle_name', 'model_alias:bundle2_name']. If a model
                    alias isn't provided for a bundle, this will attempt to
                    infer the correct model alias by reading through the
                    tests.yaml config file for a matching bundle name. If, and
                    only if, it finds a single matching bundle name, it will
                    use that alias as the model alias, otherwise it will fall
                    back to the default model alias.
    :type bundles: [str1, str2,...]
    :param force: Pass the force parameter if True to the juju deploy command
    :type force: Boolean
    :param test_directory: Set the directory containing tests.yaml and bundles.
    :type test_directory: str
    """
    utils.set_base_test_dir(test_dir=test_directory)
    if bundles is not None:
        all_bundles = None
        if not isinstance(bundles, list):
            bundles = [bundles]
        deploy = {}
        environment_deploys = []
        for bundle in bundles:
            if ':' in bundle:
                model_alias, bundle = bundle.split(':')
            else:
                if all_bundles is None:
                    all_bundles = {}
                    for name, values in utils.get_charm_config().items():
                        if '_bundles' in name:
                            all_bundles[name] = values
                matching_bundles = set()
                for _name, bundles in all_bundles.items():
                    if bundles:
                        for tests_bundle in bundles:
                            if isinstance(tests_bundle, dict):
                                for alias, tests_bundle in \
                                        tests_bundle.items():
                                    if tests_bundle == bundle:
                                        matching_bundles.add(alias)
                if len(set(matching_bundles)) == 1:
                    model_alias = matching_bundles.pop()
                else:
                    logging.info('Could not determine correct model alias'
                                 'from tests.yaml, using default')
                    model_alias = utils.DEFAULT_MODEL_ALIAS
            deploy[model_alias] = bundle
        environment_deploys.append(
            utils.get_environment_deploy(deploy)
        )
    else:
        if smoke:
            bundle_key = 'smoke_bundles'
        elif dev:
            bundle_key = 'dev_bundles'
        else:
            bundle_key = 'gate_bundles'
        environment_deploys = utils.get_environment_deploys(bundle_key)

    # Now inform any plugins of the environment deploys.
    zaza.plugins.find_and_configure_plugins(environment_deploys)

    # Now run the deploys
    last_test = environment_deploys[-1].name
    for env_deployment in environment_deploys:
        preserve_model = DESTROY_MODEL
        if (
            (keep_last_model and last_test == env_deployment.name) or
            keep_all_models
        ):
            preserve_model = KEEP_MODEL
        elif keep_faulty_model:
            preserve_model = KEEP_FAULTY_MODEL

        with notify_around(NotifyEvents.BUNDLE, env_deployment=env_deployment):
            run_env_deployment(env_deployment, keep_model=preserve_model,
                               force=force, test_directory=test_directory)