def _LockAllMachines(self, experiment):
        """Attempt to globally lock all of the machines requested for run.

    This method will use the AFE server to globally lock all of the machines
    requested for this crosperf run, to prevent any other crosperf runs from
    being able to update/use the machines while this experiment is running.
    """
        if test_flag.GetTestMode():
            self.locked_machines = self._GetMachineList()
            self._experiment.locked_machines = self.locked_machines
        else:
            lock_mgr = afe_lock_machine.AFELockManager(
                self._GetMachineList(),
                '',
                experiment.labels[0].chromeos_root,
                None,
                log=self.l,
            )
            for m in lock_mgr.machines:
                if not lock_mgr.MachineIsKnown(m):
                    lock_mgr.AddLocalMachine(m)
            machine_states = lock_mgr.GetMachineStates('lock')
            lock_mgr.CheckMachineLocks(machine_states, 'lock')
            self.locked_machines = lock_mgr.UpdateMachines(True)
            self._experiment.locked_machines = self.locked_machines
            self._UpdateMachineList(self.locked_machines)
            self._experiment.machine_manager.RemoveNonLockedMachines(
                self.locked_machines)
            if len(self.locked_machines) == 0:
                raise RuntimeError('Unable to lock any machines.')
Ejemplo n.º 2
0
def ReleaseLock(machines, chromeos_root):
    """Release locked machine(s), using AFE server for locking."""
    unlocked = True
    try:
        afe_lock_machine.AFELockManager(machines, False, chromeos_root,
                                        None).UpdateMachines(False)
    except Exception as e:
        unlocked = False
        logger.GetLogger().LogWarning('Could not unlock %s. %s' %
                                      (repr(machines), str(e)))
    return unlocked
    def _UnlockAllMachines(self, experiment):
        """Attempt to globally unlock all of the machines requested for run.

    The method will use the AFE server to globally unlock all of the machines
    requested for this crosperf run.
    """
        if not self.locked_machines or test_flag.GetTestMode():
            return

        lock_mgr = afe_lock_machine.AFELockManager(
            self.locked_machines,
            '',
            experiment.labels[0].chromeos_root,
            None,
            log=self.l,
        )
        machine_states = lock_mgr.GetMachineStates('unlock')
        lock_mgr.CheckMachineLocks(machine_states, 'unlock')
        lock_mgr.UpdateMachines(False)
Ejemplo n.º 4
0
def AcquireLock(machines, chromeos_root, timeout=1200):
    """Acquire lock for machine(s) with timeout, using AFE server for locking."""
    start_time = time.time()
    locked = True
    sleep_time = min(10, timeout / 10.0)
    while True:
        try:
            afe_lock_machine.AFELockManager(machines, False, chromeos_root,
                                            None).UpdateMachines(True)
            break
        except Exception as e:
            if time.time() - start_time > timeout:
                locked = False
                logger.GetLogger().LogWarning(
                    'Could not acquire lock on {0} within {1} seconds: {2}'.
                    format(repr(machines), timeout, str(e)))
                break
            time.sleep(sleep_time)
    return locked
Ejemplo n.º 5
0
  def Cleanup(self):
    """Make sure all machines are unlocked."""
    if self.locks_dir:
      # We are using the file locks mechanism, so call machine_manager.Cleanup
      # to unlock everything.
      self.machine_manager.Cleanup()
    else:
      if test_flag.GetTestMode():
        return

      all_machines = self.locked_machines
      if not all_machines:
        return

      # If we locked any machines earlier, make sure we unlock them now.
      lock_mgr = afe_lock_machine.AFELockManager(
          all_machines, '', self.labels[0].chromeos_root, None)
      machine_states = lock_mgr.GetMachineStates('unlock')
      for k, state in machine_states.iteritems():
        if state['locked']:
          lock_mgr.UpdateLockInAFE(False, k)