def run_env_deployment(env_deployment, keep_model=False, force=False): """Run the environment deployment. :param env_deployment: Environment Deploy to execute. :type env_deployment: utils.EnvironmentDeploy :param keep_model: Whether to destroy models at end of run :type keep_model: boolean :param force: Pass the force parameter if True :type force: Boolean """ config_steps = utils.get_config_steps() test_steps = utils.get_test_steps() model_aliases = {model_deploy.model_alias: model_deploy.model_name for model_deploy in env_deployment.model_deploys} zaza.model.set_juju_model_aliases(model_aliases) for deployment in env_deployment.model_deploys: prepare.prepare(deployment.model_name) force = force or utils.is_config_deploy_forced_for_bundle( deployment.bundle) for deployment in env_deployment.model_deploys: deploy.deploy( os.path.join( utils.BUNDLE_DIR, '{}.yaml'.format(deployment.bundle)), deployment.model_name, model_ctxt=model_aliases, force=force) # When deploying bundles with cross model relations, hooks may be triggered # in already deployedi models so wait for all models to settle. for deployment in env_deployment.model_deploys: logging.info("Waiting for {} to settle".format(deployment.model_name)) zaza.model.block_until_all_units_idle( model_name=deployment.model_name) for deployment in env_deployment.model_deploys: configure.configure( deployment.model_name, config_steps.get(deployment.model_alias, [])) for deployment in env_deployment.model_deploys: test.test( deployment.model_name, test_steps.get(deployment.model_alias, [])) # Destroy # Keep the model from the last run if keep_model is true, this is to # maintian compat with osci and should change when the zaza collect # functions take over from osci for artifact collection. if not keep_model: for model_name in model_aliases.values(): destroy.destroy(model_name) zaza.model.unset_juju_model_aliases()
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: bundles = [{utils.DEFAULT_MODEL_ALIAS: bundle}] else: if smoke: bundle_key = 'smoke_bundles' elif dev: bundle_key = 'dev_bundles' else: bundle_key = 'gate_bundles' bundles = utils.get_test_bundles(bundle_key) last_test = bundles[-1] config_steps = utils.get_config_steps() test_steps = utils.get_test_steps() for bundle in bundles: model_aliases = {} for model_alias in sorted(bundle.keys()): model_name = utils.generate_model_name() # Prepare prepare.prepare(model_name) model_aliases[model_alias] = model_name for model_alias, model_name in model_aliases.items(): # TODO Deploys should run in parallel # Deploy deploy.deploy( os.path.join( utils.BUNDLE_DIR, '{}.yaml'.format(bundle[model_alias])), model_aliases[model_alias]) for model_alias, model_name in model_aliases.items(): configure.configure( model_name, config_steps.get(model_alias, [])) # Test for model_alias, model_name in model_aliases.items(): test.test( model_name, test_steps.get(model_alias, [])) # Destroy # Keep the model from the last run if keep_model is true, this is to # maintian compat with osci and should change when the zaza collect # functions take over from osci for artifact collection. if keep_model and bundle == last_test: pass else: for model_name in model_aliases.values(): destroy.destroy(model_name)
def func_test_runner(): """Deploy the bundles and run the tests as defined by the charms tests.yaml """ test_config = utils.get_charm_config() for t in test_config['gate_bundles']: model_name = generate_model_name(test_config['charm_name'], t) # Prepare prepare.prepare(model_name) # Deploy deploy.deploy(os.path.join(utils.BUNDLE_DIR, '{}.yaml'.format(t)), model_name) # Configure configure.configure(model_name, test_config['configure']) # Test test.test(model_name, test_config['tests']) # Destroy destroy.destroy(model_name)
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 """ test_config = utils.get_charm_config() if bundle: bundles = [bundle] else: if smoke: bundle_key = 'smoke_bundles' elif dev: bundle_key = 'dev_bundles' else: bundle_key = 'gate_bundles' bundles = test_config[bundle_key] last_test = bundles[-1] for t in bundles: model_name = utils.generate_model_name() # Prepare prepare.prepare(model_name) # Deploy deploy.deploy(os.path.join(utils.BUNDLE_DIR, '{}.yaml'.format(t)), model_name) if 'configure' in test_config: # Configure configure.configure(model_name, test_config['configure']) # Test test.test(model_name, test_config['tests']) # Destroy # Keep the model from the last run if keep_model is true, this is to # maintian compat with osci and should change when the zaza collect # functions take over from osci for artifact collection. if keep_model and t == last_test: pass else: destroy.destroy(model_name)
def run_env_deployment(env_deployment, keep_model=False): """Run the environment deployment. :param env_deployment: Environment Deploy to execute. :type env_deployment: utils.EnvironmentDeploy :param keep_model: Whether to destroy models at end of run :type keep_model: boolean """ config_steps = utils.get_config_steps() test_steps = utils.get_test_steps() model_aliases = { model_deploy.model_alias: model_deploy.model_name for model_deploy in env_deployment.model_deploys } zaza.model.set_juju_model_aliases(model_aliases) for deployment in env_deployment.model_deploys: prepare.prepare(deployment.model_name) for deployment in env_deployment.model_deploys: deploy.deploy(os.path.join(utils.BUNDLE_DIR, '{}.yaml'.format(deployment.bundle)), deployment.model_name, model_ctxt=model_aliases) for deployment in env_deployment.model_deploys: configure.configure(deployment.model_name, config_steps.get(deployment.model_alias, [])) for deployment in env_deployment.model_deploys: test.test(deployment.model_name, test_steps.get(deployment.model_alias, [])) # Destroy # Keep the model from the last run if keep_model is true, this is to # maintian compat with osci and should change when the zaza collect # functions take over from osci for artifact collection. if not keep_model: for model_name in model_aliases.values(): destroy.destroy(model_name) zaza.model.unset_juju_model_aliases()
def run_env_deployment(env_deployment, keep_model=False, force=False, test_directory=None): """Run the environment deployment. :param env_deployment: Environment Deploy to execute. :type env_deployment: utils.EnvironmentDeploy :param keep_model: Whether to destroy models at end of run :type keep_model: boolean :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 """ config_steps = utils.get_config_steps() test_steps = utils.get_test_steps() before_deploy_steps = utils.get_before_deploy_steps() model_aliases = { model_deploy.model_alias: model_deploy.model_name for model_deploy in env_deployment.model_deploys } zaza.model.set_juju_model_aliases(model_aliases) for deployment in env_deployment.model_deploys: prepare.prepare(deployment.model_name, test_directory=test_directory) force = force or utils.is_config_deploy_forced_for_bundle( deployment.bundle) for deployment in env_deployment.model_deploys: # Before deploy before_deploy.before_deploy(deployment.model_name, before_deploy_steps.get( deployment.model_alias, []), test_directory=test_directory) try: for deployment in env_deployment.model_deploys: deploy.deploy(os.path.join(utils.get_bundle_dir(), '{}.yaml'.format(deployment.bundle)), deployment.model_name, model_ctxt=model_aliases, force=force, test_directory=test_directory) # When deploying bundles with cross model relations, hooks may be # triggered in already deployedi models so wait for all models to # settle. for deployment in env_deployment.model_deploys: logging.info("Waiting for {} to settle".format( deployment.model_name)) zaza.model.block_until_all_units_idle( model_name=deployment.model_name) for deployment in env_deployment.model_deploys: configure.configure(deployment.model_name, config_steps.get(deployment.model_alias, []), test_directory=test_directory) for deployment in env_deployment.model_deploys: test.test(deployment.model_name, test_steps.get(deployment.model_alias, []), test_directory=test_directory) except zaza.model.ModelTimeout: failure_report(model_aliases, show_juju_status=True) raise except Exception: failure_report(model_aliases) raise # Destroy # Keep the model from the last run if keep_model is true, this is to # maintian compat with osci and should change when the zaza collect # functions take over from osci for artifact collection. if not keep_model: for model_name in model_aliases.values(): destroy.destroy(model_name) zaza.model.unset_juju_model_aliases()
def run_env_deployment(env_deployment, keep_model=DESTROY_MODEL, force=False, test_directory=None): """Run the environment deployment. :param env_deployment: Environment Deploy to execute. :type env_deployment: utils.EnvironmentDeploy :param keep_model: Whether to destroy model at end of run :type keep_model: int :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 """ config_steps = utils.get_config_steps() test_steps = utils.get_test_steps() before_deploy_steps = utils.get_before_deploy_steps() model_aliases = {model_deploy.model_alias: model_deploy.model_name for model_deploy in env_deployment.model_deploys} zaza.model.set_juju_model_aliases(model_aliases) for deployment in env_deployment.model_deploys: prepare.prepare( deployment.model_name, test_directory=test_directory) for deployment in env_deployment.model_deploys: # Before deploy before_deploy.before_deploy( deployment.model_name, before_deploy_steps.get(deployment.model_alias, []), test_directory=test_directory) try: for deployment in env_deployment.model_deploys: force_ = force or utils.is_config_deploy_forced_for_bundle( deployment.bundle) deploy.deploy( os.path.join( utils.get_bundle_dir(), '{}.yaml'.format(deployment.bundle)), deployment.model_name, model_ctxt=model_aliases, force=force_, test_directory=test_directory) # When deploying bundles with cross model relations, hooks may be # triggered in already deployedi models so wait for all models to # settle. for deployment in env_deployment.model_deploys: logging.info("Waiting for {} to settle".format( deployment.model_name)) with notify_around(NotifyEvents.WAIT_MODEL_SETTLE, model_name=deployment.model_name): zaza.model.block_until_all_units_idle( model_name=deployment.model_name) for deployment in env_deployment.model_deploys: configure.configure( deployment.model_name, config_steps.get(deployment.model_alias, []), test_directory=test_directory) for deployment in env_deployment.model_deploys: test.test( deployment.model_name, test_steps.get(deployment.model_alias, []), test_directory=test_directory) except zaza.model.ModelTimeout: failure_report(model_aliases, show_juju_status=True) # Destroy models that were not healthy before TEST_DEPLOY_TIMEOUT # was reached (default: 3600s) if keep_model == DESTROY_MODEL: destroy_models(model_aliases, destroy) raise except Exception: failure_report(model_aliases) # Destroy models that raised any other exception. # Note(aluria): KeyboardInterrupt will be raised on underlying libs, # and other signals (e.g. SIGTERM) will also miss this handler # In those cases, models will have to be manually destroyed if keep_model == DESTROY_MODEL: destroy_models(model_aliases, destroy) raise # Destroy successful models if --keep-model is not defined if keep_model in [DESTROY_MODEL, KEEP_FAULTY_MODEL]: destroy_models(model_aliases, destroy)