Ejemplo n.º 1
0
def test(model_name, tests, test_directory=None):
    """Run all steps to execute tests against the model.

    :param test_directory: Set the directory containing tests.yaml and bundles.
    :type test_directory: str
    """
    utils.set_base_test_dir(test_dir=test_directory)
    zaza.model.set_juju_model(model_name)
    run_test_list(tests)
Ejemplo n.º 2
0
def configure(model_name, functions, test_directory=None):
    """Run all post-deployment configuration steps.

    :param functions: List of configure functions functions
    :type tests: ['zaza.charms_tests.svc.setup', ...]
    :param test_directory: Set the directory containing tests.yaml and bundles.
    :type test_directory: str
    """
    utils.set_base_test_dir(test_dir=test_directory)
    zaza.model.set_juju_model(model_name)
    run_configure_list(functions)
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 prepare(model_name, test_directory=None):
    """Run all steps to prepare the environment before a functional test run.

    :param model: Name of model to add
    :type bundle: str
    :param test_directory: Set the directory containing tests.yaml and bundles.
    :type test_directory: str
    """
    utils.set_base_test_dir(test_dir=test_directory)
    zaza.controller.add_model(model_name,
                              config=deployment_env.get_model_settings(),
                              region=deployment_env.get_cloud_region())
    zaza.model.set_model_constraints(
        model_name=model_name,
        constraints=deployment_env.get_model_constraints())
Ejemplo n.º 5
0
def main():
    """Run the tests defined by the command line args.

    Run the tests defined by the command line args or if none were provided
    read the tests from the charms tests.yaml config file
    """
    args = parse_args(sys.argv[1:])
    cli_utils.setup_logging(log_level=args.loglevel.upper())
    zaza.model.set_juju_model_aliases(args.model)
    utils.set_base_test_dir(test_dir=args.test_directory)
    for model_alias, model_name in args.model.items():
        if args.tests:
            tests = args.tests
        else:
            test_steps = utils.get_test_steps()
            tests = test_steps.get(model_alias, [])
        test(model_name, tests, test_directory=args.test_directory)
    run_report.output_event_report()
    asyncio.get_event_loop().close()
Ejemplo n.º 6
0
def deploy(bundle,
           model,
           wait=True,
           model_ctxt=None,
           force=False,
           test_directory=None):
    """Run all steps to complete deployment.

    :param bundle: Path to bundle file
    :type bundle: str
    :param model: Name of model to deploy bundle in
    :type model: str
    :param wait: Whether to wait until deployment completes
    :type wait: bool
    :param model_ctxt: Additional context to be used when rendering bundle
                       templates.
    :type model_ctxt: {}
    :param force: Pass the force parameter if True
    :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)
    run_report.register_event_start('Deploy Bundle')
    deploy_bundle(bundle, model, model_ctxt=model_ctxt, force=force)
    run_report.register_event_finish('Deploy Bundle')
    if wait:
        run_report.register_event_start('Wait for Deployment')
        test_config = utils.get_charm_config()
        logging.info("Waiting for environment to settle")
        zaza.model.set_juju_model(model)
        deploy_ctxt = deployment_env.get_deployment_context()
        timeout = int(deploy_ctxt.get('TEST_DEPLOY_TIMEOUT', '3600'))
        logging.info(
            "Timeout for deployment to settle set to: {}".format(timeout))
        zaza.model.wait_for_application_states(model,
                                               test_config.get(
                                                   'target_deploy_status', {}),
                                               timeout=timeout)
        run_report.register_event_finish('Wait for Deployment')
Ejemplo n.º 7
0
 def test_manipulate_base_test_dir(self):
     lc_utils.set_base_test_dir()
     cwd = os.getcwd()
     self.assertEqual(lc_utils.get_base_test_dir(), cwd + '/tests')
     lc_utils.unset_base_test_dir()
     # Test supplying relative path
     lc_utils.set_base_test_dir('special-tests')
     self.assertEqual(lc_utils.get_base_test_dir(), cwd + '/special-tests')
     lc_utils.unset_base_test_dir()
     # Test supplying an absolute path
     lc_utils.set_base_test_dir('/my-test-dir/special-tests')
     self.assertEqual(lc_utils.get_base_test_dir(),
                      '/my-test-dir/special-tests')
     lc_utils.unset_base_test_dir()
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 def test_get_bundle_dir(self):
     lc_utils.set_base_test_dir()
     cwd = os.getcwd()
     self.assertEqual(lc_utils.get_bundle_dir(), cwd + '/tests/bundles')
     lc_utils.unset_base_test_dir()