Exemple #1
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]
Exemple #2
0
 def _AddCommand(self,
                 request_id,
                 command_id,
                 command_line,
                 cluster,
                 run_target,
                 run_count=1,
                 priority=None,
                 shard_count=None,
                 shard_index=None,
                 ants_invocation_id=None,
                 ants_work_unit_id=None):
   """Adds a mock command and add a corresponding task to task store."""
   key = ndb.Key(
       datastore_entities.Request,
       request_id,
       datastore_entities.Command,
       command_id,
       namespace=common.NAMESPACE)
   plugin_data = {'ants_invocation_id': ants_invocation_id,
                  'ants_work_unit_id': ants_work_unit_id}
   command = datastore_entities.Command(
       key=key,
       request_id=request_id,
       command_line=command_line,
       cluster=cluster,
       run_target=run_target,
       run_count=run_count,
       shard_count=shard_count,
       shard_index=shard_index,
       priority=priority,
       plugin_data=plugin_data)
   command.put()
   command_manager.ScheduleTasks([command])
   return command
 def _CreateTestCommand(self, request, state, run_count=1):
   """Creates a Command associated with a REQUEST."""
   command = datastore_entities.Command(
       parent=request.key,
       id=str(self._command_id),
       command_line='%s --command-id %d' % (
           request.command_infos[0].command_line, self._command_id),
       cluster='cluster',
       run_target='run_target',
       run_count=run_count,
       state=state)
   command.put()
   self._command_id += 1
   return command
 def testCommandFromEntity(self):
     """Tests converting a Command entity to a message."""
     command_key = ndb.Key(datastore_entities.Request, '1',
                           datastore_entities.Command, '2')
     cmd = datastore_entities.Command(
         key=command_key,
         command_line='command_line2',
         cluster='cluster',
         run_target='run_target',
         run_count=10,
         state=common.CommandState.QUEUED,
         start_time=TIMESTAMP,
         end_time=None,
         create_time=TIMESTAMP,
         update_time=TIMESTAMP,
         cancel_reason=common.CancelReason.QUEUE_TIMEOUT,
         error_reason=common.ErrorReason.TOO_MANY_LOST_DEVICES,
         shard_count=2,
         shard_index=1)
     message = datastore_entities.ToMessage(cmd)
     self.AssertEqualCommand(cmd, message)
    def setUp(self):
        api_test.ApiTest.setUp(self)
        request_key = ndb.Key(datastore_entities.Request,
                              '1001',
                              namespace=common.NAMESPACE)
        request = datastore_test_util.CreateRequest(
            request_id=request_key.id(),
            user='******',
            command_infos=[
                datastore_entities.CommandInfo(command_line='command_line',
                                               cluster='cluster',
                                               run_target='run_target')
            ])
        request.put()

        command = datastore_entities.Command(parent=request_key,
                                             id='1',
                                             command_line='command_line',
                                             cluster='cluster',
                                             run_target='run_target',
                                             state=common.CommandState.RUNNING)
        command.put()

        command_attempt_0 = datastore_entities.CommandAttempt(
            parent=command.key,
            id='attempt_id-0',
            task_id='task-id-0',
            attempt_id='attempt_id-0',
            hostname='hostname_0',
            device_serial='device_serial_0',
            create_time=TIME,
            state=common.CommandState.COMPLETED)
        command_attempt_0.put()

        command_attempt_1 = datastore_entities.CommandAttempt(
            parent=command.key,
            id='attempt_id-1',
            task_id='task-id-1',
            attempt_id='attempt_id-1',
            hostname='hostname_0',
            device_serial='device_serial_1',
            create_time=TIME + TIME_DELTA,
            state=common.CommandState.RUNNING)
        command_attempt_1.put()

        command_attempt_2 = datastore_entities.CommandAttempt(
            parent=command.key,
            id='attempt_id-2',
            task_id='task-id-2',
            attempt_id='attempt_id-2',
            hostname='hostname_1',
            device_serial='device_serial_2',
            create_time=TIME + TIME_DELTA * 2,
            state=common.CommandState.RUNNING)
        command_attempt_2.put()

        command_attempt_3 = datastore_entities.CommandAttempt(
            parent=command.key,
            id='attempt_id-3',
            task_id='task-id-3',
            attempt_id='attempt_id-3',
            hostname='hostname_1',
            device_serial='device_serial_2',
            create_time=TIME + TIME_DELTA * 3,
            device_serials=['d2', 'd3'],
            state=common.CommandState.RUNNING)
        command_attempt_3.put()
    def testRequestFromEntity_multipleCommandsAndAttempts(self):
        """Tests converting a Request object with multiple Commands."""
        request_key = ndb.Key(datastore_entities.Request, '123')
        request = datastore_entities.Request(
            key=request_key,
            user='******',
            command_infos=[
                datastore_entities.CommandInfo(command_line='command_line',
                                               shard_count=2,
                                               run_count=3,
                                               cluster='cluster',
                                               run_target='run_target')
            ],
            state=common.RequestState.UNKNOWN,
            cancel_reason=common.CancelReason.QUEUE_TIMEOUT)
        command1_key = ndb.Key(datastore_entities.Command,
                               '456',
                               parent=request_key)
        cmd1 = datastore_entities.Command(key=command1_key,
                                          command_line='command_line1',
                                          cluster='cluster',
                                          run_target='run_target',
                                          run_count=10,
                                          state=common.CommandState.QUEUED,
                                          start_time=TIMESTAMP,
                                          end_time=None,
                                          create_time=TIMESTAMP,
                                          update_time=TIMESTAMP,
                                          shard_count=2,
                                          shard_index=0)
        command2_key = ndb.Key(datastore_entities.Command,
                               '457',
                               parent=request_key)
        cmd2 = datastore_entities.Command(key=command2_key,
                                          command_line='command_line2',
                                          cluster='cluster',
                                          run_target='run_target',
                                          run_count=10,
                                          state=common.CommandState.QUEUED,
                                          start_time=TIMESTAMP,
                                          end_time=None,
                                          create_time=TIMESTAMP,
                                          update_time=TIMESTAMP,
                                          shard_count=2,
                                          shard_index=1)
        command_attempt1_key = ndb.Key(datastore_entities.CommandAttempt,
                                       '890',
                                       parent=command1_key)
        cmd_attempt1 = datastore_entities.CommandAttempt(
            key=command_attempt1_key,
            task_id='task_id',
            attempt_id='attempt_id',
            state=common.CommandState.UNKNOWN,
            hostname='hostname',
            device_serial='device_serial',
            start_time=TIMESTAMP,
            end_time=TIMESTAMP,
            status='status',
            error='error',
            summary='summary',
            total_test_count=1000,
            failed_test_count=100,
            passed_test_count=900,
            create_time=TIMESTAMP,
            update_time=TIMESTAMP)
        command_attempt2_key = ndb.Key(datastore_entities.CommandAttempt,
                                       '891',
                                       parent=command1_key)
        cmd_attempt2 = datastore_entities.CommandAttempt(
            key=command_attempt2_key,
            task_id='task_id',
            attempt_id='attempt_id',
            state=common.CommandState.UNKNOWN,
            hostname='hostname',
            device_serial='device_serial',
            start_time=TIMESTAMP,
            end_time=TIMESTAMP,
            status='status',
            error='error',
            summary='summary',
            total_test_count=1000,
            failed_test_count=100,
            passed_test_count=900,
            create_time=TIMESTAMP,
            update_time=TIMESTAMP)
        commands = [cmd1, cmd2]
        command_attempts = [cmd_attempt1, cmd_attempt2]

        message = datastore_entities.ToMessage(
            request, command_attempts=command_attempts, commands=commands)
        self.AssertEqualRequest(request, message)
        self.assertEqual(len(message.commands), len(commands))
        for command, command_msg in zip(commands, message.commands):
            self.AssertEqualCommand(command, command_msg)
        self.assertEqual(len(message.command_attempts), len(command_attempts))
        for attempt, msg in zip(command_attempts, message.command_attempts):
            self.AssertEqualCommandAttempt(attempt, msg)