aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhizhou Yang <zhizhouy@google.com>2019-10-14 17:36:09 -0700
committerZhizhou Yang <zhizhouy@google.com>2019-10-15 22:48:08 +0000
commitbf7ee87429d2c9730349ebc22f904b5a3fac7107 (patch)
treeafe85d6bc0535e2d376f6d9be615beffdaed223c
parentea5fbd9e6c99d18e002cec6e86bfb889d0820370 (diff)
downloadtoolchain-utils-bf7ee87429d2c9730349ebc22f904b5a3fac7107.tar.gz
toolchain-utils: change naming related to AFE lock
After introducing the new locking mechanism, the behavior of AFELockManager totally changed. This file changed the naming of all related code in toochain-utils. This patch also changed the behavior of locks_dir option, deprecated the use_file_lock option explicitly. TEST=Tested with different DUT types. BUG=chromium:1006434 Change-Id: Ib15efce54ec4d4c5c2a18fecca3f350248462035 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1863530 Reviewed-by: Caroline Tice <cmtice@chromium.org> Reviewed-by: Denis Nikitin <denik@chromium.org> Commit-Queue: Zhizhou Yang <zhizhouy@google.com> Tested-by: Zhizhou Yang <zhizhouy@google.com>
-rw-r--r--cros_utils/locks.py14
-rw-r--r--crosperf/experiment.py3
-rw-r--r--crosperf/experiment_factory.py14
-rw-r--r--crosperf/experiment_runner.py4
-rw-r--r--crosperf/machine_manager.py20
-rw-r--r--crosperf/settings_factory.py10
-rwxr-xr-x[-rw-r--r--]file_lock_machine_test.py (renamed from lock_machine_test.py)36
-rwxr-xr-xlock_machine.py (renamed from afe_lock_machine.py)33
8 files changed, 72 insertions, 62 deletions
diff --git a/cros_utils/locks.py b/cros_utils/locks.py
index 07434145..4ecbe0a9 100644
--- a/cros_utils/locks.py
+++ b/cros_utils/locks.py
@@ -10,20 +10,20 @@ from __future__ import print_function
import time
-import afe_lock_machine
+import lock_machine
import logger
def AcquireLock(machines, chromeos_root, timeout=1200):
- """Acquire lock for machine(s) with timeout, using AFE server for locking."""
+ """Acquire lock for machine(s) with timeout."""
start_time = time.time()
locked = True
sleep_time = min(10, timeout / 10.0)
while True:
try:
- afe_lock_machine.AFELockManager(machines, False,
- chromeos_root).UpdateMachines(True)
+ lock_machine.LockManager(machines, False,
+ chromeos_root).UpdateMachines(True)
break
except Exception as e:
if time.time() - start_time > timeout:
@@ -37,11 +37,11 @@ def AcquireLock(machines, chromeos_root, timeout=1200):
def ReleaseLock(machines, chromeos_root):
- """Release locked machine(s), using AFE server for locking."""
+ """Release locked machine(s)."""
unlocked = True
try:
- afe_lock_machine.AFELockManager(machines, False,
- chromeos_root).UpdateMachines(False)
+ lock_machine.LockManager(machines, False,
+ chromeos_root).UpdateMachines(False)
except Exception as e:
unlocked = False
logger.GetLogger().LogWarning(
diff --git a/crosperf/experiment.py b/crosperf/experiment.py
index 7a3169b3..1d87b6e4 100644
--- a/crosperf/experiment.py
+++ b/crosperf/experiment.py
@@ -50,9 +50,6 @@ class Experiment(object):
self.num_run_complete = 0
self.share_cache = share_cache
self.active_threads = []
- # If locks_directory (self.lock_dir) not blank, we will use the file
- # locking mechanism; if it is blank then we will use the AFE server
- # locking mechanism.
self.locks_dir = locks_directory
self.locked_machines = []
self.lock_mgr = None
diff --git a/crosperf/experiment_factory.py b/crosperf/experiment_factory.py
index 563f3ac6..5b4d4b0d 100644
--- a/crosperf/experiment_factory.py
+++ b/crosperf/experiment_factory.py
@@ -143,14 +143,20 @@ class ExperimentFactory(object):
config.AddConfig('no_email', global_settings.GetField('no_email'))
share_cache = global_settings.GetField('share_cache')
results_dir = global_settings.GetField('results_dir')
+ # Warn user that option use_file_locks is deprecated.
use_file_locks = global_settings.GetField('use_file_locks')
+ if use_file_locks:
+ l = logger.GetLogger()
+ l.LogWarning('Option use_file_locks is deprecated, please remove it '
+ 'from your experiment settings.')
locks_dir = global_settings.GetField('locks_dir')
- # If we pass a blank locks_dir to the Experiment, it will use the AFE server
- # lock mechanism. So if the user specified use_file_locks, but did not
- # specify a locks dir, set the locks dir to the default locks dir in
+ # If not specified, set the locks dir to the default locks dir in
# file_lock_machine.
- if use_file_locks and not locks_dir:
+ if not locks_dir:
locks_dir = file_lock_machine.Machine.LOCKS_DIR
+ if not os.path.exists(locks_dir):
+ raise RuntimeError('Cannot access default lock directory. '
+ 'Please run prodaccess or specify a local directory')
chrome_src = global_settings.GetField('chrome_src')
show_all_results = global_settings.GetField('show_all_results')
cwp_dso = global_settings.GetField('cwp_dso')
diff --git a/crosperf/experiment_runner.py b/crosperf/experiment_runner.py
index 1bca6b8c..1e2c3142 100644
--- a/crosperf/experiment_runner.py
+++ b/crosperf/experiment_runner.py
@@ -11,7 +11,7 @@ import os
import shutil
import time
-import afe_lock_machine
+import lock_machine
import test_flag
from cros_utils import command_executer
@@ -129,7 +129,7 @@ class ExperimentRunner(object):
self.locked_machines = self._GetMachineList()
experiment.locked_machines = self.locked_machines
else:
- experiment.lock_mgr = afe_lock_machine.AFELockManager(
+ experiment.lock_mgr = lock_machine.LockManager(
self._GetMachineList(),
'',
experiment.labels[0].chromeos_root,
diff --git a/crosperf/machine_manager.py b/crosperf/machine_manager.py
index b9dda148..ea3d105a 100644
--- a/crosperf/machine_manager.py
+++ b/crosperf/machine_manager.py
@@ -1,6 +1,7 @@
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+
"""Machine Manager module."""
from __future__ import print_function
@@ -184,10 +185,10 @@ class MachineManager(object):
This class contains methods and calls to lock, unlock and image
machines and distribute machines to each benchmark run. The assumption is
that all of the machines for the experiment have been globally locked
- (using an AFE server) in the ExperimentRunner, but the machines still need
- to be locally locked/unlocked (allocated to benchmark runs) to prevent
- multiple benchmark runs within the same experiment from trying to use the
- same machine at the same time.
+ in the ExperimentRunner, but the machines still need to be locally
+ locked/unlocked (allocated to benchmark runs) to prevent multiple benchmark
+ runs within the same experiment from trying to use the same machine at the
+ same time.
"""
def __init__(self,
@@ -254,7 +255,8 @@ class MachineManager(object):
image_chromeos.__file__, '--no_lock',
'--chromeos_root=%s' % chromeos_root,
'--image=%s' % label.chromeos_image,
- '--image_args=%s' % label.image_args, '--remote=%s' % machine.name,
+ '--image_args=%s' % label.image_args,
+ '--remote=%s' % machine.name,
'--logging_level=%s' % self.log_level
]
if label.board:
@@ -401,10 +403,10 @@ class MachineManager(object):
self.acquire_timeout -= sleep_time
if self.acquire_timeout < 0:
- self.logger.LogFatal(
- 'Could not acquire any of the '
- "following machines: '%s'" % ', '.join(machine.name
- for machine in machines))
+ self.logger.LogFatal('Could not acquire any of the '
+ "following machines: '%s'" % ', '.join(
+ machine.name for machine in machines))
+
### for m in self._machines:
### if (m.locked and time.time() - m.released_time < 10 and
diff --git a/crosperf/settings_factory.py b/crosperf/settings_factory.py
index 1f2693c6..9057703f 100644
--- a/crosperf/settings_factory.py
+++ b/crosperf/settings_factory.py
@@ -202,9 +202,8 @@ class GlobalSettings(Settings):
BooleanField(
'use_file_locks',
default=False,
- description='Whether to use the file locks '
- 'mechanism (deprecated) instead of the AFE '
- 'server lock mechanism.'))
+ description='DEPRECATED: Whether to use the file locks '
+ 'or AFE server lock mechanism.'))
self.AddField(
IntegerField(
'iterations',
@@ -286,8 +285,9 @@ class GlobalSettings(Settings):
'locks_dir',
default='',
description='An alternate directory to use for '
- 'storing/checking machine locks. Using this field '
- 'automatically sets use_file_locks to True.\n'
+ 'storing/checking machine file locks for local machines. '
+ 'By default the file locks directory is '
+ '/google/data/rw/users/mo/mobiletc-prebuild/locks.\n'
'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 '
diff --git a/lock_machine_test.py b/file_lock_machine_test.py
index 0ffe094d..340f9149 100644..100755
--- a/lock_machine_test.py
+++ b/file_lock_machine_test.py
@@ -1,4 +1,10 @@
-# Copyright 2010 Google Inc. All Rights Reserved.
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
"""lock_machine.py related unit-tests.
MachineManagerTest tests MachineManager.
@@ -16,7 +22,7 @@ import file_lock_machine
def LockAndSleep(machine):
- file_lock_machine.Machine(machine, auto=True).Lock(exclusive=True)
+ file_lock_machine.Machine(machine, '/tmp', auto=True).Lock(exclusive=True)
time.sleep(1)
@@ -27,12 +33,12 @@ class MachineTest(unittest.TestCase):
pass
def testRepeatedUnlock(self):
- mach = file_lock_machine.Machine('qqqraymes.mtv')
+ mach = file_lock_machine.Machine('qqqraymes.mtv', '/tmp')
for _ in range(10):
- self.assertFalse(mach.Unlock())
- mach = file_lock_machine.Machine('qqqraymes.mtv', auto=True)
+ self.assertTrue(mach.Unlock())
+ mach = file_lock_machine.Machine('qqqraymes.mtv', '/tmp', auto=True)
for _ in range(10):
- self.assertFalse(mach.Unlock())
+ self.assertTrue(mach.Unlock())
def testLockUnlock(self):
mach = file_lock_machine.Machine('otter.mtv', '/tmp')
@@ -46,7 +52,7 @@ class MachineTest(unittest.TestCase):
self.assertTrue(mach.Unlock(exclusive=True))
def testSharedLock(self):
- mach = file_lock_machine.Machine('chrotomation.mtv')
+ mach = file_lock_machine.Machine('chrotomation.mtv', '/tmp')
for _ in range(10):
self.assertTrue(mach.Lock(exclusive=False))
for _ in range(10):
@@ -54,7 +60,7 @@ class MachineTest(unittest.TestCase):
self.assertTrue(mach.Lock(exclusive=True))
self.assertTrue(mach.Unlock(exclusive=True))
- mach = file_lock_machine.Machine('chrotomation.mtv', auto=True)
+ mach = file_lock_machine.Machine('chrotomation.mtv', '/tmp', auto=True)
for _ in range(10):
self.assertTrue(mach.Lock(exclusive=False))
for _ in range(10):
@@ -63,14 +69,14 @@ class MachineTest(unittest.TestCase):
self.assertTrue(mach.Unlock(exclusive=True))
def testExclusiveLock(self):
- mach = file_lock_machine.Machine('atree.mtv')
+ mach = file_lock_machine.Machine('atree.mtv', '/tmp')
self.assertTrue(mach.Lock(exclusive=True))
for _ in range(10):
self.assertFalse(mach.Lock(exclusive=True))
self.assertFalse(mach.Lock(exclusive=False))
self.assertTrue(mach.Unlock(exclusive=True))
- mach = file_lock_machine.Machine('atree.mtv', auto=True)
+ mach = file_lock_machine.Machine('atree.mtv', '/tmp', auto=True)
self.assertTrue(mach.Lock(exclusive=True))
for _ in range(10):
self.assertFalse(mach.Lock(exclusive=True))
@@ -78,20 +84,20 @@ class MachineTest(unittest.TestCase):
self.assertTrue(mach.Unlock(exclusive=True))
def testExclusiveState(self):
- mach = file_lock_machine.Machine('testExclusiveState')
+ mach = file_lock_machine.Machine('testExclusiveState', '/tmp')
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)
+ mach = file_lock_machine.Machine('testExclusiveState', '/tmp', 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)
+ mach = file_lock_machine.Machine('lockgone', '/tmp', auto=True)
p = Process(target=LockAndSleep, args=('lockgone',))
p.start()
time.sleep(1.1)
@@ -99,7 +105,7 @@ class MachineTest(unittest.TestCase):
self.assertTrue(mach.Lock(exclusive=True))
def testAutoLockFromOther(self):
- mach = file_lock_machine.Machine('other_lock', auto=True)
+ mach = file_lock_machine.Machine('other_lock', '/tmp', auto=True)
p = Process(target=LockAndSleep, args=('other_lock',))
p.start()
time.sleep(0.5)
@@ -109,7 +115,7 @@ class MachineTest(unittest.TestCase):
self.assertTrue(mach.Lock(exclusive=True))
def testUnlockByOthers(self):
- mach = file_lock_machine.Machine('other_unlock', auto=True)
+ mach = file_lock_machine.Machine('other_unlock', '/tmp', auto=True)
p = Process(target=LockAndSleep, args=('other_unlock',))
p.start()
time.sleep(0.5)
diff --git a/afe_lock_machine.py b/lock_machine.py
index 5f3c7fc6..40c7d8fd 100755
--- a/afe_lock_machine.py
+++ b/lock_machine.py
@@ -22,28 +22,28 @@ from cros_utils import logger
from cros_utils import machines
-class AFELockException(Exception):
+class LockException(Exception):
"""Base class for exceptions in this module."""
-class MachineNotPingable(AFELockException):
+class MachineNotPingable(LockException):
"""Raised when machine does not respond to ping."""
-class LockingError(AFELockException):
+class LockingError(LockException):
"""Raised when server fails to lock/unlock machine as requested."""
-class DontOwnLock(AFELockException):
+class DontOwnLock(LockException):
"""Raised when user attmepts to unlock machine locked by someone else."""
# This should not be raised if the user specified '--force'
-class NoAFEServer(AFELockException):
+class NoAFEServer(LockException):
"""Raised when cannot find/access the autotest server."""
-class AFEAccessError(AFELockException):
+class AFEAccessError(LockException):
"""Raised when cannot get information about lab machine from lab server."""
@@ -54,8 +54,8 @@ class MachineType(enum.Enum):
SKYLAB = 'skylab'
-class AFELockManager(object):
- """Class for locking/unlocking machines vie Autotest Front End servers.
+class LockManager(object):
+ """Class for locking/unlocking machines vie three different modes.
This class contains methods for checking the locked status of machines,
and for changing the locked status. It handles HW lab machines (both AFE
@@ -82,7 +82,7 @@ class AFELockManager(object):
chromeos_root,
locks_dir='',
log=None):
- """Initializes an AFELockManager object.
+ """Initializes an LockManager object.
Args:
remotes: A list of machine names or ip addresses to be managed. Names
@@ -225,12 +225,12 @@ class AFELockManager(object):
"""Gets and prints the current status for a list of machines.
Prints out the current status for all of the machines in the current
- AFELockManager's list of machines (set when the object is initialized).
+ LockManager's list of machines (set when the object is initialized).
Args:
machine_states: A dictionary of the current state of every machine in
- the current AFELockManager's list of machines. Normally obtained by
- calling AFELockManager::GetMachineStates.
+ the current LockManager's list of machines. Normally obtained by
+ calling LockManager::GetMachineStates.
"""
self.PrintStatusHeader()
for m in machine_states:
@@ -368,8 +368,8 @@ class AFELockManager(object):
Args:
machine_states: A dictionary of the current state of every machine in
- the current AFELockManager's list of machines. Normally obtained by
- calling AFELockManager::GetMachineStates.
+ the current LockManager's list of machines. Normally obtained by
+ calling LockManager::GetMachineStates.
cmd: The user-requested action for the machines: 'lock' or 'unlock'.
Raises:
@@ -406,7 +406,7 @@ class AFELockManager(object):
an exception, unless the requested command is 'add'.
Returns:
- A dictionary of machine states for all the machines in the AFELockManager
+ A dictionary of machine states for all the machines in the LockManager
object.
Raises:
@@ -587,8 +587,7 @@ def Main(argv):
if options.remote:
machine_list = options.remote.split()
- lock_manager = AFELockManager(machine_list, options.force,
- options.chromeos_root)
+ lock_manager = LockManager(machine_list, options.force, options.chromeos_root)
machine_states = lock_manager.GetMachineStates(cmd=options.cmd)
cmd = options.cmd