Example #1
0
  def setUp(self):
    super(CommandMonitorTest, self).setUp()
    self.testapp = webtest.TestApp(command_monitor.APP)
    self.plugin_patcher = mock.patch(
        '__main__.env_config.CONFIG.plugin')
    self.plugin_patcher.start()

    self.request = request_manager.CreateRequest(
        request_id='1001',
        user='******',
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='command_line',
                cluster='cluster',
                run_target='run_target')
        ])
    self.request_2 = request_manager.CreateRequest(
        request_id='1002',
        user='******',
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='command_line',
                cluster='cluster',
                run_target='run_target')
        ])
    # Clear Datastore cache
    ndb.get_context().clear_cache()
Example #2
0
  def setUp(self):
    api_test.ApiTest.setUp(self)
    self.request1 = request_manager.CreateRequest(
        request_id='1',
        user='******',
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='command_line1',
                cluster='cluster',
                run_target='run_target')
        ])
    self.request1.state = common.RequestState.RUNNING
    self.request1.put()
    self.request2 = request_manager.CreateRequest(
        request_id='2',
        user='******',
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='command_line2',
                cluster='cluster',
                run_target='run_target')
        ])
    self.request2.state = common.RequestState.COMPLETED
    self.request2.put()
    self.requests = [self.request1, self.request2]

    self.command1 = datastore_entities.Command(
        parent=self.request1.key,
        id='1',
        request_id='1',
        command_line='command_line',
        cluster='cluster',
        run_target='run_target',
        run_count=1,
        state=common.CommandState.RUNNING,
        start_time=START_TIME,
        end_time=None,
        create_time=START_TIME,
        update_time=START_TIME)
    self.command1.put()

    self.command2 = datastore_entities.Command(
        parent=self.request1.key,
        id='2',
        request_id='1',
        command_line='command_line',
        cluster='cluster',
        run_target='run_target',
        run_count=1,
        state=common.CommandState.RUNNING,
        start_time=START_TIME,
        end_time=None,
        create_time=START_TIME,
        update_time=START_TIME)
    self.command2.put()
    self.commands = [self.command1, self.command2]
Example #3
0
  def setUp(self):
    super(CommandAttemptMonitorTest, self).setUp()
    self.testapp = webtest.TestApp(command_attempt_monitor.APP)
    self.plugin_patcher = mock.patch(
        '__main__.env_config.CONFIG.plugin')
    self.plugin_patcher.start()

    self.request = request_manager.CreateRequest(
        request_id='1001',
        user='******',
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='command_line',
                cluster='cluster',
                run_target='run_target'),
        ])
    self.command = command_manager.CreateCommands(
        request_id=self.request.key.id(),
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='long command line',
                cluster='foobar',
                run_target='foo',
                run_count=1,
                shard_count=1),
        ],
        shard_indexes=list(range(1)),
        request_plugin_data={
            'ants_invocation_id': 'i123',
            'ants_work_unit_id': 'w123'
        })[0]
    # Clear Datastore cache
    ndb.get_context().clear_cache()
  def setUp(self):
    super(CommandEventHandlerTest, self).setUp()
    self.testapp = webtest.TestApp(command_event_handler.APP)
    self.plugin_patcher = mock.patch(
        "__main__.env_config.CONFIG.plugin")
    self.plugin_patcher.start()

    self.request = request_manager.CreateRequest(
        request_id="1001",
        user="******",
        command_infos=[
            datastore_entities.CommandInfo(
                command_line="command_line",
                cluster="cluster",
                run_target="run_target"),
        ])
    self.command = command_manager.CreateCommands(
        request_id=self.request.key.id(),
        command_infos=[
            datastore_entities.CommandInfo(
                command_line="long command line",
                cluster="foobar",
                run_target="foo",
                run_count=1,
                shard_count=1),
        ],
        shard_indexes=list(range(1)),
        request_plugin_data={
            "ants_invocation_id": "i123",
            "ants_work_unit_id": "w123"
        })[0]
    self.now_patcher = mock.patch.object(common, "Now")
    self.mock_now = self.now_patcher.start()
    self.mock_now.return_value = TIMESTAMP
Example #5
0
  def testListRequests(self):
    for request_id in range(1, 11):
      request_id = str(request_id)
      request_manager.CreateRequest(
          user='******',
          request_id=request_id,
          command_infos=[
              datastore_entities.CommandInfo(
                  command_line='command_line1',
                  cluster='cluster',
                  run_target='run_target')
          ])
    api_request = {
        'user': '******',
        'state': 0,
        'offset': 1,
        'count': 2,
    }
    api_response = self.testapp.post_json('/_ah/api/RequestApi.ListRequest',
                                          api_request)
    request_collection = (protojson
                          .decode_message(api_messages.RequestMessageCollection,
                                          api_response.body))

    self.assertEqual(2, len(request_collection.requests))
    self.assertEqual('9', request_collection.requests[0].id)
    self.assertEqual('8', request_collection.requests[1].id)
  def testEnqueueCommandEvents_multipleEvents(self):
    self.request = request_manager.CreateRequest(
        request_id="9999",
        user="******",
        command_infos=[
            datastore_entities.CommandInfo(
                command_line="command_line",
                cluster="cluster",
                run_target="run_target",
                shard_count=2)
        ])
    command_1, command_2 = command_manager.CreateCommands(
        request_id=self.request.key.id(),
        command_infos=[
            datastore_entities.CommandInfo(
                command_line="long command line 0",
                cluster="foobar",
                run_target="foo",
                run_count=1,
                shard_count=2),
            datastore_entities.CommandInfo(
                command_line="long command line 1",
                cluster="foobar",
                run_target="foo",
                run_count=1,
                shard_count=2)
        ],
        shard_indexes=list(range(2)))
    _, request_id, _, command_1_id = command_1.key.flat()
    _, _, _, command_2_id = command_2.key.flat()
    command_event_test_util.CreateCommandAttempt(
        command_1, "aid", common.CommandState.QUEUED)
    command_event_test_util.CreateCommandAttempt(
        command_2, "aid", common.CommandState.QUEUED)

    event = command_event_test_util.CreateTestCommandEventJson(
        request_id, command_1_id, "aid", "InvocationStarted")
    event2 = command_event_test_util.CreateTestCommandEventJson(
        request_id, command_2_id, "aid", "InvocationStarted")
    event3 = command_event_test_util.CreateTestCommandEventJson(
        request_id, command_1_id, "aid", "InvocationCompleted")
    event4 = command_event_test_util.CreateTestCommandEventJson(
        request_id, command_2_id, "aid", "InvocationCompleted")
    command_event_handler.EnqueueCommandEvents([event, event2, event3, event4])

    tasks = self.mock_task_scheduler.GetTasks()
    self.assertEqual(len(tasks), 4)
    for task in tasks:
      self.testapp.post(
          command_event_handler.COMMAND_EVENT_HANDLER_PATH, task.payload)

    command_attempts = command_manager.GetCommandAttempts(
        request_id, command_1_id)
    self.assertEqual(len(command_attempts), 1)
    self.assertEqual(common.CommandState.COMPLETED, command_attempts[0].state)
    command_attempts = command_manager.GetCommandAttempts(
        request_id, command_2_id)
    self.assertEqual(len(command_attempts), 1)
    self.assertEqual(common.CommandState.COMPLETED, command_attempts[0].state)
  def testBackfillRequestSyncs(self, mock_monitor):
    queued_request = request_manager.CreateRequest(
        request_id='queued_id', user='******', command_infos=[
            datastore_entities.CommandInfo(command_line='command_line2')
        ])
    queued_request.state = common.RequestState.QUEUED
    queued_request.put()

    response = self.testapp.post_json(
        '/_ah/api/CoordinatorApi.BackfillRequestSyncs', {})
    self.assertEqual('200 OK', response.status)
    mock_monitor.assert_has_calls(
        [mock.call(self.request.key.id()),
         mock.call(queued_request.key.id())])
  def setUp(self):
    super(CoordinatorApiTest, self).setUp()
    self.plugin_patcher = mock.patch(
        '__main__.env_config.CONFIG.plugin')
    self.plugin_patcher.start()

    self.request = request_manager.CreateRequest(
        request_id='1001',
        user='******',
        command_infos=[
            datastore_entities.CommandInfo(
                command_line='command_line',
                cluster='cluster',
                run_target='run_target')
        ])