Exemplo n.º 1
0
    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']
Exemplo n.º 2
0
  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']
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
  def test_new_ok_deduped(self):
    """Asserts that new returns task result for deduped."""
    # Run a task to completion.
    self.mock(random, 'getrandbits', lambda _: 0x88)
    now = self.mock_now(datetime.datetime(2010, 1, 2, 3, 4, 5))
    str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
    self.client_create_task_raw(
        name='task', tags=['project:yay', 'commit:post', 'os:Win'],
        properties=dict(idempotent=True))
    self.set_as_bot()
    self.bot_run_task()

    self.mock(random, 'getrandbits', lambda _: 0x66)
    now_30 = self.mock_now(now, 30)
    str_now_30 = unicode(now_30.strftime(self.DATETIME_NO_MICRO))
    self.set_as_user()

    request = swarming_rpcs.NewTaskRequest(
        expiration_secs=30,
        name='job1',
        priority=200,
        properties=swarming_rpcs.TaskProperties(
            command=['python', 'run_test.py'],
            dimensions=[
              swarming_rpcs.StringPair(key='os', value='Amiga'),
              swarming_rpcs.StringPair(key='pool', value='default'),
            ],
            execution_timeout_secs=3600,
            idempotent=True,
            io_timeout_secs=1200,
            packages=[
              swarming_rpcs.CipdPackage(
                  package_name='rm',
                  version=test_env_handlers.PINNED_PACKAGE_VERSION),
            ]),
        tags=['foo:bar'],
        user='******')
    expected = {
      u'request': {
        u'authenticated': u'user:[email protected]',
        u'created_ts': str_now_30,
        u'expiration_secs': u'30',
        u'name': u'job1',
        u'priority': u'200',
        u'properties': {
          u'command': [u'python', u'run_test.py'],
          u'dimensions': [
            {u'key': u'os', u'value': u'Amiga'},
            {u'key': u'pool', u'value': u'default'},
          ],
          u'execution_timeout_secs': u'3600',
          u'grace_period_secs': u'30',
          u'idempotent': True,
          u'io_timeout_secs': u'1200',
          u'packages': [{
            u'package_name': u'rm',
            u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
          }],
        },
        u'tags': [
          u'foo:bar',
          u'os:Amiga',
          u'pool:default',
          u'priority:200',
          u'user:joe@localhost',
        ],
        u'user': u'joe@localhost',
      },
      u'task_id': u'5cf59b8006610',
      u'task_result': {
        u'bot_dimensions': [
          {u'key': u'id', u'value': [u'bot1']},
          {u'key': u'os', u'value': [u'Amiga']},
          {u'key': u'pool', u'value': [u'default']},
        ],
        u'bot_id': u'bot1',
        u'bot_version': self.bot_version,
        u'completed_ts': str_now,
        u'cost_saved_usd': 0.1,
        u'created_ts': str_now_30,
        u'deduped_from': u'5cee488008811',
        u'duration': 0.1,
        u'exit_code': u'0',
        u'failure': False,
        u'internal_failure': False,
        u'modified_ts': str_now_30,
        u'name': u'job1',
        u'server_versions': [u'v1a'],
        u'started_ts': str_now,
        u'state': u'COMPLETED',
        u'tags': [
          u'foo:bar',
          u'os:Amiga',
          u'pool:default',
          u'priority:200',
          u'user:joe@localhost',
        ],
        u'task_id': u'5cf59b8006610',
        u'try_number': u'0',
        u'user': u'joe@localhost',
      },
    }
    response = self.call_api('new', body=message_to_dict(request))
    self.assertEqual(expected, response.json)

    request = swarming_rpcs.TasksRequest(state=swarming_rpcs.TaskState.DEDUPED)
    expected = {
      u'items': [
        {
          u'bot_dimensions': [
            {u'key': u'id', u'value': [u'bot1']},
            {u'key': u'os', u'value': [u'Amiga']},
            {u'key': u'pool', u'value': [u'default']},
          ],
          u'bot_id': u'bot1',
          u'bot_version': self.bot_version,
          u'completed_ts': str_now,
          u'cost_saved_usd': 0.1,
          u'created_ts': str_now_30,
          u'deduped_from': u'5cee488008811',
          u'duration': 0.1,
          u'exit_code': u'0',
          u'failure': False,
          u'internal_failure': False,
          u'modified_ts': str_now_30,
          u'name': u'job1',
          u'server_versions': [u'v1a'],
          u'started_ts': str_now,
          u'state': u'COMPLETED',
          u'tags': [
            u'foo:bar',
            u'os:Amiga',
            u'pool:default',
            u'priority:200',
            u'user:joe@localhost',
          ],
          u'task_id': u'5cf59b8006610',
          u'try_number': u'0',
          u'user': u'joe@localhost',
        },
      ],
      u'now': str_now_30,
    }
    self.assertEqual(
        expected,
        self.call_api('list', body=message_to_dict(request)).json)
    # Assert the entity presence.
    self.assertEqual(2, task_request.TaskRequest.query().count())
    self.assertEqual(2, task_result.TaskResultSummary.query().count())
    self.assertEqual(1, task_result.TaskRunResult.query().count())

    # Deduped task have no performance data associated.
    request = swarming_rpcs.TasksRequest(
        state=swarming_rpcs.TaskState.DEDUPED,
        include_performance_stats=True)
    actual = self.call_api('list', body=message_to_dict(request)).json
    self.assertEqual(expected, actual)

    # Use the occasion to test 'count' and 'requests'.
    start = utils.datetime_to_timestamp(now) / 1000000. - 1
    end = utils.datetime_to_timestamp(now_30) / 1000000. + 1
    request = swarming_rpcs.TasksCountRequest(
        start=start, end=end, state=swarming_rpcs.TaskState.DEDUPED)
    self.assertEqual(
        {u'now': str_now_30, u'count': u'1'},
        self.call_api('count', body=message_to_dict(request)).json)
    request = swarming_rpcs.TasksRequest(start=start, end=end)
    expected = {
      u'items': [
        {
          u'authenticated': u'user:[email protected]',
          u'created_ts': str_now_30,
          u'expiration_secs': u'30',
          u'name': u'job1',
          u'priority': u'200',
          u'properties': {
            u'command': [u'python', u'run_test.py'],
            u'dimensions': [
              {u'key': u'os', u'value': u'Amiga'},
              {u'key': u'pool', u'value': u'default'},
            ],
            u'execution_timeout_secs': u'3600',
            u'grace_period_secs': u'30',
            u'idempotent': True,
            u'io_timeout_secs': u'1200',
            u'packages': [{
              u'package_name': u'rm',
              u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
            }],
          },
          u'tags': [
            u'foo:bar',
            u'os:Amiga',
            u'pool:default',
            u'priority:200',
            u'user:joe@localhost',
          ],
          u'user': u'joe@localhost',
        },
        {
          u'authenticated': u'user:[email protected]',
          u'created_ts': str_now,
          u'expiration_secs': u'86400',
          u'name': u'task',
          u'priority': u'10',
          u'properties': {
            u'command': [u'python', u'run_test.py'],
            u'dimensions': [
              {u'key': u'os', u'value': u'Amiga'},
              {u'key': u'pool', u'value': u'default'},
            ],
            u'execution_timeout_secs': u'3600',
            u'grace_period_secs': u'30',
            u'idempotent': True,
            u'io_timeout_secs': u'1200',
            u'packages': [{
              u'package_name': u'rm',
              u'version': test_env_handlers.PINNED_PACKAGE_VERSION,
            }],
          },
          u'tags': [
            u'commit:post',
            u'os:Amiga',
            u'os:Win',
            u'pool:default',
            u'priority:10',
            u'project:yay',
            u'user:joe@localhost',
          ],
          u'user': u'joe@localhost',
        },
      ],
      u'now': str_now_30,
    }
    self.assertEqual(
        expected,
        self.call_api('requests', body=message_to_dict(request)).json)
Exemplo n.º 5
0
 def test_new_ok_raw(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.NewTaskRequest(
       expiration_secs=30,
       name='job1',
       priority=200,
       properties=swarming_rpcs.TaskProperties(
           command=['rm', '-rf', '/'],
           packages=[
             swarming_rpcs.CipdPackage(package_name='rm', version='latest'),
           ],
           dimensions=[
             swarming_rpcs.StringPair(key='pool', value='default'),
           ],
           env=[
             swarming_rpcs.StringPair(key='PATH', value='/'),
           ],
           execution_timeout_secs=30,
           io_timeout_secs=30),
       tags=['foo:bar'],
       user='******',
       pubsub_topic='projects/abc/topics/def',
       pubsub_auth_token='secret that must not be shown',
       pubsub_userdata='userdata')
   expected = {
     u'request': {
       u'authenticated': u'user:[email protected]',
       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'packages': [{
           u'package_name': u'rm',
           u'version': u'latest',
         }],
         u'dimensions': [
           {u'key': u'pool', u'value': u'default'},
         ],
         u'env': [
           {u'key': u'PATH', u'value': u'/'},
         ],
         u'execution_timeout_secs': u'30',
         u'grace_period_secs': u'30',
         u'idempotent': False,
         u'io_timeout_secs': u'30',
       },
       u'pubsub_topic': u'projects/abc/topics/def',
       u'pubsub_userdata': u'userdata',
       u'tags': [
         u'foo:bar',
         u'pool:default',
         u'priority:200',
         u'user:joe@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)