Esempio n. 1
0
    def test_cancel_ok(self):
        """Asserts that task cancellation goes smoothly."""
        # create and cancel a task
        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))
        self.set_as_admin()
        _, task_id = self.client_create_task()
        request = swarming_rpcs.TaskId(task_id=task_id)
        expected = {u'ok': True, u'was_running': False}
        response = self.call_api('cancel', message_to_dict(request), 200)
        self.assertEqual(expected, response.json)

        # determine that the task's state updates correctly
        request = swarming_rpcs.TaskId(task_id=task_id)
        expected = {
            u'abandoned_ts': str_now,
            u'created_ts': str_now,
            u'failure': False,
            u'id': task_id,
            u'internal_failure': False,
            u'modified_ts': str_now,
            u'name': u'hi',
            u'state': u'CANCELED',
            u'user': u'joe@localhost',
        }
        response = self.call_api('result', message_to_dict(request), 200)
        self.assertEqual(expected, response.json)
Esempio n. 2
0
 def test_request_ok(self):
     """Asserts that request produces a task request."""
     now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
     self.mock_now(now)
     _, task_id = self.client_create_task()
     self.set_as_bot()
     request = swarming_rpcs.TaskId(task_id=task_id)
     response = self.call_api('request', message_to_dict(request), 200)
     expected = {
         u'authenticated': u'[email protected]',
         u'created_ts': unicode(now.strftime(self.DATETIME_FORMAT)),
         u'expiration_secs': unicode(24 * 60 * 60),
         u'name': u'hi',
         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'execution_timeout_secs': u'3600',
             u'grace_period_secs': u'30',
             u'idempotent': False,
             u'io_timeout_secs': u'1200',
         },
         u'tags': [u'os:Amiga', u'priority:10', u'user:joe@localhost'],
         u'user': u'joe@localhost',
     }
     self.assertEqual(expected, response.json)
Esempio n. 3
0
 def test_result_run_not_found(self):
     """Asserts that getting results from incipient tasks raises 404."""
     _, task_id = self.client_create_task()
     run_id = task_id[:-1] + '1'
     request = swarming_rpcs.TaskId(task_id=run_id)
     with self.call_should_fail('404'):
         _ = self.call_api('result_output', message_to_dict(request), 200)
Esempio n. 4
0
    def test_result_ok(self):
        """Asserts that result produces a result entity."""
        self.mock(random, 'getrandbits', lambda _: 0x88)

        # pending task
        now = datetime.datetime(2010, 1, 2, 3, 4, 5)
        self.mock_now(now)
        str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
        _, task_id = self.client_create_task()
        request = swarming_rpcs.TaskId(task_id=task_id)
        response = self.call_api('result', message_to_dict(request), 200)
        expected = {
            u'created_ts': str_now,
            u'failure': False,
            u'id': u'5cee488008810',
            u'internal_failure': False,
            u'modified_ts': str_now,
            u'name': u'hi',
            u'state': u'PENDING',
            u'user': u'joe@localhost',
        }
        self.assertEqual(expected, response.json)

        # no bot started: running task
        run_id = task_id[:-1] + '1'
        request = swarming_rpcs.TaskId(task_id=run_id)
        with self.call_should_fail('404'):
            _ = self.call_api('result', message_to_dict(request), 200)

        # run as bot
        self.set_as_bot()
        self.bot_poll('bot1')
        self.set_as_user()
        response = self.call_api('result', message_to_dict(request), 200)
        expected = {
            u'bot_id': u'bot1',
            u'failure': False,
            u'id': u'5cee488008811',
            u'internal_failure': False,
            u'modified_ts': str_now,
            u'started_ts': str_now,
            u'state': u'RUNNING',
            u'try_number': u'1',
        }
        self.assertEqual(expected, response.json)
Esempio n. 5
0
    def test_result_output_empty(self):
        """Asserts that incipient tasks produce no output."""
        _, task_id = self.client_create_task()
        request = swarming_rpcs.TaskId(task_id=task_id)
        response = self.call_api('result_output', message_to_dict(request),
                                 200)
        self.assertEqual({}, response.json)

        run_id = task_id[:-1] + '1'
        with self.call_should_fail('404'):
            _ = self.call_api('result_output', {'task_id': run_id}, 200)
Esempio n. 6
0
    def test_result_output_ok(self):
        """Asserts that result_output reports a task's output."""
        self.client_create_task()

        # task_id determined by bot run
        self.set_as_bot()
        task_id = self.bot_run_task()

        self.set_as_privileged_user()
        run_id = task_id[:-1] + '1'
        requests = [
            swarming_rpcs.TaskId(task_id=ident) for ident in [task_id, run_id]
        ]
        expected = {u'output': u'rÉsult string'}
        for request in requests:
            response = self.call_api('result_output', message_to_dict(request),
                                     200)
            self.assertEqual(expected, response.json)
Esempio n. 7
0
 def test_result_completed_task(self):
     """Tests that completed tasks are correctly reported."""
     self.client_create_task()
     self.set_as_bot()
     now = datetime.datetime(2010, 1, 2, 3, 4, 5, 6)
     str_now = unicode(now.strftime(self.DATETIME_NO_MICRO))
     self.mock_now(now)
     task_id = self.bot_run_task()
     request = swarming_rpcs.TaskId(task_id=task_id)
     response = self.call_api('result', message_to_dict(request), 200)
     expected = {
         u'bot_id': u'bot1',
         u'completed_ts': str_now,
         u'duration': 0.1,
         u'exit_code': u'0',
         u'failure': False,
         u'id': task_id,
         u'internal_failure': False,
         u'modified_ts': str_now,
         u'started_ts': str_now,
         u'state': u'COMPLETED',
         u'try_number': u'1',
     }
     self.assertEqual(expected, response.json)
Esempio n. 8
0
 def test_request_unknown(self):
     """Asserts that 404 is raised for unknown tasks."""
     request = swarming_rpcs.TaskId(task_id='12300')
     with self.call_should_fail('404'):
         _ = self.call_api('request', message_to_dict(request), 200)