def start(self, verifier_id, deployment_id, tags=None, **run_args): """Start a verification. # The check is needed in `rally verify` command to validate that we can perform # all actions on the specific deployment. `rally task` has the same check, so we # do not need to copy that anywhere. deployment = objects.Deployment.get(deployment_id) if deployment["status"] != consts.DeployStatus.DEPLOY_FINISHED: raise exceptions.DeploymentNotFinishedStatus( name=deployment["name"], uuid=deployment["uuid"], status=deployment["status"]) # In Rally < 0.8.0 there was a tempest context that installs tempest if # needed. https://github.com/openstack/rally/blob/0.7.0/rally/plugins/openstack/context/not_for_production/tempest.py # The similar context should be implemented. As for the first version of # implementation, let's implement the simple context that will accept verifier ID and # check that it is already configured, if not - call configure. verifier = self.api.verifier._get(verifier_id) if verifier.status != consts.VerifierStatus.INSTALLED: raise exceptions.RallyException( "Failed to start verification because verifier %s is in '%s' " "status, but should be in '%s'." % ( verifier, verifier.status, consts.VerifierStatus.INSTALLED) ) verifier.set_deployment(deployment_id) if not verifier.manager.is_configured(): self.api.verifier.configure(verifier, deployment_id) # It can be ignored for now. verifier.manager.validate(run_args) # we do not need to create Verification object since we will save results # as task results verification = objects.Verification.create( verifier_id=verifier_id, deployment_id=deployment_id, tags=tags, run_args=run_args) LOG.info("Starting verification (UUID=%s) for deployment '%s' " "(UUID=%s) by verifier %s.", verification.uuid, verifier.deployment["name"], verifier.deployment["uuid"], verifier) verification.update_status(consts.VerificationStatus.RUNNING) context = {"config": verifier.manager._meta_get("context"), "run_args": run_args, "verification": verification, "verifier": verifier} try: with vcontext.ContextManager(context): results = verifier.manager.run(context) except Exception as e: verification.set_error(e) raise # TODO(ylobankov): Check that verification exists in the database # because users may delete verification before tests # finish. verification.finish(results.totals, results.tests) LOG.info("Verification (UUID=%s) has been successfully finished for " "deployment '%s' (UUID=%s)!", verification.uuid, verifier.deployment["name"], verifier.deployment["uuid"]) return {"verification": verification.to_dict(), "totals": results.totals, "tests": results.tests}