def _execute_workflow_actions(self, wf_obj, app_obj, assem, verb='launch_workflow', commit_sha='', status_url=None, du_id=None): image = objects.registry.Image() image.name = app_obj.name image.source_uri = wf_obj.source['repository'] image.base_image_id = app_obj.languagepack image.image_format = CONF.api.image_format image.uuid = str(uuid.uuid4()) image.user_id = self.context.user image.project_id = self.context.tenant image.status = IMAGE_STATES.QUEUED image.create(self.context) test_cmd = wf_obj.config['test_cmd'] run_cmd = wf_obj.config['run_cmd'] ports = app_obj.ports repo_token = wf_obj.source['repo_token'] # TODO(devkulkarni): Check whether we need image.source_format image.source_format = 'solum' git_info = { 'source_url': image.source_uri, 'commit_sha': commit_sha, 'repo_token': repo_token, 'status_url': status_url, 'private': wf_obj.source['private'], 'private_ssh_key': wf_obj.source['private_ssh_key'] } if test_cmd: repo_utils.send_status(0, status_url, repo_token, pending=True) worker_api.API(context=self.context).build_app( verb=verb, build_id=image.id, git_info=git_info, ports=ports, name=image.name, base_image_id=image.base_image_id, source_format=image.source_format, image_format=image.image_format, assembly_id=assem.id, workflow=assem.workflow, test_cmd=test_cmd, run_cmd=run_cmd, du_id=du_id)
def _build_artifact(self, assem, artifact, verb='launch_workflow', commit_sha='', status_url=None): # This is a tempory hack so we don't need the build client # in the requirements. image = objects.registry.Image() image.name = artifact['name'] image.source_uri = artifact['content']['href'] image.base_image_id = artifact.get('language_pack', 'auto') image.source_format = artifact.get('artifact_type', CONF.api.source_format) image.image_format = CONF.api.image_format image.uuid = uuidutils.generate_uuid() image.user_id = self.context.user image.project_id = self.context.tenant image.status = IMAGE_STATES.QUEUED image.create(self.context) test_cmd = artifact.get('unittest_cmd') run_cmd = artifact.get('run_cmd') repo_token = artifact.get('repo_token') ports = artifact.get('ports', [80]) git_info = { 'source_url': image.source_uri, 'commit_sha': commit_sha, 'repo_token': repo_token, 'status_url': status_url } if test_cmd: repo_utils.send_status(0, status_url, repo_token, pending=True) worker_api.API(context=self.context).build_app( verb=verb, build_id=image.id, git_info=git_info, ports=ports, name=image.name, base_image_id=image.base_image_id, source_format=image.source_format, image_format=image.image_format, assembly_id=assem.id, workflow=assem.workflow, test_cmd=test_cmd, run_cmd=run_cmd)
def _build_artifact(self, assem, artifact, verb='launch_workflow', commit_sha='', status_url=None): # This is a tempory hack so we don't need the build client # in the requirements. image = objects.registry.Image() image.name = artifact['name'] image.source_uri = artifact['content']['href'] image.base_image_id = artifact.get('language_pack', 'auto') image.source_format = artifact.get('artifact_type', CONF.api.source_format) image.image_format = CONF.api.image_format image.uuid = str(uuid.uuid4()) image.user_id = self.context.user image.project_id = self.context.tenant image.status = IMAGE_STATES.QUEUED image.create(self.context) test_cmd = artifact.get('unittest_cmd') run_cmd = artifact.get('run_cmd') repo_token = artifact.get('repo_token') ports = artifact.get('ports', [80]) git_info = { 'source_url': image.source_uri, 'commit_sha': commit_sha, 'repo_token': repo_token, 'status_url': status_url } if test_cmd: repo_utils.send_status(0, status_url, repo_token, pending=True) worker_api.API(context=self.context).build_app( verb=verb, build_id=image.id, git_info=git_info, ports=ports, name=image.name, base_image_id=image.base_image_id, source_format=image.source_format, image_format=image.image_format, assembly_id=assem.id, workflow=assem.workflow, test_cmd=test_cmd, run_cmd=run_cmd)
def _do_unittest(self, ctxt, build_id, git_info, name, base_image_id, source_format, image_format, assembly_id, test_cmd): if test_cmd is None: LOG.debug("Unit test command is None; skipping unittests.") return 0 commit_sha = git_info.get('commit_sha', '') status_url = git_info.get('status_url') repo_token = git_info.get('repo_token') LOG.debug("Running unittests.") update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.UNIT_TESTING) image_tag = '' lp_access = '' if base_image_id != 'auto': image = objects.registry.Image.get_lp_by_name_or_uuid( ctxt, base_image_id, include_operators_lp=True) if (not image or not image.project_id or not image.status or not image.external_ref or not image.docker_image_name or image.status.lower() != 'ready'): LOG.warn("Error running unittest due to language pack" " not ready. assembly ID: %s" % assembly_id) update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.ERROR) return base_image_id = image.external_ref image_tag = image.docker_image_name lp_access = get_lp_access_method(image.project_id) git_url = git_info['source_url'] command = self._get_build_command(ctxt, 'unittest', git_url, name, base_image_id, source_format, image_format, commit_sha, lp_image_tag=image_tag) solum.TLS.trace.clear() solum.TLS.trace.import_context(ctxt) user_env = self._get_environment(ctxt, git_url, assembly_id=assembly_id, test_cmd=test_cmd, lp_access=lp_access) log_env = user_env.copy() if 'OS_AUTH_TOKEN' in log_env: del log_env['OS_AUTH_TOKEN'] if 'OPER_AUTH_TOKEN' in log_env: del log_env['OPER_AUTH_TOKEN'] if 'OPER_OS_STORAGE_URL' in log_env: del log_env['OPER_OS_STORAGE_URL'] solum.TLS.trace.support_info(environment=log_env) logpath = "%s/%s-%s.log" % (user_env['SOLUM_TASK_DIR'], 'unittest', user_env['BUILD_ID']) LOG.debug("Unittest logs stored at %s" % logpath) returncode = -1 assem = None if assembly_id is not None: assem = get_assembly_by_id(ctxt, assembly_id) if assem.status == ASSEMBLY_STATES.DELETING: return returncode try: runtest = subprocess.Popen(command, env=user_env, stdout=subprocess.PIPE) returncode = runtest.wait() except OSError as subex: LOG.exception("Exception running unit tests:") LOG.exception(subex) if assem is not None: assem.type = 'app' upload_task_log(ctxt, logpath, assem, user_env['BUILD_ID'], 'unittest') if returncode == 0: update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.UNIT_TESTING_PASSED) elif returncode > 0: LOG.error("Unit tests failed. Return code is %r" % (returncode)) update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.UNIT_TESTING_FAILED) elif returncode < 0: LOG.error("Error running unit tests.") update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.ERROR) repo_utils.send_status(returncode, status_url, repo_token) return returncode
def _do_unittest(self, ctxt, build_id, git_info, name, base_image_id, source_format, image_format, assembly_id, test_cmd): if test_cmd is None: LOG.debug("Unit test command is None; skipping unittests.") return 0 commit_sha = git_info.get('commit_sha', '') status_url = git_info.get('status_url') repo_token = git_info.get('repo_token') LOG.debug("Running unittests.") update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.UNIT_TESTING) image_tag = '' lp_access = '' if base_image_id != 'auto': image = objects.registry.Image.get_lp_by_name_or_uuid( ctxt, base_image_id, include_operators_lp=True) if (not image or not image.project_id or not image.status or not image.external_ref or not image.docker_image_name or image.status.lower() != 'ready'): LOG.warning("Error running unittest due to language pack" " not ready. assembly ID: %s" % assembly_id) update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.ERROR) return base_image_id = image.external_ref image_tag = image.docker_image_name lp_access = get_lp_access_method(image.project_id) git_url = git_info['source_url'] command = self._get_build_command(ctxt, 'unittest', git_url, name, base_image_id, source_format, image_format, commit_sha, lp_image_tag=image_tag) solum.TLS.trace.clear() solum.TLS.trace.import_context(ctxt) user_env = self._get_environment(ctxt, git_url, assembly_id=assembly_id, test_cmd=test_cmd, lp_access=lp_access) log_env = user_env.copy() if 'OS_AUTH_TOKEN' in log_env: del log_env['OS_AUTH_TOKEN'] if 'OPER_AUTH_TOKEN' in log_env: del log_env['OPER_AUTH_TOKEN'] if 'OPER_OS_STORAGE_URL' in log_env: del log_env['OPER_OS_STORAGE_URL'] solum.TLS.trace.support_info(environment=log_env) logpath = "%s/%s-%s.log" % (user_env['SOLUM_TASK_DIR'], 'unittest', user_env['BUILD_ID']) LOG.debug("Unittest logs stored at %s" % logpath) returncode = -1 assem = None if assembly_id is not None: assem = get_assembly_by_id(ctxt, assembly_id) if assem.status == ASSEMBLY_STATES.DELETING: return returncode try: runtest = subprocess.Popen(command, env=user_env, stdout=subprocess.PIPE) returncode = runtest.wait() except OSError as subex: LOG.exception("Exception running unit tests:") LOG.exception(subex) if assem is not None: assem.type = 'app' wf = objects.registry.Workflow.get_by_assembly_id(assem.id) upload_task_log(ctxt, logpath, assem, wf.id, 'unittest') if returncode == 0: update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.UNIT_TESTING_PASSED) elif returncode > 0: LOG.error("Unit tests failed. Return code is %r" % (returncode)) update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.UNIT_TESTING_FAILED) elif returncode < 0: LOG.error("Error running unit tests.") update_assembly_status(ctxt, assembly_id, ASSEMBLY_STATES.ERROR) repo_utils.send_status(returncode, status_url, repo_token) return returncode