aboutsummaryrefslogtreecommitdiff
path: root/crosperf/machine_manager.py
diff options
context:
space:
mode:
authorcmtice <cmtice@google.com>2015-04-22 09:25:53 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-04-26 04:18:33 +0000
commit5c09fc2966ac49263ce7154c2905f2a86aeda297 (patch)
treeafb3ec9829c59f98cf1cabdc2a26c71465cf9153 /crosperf/machine_manager.py
parentd7d5084ffa40651b5adbaea4f4659a51e1045f06 (diff)
downloadtoolchain-utils-5c09fc2966ac49263ce7154c2905f2a86aeda297.tar.gz
Fix current problem with machine locks.
Currently if crosperf can't access the default locks directory, it assumes that it is safe to proceed without locks and it uses machines without checking locks. This script does two things: It causes crosperf to fail if it can't access a locks directory; and it allows the user to specify an alternate locks directory. As a by-product it also adds a boolean prompting function to utils/misc.py BUG=None TEST=Tested with default directory accessible & inaccessible; tested using local locks directory. Change-Id: I6f24f772986813bf089f5f4e40335a15e8ee4837 Reviewed-on: https://chrome-internal-review.googlesource.com/214129 Reviewed-by: Luis Lozano <llozano@chromium.org> Commit-Queue: Caroline Tice <cmtice@google.com> Tested-by: Caroline Tice <cmtice@google.com>
Diffstat (limited to 'crosperf/machine_manager.py')
-rw-r--r--crosperf/machine_manager.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/crosperf/machine_manager.py b/crosperf/machine_manager.py
index ad214a27..78438839 100644
--- a/crosperf/machine_manager.py
+++ b/crosperf/machine_manager.py
@@ -17,6 +17,7 @@ import time
from utils import command_executer
from utils import logger
+from utils import misc
from utils.file_utils import FileUtils
from image_checksummer import ImageChecksummer
@@ -26,6 +27,9 @@ CHECKSUM_FILE = "/usr/local/osimage_checksum_file"
class NonMatchingMachines(Exception):
pass
+class MissingLocksDirectory(Exception):
+ """Raised when cannot find/access the machine locks directory."""
+
class CrosMachine(object):
def __init__(self, name, chromeos_root, log_level, cmd_exec=None):
self.name = name
@@ -168,8 +172,8 @@ class CrosMachine(object):
class MachineManager(object):
- def __init__(self, chromeos_root, acquire_timeout, log_level, cmd_exec=None,
- lgr=None):
+ def __init__(self, chromeos_root, acquire_timeout, log_level, locks_dir,
+ cmd_exec=None, lgr=None):
self._lock = threading.RLock()
self._all_machines = []
self._machines = []
@@ -180,14 +184,20 @@ class MachineManager(object):
self.machine_checksum_string = {}
self.acquire_timeout = acquire_timeout
self.log_level = log_level
+ self.locks_dir = locks_dir
self.ce = cmd_exec or command_executer.GetCommandExecuter(
log_level=self.log_level)
self.logger = lgr or logger.GetLogger()
- if os.path.isdir(lock_machine.Machine.LOCKS_DIR):
- self.no_lock = False
- else:
- self.no_lock = True
+ if self.locks_dir != lock_machine.Machine.LOCKS_DIR:
+ msg = ("WARNING: If you use your own locks directory, there is no"
+ " guarantee that someone else might not hold a lock on the same"
+ " machine in a different locks directory.")
+ self.logger.LogOutput(msg)
+
+ if not os.path.isdir(self.locks_dir):
+ raise MissingLocksDirectory ("Cannot access locks directory: %s"
+ % self.locks_dir)
self._initialized_machines = []
self.chromeos_root = chromeos_root
@@ -265,10 +275,9 @@ class MachineManager(object):
for m in self._machines:
if m.name == cros_machine.name:
return
- if self.no_lock:
- locked = True
- else:
- locked = lock_machine.Machine(cros_machine.name).Lock(True, sys.argv[0])
+ locked = 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
@@ -304,7 +313,9 @@ class MachineManager(object):
with self._lock:
self._machines = [m for m in self._machines
if m.name != machine_name]
- res = lock_machine.Machine(machine_name).Unlock(True)
+ res = lock_machine.Machine(machine_name,
+ self.locks_dir).Unlock(True)
+
if not res:
self.logger.LogError("Could not unlock machine: '%s'."
% m.name)
@@ -413,11 +424,11 @@ class MachineManager(object):
with self._lock:
# Unlock all machines.
for m in self._machines:
- if not self.no_lock:
- res = lock_machine.Machine(m.name).Unlock(True)
- if not res:
- self.logger.LogError("Could not unlock machine: '%s'."
- % m.name)
+ res = lock_machine.Machine(m.name, self.locks_dir).Unlock(True)
+
+ if not res:
+ self.logger.LogError("Could not unlock machine: '%s'."
+ % m.name)
def __str__(self):
with self._lock: