Esempio n. 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))
Esempio n. 2
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)
Esempio n. 3
0
  def testCreateCommandAttempt(self):
    request_id = 'request_id'
    command_id = 'command_id'
    leased_tasks = [
        command_task_api.CommandTask(
            task_id='task_id0',
            request_id=request_id,
            command_id=command_id,
            device_serials=['d1'],
            plugin_data=[
                api_messages.KeyValuePair(key='key0', value='value0'),
                api_messages.KeyValuePair(key='key1', value='value1'),
                api_messages.KeyValuePair(key='hostname', value='ahost'),
                api_messages.KeyValuePair(key='lab_name', value='alab'),
                api_messages.KeyValuePair(key='host_group', value='cluster'),
            ]),
        command_task_api.CommandTask(
            task_id='task_id1',
            request_id=request_id,
            command_id=command_id,
            device_serials=['d2', 'd3'],
            plugin_data=[
                api_messages.KeyValuePair(key='key2', value='value2'),
                api_messages.KeyValuePair(key='key3', value='value3'),
                api_messages.KeyValuePair(key='hostname', value='ahost'),
                api_messages.KeyValuePair(key='lab_name', value='alab'),
                api_messages.KeyValuePair(key='host_group', value='agroup'),
            ])
    ]
    command_task_api.CommandTaskApi()._CreateCommandAttempt(leased_tasks)
    attempts = command_manager.GetCommandAttempts(request_id='request_id',
                                                  command_id='command_id')

    self.assertEqual(2, len(attempts))
    self.assertEqual('command_id', attempts[0].command_id)
    self.assertEqual('task_id0', attempts[0].task_id)
    self.assertEqual('ahost', attempts[0].hostname)
    self.assertEqual(['d1'], attempts[0].device_serials)
    self.assertEqual(
        {'host_group': 'cluster', 'hostname': 'ahost', 'lab_name': 'alab',
         'key0': 'value0', 'key1': 'value1'},
        attempts[0].plugin_data)
    self.assertIsNotNone(attempts[0].last_event_time)
    self.assertEqual('command_id', attempts[1].command_id)
    self.assertEqual('task_id1', attempts[1].task_id)
    self.assertEqual('ahost', attempts[1].hostname)
    self.assertEqual(['d2', 'd3'], attempts[1].device_serials)
    self.assertEqual(
        {'host_group': 'agroup', 'hostname': 'ahost', 'lab_name': 'alab',
         'key2': 'value2', 'key3': 'value3'},
        attempts[1].plugin_data)
    self.assertIsNotNone(attempts[1].last_event_time)
Esempio n. 4
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)
Esempio n. 5
0
  def testEnsureCommandConsistency_cancelledCommand(self):
    """Cancelled command should be inconsistent."""
    # Marking existing command as cancelled. Request will remain as queued.
    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)
    # tasks is deleted from task store.
    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)
Esempio n. 6
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)