def job_execution_requires_proxy_user(job_execution): '''Returns True if the job execution requires a proxy user.''' def _check_values(values): return any(value.startswith( su.SWIFT_INTERNAL_PREFIX) for value in values if ( isinstance(value, six.string_types))) if CONF.use_domain_for_proxy_users is False: return False paths = [conductor.data_source_get(context.ctx(), job_execution.output_id), conductor.data_source_get(context.ctx(), job_execution.input_id)] if _check_values(ds.url for ds in paths if ds): return True if _check_values(six.itervalues( job_execution.job_configs.get('configs', {}))): return True if _check_values(six.itervalues( job_execution.job_configs.get('params', {}))): return True if _check_values(job_execution.job_configs.get('args', [])): return True job = conductor.job_get(context.ctx(), job_execution.job_id) if _check_values(main.url for main in job.mains): return True if _check_values(lib.url for lib in job.libs): return True # We did the simple checks, now if data_source referencing is # enabled and we have values that could be a name or uuid, # query for data_sources that match and contain a swift path by_name, by_uuid = job_utils.may_contain_data_source_refs( job_execution.job_configs) if by_name: names = tuple(job_utils.find_possible_data_source_refs_by_name( job_execution.job_configs)) # do a query here for name in names and path starts with swift-prefix if names and conductor.data_source_count( context.ctx(), name=names, url=su.SWIFT_INTERNAL_PREFIX+'%') > 0: return True if by_uuid: uuids = tuple(job_utils.find_possible_data_source_refs_by_uuid( job_execution.job_configs)) # do a query here for id in uuids and path starts with swift-prefix if uuids and conductor.data_source_count( context.ctx(), id=uuids, url=su.SWIFT_INTERNAL_PREFIX+'%') > 0: return True return False
def test_find_possible_data_source_refs_by_name(self): id = six.text_type(uuid.uuid4()) job_configs = {} self.assertEqual([], job_utils.find_possible_data_source_refs_by_name( job_configs)) name_ref = job_utils.DATA_SOURCE_PREFIX+'name' name_ref2 = name_ref+'2' job_configs = {'args': ['first', id], 'configs': {'config': 'value'}, 'params': {'param': 'value'}} self.assertEqual([], job_utils.find_possible_data_source_refs_by_name( job_configs)) job_configs = {'args': [name_ref, id], 'configs': {'config': 'value'}, 'params': {'param': 'value'}} self.assertEqual( ['name'], job_utils.find_possible_data_source_refs_by_name(job_configs)) job_configs = {'args': ['first', id], 'configs': {'config': name_ref}, 'params': {'param': 'value'}} self.assertEqual( ['name'], job_utils.find_possible_data_source_refs_by_name(job_configs)) job_configs = {'args': ['first', id], 'configs': {'config': 'value'}, 'params': {'param': name_ref}} self.assertEqual( ['name'], job_utils.find_possible_data_source_refs_by_name(job_configs)) job_configs = {'args': [name_ref, name_ref2, id], 'configs': {'config': name_ref}, 'params': {'param': name_ref}} self.assertItemsEqual( ['name', 'name2'], job_utils.find_possible_data_source_refs_by_name(job_configs))
def test_find_possible_data_source_refs_by_name(self): id = uuidutils.generate_uuid() job_configs = {} self.assertEqual([], job_utils.find_possible_data_source_refs_by_name( job_configs)) name_ref = job_utils.DATA_SOURCE_PREFIX+'name' name_ref2 = name_ref+'2' job_configs = {'args': ['first', id], 'configs': {'config': 'value'}, 'params': {'param': 'value'}} self.assertEqual([], job_utils.find_possible_data_source_refs_by_name( job_configs)) job_configs = {'args': [name_ref, id], 'configs': {'config': 'value'}, 'params': {'param': 'value'}} self.assertEqual( ['name'], job_utils.find_possible_data_source_refs_by_name(job_configs)) job_configs = {'args': ['first', id], 'configs': {'config': name_ref}, 'params': {'param': 'value'}} self.assertEqual( ['name'], job_utils.find_possible_data_source_refs_by_name(job_configs)) job_configs = {'args': ['first', id], 'configs': {'config': 'value'}, 'params': {'param': name_ref}} self.assertEqual( ['name'], job_utils.find_possible_data_source_refs_by_name(job_configs)) job_configs = {'args': [name_ref, name_ref2, id], 'configs': {'config': name_ref}, 'params': {'param': name_ref}} self.assertItemsEqual( ['name', 'name2'], job_utils.find_possible_data_source_refs_by_name(job_configs))