Beispiel #1
0
  def testEnsureCommandConsistency_deletedCommandAndRequest(self):
    """Tasks for deleted command and request should be inconsistent."""
    self.assertIsNotNone(command_task_store.GetTask('%s-1-0' % REQUEST_ID))
    self.command.key.delete()
    self.request.key.delete()
    is_consistency = (
        command_task_api.CommandTaskApi()._EnsureCommandConsistency(
            REQUEST_ID, '1', '%s-1-0' % REQUEST_ID))
    self.assertFalse(is_consistency)

    self.assertIsNone(command_task_store.GetTask('%s-1-0' % REQUEST_ID))
Beispiel #2
0
  def testEnsureCommandConsistency_commandFinalized(self):
    """Tasks for finalized command or request should be inconsistent."""
    # Marking existing request as cancelled. Command is completed.
    self.request.state = common.RequestState.CANCELED
    self.request.put()
    self.command.state = common.CommandState.COMPLETED
    self.command.put()
    self.assertIsNotNone(command_task_store.GetTask('%s-1-0' % REQUEST_ID))

    is_consistency = (
        command_task_api.CommandTaskApi()._EnsureCommandConsistency(
            REQUEST_ID, '1', '%s-1-0' % REQUEST_ID))

    self.assertFalse(is_consistency)
    self.assertIsNone(command_task_store.GetTask('%s-1-0' % REQUEST_ID))

    # Command state should stay the same.
    command = self.command.key.get(use_cache=False)
    self.assertEqual(common.CommandState.COMPLETED, command.state)
Beispiel #3
0
  def testEnsureCommandConsistency_cancelledRequest(self):
    """Task for canceled request should be inconsistant."""
    # Marking existing request as cancelled. Command will remain as queued.
    self.request.state = common.RequestState.CANCELED
    self.request.put()
    task = command_task_store.GetTask('%s-1-0' % REQUEST_ID)
    self.assertIsNotNone(task)

    is_consistency = (
        command_task_api.CommandTaskApi()._EnsureCommandConsistency(
            REQUEST_ID, '1', '%s-1-0' % REQUEST_ID))
    self.assertFalse(is_consistency)

    task = command_task_store.GetTask('%s-1-0' % REQUEST_ID)
    self.assertIsNone(task)
    # Both request and command should be cancelled
    command = self.command.key.get(use_cache=False)
    self.assertEqual(common.CommandState.CANCELED, command.state)
    request = self.command.key.parent().get(use_cache=False)
    self.assertEqual(common.RequestState.CANCELED, request.state)
Beispiel #4
0
 def testEnsureCommandConsistency_cancelledCommand_otherTask(self):
   """Cancelled command should not cancel unrelated commands."""
   self._AddCommand(REQUEST_ID, '2', 'command', 'cluster', 'run_target1')
   self.command.state = common.CommandState.CANCELED
   self.command.put()
   is_consistency = (
       command_task_api.CommandTaskApi()._EnsureCommandConsistency(
           REQUEST_ID, '1', '%s-1-0' % REQUEST_ID))
   self.assertFalse(is_consistency)
   task = command_task_store.GetTask('%s-2-0' % REQUEST_ID)
   self.assertIsNotNone(task)
Beispiel #5
0
  def testEnsureCommandConsistency_errorCommand(self):
    """Final command should be inconsistent."""
    # Marking existing command as Error. Request will remain as queued.
    self.command.state = common.CommandState.ERROR
    self.command.put()

    is_consistent = (
        command_task_api.CommandTaskApi()._EnsureCommandConsistency(
            REQUEST_ID, '1', '%s-1-0' % REQUEST_ID))
    self.assertFalse(is_consistent)
    # tasks is deleted from task store.
    task = command_task_store.GetTask('%s-1-0' % REQUEST_ID)
    self.assertIsNone(task)
Beispiel #6
0
 def testGetTask_notExist(self):
   task = command_task_store.GetTask('not_exist_task')
   self.assertIsNone(task)
Beispiel #7
0
 def testGetTask(self):
   task = command_task_store.GetTask('task_id1')
   self.assertEqual('task_id1', task.key.id())