def testTriggerSwarmingTask(self, mock_ref, mock_create, mock_trigger, _): runner_id = 'runner_id' master_name = 'm' builder_name = 'b' build_number = 6 step_name = 's' tests = ['test'] WfSwarmingTask.Create(master_name, builder_name, build_number, step_name).put() parameters = RunSwarmingTaskParameters(build_key=BuildKey( master_name=master_name, builder_name=builder_name, build_number=build_number), step_name=step_name, tests=tests) new_request = SwarmingTaskRequest.FromSerializable( _SAMPLE_REQUEST_JSON) mock_create.return_value = new_request task_id = test_swarming.TriggerSwarmingTask(parameters, runner_id) self.assertEqual('new_task_id', task_id) mock_ref.assert_called_once_with(master_name, builder_name, build_number, step_name, None) mock_create.assert_called_once_with('runner_id', 'task_id', 'ref_request', master_name, builder_name, step_name, tests, 10) mock_trigger.assert_called_once_with('chromium-swarm.appspot.com', new_request, None)
def testGetReferredSwarmingTaskRequestInfo(self, mock_get, _): request = SwarmingTaskRequest.FromSerializable(_REF_REQUEST) mock_get.return_value = request task_id, ref_request = swarming.GetReferredSwarmingTaskRequestInfo( 'm', 'b', 123, 's', None) self.assertEqual('task_id', task_id) self.assertEqual(request, ref_request)
def GetSwarmingTaskRequest(host, task_id, http_client): """Returns request data of the given task.""" url = _TASK_ID_URL % (host, task_id) content, error = http_client_util.SendRequestToServer(url, http_client) if not error: json_data = json.loads(content) return SwarmingTaskRequest.FromSerializable(json_data) return None
def testGetSwarmingTaskRequest(self, mock_get): task_request_json = { 'expiration_secs': '2', 'name': 'name', 'parent_task_id': 'pti', 'priority': '1', 'properties': { 'command': 'cmd', 'dimensions': [{ 'key': 'd', 'value': 'dv' }], 'env': [{ 'key': 'e', 'value': 'ev' }], 'execution_timeout_secs': '4', 'extra_args': ['--flag'], 'grace_period_secs': '5', 'idempotent': True, 'inputs_ref': { 'isolated': 'i', 'isolatedserver': 'is', 'namespace': 'ns', }, 'io_timeout_secs': '3', }, 'tags': ['tag'], 'user': '******', 'pubsub_topic': None, 'pubsub_auth_token': None, 'pubsub_userdata': None, } task_id = '1' mock_get.return_value = (json.dumps(task_request_json), None) task_request = swarming_util.GetSwarmingTaskRequest( 'host', task_id, None) self.assertEqual( SwarmingTaskRequest.FromSerializable(task_request_json), task_request)
def testTriggerSwarmingTask(self, mock_post): task_request_json = { 'expiration_secs': '72000', 'name': 'name', 'parent_task_id': 'pti', 'priority': '150', 'properties': { 'command': 'cmd', 'dimensions': [{ 'key': 'd', 'value': 'dv' }], 'env': [{ 'key': 'e', 'value': 'ev' }], 'execution_timeout_secs': '4', 'extra_args': ['--flag'], 'grace_period_secs': '5', 'idempotent': True, 'inputs_ref': { 'isolated': 'i' }, 'io_timeout_secs': '3', }, 'tags': ['tag', 'findit:1', 'project:Chromium', 'purpose:post-commit'], 'user': '******', 'pubsub_topic': None, 'pubsub_auth_token': None, 'pubsub_userdata': None, } mock_post.return_value = json.dumps({'task_id': '1'}), None task_id, error = swarming_util.TriggerSwarmingTask( 'host', SwarmingTaskRequest.FromSerializable(task_request_json), None) self.assertEqual('1', task_id) self.assertIsNone(error)
def testFromSerializable(self): data = { 'expiration_secs': '50', 'name': 'a swarming task', 'parent_task_id': 'parent task id', 'priority': '150', 'tags': ['a'], 'user': '******', 'some_unused_field': 'blabla', 'pubsub_topic': 'topic', 'pubsub_auth_token': 'token', 'pubsub_userdata': 'data', 'properties': { 'command': 'path/to/binary', 'unused_property': 'blabla', 'dimensions': [ { 'key': 'cpu', 'value': 'x86-64', }, ], 'env': [ { 'key': 'name', 'value': '1', }, ], 'execution_timeout_secs': 10, 'grace_period_secs': 5, 'extra_args': ['--arg=value'], 'idempotent': True, 'inputs_ref': { 'namespace': 'default-gzip', 'isolated': 'a-hash', 'random_field': 'blabla' }, 'io_timeout_secs': 10, }, } expected_request = SwarmingTaskRequest( created_ts=None, expiration_secs='50', name='a swarming task', parent_task_id='parent task id', priority='150', properties=SwarmingTaskProperties( caches=None, command='path/to/binary', dimensions=[ { 'key': 'cpu', 'value': 'x86-64', }, ], env=[ { 'key': 'name', 'value': '1', }, ], env_prefixes=[], execution_timeout_secs='10', extra_args=ListOfBasestring.FromSerializable(['--arg=value']), grace_period_secs='5', io_timeout_secs='10', idempotent=True, inputs_ref=SwarmingTaskInputsRef(isolated='a-hash', isolatedserver=None, namespace='default-gzip')), pubsub_auth_token='token', pubsub_topic='topic', pubsub_userdata='data', service_account=None, tags=ListOfBasestring.FromSerializable(['a']), user='******') self.assertEqual(expected_request, SwarmingTaskRequest.FromSerializable(data))
def testTriggerSwarmingTask(self, mocked_request, mocked_trigger, mocked_reference_info): master_name = 'm' builder_name = 'b' build_number = 123 step_name = 's' test_name = 't' isolate_sha = 'sha1' iterations = 50 timeout_seconds = 3600 runner_id = 'pipeline_id' ref_task_id = 'ref_task_id' ref_request = SwarmingTaskRequest.FromSerializable( _SAMPLE_REQUEST_JSON) task_id = 'task_id' request = SwarmingTaskRequest( created_ts=None, name='findit/ref_task_id/ref_task_id/2018-03-15 00:00:00 000000', tags=ListOfBasestring.FromSerializable([ 'ref_master:m', 'ref_buildername:b', 'ref_buildnumber:4', 'ref_stepname:s', 'ref_name:test', 'purpose:identify-regression-range', ]), pubsub_topic='projects/app-id/topics/swarming', properties=SwarmingTaskProperties( dimensions=[{ 'value': 'v', 'key': 'k' }], idempotent=False, inputs_ref=SwarmingTaskInputsRef( isolatedserver='isolatedserver', namespace=None, isolated='sha1'), extra_args=ListOfBasestring.FromSerializable([ '--flag=value', '--gtest_filter=a.b:a.c', '--gtest_repeat=50', '--test-launcher-retry-limit=0', '--gtest_also_run_disabled_tests' ]), io_timeout_secs='1200', command='cmd', env=[{ 'value': '1', 'key': 'a' }], execution_timeout_secs='3600', env_prefixes=[], grace_period_secs='30', caches=None), priority='25', parent_task_id='', user='', service_account=None, pubsub_userdata='{"runner_id": "runner_id"}', expiration_secs='3600', pubsub_auth_token='auth_token') mocked_reference_info.return_value = (ref_task_id, ref_request) mocked_request.return_value = request mocked_trigger.return_value = (task_id, None) self.assertEqual( task_id, flake_swarming.TriggerSwarmingTask(master_name, builder_name, build_number, step_name, test_name, isolate_sha, iterations, timeout_seconds, runner_id)) mocked_request.assert_called_once_with(runner_id, ref_task_id, ref_request, master_name, builder_name, step_name, test_name, isolate_sha, iterations, timeout_seconds)
def testCreateNewSwarmingTaskRequest(self, mocked_template): mocked_template.return_value = SwarmingTaskRequest.FromSerializable( _SAMPLE_REQUEST_JSON) runner_id = 'pipeline_id' ref_task_id = 'ref_task_id' ref_request = SwarmingTaskRequest.GetSwarmingTaskRequestTemplate() master_name = 'm' builder_name = 'b' step_name = 's' test_name = 't' iterations = 50 timeout_seconds = 3600 isolate_sha = 'sha1' expected_request = SwarmingTaskRequest( created_ts=None, name='findit/ref_task_id/ref_task_id/2018-03-15 00:00:00 000000', tags=ListOfBasestring.FromSerializable([ 'ref_master:m', 'ref_buildername:b', 'ref_buildnumber:4', 'ref_stepname:s', 'ref_name:test', 'purpose:identify-regression-range', ]), pubsub_topic='projects/app-id/topics/swarming', properties=SwarmingTaskProperties( dimensions=[{ 'value': 'v', 'key': 'k' }], idempotent=False, inputs_ref=SwarmingTaskInputsRef( isolatedserver='isolatedserver', namespace=None, isolated='sha1'), extra_args=ListOfBasestring.FromSerializable([ '--flag=value', '--gtest_filter=a.b:a.c', '--gtest_repeat=50', '--test-launcher-retry-limit=0', '--gtest_also_run_disabled_tests' ]), io_timeout_secs='1200', command='cmd', env=[{ 'value': '1', 'key': 'a' }], execution_timeout_secs='3600', env_prefixes=[], grace_period_secs='30', caches=None, cipd_input=swarming_task_request.CIPDInput( packages=swarming_task_request.CIPDPackages(), client_package=swarming_task_request.CIPDClientPackage( version=None, package_name=None, ), server=None)), priority='25', parent_task_id='', user='', service_account=None, pubsub_userdata='{"runner_id": "runner_id"}', expiration_secs='3600', pubsub_auth_token='auth_token') self.assertEqual( expected_request, flake_swarming.CreateNewSwarmingTaskRequest( runner_id, ref_task_id, ref_request, master_name, builder_name, step_name, test_name, isolate_sha, iterations, timeout_seconds))
def testCreateNewSwarmingTaskRequestTemplate(self, *_): ref_task_id = 'ref_task_id' master_name = 'm' builder_name = 'b' step_name = 'a_tests on platform' tests = ['a.b', 'a.c'] iterations = 100 new_request = swarming.CreateNewSwarmingTaskRequestTemplate( 'runner_id', ref_task_id, SwarmingTaskRequest.FromSerializable(_REF_REQUEST), master_name, builder_name, step_name, tests, iterations) expected_new_request_json = { 'expiration_secs': '72000', 'name': 'findit/ref_task_id/ref_task_id/2018-03-15 00:00:00 000000', 'parent_task_id': '', 'priority': '150', 'properties': { 'command': 'cmd', 'dimensions': [{ 'key': 'k', 'value': 'v' }], 'env': [ { 'key': 'a', 'value': '1' }, ], 'execution_timeout_secs': '3600', 'extra_args': [ '--flag=value', '--isolated-script-test-filter=a.b::a.c', '--isolated-script-test-repeat=%d' % iterations, '--isolated-script-test-launcher-retry-limit=0', '--isolated-script-test-also-run-disabled-tests', ], 'grace_period_secs': '30', 'idempotent': False, 'inputs_ref': { 'isolatedserver': 'isolatedserver', }, 'io_timeout_secs': '1200', }, 'tags': [ 'ref_master:%s' % master_name, 'ref_buildername:%s' % builder_name, 'ref_stepname:%s' % step_name, 'ref_name:a_tests', 'findit:1', 'project:Chromium', 'purpose:post-commit' ], 'user': '', 'pubsub_auth_token': 'auth_token', 'pubsub_topic': 'projects/app-id/topics/swarming', 'pubsub_userdata': json.dumps({'runner_id': 'runner_id'}), } self.assertEqual( SwarmingTaskRequest.FromSerializable(expected_new_request_json), new_request)
def testTriggerSwarmingTaskError(self, _): request = SwarmingTaskRequest.FromSerializable({}) task_id, error = swarming_util.TriggerSwarmingTask( 'host', request, None) self.assertIsNone(task_id) self.assertIsNotNone(error)
def testOnSwarmingTaskTriggered(self): master_name = 'm' builder_name = 'b' build_number = 6 step_name = 's' task = WfSwarmingTask.Create(master_name, builder_name, build_number, step_name) task.put() task_id = 'task_id' tests = ['t'] iterations = 100 new_request = { 'expiration_secs': '3600', 'name': 'findit/ref_task_id/ref_task_id/2018-03-15 00:00:00 000000', 'parent_task_id': '', 'priority': '25', 'properties': { 'command': 'cmd', 'dimensions': [{ 'key': 'k', 'value': 'v' }], 'env': [ { 'key': 'a', 'value': '1' }, ], 'execution_timeout_secs': '10', 'extra_args': [ '--flag=value', '--gtest_filter=a.b:a.c', '--gtest_repeat=30', '--test-launcher-retry-limit=0', '--gtest_also_run_disabled_tests', ], 'grace_period_secs': '30', 'idempotent': False, 'inputs_ref': { 'isolatedserver': 'isolatedserver', 'isolated': 'sha' }, 'io_timeout_secs': '1200', }, 'tags': [ 'ref_master:m', 'ref_buildername:b', 'ref_buildnumber:4', 'ref_stepname:s', 'ref_name:test', ], 'user': '', 'pubsub_auth_token': 'auth_token', 'pubsub_topic': 'projects/app-id/topics/swarming', 'pubsub_userdata': json.dumps({'runner_id': 'runner_id'}), } test_swarming.OnSwarmingTaskTriggered( master_name, builder_name, build_number, step_name, tests, 'task_id', iterations, SwarmingTaskRequest.FromSerializable(new_request)) task = WfSwarmingTask.Get(master_name, builder_name, build_number, step_name) self.assertEqual(task.task_id, task_id)