def _client_create_task(self, properties=None, **kwargs): """Creates an isolated command TaskRequest via the Cloud Endpoints API.""" params = { 'dimensions': [ { 'key': 'os', 'value': 'Amiga' }, ], 'env': [], 'execution_timeout_secs': 3600, 'io_timeout_secs': 1200, } params.update(properties or {}) props = swarming_rpcs.TaskProperties(**params) params = { 'expiration_secs': 24 * 60 * 60, 'name': 'hi', 'priority': 10, 'tags': [], 'user': '******', } params.update(kwargs) request = swarming_rpcs.TaskRequest(properties=props, **params) response = self.endpoint_call(handlers_endpoints.SwarmingTasksService, 'new', request) return response, response['task_id']
def test_new_ok(self): """Asserts that new generates appropriate metadata.""" self.mock(random, 'getrandbits', lambda _: 0x88) now = datetime.datetime(2010, 1, 2, 3, 4, 5) self.mock_now(now) str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) request = swarming_rpcs.TaskRequest( expiration_secs=30, name='job1', priority=200, properties=swarming_rpcs.TaskProperty( command=['rm', '-rf', '/'], data=[swarming_rpcs.StringPair(key='foo', value='bar')], dimensions=[], env=[], execution_timeout_secs=30, io_timeout_secs=30), tags=['foo:bar'], user='******') expected = { u'request': { u'authenticated': u'anonymous=anonymous', u'created_ts': str_now, u'expiration_secs': u'30', u'name': u'job1', u'priority': u'200', u'properties': { u'command': [u'rm', u'-rf', u'/'], u'data': [{ u'key': u'foo', u'value': u'bar' }], u'execution_timeout_secs': u'30', u'grace_period_secs': u'30', u'idempotent': False, u'io_timeout_secs': u'30', }, u'tags': [ u'foo:bar', u'priority:200', u'user:joe@localhost', ], u'user': u'joe@localhost', }, u'task_id': u'5cee488008810', } response = self.call_api('new', message_to_dict(request), 200) self.assertEqual(expected, response.json)
def client_create_task_isolated(self, properties=None, **kwargs): """Creates a TaskRequest via the Cloud Endpoints API.""" params = { 'dimensions': [ {'key': 'os', 'value': 'Amiga'}, ], 'env': [], 'execution_timeout_secs': 3600, 'io_timeout_secs': 1200, 'inputs_ref': { 'isolated': '0123456789012345678901234567890123456789', 'isolatedserver': 'http://*****:*****@example.com', 'localhost') try: response = api.call_api( 'new', body=json.loads(protojson.encode_message(request))) finally: endpoints.get_current_user = old_get_current_user response = response.json return response, response['task_id']
def test_new_ok_isolated(self): """Asserts that new generates appropriate metadata.""" self.mock(random, 'getrandbits', lambda _: 0x88) now = datetime.datetime(2010, 1, 2, 3, 4, 5) self.mock_now(now) str_now = unicode(now.strftime(self.DATETIME_NO_MICRO)) request = swarming_rpcs.TaskRequest( expiration_secs=30, name='job1', priority=200, properties=swarming_rpcs.TaskProperties( dimensions=[ swarming_rpcs.StringPair(key='foo', value='bar'), swarming_rpcs.StringPair(key='a', value='b'), ], env=[ swarming_rpcs.StringPair(key='PATH', value='/'), ], execution_timeout_secs=30, inputs_ref=swarming_rpcs.FilesRef( isolated='1' * 40, isolatedserver='http://*****:*****@localhost', ], u'user': u'joe@localhost', }, u'task_id': u'5cee488008810', } response = self.call_api('new', body=message_to_dict(request)) self.assertEqual(expected, response.json)