def _get_environment(self, ctxt, source_uri, assembly_id=None, test_cmd=None, run_cmd=None, lp_access=None): # create a minimal environment user_env = {} for var in ['PATH', 'LOGNAME', 'LANG', 'HOME', 'USER', 'TERM']: if var in os.environ: user_env[var] = os.environ[var] if assembly_id is not None: assem = get_assembly_by_id(ctxt, assembly_id) user_env['ASSEMBLY_ID'] = str(assem.uuid) else: str_assem = (''.join(random.choice(string.ascii_uppercase) for i in range(20))) user_env['ASSEMBLY_ID'] = str_assem user_env['IMAGE_STORAGE'] = cfg.CONF.worker.image_storage user_env['DELETE_LOCAL_CACHE'] = cfg.CONF.worker.delete_local_cache if cfg.CONF.worker.image_storage == 'docker_registry': if cfg.CONF.worker.docker_reg_endpoint is None: LOG.debug("DU upload set to docker registry,") LOG.debug("but docker registry endpoint is not set.") LOG.debug("Setting it to 127.0.0.1") cfg.CONF.worker.docker_reg_endpoint = '127.0.0.1' user_env['DOCKER_REGISTRY'] = cfg.CONF.worker.docker_reg_endpoint else: client_region_name = clients.get_client_option('swift', 'region_name') user_env['OS_AUTH_TOKEN'] = ctxt.auth_token user_env['OS_AUTH_URL'] = ctxt.auth_url or '' user_env['OS_REGION_NAME'] = client_region_name kc = clients.OpenStackClients(ctxt).keystone() user_env['OS_IMAGE_URL'] = kc.client.service_catalog.url_for( service_type='image', endpoint_type='publicURL') user_env['OS_STORAGE_URL'] = kc.client.service_catalog.url_for( service_type='object-store', endpoint_type='publicURL', region_name=client_region_name) user_env['TEMP_URL_SECRET'] = cfg.CONF.worker.temp_url_secret user_env['TEMP_URL_PROTOCOL'] = cfg.CONF.worker.temp_url_protocol user_env['TEMP_URL_TTL'] = cfg.CONF.worker.temp_url_ttl user_env['OPR_LP_DOWNLOAD_STRATEGY'] = ( cfg.CONF.worker.operator_lp_download_strategy) # Get LP Operator context for downloading operator LPs lp_kc = clients.OpenStackClients(None).keystone().lp_admin_client user_env['OPER_AUTH_TOKEN'] = lp_kc.auth_token user_env['OPER_OS_STORAGE_URL'] = lp_kc.service_catalog.url_for( service_type='object-store', endpoint_type='publicURL', region_name=client_region_name) if test_cmd is not None: user_env['TEST_CMD'] = test_cmd if run_cmd is not None: user_env['RUN_CMD'] = run_cmd user_env['PROJECT_ID'] = ctxt.tenant user_env['BUILD_ID'] = uuidutils.generate_uuid() user_env['SOLUM_TASK_DIR'] = cfg.CONF.worker.task_log_dir if lp_access is not None: user_env['ACCESS'] = lp_access params_env = self._get_parameter_env(ctxt, source_uri, assembly_id, user_env['BUILD_ID']) user_env.update(params_env) return user_env
def _get_environment(self, ctxt, source_uri, assembly_id=None, test_cmd=None, run_cmd=None, lp_access=None): # create a minimal environment user_env = {} for var in ['PATH', 'LOGNAME', 'LANG', 'HOME', 'USER', 'TERM']: if var in os.environ: user_env[var] = os.environ[var] if assembly_id is not None: assem = get_assembly_by_id(ctxt, assembly_id) user_env['ASSEMBLY_ID'] = str(assem.uuid) else: str_assem = (''.join( random.choice(string.ascii_uppercase) for i in range(20))) user_env['ASSEMBLY_ID'] = str_assem user_env['IMAGE_STORAGE'] = cfg.CONF.worker.image_storage user_env['DELETE_LOCAL_CACHE'] = cfg.CONF.worker.delete_local_cache if cfg.CONF.worker.image_storage == 'docker_registry': if cfg.CONF.worker.docker_reg_endpoint is None: LOG.debug("DU upload set to docker registry,") LOG.debug("but docker registry endpoint is not set.") LOG.debug("Setting it to 127.0.0.1") cfg.CONF.worker.docker_reg_endpoint = '127.0.0.1' user_env['DOCKER_REGISTRY'] = cfg.CONF.worker.docker_reg_endpoint else: client_region_name = clients.get_client_option( 'swift', 'region_name') user_env['OS_AUTH_TOKEN'] = ctxt.auth_token user_env['OS_AUTH_URL'] = ctxt.auth_url or '' user_env['OS_REGION_NAME'] = client_region_name kc = clients.OpenStackClients(ctxt).keystone() user_env['OS_IMAGE_URL'] = kc.client.service_catalog.url_for( service_type='image', endpoint_type='publicURL') user_env['OS_STORAGE_URL'] = kc.client.service_catalog.url_for( service_type='object-store', endpoint_type='publicURL', region_name=client_region_name) user_env['TEMP_URL_SECRET'] = cfg.CONF.worker.temp_url_secret user_env['TEMP_URL_PROTOCOL'] = cfg.CONF.worker.temp_url_protocol user_env['TEMP_URL_TTL'] = cfg.CONF.worker.temp_url_ttl user_env['OPR_LP_DOWNLOAD_STRATEGY'] = ( cfg.CONF.worker.operator_lp_download_strategy) # Get LP Operator context for downloading operator LPs lp_kc = clients.OpenStackClients(None).keystone().lp_admin_client user_env['OPER_AUTH_TOKEN'] = lp_kc.auth_token user_env['OPER_OS_STORAGE_URL'] = lp_kc.service_catalog.url_for( service_type='object-store', endpoint_type='publicURL', region_name=client_region_name) if test_cmd is not None: user_env['TEST_CMD'] = test_cmd if run_cmd is not None: user_env['RUN_CMD'] = run_cmd user_env['PROJECT_ID'] = ctxt.tenant user_env['BUILD_ID'] = uuidutils.generate_uuid() user_env['SOLUM_TASK_DIR'] = cfg.CONF.worker.task_log_dir if lp_access is not None: user_env['ACCESS'] = lp_access params_env = self._get_parameter_env(ctxt, source_uri, assembly_id, user_env['BUILD_ID']) user_env.update(params_env) return user_env