def destroy_models(model_aliases, destroy): """Destroy models created during integration tests.""" # Destroy # Keep the model from the last run if keep_model is true, this is to # maintain compat with osci and should change when the zaza collect # functions take over from osci for artifact collection. 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): """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 test_destroy(self): self.patch_object(lc_destroy.zaza.controller, 'destroy_model') self.patch_object(lc_destroy.model, 'get_status', return_value={'machines': "the-machines"}) self.patch_object(lc_destroy.juju_utils, 'get_provider_type', return_value="maas") self.patch("zaza.utilities.openstack_provider.clean_up_instances", name='clean_up_instances') lc_destroy.destroy('doomed') self.destroy_model.assert_called_once_with('doomed') self.clean_up_instances.assert_not_called()
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 test_destroy(self): self.patch_object(lc_destroy.zaza.controller, 'destroy_model') lc_destroy.destroy('doomed') self.destroy_model.assert_called_once_with('doomed')