Yunlian Jiang | 36f91ad | 2013-03-28 17:13:29 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 4 | |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 5 | """Machine Manager module.""" |
| 6 | |
| 7 | from __future__ import print_function |
| 8 | |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 9 | import hashlib |
| 10 | import image_chromeos |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 11 | import file_lock_machine |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 12 | import math |
| 13 | import os.path |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 14 | import re |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 15 | import sys |
| 16 | import threading |
| 17 | import time |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 18 | |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 19 | |
Yunlian Jiang | 0d1a9f3 | 2015-12-09 10:47:11 -0800 | [diff] [blame] | 20 | from cros_utils import command_executer |
| 21 | from cros_utils import logger |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 22 | |
| 23 | CHECKSUM_FILE = "/usr/local/osimage_checksum_file" |
| 24 | |
Caroline Tice | 5ea9f00 | 2015-09-02 12:36:47 -0700 | [diff] [blame] | 25 | class BadChecksum(Exception): |
| 26 | """Raised if all machines for a label don't have the same checksum.""" |
| 27 | pass |
| 28 | |
| 29 | class BadChecksumString(Exception): |
| 30 | """Raised if all machines for a label don't have the same checksum string.""" |
cmtice | 798a8fa | 2014-05-12 13:56:42 -0700 | [diff] [blame] | 31 | pass |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 32 | |
cmtice | 5c09fc2 | 2015-04-22 09:25:53 -0700 | [diff] [blame] | 33 | class MissingLocksDirectory(Exception): |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 34 | """Raised when cannot find/access the machine locks directory.""" |
cmtice | 5c09fc2 | 2015-04-22 09:25:53 -0700 | [diff] [blame] | 35 | |
Caroline Tice | 31fedb0 | 2015-09-14 16:30:37 -0700 | [diff] [blame] | 36 | class CrosCommandError(Exception): |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 37 | """Raised when an error occurs running command on DUT.""" |
Caroline Tice | 31fedb0 | 2015-09-14 16:30:37 -0700 | [diff] [blame] | 38 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 39 | class CrosMachine(object): |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 40 | """The machine class.""" |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 41 | def __init__(self, name, chromeos_root, log_level, cmd_exec=None): |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 42 | self.name = name |
| 43 | self.image = None |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 44 | # We relate a dut with a label if we reimage the dut using label or we |
| 45 | # detect at the very beginning that the dut is running this label. |
| 46 | self.label = None |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 47 | self.checksum = None |
| 48 | self.locked = False |
| 49 | self.released_time = time.time() |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 50 | self.test_run = None |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 51 | self.chromeos_root = chromeos_root |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 52 | self.log_level = log_level |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 53 | self.cpuinfo = None |
| 54 | self.machine_id = None |
| 55 | self.checksum_string = None |
| 56 | self.meminfo = None |
| 57 | self.phys_kbytes = None |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 58 | self.ce = cmd_exec or command_executer.GetCommandExecuter( |
| 59 | log_level=self.log_level) |
cmtice | 798a8fa | 2014-05-12 13:56:42 -0700 | [diff] [blame] | 60 | self.SetUpChecksumInfo() |
| 61 | |
| 62 | def SetUpChecksumInfo(self): |
Yunlian Jiang | e5b673f | 2013-05-23 11:42:53 -0700 | [diff] [blame] | 63 | if not self.IsReachable(): |
Yunlian Jiang | 837e07a | 2013-05-22 16:23:28 -0700 | [diff] [blame] | 64 | self.machine_checksum = None |
| 65 | return |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 66 | self._GetMemoryInfo() |
| 67 | self._GetCPUInfo() |
| 68 | self._ComputeMachineChecksumString() |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 69 | self._GetMachineID() |
| 70 | self.machine_checksum = self._GetMD5Checksum(self.checksum_string) |
| 71 | self.machine_id_checksum = self._GetMD5Checksum(self.machine_id) |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 72 | |
Yunlian Jiang | e5b673f | 2013-05-23 11:42:53 -0700 | [diff] [blame] | 73 | def IsReachable(self): |
Yunlian Jiang | 837e07a | 2013-05-22 16:23:28 -0700 | [diff] [blame] | 74 | command = "ls" |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 75 | ret = self.ce.CrosRunCommand(command, |
| 76 | machine=self.name, |
| 77 | chromeos_root=self.chromeos_root) |
Yunlian Jiang | 837e07a | 2013-05-22 16:23:28 -0700 | [diff] [blame] | 78 | if ret: |
| 79 | return False |
| 80 | return True |
| 81 | |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 82 | def _ParseMemoryInfo(self): |
| 83 | line = self.meminfo.splitlines()[0] |
| 84 | usable_kbytes = int(line.split()[1]) |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 85 | # This code is from src/third_party/test/files/client/bin/base_utils.py |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 86 | # usable_kbytes is system's usable DRAM in kbytes, |
| 87 | # as reported by memtotal() from device /proc/meminfo memtotal |
| 88 | # after Linux deducts 1.5% to 9.5% for system table overhead |
| 89 | # Undo the unknown actual deduction by rounding up |
| 90 | # to next small multiple of a big power-of-two |
| 91 | # eg 12GB - 5.1% gets rounded back up to 12GB |
| 92 | mindeduct = 0.005 # 0.5 percent |
| 93 | maxdeduct = 0.095 # 9.5 percent |
| 94 | # deduction range 1.5% .. 9.5% supports physical mem sizes |
| 95 | # 6GB .. 12GB in steps of .5GB |
| 96 | # 12GB .. 24GB in steps of 1 GB |
| 97 | # 24GB .. 48GB in steps of 2 GB ... |
| 98 | # Finer granularity in physical mem sizes would require |
| 99 | # tighter spread between min and max possible deductions |
| 100 | |
| 101 | # increase mem size by at least min deduction, without rounding |
| 102 | min_kbytes = int(usable_kbytes / (1.0 - mindeduct)) |
| 103 | # increase mem size further by 2**n rounding, by 0..roundKb or more |
| 104 | round_kbytes = int(usable_kbytes / (1.0 - maxdeduct)) - min_kbytes |
| 105 | # find least binary roundup 2**n that covers worst-cast roundKb |
| 106 | mod2n = 1 << int(math.ceil(math.log(round_kbytes, 2))) |
| 107 | # have round_kbytes <= mod2n < round_kbytes*2 |
| 108 | # round min_kbytes up to next multiple of mod2n |
| 109 | phys_kbytes = min_kbytes + mod2n - 1 |
| 110 | phys_kbytes -= phys_kbytes % mod2n # clear low bits |
| 111 | self.phys_kbytes = phys_kbytes |
| 112 | |
| 113 | def _GetMemoryInfo(self): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 114 | #TODO yunlian: when the machine in rebooting, it will not return |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 115 | #meminfo, the assert does not catch it either |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 116 | command = "cat /proc/meminfo" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 117 | ret, self.meminfo, _ = self.ce.CrosRunCommand( |
| 118 | command, return_output=True, |
| 119 | machine=self.name, |
| 120 | chromeos_root=self.chromeos_root) |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 121 | assert ret == 0, "Could not get meminfo from machine: %s" % self.name |
| 122 | if ret == 0: |
| 123 | self._ParseMemoryInfo() |
| 124 | |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 125 | def _GetCPUInfo(self): |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 126 | command = "cat /proc/cpuinfo" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 127 | ret, self.cpuinfo, _ = self.ce.CrosRunCommand( |
| 128 | command, return_output=True, |
| 129 | machine=self.name, |
| 130 | chromeos_root=self.chromeos_root) |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 131 | assert ret == 0, "Could not get cpuinfo from machine: %s" % self.name |
| 132 | if ret == 0: |
| 133 | self._ParseCPUInfo(self.cpuinfo) |
| 134 | |
| 135 | def _ComputeMachineChecksumString(self): |
| 136 | self.checksum_string = "" |
| 137 | exclude_lines_list = ["MHz", "BogoMIPS", "bogomips"] |
| 138 | for line in self.cpuinfo.splitlines(): |
| 139 | if not any([e in line for e in exclude_lines_list]): |
| 140 | self.checksum_string += line |
| 141 | self.checksum_string += " " + str(self.phys_kbytes) |
| 142 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 143 | def _GetMD5Checksum(self, ss): |
| 144 | if ss: |
| 145 | return hashlib.md5(ss).hexdigest() |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 146 | else: |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 147 | return "" |
| 148 | |
| 149 | def _GetMachineID(self): |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 150 | command = "dump_vpd_log --full --stdout" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 151 | _, if_out, _ = self.ce.CrosRunCommand(command, return_output=True, |
| 152 | machine=self.name, |
| 153 | chromeos_root=self.chromeos_root) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 154 | b = if_out.splitlines() |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 155 | a = [l for l in b if "Product" in l] |
Yunlian Jiang | 9fc9919 | 2013-05-29 16:29:51 -0700 | [diff] [blame] | 156 | if len(a): |
| 157 | self.machine_id = a[0] |
| 158 | return |
| 159 | command = "ifconfig" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 160 | _, if_out, _ = self.ce.CrosRunCommand(command, return_output=True, |
| 161 | machine=self.name, |
| 162 | chromeos_root=self.chromeos_root) |
Yunlian Jiang | 9fc9919 | 2013-05-29 16:29:51 -0700 | [diff] [blame] | 163 | b = if_out.splitlines() |
| 164 | a = [l for l in b if "HWaddr" in l] |
| 165 | if len(a): |
| 166 | self.machine_id = "_".join(a) |
| 167 | return |
cmtice | 870c184 | 2013-11-27 11:17:57 -0800 | [diff] [blame] | 168 | a = [l for l in b if "ether" in l] |
| 169 | if len(a): |
| 170 | self.machine_id = "_".join(a) |
| 171 | return |
Yunlian Jiang | 9fc9919 | 2013-05-29 16:29:51 -0700 | [diff] [blame] | 172 | assert 0, "Could not get machine_id from machine: %s" % self.name |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 173 | |
| 174 | def __str__(self): |
| 175 | l = [] |
| 176 | l.append(self.name) |
| 177 | l.append(str(self.image)) |
| 178 | l.append(str(self.checksum)) |
| 179 | l.append(str(self.locked)) |
| 180 | l.append(str(self.released_time)) |
| 181 | return ", ".join(l) |
| 182 | |
| 183 | |
| 184 | class MachineManager(object): |
cmtice | e5bc63b | 2015-05-27 16:59:37 -0700 | [diff] [blame] | 185 | """Lock, image and unlock machines locally for benchmark runs. |
| 186 | |
| 187 | This class contains methods and calls to lock, unlock and image |
| 188 | machines and distribute machines to each benchmark run. The assumption is |
| 189 | that all of the machines for the experiment have been globally locked |
| 190 | (using an AFE server) in the ExperimentRunner, but the machines still need |
| 191 | to be locally locked/unlocked (allocated to benchmark runs) to prevent |
| 192 | multiple benchmark runs within the same experiment from trying to use the |
| 193 | same machine at the same time. |
| 194 | """ |
cmtice | 5c09fc2 | 2015-04-22 09:25:53 -0700 | [diff] [blame] | 195 | def __init__(self, chromeos_root, acquire_timeout, log_level, locks_dir, |
| 196 | cmd_exec=None, lgr=None): |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 197 | self._lock = threading.RLock() |
| 198 | self._all_machines = [] |
| 199 | self._machines = [] |
| 200 | self.image_lock = threading.Lock() |
| 201 | self.num_reimages = 0 |
| 202 | self.chromeos_root = None |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 203 | self.machine_checksum = {} |
| 204 | self.machine_checksum_string = {} |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 205 | self.acquire_timeout = acquire_timeout |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 206 | self.log_level = log_level |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 207 | self.locks_dir = locks_dir |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 208 | self.ce = cmd_exec or command_executer.GetCommandExecuter( |
| 209 | log_level=self.log_level) |
| 210 | self.logger = lgr or logger.GetLogger() |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 211 | |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 212 | if self.locks_dir and not os.path.isdir(self.locks_dir): |
| 213 | raise MissingLocksDirectory("Cannot access locks directory: %s" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 214 | % self.locks_dir) |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 215 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 216 | self._initialized_machines = [] |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 217 | self.chromeos_root = chromeos_root |
| 218 | |
cmtice | f3eb803 | 2015-07-27 13:55:52 -0700 | [diff] [blame] | 219 | def RemoveNonLockedMachines(self, locked_machines): |
| 220 | for m in self._all_machines: |
| 221 | if m.name not in locked_machines: |
| 222 | self._all_machines.remove(m) |
| 223 | |
| 224 | for m in self._machines: |
| 225 | if m.name not in locked_machines: |
| 226 | self._machines.remove(m) |
| 227 | |
Caroline Tice | 31fedb0 | 2015-09-14 16:30:37 -0700 | [diff] [blame] | 228 | def GetChromeVersion(self, machine): |
| 229 | """Get the version of Chrome running on the DUT.""" |
| 230 | |
| 231 | cmd = "/opt/google/chrome/chrome --version" |
| 232 | ret, version, _ = self.ce.CrosRunCommand(cmd, return_output=True, |
| 233 | machine=machine.name, |
Caroline Tice | 31fedb0 | 2015-09-14 16:30:37 -0700 | [diff] [blame] | 234 | chromeos_root=self.chromeos_root) |
| 235 | if ret != 0: |
| 236 | raise CrosCommandError("Couldn't get Chrome version from %s." |
| 237 | % machine.name) |
| 238 | |
| 239 | if ret != 0: |
| 240 | version = "" |
| 241 | return version.rstrip() |
| 242 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 243 | def ImageMachine(self, machine, label): |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 244 | checksum = label.checksum |
cmtice | 0cc4e77 | 2014-01-30 15:52:37 -0800 | [diff] [blame] | 245 | |
| 246 | if checksum and (machine.checksum == checksum): |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 247 | return |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 248 | chromeos_root = label.chromeos_root |
Ahmad Sharif | f1d70cb | 2012-02-06 21:51:59 -0800 | [diff] [blame] | 249 | if not chromeos_root: |
| 250 | chromeos_root = self.chromeos_root |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 251 | image_chromeos_args = [image_chromeos.__file__, |
cmtice | e5bc63b | 2015-05-27 16:59:37 -0700 | [diff] [blame] | 252 | "--no_lock", |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 253 | "--chromeos_root=%s" % chromeos_root, |
| 254 | "--image=%s" % label.chromeos_image, |
| 255 | "--image_args=%s" % label.image_args, |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 256 | "--remote=%s" % machine.name, |
| 257 | "--logging_level=%s" % self.log_level] |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 258 | if label.board: |
| 259 | image_chromeos_args.append("--board=%s" % label.board) |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 260 | |
| 261 | # Currently can't image two machines at once. |
| 262 | # So have to serialized on this lock. |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 263 | save_ce_log_level = self.ce.log_level |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 264 | if self.log_level != "verbose": |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 265 | self.ce.log_level = "average" |
| 266 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 267 | with self.image_lock: |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 268 | if self.log_level != "verbose": |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 269 | self.logger.LogOutput("Pushing image onto machine.") |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 270 | self.logger.LogOutput("Running image_chromeos.DoImage with %s" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 271 | % " ".join(image_chromeos_args)) |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 272 | retval = image_chromeos.DoImage(image_chromeos_args) |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 273 | if retval: |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 274 | cmd = "reboot && exit" |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 275 | if self.log_level != "verbose": |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 276 | self.logger.LogOutput("reboot & exit.") |
| 277 | self.ce.CrosRunCommand(cmd, machine=machine.name, |
| 278 | chromeos_root=self.chromeos_root) |
Yunlian Jiang | 36f91ad | 2013-03-28 17:13:29 -0700 | [diff] [blame] | 279 | time.sleep(60) |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 280 | if self.log_level != "verbose": |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 281 | self.logger.LogOutput("Pushing image onto machine.") |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 282 | self.logger.LogOutput("Running image_chromeos.DoImage with %s" |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 283 | % " ".join(image_chromeos_args)) |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 284 | retval = image_chromeos.DoImage(image_chromeos_args) |
Yunlian Jiang | 36f91ad | 2013-03-28 17:13:29 -0700 | [diff] [blame] | 285 | if retval: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 286 | raise Exception("Could not image machine: '%s'." % machine.name) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 287 | else: |
| 288 | self.num_reimages += 1 |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 289 | machine.checksum = checksum |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 290 | machine.image = label.chromeos_image |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 291 | machine.label = label |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 292 | |
Caroline Tice | 31fedb0 | 2015-09-14 16:30:37 -0700 | [diff] [blame] | 293 | if not label.chrome_version: |
| 294 | label.chrome_version = self.GetChromeVersion(machine) |
| 295 | |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 296 | self.ce.log_level = save_ce_log_level |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 297 | return retval |
| 298 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 299 | def ComputeCommonCheckSum(self, label): |
Caroline Tice | 5ea9f00 | 2015-09-02 12:36:47 -0700 | [diff] [blame] | 300 | # Since this is used for cache lookups before the machines have been |
| 301 | # compared/verified, check here to make sure they all have the same |
| 302 | # checksum (otherwise the cache lookup may not be valid). |
| 303 | common_checksum = None |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 304 | for machine in self.GetMachines(label): |
Caroline Tice | 5ea9f00 | 2015-09-02 12:36:47 -0700 | [diff] [blame] | 305 | # Make sure the machine's checksums are calculated. |
| 306 | if not machine.machine_checksum: |
| 307 | machine.SetUpChecksumInfo() |
| 308 | cs = machine.machine_checksum |
| 309 | # If this is the first machine we've examined, initialize |
| 310 | # common_checksum. |
| 311 | if not common_checksum: |
| 312 | common_checksum = cs |
| 313 | # Make sure this machine's checksum matches our 'common' checksum. |
| 314 | if cs != common_checksum: |
| 315 | raise BadChecksum("Machine checksums do not match!") |
| 316 | self.machine_checksum[label.name] = common_checksum |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 317 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 318 | def ComputeCommonCheckSumString(self, label): |
Caroline Tice | 5ea9f00 | 2015-09-02 12:36:47 -0700 | [diff] [blame] | 319 | # The assumption is that this function is only called AFTER |
| 320 | # ComputeCommonCheckSum, so there is no need to verify the machines |
| 321 | # are the same here. If this is ever changed, this function should be |
| 322 | # modified to verify that all the machines for a given label are the |
| 323 | # same. |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 324 | for machine in self.GetMachines(label): |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 325 | if machine.checksum_string: |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 326 | self.machine_checksum_string[label.name] = machine.checksum_string |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 327 | break |
| 328 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 329 | def _TryToLockMachine(self, cros_machine): |
| 330 | with self._lock: |
| 331 | assert cros_machine, "Machine can't be None" |
| 332 | for m in self._machines: |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 333 | if m.name == cros_machine.name: |
| 334 | return |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 335 | locked = True |
| 336 | if self.locks_dir: |
| 337 | locked = file_lock_machine.Machine(cros_machine.name, |
| 338 | self.locks_dir).Lock(True, |
| 339 | sys.argv[0]) |
| 340 | if locked: |
| 341 | self._machines.append(cros_machine) |
| 342 | command = "cat %s" % CHECKSUM_FILE |
| 343 | ret, out, _ = self.ce.CrosRunCommand( |
| 344 | command, return_output=True, chromeos_root=self.chromeos_root, |
| 345 | machine=cros_machine.name) |
| 346 | if ret == 0: |
| 347 | cros_machine.checksum = out.strip() |
| 348 | elif self.locks_dir: |
| 349 | self.logger.LogOutput("Couldn't lock: %s" % cros_machine.name) |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 350 | |
| 351 | # This is called from single threaded mode. |
| 352 | def AddMachine(self, machine_name): |
| 353 | with self._lock: |
| 354 | for m in self._all_machines: |
| 355 | assert m.name != machine_name, "Tried to double-add %s" % machine_name |
Han Shen | 98eacdf | 2015-12-07 16:00:43 -0800 | [diff] [blame] | 356 | |
| 357 | if self.log_level != "verbose": |
| 358 | self.logger.LogOutput("Setting up remote access to %s" % machine_name) |
| 359 | self.logger.LogOutput( |
| 360 | "Checking machine characteristics for %s" % machine_name) |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 361 | cm = CrosMachine(machine_name, self.chromeos_root, self.log_level) |
Yunlian Jiang | 837e07a | 2013-05-22 16:23:28 -0700 | [diff] [blame] | 362 | if cm.machine_checksum: |
| 363 | self._all_machines.append(cm) |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 364 | |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 365 | |
Yunlian Jiang | e5b673f | 2013-05-23 11:42:53 -0700 | [diff] [blame] | 366 | def RemoveMachine(self, machine_name): |
| 367 | with self._lock: |
| 368 | self._machines = [m for m in self._machines |
| 369 | if m.name != machine_name] |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 370 | if self.locks_dir: |
| 371 | res = file_lock_machine.Machine(machine_name, |
| 372 | self.locks_dir).Unlock(True) |
| 373 | if not res: |
| 374 | self.logger.LogError("Could not unlock machine: '%s'." |
| 375 | % machine_name) |
Yunlian Jiang | e5b673f | 2013-05-23 11:42:53 -0700 | [diff] [blame] | 376 | |
cmtice | 798a8fa | 2014-05-12 13:56:42 -0700 | [diff] [blame] | 377 | def ForceSameImageToAllMachines(self, label): |
| 378 | machines = self.GetMachines(label) |
cmtice | 798a8fa | 2014-05-12 13:56:42 -0700 | [diff] [blame] | 379 | for m in machines: |
| 380 | self.ImageMachine(m, label) |
| 381 | m.SetUpChecksumInfo() |
| 382 | |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 383 | def AcquireMachine(self, label): |
Han Shen | ba64928 | 2015-08-05 17:19:55 -0700 | [diff] [blame] | 384 | image_checksum = label.checksum |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 385 | machines = self.GetMachines(label) |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 386 | check_interval_time = 120 |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 387 | with self._lock: |
| 388 | # Lazily external lock machines |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 389 | while self.acquire_timeout >= 0: |
| 390 | for m in machines: |
| 391 | new_machine = m not in self._all_machines |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 392 | self._TryToLockMachine(m) |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 393 | if new_machine: |
| 394 | m.released_time = time.time() |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 395 | if self.GetAvailableMachines(label): |
| 396 | break |
| 397 | else: |
| 398 | sleep_time = max(1, min(self.acquire_timeout, check_interval_time)) |
| 399 | time.sleep(sleep_time) |
| 400 | self.acquire_timeout -= sleep_time |
| 401 | |
| 402 | if self.acquire_timeout < 0: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 403 | machine_names = [] |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 404 | for machine in machines: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 405 | machine_names.append(machine.name) |
cmtice | 1505b6a | 2014-06-04 14:19:19 -0700 | [diff] [blame] | 406 | self.logger.LogFatal("Could not acquire any of the " |
| 407 | "following machines: '%s'" |
| 408 | % ", ".join(machine_names)) |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 409 | |
| 410 | ### for m in self._machines: |
| 411 | ### if (m.locked and time.time() - m.released_time < 10 and |
| 412 | ### m.checksum == image_checksum): |
| 413 | ### return None |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 414 | for m in [machine for machine in self.GetAvailableMachines(label) |
| 415 | if not machine.locked]: |
cmtice | 0cc4e77 | 2014-01-30 15:52:37 -0800 | [diff] [blame] | 416 | if image_checksum and (m.checksum == image_checksum): |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 417 | m.locked = True |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 418 | m.test_run = threading.current_thread() |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 419 | return m |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 420 | for m in [machine for machine in self.GetAvailableMachines(label) |
| 421 | if not machine.locked]: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 422 | if not m.checksum: |
| 423 | m.locked = True |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 424 | m.test_run = threading.current_thread() |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 425 | return m |
| 426 | # This logic ensures that threads waiting on a machine will get a machine |
| 427 | # with a checksum equal to their image over other threads. This saves time |
| 428 | # when crosperf initially assigns the machines to threads by minimizing |
| 429 | # the number of re-images. |
| 430 | # TODO(asharif): If we centralize the thread-scheduler, we wont need this |
| 431 | # code and can implement minimal reimaging code more cleanly. |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 432 | for m in [machine for machine in self.GetAvailableMachines(label) |
| 433 | if not machine.locked]: |
Yunlian Jiang | a844671 | 2015-02-26 10:25:11 -0800 | [diff] [blame] | 434 | if time.time() - m.released_time > 15: |
| 435 | # The release time gap is too large, so it is probably in the start |
| 436 | # stage, we need to reset the released_time. |
| 437 | m.released_time = time.time() |
| 438 | elif time.time() - m.released_time > 8: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 439 | m.locked = True |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 440 | m.test_run = threading.current_thread() |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 441 | return m |
| 442 | return None |
| 443 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 444 | def GetAvailableMachines(self, label=None): |
| 445 | if not label: |
| 446 | return self._machines |
| 447 | return [m for m in self._machines if m.name in label.remote] |
| 448 | |
| 449 | def GetMachines(self, label=None): |
| 450 | if not label: |
| 451 | return self._all_machines |
| 452 | return [m for m in self._all_machines if m.name in label.remote] |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 453 | |
| 454 | def ReleaseMachine(self, machine): |
| 455 | with self._lock: |
| 456 | for m in self._machines: |
| 457 | if machine.name == m.name: |
| 458 | assert m.locked == True, "Tried to double-release %s" % m.name |
| 459 | m.released_time = time.time() |
| 460 | m.locked = False |
| 461 | m.status = "Available" |
| 462 | break |
| 463 | |
cmtice | 517dc98 | 2015-06-12 12:22:32 -0700 | [diff] [blame] | 464 | def Cleanup(self): |
| 465 | with self._lock: |
| 466 | # Unlock all machines (via file lock) |
| 467 | for m in self._machines: |
| 468 | res = file_lock_machine.Machine(m.name, self.locks_dir).Unlock(True) |
| 469 | |
| 470 | if not res: |
| 471 | self.logger.LogError("Could not unlock machine: '%s'." |
| 472 | % m.name) |
| 473 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 474 | def __str__(self): |
| 475 | with self._lock: |
| 476 | l = ["MachineManager Status:"] |
| 477 | for m in self._machines: |
| 478 | l.append(str(m)) |
| 479 | return "\n".join(l) |
| 480 | |
| 481 | def AsString(self): |
| 482 | with self._lock: |
| 483 | stringify_fmt = "%-30s %-10s %-4s %-25s %-32s" |
| 484 | header = stringify_fmt % ("Machine", "Thread", "Lock", "Status", |
| 485 | "Checksum") |
| 486 | table = [header] |
| 487 | for m in self._machines: |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 488 | if m.test_run: |
| 489 | test_name = m.test_run.name |
| 490 | test_status = m.test_run.timeline.GetLastEvent() |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 491 | else: |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 492 | test_name = "" |
| 493 | test_status = "" |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 494 | |
| 495 | try: |
| 496 | machine_string = stringify_fmt % (m.name, |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 497 | test_name, |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 498 | m.locked, |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 499 | test_status, |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 500 | m.checksum) |
Yunlian Jiang | c152cdb | 2015-12-07 09:39:26 -0800 | [diff] [blame] | 501 | except ValueError: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 502 | machine_string = "" |
| 503 | table.append(machine_string) |
| 504 | return "Machine Status:\n%s" % "\n".join(table) |
| 505 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 506 | def GetAllCPUInfo(self, labels): |
| 507 | """Get cpuinfo for labels, merge them if their cpuinfo are the same.""" |
| 508 | dic = {} |
| 509 | for label in labels: |
| 510 | for machine in self._all_machines: |
| 511 | if machine.name in label.remote: |
| 512 | if machine.cpuinfo not in dic: |
| 513 | dic[machine.cpuinfo] = [label.name] |
| 514 | else: |
| 515 | dic[machine.cpuinfo].append(label.name) |
| 516 | break |
| 517 | output = "" |
| 518 | for key, v in dic.items(): |
| 519 | output += " ".join(v) |
| 520 | output += "\n-------------------\n" |
| 521 | output += key |
| 522 | output += "\n\n\n" |
| 523 | return output |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 524 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 525 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 526 | class MockCrosMachine(CrosMachine): |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 527 | """Mock cros machine class.""" |
| 528 | # pylint: disable=super-init-not-called |
Caroline Tice | 7057cf6 | 2015-12-10 12:09:40 -0800 | [diff] [blame^] | 529 | |
| 530 | MEMINFO_STRING = """MemTotal: 3990332 kB |
| 531 | MemFree: 2608396 kB |
| 532 | Buffers: 147168 kB |
| 533 | Cached: 811560 kB |
| 534 | SwapCached: 0 kB |
| 535 | Active: 503480 kB |
| 536 | Inactive: 628572 kB |
| 537 | Active(anon): 174532 kB |
| 538 | Inactive(anon): 88576 kB |
| 539 | Active(file): 328948 kB |
| 540 | Inactive(file): 539996 kB |
| 541 | Unevictable: 0 kB |
| 542 | Mlocked: 0 kB |
| 543 | SwapTotal: 5845212 kB |
| 544 | SwapFree: 5845212 kB |
| 545 | Dirty: 9384 kB |
| 546 | Writeback: 0 kB |
| 547 | AnonPages: 173408 kB |
| 548 | Mapped: 146268 kB |
| 549 | Shmem: 89676 kB |
| 550 | Slab: 188260 kB |
| 551 | SReclaimable: 169208 kB |
| 552 | SUnreclaim: 19052 kB |
| 553 | KernelStack: 2032 kB |
| 554 | PageTables: 7120 kB |
| 555 | NFS_Unstable: 0 kB |
| 556 | Bounce: 0 kB |
| 557 | WritebackTmp: 0 kB |
| 558 | CommitLimit: 7840376 kB |
| 559 | Committed_AS: 1082032 kB |
| 560 | VmallocTotal: 34359738367 kB |
| 561 | VmallocUsed: 364980 kB |
| 562 | VmallocChunk: 34359369407 kB |
| 563 | DirectMap4k: 45824 kB |
| 564 | DirectMap2M: 4096000 kB |
| 565 | """ |
| 566 | |
| 567 | CPUINFO_STRING = """processor: 0 |
| 568 | vendor_id: GenuineIntel |
| 569 | cpu family: 6 |
| 570 | model: 42 |
| 571 | model name: Intel(R) Celeron(R) CPU 867 @ 1.30GHz |
| 572 | stepping: 7 |
| 573 | microcode: 0x25 |
| 574 | cpu MHz: 1300.000 |
| 575 | cache size: 2048 KB |
| 576 | physical id: 0 |
| 577 | siblings: 2 |
| 578 | core id: 0 |
| 579 | cpu cores: 2 |
| 580 | apicid: 0 |
| 581 | initial apicid: 0 |
| 582 | fpu: yes |
| 583 | fpu_exception: yes |
| 584 | cpuid level: 13 |
| 585 | wp: yes |
| 586 | flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave lahf_lm arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid |
| 587 | bogomips: 2594.17 |
| 588 | clflush size: 64 |
| 589 | cache_alignment: 64 |
| 590 | address sizes: 36 bits physical, 48 bits virtual |
| 591 | power management: |
| 592 | |
| 593 | processor: 1 |
| 594 | vendor_id: GenuineIntel |
| 595 | cpu family: 6 |
| 596 | model: 42 |
| 597 | model name: Intel(R) Celeron(R) CPU 867 @ 1.30GHz |
| 598 | stepping: 7 |
| 599 | microcode: 0x25 |
| 600 | cpu MHz: 1300.000 |
| 601 | cache size: 2048 KB |
| 602 | physical id: 0 |
| 603 | siblings: 2 |
| 604 | core id: 1 |
| 605 | cpu cores: 2 |
| 606 | apicid: 2 |
| 607 | initial apicid: 2 |
| 608 | fpu: yes |
| 609 | fpu_exception: yes |
| 610 | cpuid level: 13 |
| 611 | wp: yes |
| 612 | flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer xsave lahf_lm arat epb xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid |
| 613 | bogomips: 2594.17 |
| 614 | clflush size: 64 |
| 615 | cache_alignment: 64 |
| 616 | address sizes: 36 bits physical, 48 bits virtual |
| 617 | power management: |
| 618 | """ |
| 619 | |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 620 | def __init__(self, name, chromeos_root, log_level): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 621 | self.name = name |
| 622 | self.image = None |
| 623 | self.checksum = None |
| 624 | self.locked = False |
| 625 | self.released_time = time.time() |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 626 | self.test_run = None |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 627 | self.chromeos_root = chromeos_root |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 628 | self.checksum_string = re.sub(r"\d", "", name) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 629 | #In test, we assume "lumpy1", "lumpy2" are the same machine. |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 630 | self.machine_checksum = self._GetMD5Checksum(self.checksum_string) |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 631 | self.log_level = log_level |
Han Shen | e066297 | 2015-09-18 16:53:34 -0700 | [diff] [blame] | 632 | self.label = None |
Caroline Tice | 7057cf6 | 2015-12-10 12:09:40 -0800 | [diff] [blame^] | 633 | self.ce = command_executer.GetCommandExecuter(log_level=self.log_level) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 634 | |
cmtice | c454cee | 2014-04-09 10:58:51 -0700 | [diff] [blame] | 635 | def IsReachable(self): |
| 636 | return True |
| 637 | |
Caroline Tice | 7057cf6 | 2015-12-10 12:09:40 -0800 | [diff] [blame^] | 638 | def _GetMemoryInfo(self): |
| 639 | self.meminfo = self.MEMINFO_STRING |
| 640 | self._ParseMemoryInfo() |
| 641 | |
| 642 | def _GetCPUInfo(self): |
| 643 | self.cpuinfo = self.CPUINFO_STRING |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 644 | |
| 645 | class MockMachineManager(MachineManager): |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 646 | """Mock machine manager class.""" |
| 647 | def __init__(self, chromeos_root, acquire_timeout, |
| 648 | log_level): |
| 649 | super(MockMachineManager, self).__init__( |
| 650 | chromeos_root, acquire_timeout, |
| 651 | log_level, |
| 652 | file_lock_machine.Machine.LOCKS_DIR) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 653 | |
| 654 | def _TryToLockMachine(self, cros_machine): |
| 655 | self._machines.append(cros_machine) |
| 656 | cros_machine.checksum = "" |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 657 | |
| 658 | def AddMachine(self, machine_name): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 659 | with self._lock: |
| 660 | for m in self._all_machines: |
| 661 | assert m.name != machine_name, "Tried to double-add %s" % machine_name |
cmtice | 1390924 | 2014-03-11 13:38:07 -0700 | [diff] [blame] | 662 | cm = MockCrosMachine(machine_name, self.chromeos_root, self.log_level) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 663 | assert cm.machine_checksum, ("Could not find checksum for machine %s" % |
| 664 | machine_name) |
Han Shen | 624bae7 | 2015-09-17 15:07:31 -0700 | [diff] [blame] | 665 | # In Original MachineManager, the test is 'if cm.machine_checksum:' - if a |
| 666 | # machine is unreachable, then its machine_checksum is None. Here we |
| 667 | # cannot do this, because machine_checksum is always faked, so we directly |
| 668 | # test cm.IsReachable, which is properly mocked. |
| 669 | if cm.IsReachable(): |
| 670 | self._all_machines.append(cm) |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 671 | |
Caroline Tice | 7057cf6 | 2015-12-10 12:09:40 -0800 | [diff] [blame^] | 672 | def GetChromeVersion(self, machine): |
| 673 | return "Mock Chrome Version R50" |
| 674 | |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 675 | def AcquireMachine(self, label): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 676 | for machine in self._all_machines: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 677 | if not machine.locked: |
| 678 | machine.locked = True |
| 679 | return machine |
| 680 | return None |
| 681 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 682 | def ImageMachine(self, machine_name, label): |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 683 | if machine_name or label: |
| 684 | return 0 |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 685 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 686 | def ReleaseMachine(self, machine): |
| 687 | machine.locked = False |
| 688 | |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 689 | def GetMachines(self, label=None): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 690 | return self._all_machines |
| 691 | |
Yunlian Jiang | 9395017 | 2015-12-10 13:20:48 -0800 | [diff] [blame] | 692 | def GetAvailableMachines(self, label=None): |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 693 | return self._all_machines |
Caroline Tice | 7057cf6 | 2015-12-10 12:09:40 -0800 | [diff] [blame^] | 694 | |
| 695 | def ForceSameImageToAllMachines(self, label): |
| 696 | return 0 |
| 697 | |
| 698 | def ComputeCommonCheckSum(self, label): |
| 699 | common_checksum = 12345 |
| 700 | for machine in self.GetMachines(label): |
| 701 | machine.machine_checksum = common_checksum |
| 702 | self.machine_checksum[label.name] = common_checksum |