def testRepeatedUnlock(self):
   mach = file_lock_machine.Machine('qqqraymes.mtv')
   for _ in range(10):
     self.assertFalse(mach.Unlock())
   mach = file_lock_machine.Machine('qqqraymes.mtv', auto=True)
   for _ in range(10):
     self.assertFalse(mach.Unlock())
  def testLockUnlock(self):
    mach = file_lock_machine.Machine('otter.mtv', '/tmp')
    for _ in range(10):
      self.assertTrue(mach.Lock(exclusive=True))
      self.assertTrue(mach.Unlock(exclusive=True))

    mach = file_lock_machine.Machine('otter.mtv', '/tmp', True)
    for _ in range(10):
      self.assertTrue(mach.Lock(exclusive=True))
      self.assertTrue(mach.Unlock(exclusive=True))
  def testExclusiveState(self):
    mach = file_lock_machine.Machine('testExclusiveState')
    self.assertTrue(mach.Lock(exclusive=True))
    for _ in range(10):
      self.assertFalse(mach.Lock(exclusive=False))
    self.assertTrue(mach.Unlock(exclusive=True))

    mach = file_lock_machine.Machine('testExclusiveState', auto=True)
    self.assertTrue(mach.Lock(exclusive=True))
    for _ in range(10):
      self.assertFalse(mach.Lock(exclusive=False))
    self.assertTrue(mach.Unlock(exclusive=True))
 def testAutoLockGone(self):
   mach = file_lock_machine.Machine('lockgone', auto=True)
   p = Process(target=LockAndSleep, args=('lockgone',))
   p.start()
   time.sleep(1.1)
   p.join()
   self.assertTrue(mach.Lock(exclusive=True))
  def testSharedLock(self):
    mach = file_lock_machine.Machine('chrotomation.mtv')
    for _ in range(10):
      self.assertTrue(mach.Lock(exclusive=False))
    for _ in range(10):
      self.assertTrue(mach.Unlock(exclusive=False))
    self.assertTrue(mach.Lock(exclusive=True))
    self.assertTrue(mach.Unlock(exclusive=True))

    mach = file_lock_machine.Machine('chrotomation.mtv', auto=True)
    for _ in range(10):
      self.assertTrue(mach.Lock(exclusive=False))
    for _ in range(10):
      self.assertTrue(mach.Unlock(exclusive=False))
    self.assertTrue(mach.Lock(exclusive=True))
    self.assertTrue(mach.Unlock(exclusive=True))
 def testUnlockByOthers(self):
   mach = file_lock_machine.Machine('other_unlock', auto=True)
   p = Process(target=LockAndSleep, args=('other_unlock',))
   p.start()
   time.sleep(0.5)
   self.assertTrue(mach.Unlock(exclusive=True))
   self.assertTrue(mach.Lock(exclusive=True))
 def testAutoLockFromOther(self):
   mach = file_lock_machine.Machine('other_lock', auto=True)
   p = Process(target=LockAndSleep, args=('other_lock',))
   p.start()
   time.sleep(0.5)
   self.assertFalse(mach.Lock(exclusive=True))
   p.join()
   time.sleep(0.6)
   self.assertTrue(mach.Lock(exclusive=True))
Beispiel #8
0
    def Cleanup(self):
        with self._lock:
            # Unlock all machines (via file lock)
            for m in self._machines:
                res = file_lock_machine.Machine(m.name,
                                                self.locks_dir).Unlock(True)

                if not res:
                    self.logger.LogError("Could not unlock machine: '%s'." %
                                         m.name)
Beispiel #9
0
 def RemoveMachine(self, machine_name):
     with self._lock:
         self._machines = [
             m for m in self._machines if m.name != machine_name
         ]
         if self.locks_dir:
             res = file_lock_machine.Machine(machine_name,
                                             self.locks_dir).Unlock(True)
             if not res:
                 self.logger.LogError("Could not unlock machine: '%s'." %
                                      machine_name)
Beispiel #10
0
 def _TryToLockMachine(self, cros_machine):
     with self._lock:
         assert cros_machine, "Machine can't be None"
         for m in self._machines:
             if m.name == cros_machine.name:
                 return
         locked = True
         if self.locks_dir:
             locked = file_lock_machine.Machine(cros_machine.name,
                                                self.locks_dir).Lock(
                                                    True, sys.argv[0])
         if locked:
             self._machines.append(cros_machine)
             command = 'cat %s' % CHECKSUM_FILE
             ret, out, _ = self.ce.CrosRunCommandWOutput(
                 command,
                 chromeos_root=self.chromeos_root,
                 machine=cros_machine.name)
             if ret == 0:
                 cros_machine.checksum = out.strip()
         elif self.locks_dir:
             self.logger.LogOutput("Couldn't lock: %s" % cros_machine.name)
def LockAndSleep(machine):
  file_lock_machine.Machine(machine, auto=True).Lock(exclusive=True)
  time.sleep(1)