diff options
29 files changed, 249 insertions, 204 deletions
diff --git a/auto_delete_nightly_test_data.py b/auto_delete_nightly_test_data.py index 17e67e74..f8eaeacc 100755 --- a/auto_delete_nightly_test_data.py +++ b/auto_delete_nightly_test_data.py @@ -47,8 +47,7 @@ def CleanNumberedDir(s, dry_run=False): if dry_run: print cmd else: - if ce.RunCommand(cmd, return_output=False, print_to_console=False, - terminated_timeout=480) == 0: + if ce.RunCommand(cmd, print_to_console=False, terminated_timeout=480) == 0: print 'Successfully removed "{0}".'.format(s) else: all_succeeded = False @@ -97,7 +96,7 @@ def CleanChromeOsTmpAndImages(): r'-amin +1440 ' r'-exec bash -c "echo rm -fr {{}}" \; ' r'-exec bash -c "rm -fr {{}}" \;').format(chromeos_chroot_tmp) - rv = ce.RunCommand(cmd, return_output=False, print_to_console=False) + rv = ce.RunCommand(cmd, print_to_console=False) if rv == 0: print ('Successfully cleaned chromeos tree tmp directory ' '"{0}".'.format(chromeos_chroot_tmp)) @@ -113,7 +112,7 @@ def CleanChromeOsTmpAndImages(): r' -name "chromiumos_test_image.bin" -amin +1440 \) ' r'-exec bash -c "echo rm -f {{}}" \; ' r'-exec bash -c "rm -f {{}}" \;').format(chromeos_chroot_tmp) - rv2 = ce.RunCommand(cmd, return_output=False, print_to_console=False) + rv2 = ce.RunCommand(cmd, print_to_console=False) if rv2 == 0: print 'Successfully cleaned chromeos images.' else: diff --git a/binary_search_tool/binary_search_state.py b/binary_search_tool/binary_search_state.py index 7c85b975..2f90f78d 100755 --- a/binary_search_tool/binary_search_state.py +++ b/binary_search_tool/binary_search_state.py @@ -179,7 +179,7 @@ class BinarySearchState(object): def PopulateItemsUsingCommand(self, command): ce = command_executer.GetCommandExecuter() - [_, out, _] = ce.RunCommand(command, return_output=True) + _, out, _ = ce.RunCommandWOutput(command) all_items = out.split() self.PopulateItemsUsingList(all_items) diff --git a/binary_search_tool/test/binary_search_tool_tester.py b/binary_search_tool/test/binary_search_tool_tester.py index 211c16f2..91b5845d 100755 --- a/binary_search_tool/test/binary_search_tool_tester.py +++ b/binary_search_tool/test/binary_search_tool_tester.py @@ -43,8 +43,8 @@ class BisectingUtilsTest(unittest.TestCase): '--prune', '--file_args'] binary_search_state.Main(args) - _, out, _ = command_executer.GetCommandExecuter().RunCommand( - 'tail -n 10 logs/binary_search_state.py.out', return_output=True) + _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput( + 'tail -n 10 logs/binary_search_state.py.out') ls = out.splitlines() for l in ls: t = l.find('Bad items are: ') diff --git a/binary_search_tool/test/gen_init_list.py b/binary_search_tool/test/gen_init_list.py index ce72d632..4ac5da83 100755 --- a/binary_search_tool/test/gen_init_list.py +++ b/binary_search_tool/test/gen_init_list.py @@ -9,8 +9,8 @@ import common def Main(): ce = command_executer.GetCommandExecuter() - _, l, _ = ce.RunCommand('cat {0} | wc -l'.format(common.OBJECTS_FILE), - return_output=True, print_to_console=False) + _, l, _ = ce.RunCommandWOutput( + 'cat {0} | wc -l'.format(common.OBJECTS_FILE), print_to_console=False) for i in range(0, int(l)): print i diff --git a/build_chrome_browser.py b/build_chrome_browser.py index f162c1d4..63365692 100755 --- a/build_chrome_browser.py +++ b/build_chrome_browser.py @@ -139,8 +139,7 @@ def Main(argv): chrome_origin = "LOCAL_SOURCE" command = 'cros_workon --board={0} start chromeos-chrome'.format( options.board) - ret = cmd_executer.ChrootRunCommand( - options.chromeos_root, command, return_output=True) + ret = cmd_executer.ChrootRunCommandWOutput(options.chromeos_root, command) # cros_workon start returns non-zero if chromeos-chrome is already a # cros_workon package. diff --git a/build_tool.py b/build_tool.py index 5ee797e0..3d7dc6ab 100755 --- a/build_tool.py +++ b/build_tool.py @@ -152,8 +152,8 @@ class Bootstrapper(object): # 4.1 Try to get some information about the tool dir we are using. cmd = 'cd {0} && git log -1 --pretty=oneline'.format(tool_dir) tool_dir_extra_info = None - ret, tool_dir_extra_info, _ = self._ce.RunCommand( - cmd, return_output=True, print_to_console=False) + ret, tool_dir_extra_info, _ = self._ce.RunCommandWOutput( + cmd, print_to_console=False) commit_message = 'Synced with tool source tree at - "{0}".'.format(tool_dir) if not ret: commit_message += '\nGit log for {0}:\n{1}'.format( @@ -206,8 +206,8 @@ class Bootstrapper(object): command = ('cd "{0}" && git cat-file -p {1} ' '| grep -E "^tree [a-f0-9]+$" ' '| cut -d" " -f2').format(chrome_tool_dir, tool_branch) - ret, stdout, _ = self._ce.RunCommand( - command, return_output=True, print_to_console=False) + ret, stdout, _ = self._ce.RunCommandWOutput( + command, print_to_console=False) # Pipe operation always has a zero return value. So need to check if # stdout is valid. if not ret and stdout and re.match( @@ -265,9 +265,9 @@ class Bootstrapper(object): 'in-complete chroot.')) return (False, None, None) - rv, stdout, _ = self._ce.ChrootRunCommand( + rv, stdout, _ = self._ce.ChrootRunCommandWOutput( self._chromeos_root, 'equery w sys-devel/{0}'.format(tool_name), - return_output=True, print_to_console=True) + print_to_console=True) if rv: self._logger.LogError( ('Failed to execute inside chroot ' @@ -433,7 +433,7 @@ class Bootstrapper(object): command = 'sudo emerge cross-{0}/{1}'.format(target, tool_name) rv = self._ce.ChrootRunCommand(self._chromeos_root, command, - return_output=False, print_to_console=True) + print_to_console=True) if rv: self._logger.LogError( 'Build {0} failed for {1}, aborted.'.format(tool_name, board)) @@ -463,8 +463,7 @@ class Bootstrapper(object): logfile = os.path.join(self._chromeos_root, 'bootstrap.log') command = 'cd "{0}" && cros_sdk --delete --bootstrap |& tee "{1}"'.format( self._chromeos_root, logfile) - rv = self._ce.RunCommand(command, return_output=False, - print_to_console=True) + rv = self._ce.RunCommand(command, print_to_console=True) if rv: self._logger.LogError('Bootstrapping failed, log file - "{0}"\n'.format( logfile)) @@ -492,7 +491,7 @@ class Bootstrapper(object): cmd = ('cd {0} && cros_sdk -- -- ./setup_board --board=amd64-host ' '--accept_licenses=@CHROMEOS --skip_chroot_upgrade --nousepkg ' '--reuse_pkgs_from_local_boards').format(self._chromeos_root) - rv = self._ce.RunCommand(cmd, return_output=False, print_to_console=True) + rv = self._ce.RunCommand(cmd, print_to_console=True) if rv: self._logger.LogError('Build amd64-host failed.') return False @@ -504,7 +503,7 @@ class Bootstrapper(object): '--exclude="tmp/*" --exclude="usr/local/build/autotest/*" ' '--sparse -I xz -vcf {1} . && sudo chmod a+r {1}').format( self._chromeos_root, sdk_package) - rv = self._ce.RunCommand(cmd, return_output=False, print_to_console=True) + rv = self._ce.RunCommand(cmd, print_to_console=True) if rv: self._logger.LogError('Failed to create "built-sdk.tar.xz".') return False @@ -513,7 +512,7 @@ class Bootstrapper(object): cmd = ('cd {0} && cros_sdk --chroot new-sdk-chroot --download --replace ' '--nousepkg --url file://{1}').format( self._chromeos_root, sdk_package) - rv = self._ce.RunCommand(cmd, return_output=False, print_to_console=True) + rv = self._ce.RunCommand(cmd, print_to_console=True) if rv: self._logger.LogError('Failed to install "built-sdk.tar.xz".') return False @@ -523,7 +522,7 @@ class Bootstrapper(object): # Rename the newly created new-sdk-chroot to chroot. cmd = ('cd {0} && sudo mv chroot chroot-old && ' 'sudo mv new-sdk-chroot chroot').format(self._chromeos_root) - rv = self._ce.RunCommand(cmd, return_output=False, print_to_console=True) + rv = self._ce.RunCommand(cmd, print_to_console=True) return rv == 0 def Do(self): diff --git a/chromiumos_image_diff.py b/chromiumos_image_diff.py index 6b455829..7d9b5e34 100755 --- a/chromiumos_image_diff.py +++ b/chromiumos_image_diff.py @@ -63,8 +63,7 @@ class CrosImage(object): self.CreateUnmountScript() command = image_chromeos.GetImageMountCommand( self.chromeos_root, self.image, self.rootfs, self.stateful) - rv = self._ce.RunCommand( - command, return_output=False, print_to_console=True) + rv = self._ce.RunCommand(command, print_to_console=True) self.mounted = (rv == 0) if not self.mounted: self.logger.LogError('Failed to mount "{0}" onto "{1}" and "{2}".'.format( @@ -79,7 +78,7 @@ class CrosImage(object): f.write(command) f.close() self._ce.RunCommand('chmod +x {}'.format(self.unmount_script), - print_to_console=False, return_output=False) + print_to_console=False) self.logger.LogOutput('Created an unmount script - "{0}"'.format( self.unmount_script)) @@ -94,8 +93,7 @@ class CrosImage(object): self.logger.LogOutput(('Please unmount manually - \n' '\t bash "{0}"'.format(self.unmount_script))) else: - if self._ce.RunCommand( - command, return_output=False, print_to_console=True) == 0: + if self._ce.RunCommand(command, print_to_console=True) == 0: self._ce.RunCommand('rm {0}'.format(self.unmount_script)) self.mounted = False self.rootfs = None @@ -118,8 +116,7 @@ class CrosImage(object): 'bash -c \'file -b "{{}}" | grep -q "ELF"\'' r' \; ' r'-exec echo "{{}}" \;').format(self.rootfs) self.logger.LogCmd(command) - _, out, _ = self._ce.RunCommand( - command, return_output=True, print_to_console=False) + _, out, _ = self._ce.RunCommandWOutput(command, print_to_console=False) self.elf_files = out.splitlines() self.logger.LogOutput( 'Total {0} elf files found.'.format(len(self.elf_files))) @@ -212,8 +209,7 @@ class ImageComparator(object): f1=full_path1, f2=full_path2, rootfs1=i1.rootfs, rootfs2=i2.rootfs, tempf1=self.tempf1, tempf2=self.tempf2) - ret = cmde.RunCommand(command, return_output=False, - print_to_console=False) + ret = cmde.RunCommand(command, print_to_console=False) if ret != 0: self.logger.LogOutput('*** Not match - "{0}" "{1}"'.format( full_path1, full_path2)) @@ -225,7 +221,7 @@ class ImageComparator(object): '>> {diff_file}').format( f1=full_path1, f2=full_path2, diff_file=self.diff_file, tempf1=self.tempf1, tempf2=self.tempf2) - cmde.RunCommand(command, return_output=False, print_to_console=False) + cmde.RunCommand(command, print_to_console=False) else: match_count += 1 ## End of comparing every elf files. diff --git a/crb/autotest_run.py b/crb/autotest_run.py index bae2547f..565246db 100644 --- a/crb/autotest_run.py +++ b/crb/autotest_run.py @@ -254,7 +254,7 @@ class AutotestRun(threading.Thread): " cros_sdk -- /usr/sbin/perf report --symfs=/build/%s" " -i %s --stdio" % (self.chromeos_root, self.board, perf_data_file)) - ret, out, err = self._ce.RunCommand(command, return_output=True) + ret, out, err = self._ce.RunCommandWOutput(command) with open(os.path.join(self.cache_dir, "perf.report"), "wb") as f: f.write(out) return self.retval diff --git a/crb/machine_manager_singleton.py b/crb/machine_manager_singleton.py index 93629c4c..80369216 100644 --- a/crb/machine_manager_singleton.py +++ b/crb/machine_manager_singleton.py @@ -56,8 +56,8 @@ class MachineManagerSingleton(object): if locked: ce = command_executer.GetCommandExecuter() command = "cat %s" % image_chromeos.checksum_file - ret, out, err = ce.CrosRunCommand( - command, return_output=True, chromeos_root=self.chromeos_root, + ret, out, err = ce.CrosRunCommandWOutput( + command, chromeos_root=self.chromeos_root, machine=cros_machine.name) if ret == 0: cros_machine.checksum = out.strip() diff --git a/crosperf/download_images.py b/crosperf/download_images.py index 72f3fb04..8fecf8b3 100644 --- a/crosperf/download_images.py +++ b/crosperf/download_images.py @@ -28,8 +28,8 @@ class ImageDownloader(object): # image name. command = ("cd ~/trunk/src/third_party/toolchain-utils/crosperf; " "python translate_xbuddy.py '%s'" % xbuddy_label) - retval, build_id_tuple_str, _ = self._ce.ChrootRunCommand(chromeos_root, - command, True) + retval, build_id_tuple_str, _ = self._ce.ChrootRunCommandWOutput( + chromeos_root, command) if not build_id_tuple_str: raise MissingImage ("Unable to find image for '%s'" % xbuddy_label) diff --git a/crosperf/machine_manager.py b/crosperf/machine_manager.py index f8834d73..7bada0d1 100644 --- a/crosperf/machine_manager.py +++ b/crosperf/machine_manager.py @@ -114,20 +114,16 @@ class CrosMachine(object): #TODO yunlian: when the machine in rebooting, it will not return #meminfo, the assert does not catch it either command = "cat /proc/meminfo" - ret, self.meminfo, _ = self.ce.CrosRunCommand( - command, return_output=True, - machine=self.name, - chromeos_root=self.chromeos_root) + ret, self.meminfo, _ = self.ce.CrosRunCommandWOutput( + command, machine=self.name, chromeos_root=self.chromeos_root) assert ret == 0, "Could not get meminfo from machine: %s" % self.name if ret == 0: self._ParseMemoryInfo() def _GetCPUInfo(self): command = "cat /proc/cpuinfo" - ret, self.cpuinfo, _ = self.ce.CrosRunCommand( - command, return_output=True, - machine=self.name, - chromeos_root=self.chromeos_root) + ret, self.cpuinfo, _ = self.ce.CrosRunCommandWOutput( + command, machine=self.name, chromeos_root=self.chromeos_root) assert ret == 0, "Could not get cpuinfo from machine: %s" % self.name def _ComputeMachineChecksumString(self): @@ -146,18 +142,16 @@ class CrosMachine(object): def _GetMachineID(self): command = "dump_vpd_log --full --stdout" - _, if_out, _ = self.ce.CrosRunCommand(command, return_output=True, - machine=self.name, - chromeos_root=self.chromeos_root) + _, if_out, _ = self.ce.CrosRunCommandWOutput( + command, machine=self.name, chromeos_root=self.chromeos_root) b = if_out.splitlines() a = [l for l in b if "Product" in l] if len(a): self.machine_id = a[0] return command = "ifconfig" - _, if_out, _ = self.ce.CrosRunCommand(command, return_output=True, - machine=self.name, - chromeos_root=self.chromeos_root) + _, if_out, _ = self.ce.CrosRunCommandWOutput( + command, machine=self.name, chromeos_root=self.chromeos_root) b = if_out.splitlines() a = [l for l in b if "HWaddr" in l] if len(a): @@ -227,9 +221,8 @@ class MachineManager(object): """Get the version of Chrome running on the DUT.""" cmd = "/opt/google/chrome/chrome --version" - ret, version, _ = self.ce.CrosRunCommand(cmd, return_output=True, - machine=machine.name, - chromeos_root=self.chromeos_root) + ret, version, _ = self.ce.CrosRunCommandWOutput( + cmd, machine=machine.name, chromeos_root=self.chromeos_root) if ret != 0: raise CrosCommandError("Couldn't get Chrome version from %s." % machine.name) @@ -340,8 +333,8 @@ class MachineManager(object): if locked: self._machines.append(cros_machine) command = "cat %s" % CHECKSUM_FILE - ret, out, _ = self.ce.CrosRunCommand( - command, return_output=True, chromeos_root=self.chromeos_root, + ret, out, _ = self.ce.CrosRunCommandWOutput( + command, chromeos_root=self.chromeos_root, machine=cros_machine.name) if ret == 0: cros_machine.checksum = out.strip() diff --git a/crosperf/machine_manager_unittest.py b/crosperf/machine_manager_unittest.py index bf04ee4c..7aed09d4 100755 --- a/crosperf/machine_manager_unittest.py +++ b/crosperf/machine_manager_unittest.py @@ -236,7 +236,7 @@ class MachineManagerTest(unittest.TestCase): 'daisy_checksum_str') - @mock.patch.object(command_executer.CommandExecuter, 'CrosRunCommand') + @mock.patch.object(command_executer.CommandExecuter, 'CrosRunCommandWOutput') def test_try_to_lock_machine(self, mock_cros_runcmd): self.assertRaises(self.mm._TryToLockMachine, None) @@ -252,10 +252,9 @@ class MachineManagerTest(unittest.TestCase): cmd_str = mock_cros_runcmd.call_args[0][0] self.assertEqual(cmd_str, 'cat /usr/local/osimage_checksum_file') args_dict = mock_cros_runcmd.call_args[1] - self.assertEqual(len(args_dict), 3) + self.assertEqual(len(args_dict), 2) self.assertEqual(args_dict['machine'], self.mock_lumpy1.name) self.assertEqual(args_dict['chromeos_root'], '/usr/local/chromeos') - self.assertTrue(args_dict['return_output']) @mock.patch.object(machine_manager, 'CrosMachine') @@ -730,7 +729,7 @@ class CrosMachineTest(unittest.TestCase): self.assertEqual(cm.phys_kbytes, 4194304) - @mock.patch.object(command_executer.CommandExecuter, 'CrosRunCommand') + @mock.patch.object(command_executer.CommandExecuter, 'CrosRunCommandWOutput') @mock.patch.object(machine_manager.CrosMachine, "SetUpChecksumInfo") def test_get_memory_info(self, mock_setup, mock_run_cmd): cm = machine_manager.CrosMachine("daisy.cros", "/usr/local/chromeos", @@ -744,7 +743,6 @@ class CrosMachineTest(unittest.TestCase): args_dict = call_args[1] self.assertEqual(args_dict['machine'], 'daisy.cros') self.assertEqual(args_dict['chromeos_root'], '/usr/local/chromeos') - self.assertEqual(args_dict['return_output'], True) self.assertEqual(cm.meminfo, MEMINFO_STRING) self.assertEqual(cm.phys_kbytes, 4194304) @@ -752,7 +750,7 @@ class CrosMachineTest(unittest.TestCase): self.assertRaises (cm._GetMemoryInfo) - @mock.patch.object(command_executer.CommandExecuter, 'CrosRunCommand') + @mock.patch.object(command_executer.CommandExecuter, 'CrosRunCommandWOutput') @mock.patch.object(machine_manager.CrosMachine, "SetUpChecksumInfo") def test_get_cpu_info(self, mock_setup, mock_run_cmd): cm = machine_manager.CrosMachine("daisy.cros", "/usr/local/chromeos", @@ -766,7 +764,6 @@ class CrosMachineTest(unittest.TestCase): args_dict = call_args[1] self.assertEqual(args_dict['machine'], 'daisy.cros') self.assertEqual(args_dict['chromeos_root'], '/usr/local/chromeos') - self.assertEqual(args_dict['return_output'], True) self.assertEqual(cm.cpuinfo, CPUINFO_STRING) diff --git a/crosperf/results_cache.py b/crosperf/results_cache.py index 9431e88a..cdf14315 100644 --- a/crosperf/results_cache.py +++ b/crosperf/results_cache.py @@ -137,10 +137,8 @@ class Result(object): command = ("python generate_test_report --no-color --csv %s" % (os.path.join("/tmp", os.path.basename(self._temp_dir)))) - [_, out, _] = self._ce.ChrootRunCommand(self._chromeos_root, - command, - return_output=True, - print_to_console=False) + _, out, _ = self._ce.ChrootRunCommandWOutput( + self._chromeos_root, command, print_to_console=False) keyvals_dict = {} tmp_dir_in_chroot = misc.GetInsideChrootPath(self._chromeos_root, self._temp_dir) @@ -175,8 +173,7 @@ class Result(object): command = "find %s %s" % (self.results_dir, find_args) - ret, out, _ = self._ce.RunCommand(command, return_output=True, - print_to_console=False) + ret, out, _ = self._ce.RunCommandWOutput(command, print_to_console=False) if ret: raise Exception("Could not run find command!") return out @@ -239,8 +236,7 @@ class Result(object): self._board, chroot_perf_data_file, chroot_perf_report_file)) - self._ce.ChrootRunCommand(self._chromeos_root, - command) + self._ce.ChrootRunCommand(self._chromeos_root, command) # Add a keyval to the dictionary for the events captured. perf_report_files.append( diff --git a/crosperf/results_cache_unittest.py b/crosperf/results_cache_unittest.py index e858a4e4..790b4718 100755 --- a/crosperf/results_cache_unittest.py +++ b/crosperf/results_cache_unittest.py @@ -713,13 +713,13 @@ class ResultTest(unittest.TestCase): f1 = os.path.join(test_dir, 'machine.txt') f2 = os.path.join(base_dir, 'machine.txt') cmd = 'diff %s %s' % (f1, f2) - [_, out, _] = self.result._ce.RunCommand(cmd, return_output=True) + [_, out, _] = self.result._ce.RunCommandWOutput(cmd) self.assertEqual(len(out), 0) f1 = os.path.join(test_dir, 'results.txt') f2 = os.path.join(base_dir, 'results.txt') cmd = 'diff %s %s' % (f1, f2) - [_, out, _] = self.result._ce.RunCommand(cmd, return_output=True) + [_, out, _] = self.result._ce.RunCommandWOutput(cmd) self.assertEqual(len(out), 0) # Clean up after test. diff --git a/crosperf/schedv2.py b/crosperf/schedv2.py index 46d5657b..b73d384f 100644 --- a/crosperf/schedv2.py +++ b/crosperf/schedv2.py @@ -152,9 +152,8 @@ class DutWorker(Thread): checksum_file = "/usr/local/osimage_checksum_file" try: rv, checksum, _ = command_executer.GetCommandExecuter().\ - CrosRunCommand( + CrosRunCommandWOutput( "cat " + checksum_file, - return_output=True, chromeos_root=self._sched._labels[0].chromeos_root, machine=self._dut.name, print_to_console=False) diff --git a/crosperf/suite_runner.py b/crosperf/suite_runner.py index afec6c85..4c94de20 100644 --- a/crosperf/suite_runner.py +++ b/crosperf/suite_runner.py @@ -85,9 +85,8 @@ class SuiteRunner(object): "else " " cat scaling_max_freq ; " "fi") - ret, freqs_str, _ = self._ce.CrosRunCommand( - get_avail_freqs, return_output=True, machine=machine_name, - chromeos_root=chromeos_root) + ret, freqs_str, _ = self._ce.CrosRunCommandWOutput( + get_avail_freqs, machine=machine_name, chromeos_root=chromeos_root) self._logger.LogFatalIf(ret, "Could not get available frequencies " "from machine: %s" % machine_name) freqs = freqs_str.split() @@ -163,11 +162,9 @@ class SuiteRunner(object): # Use --no-ns-pid so that cros_sdk does not create a different # process namespace and we can kill process created easily by # their process group. - return self._ce.ChrootRunCommand(label.chromeos_root, - command, - True, - self._ct, - cros_sdk_options="--no-ns-pid") + return self._ce.ChrootRunCommandWOutput( + label.chromeos_root, command, command_terminator=self._ct, + cros_sdk_options="--no-ns-pid") def RemoveTelemetryTempFile (self, machine, chromeos_root): filename = "telemetry@%s" % machine @@ -230,11 +227,9 @@ class SuiteRunner(object): if self.log_level != "verbose": self._logger.LogOutput("Running test.") self._logger.LogOutput("CMD: %s" % cmd) - return self._ce.ChrootRunCommand(label.chromeos_root, - cmd, - return_output=True, - command_terminator=self._ct, - cros_sdk_options=chrome_root_options) + return self._ce.ChrootRunCommandWOutput( + label.chromeos_root, cmd, command_terminator=self._ct, + cros_sdk_options=chrome_root_options) def Telemetry_Run(self, machine, label, benchmark, profiler_args): @@ -272,8 +267,7 @@ class SuiteRunner(object): if self.log_level != "verbose": self._logger.LogOutput("Running test.") self._logger.LogOutput("CMD: %s" % cmd) - return self._ce.RunCommand(cmd, return_output=True, - print_to_console=False) + return self._ce.RunCommandWOutput(cmd, print_to_console=False) def Terminate(self): self._ct.Terminate() diff --git a/crosperf/suite_runner_unittest.py b/crosperf/suite_runner_unittest.py index 41013f74..d534f3a8 100755 --- a/crosperf/suite_runner_unittest.py +++ b/crosperf/suite_runner_unittest.py @@ -150,10 +150,10 @@ class SuiteRunnerTest(unittest.TestCase): - @mock.patch.object (command_executer.CommandExecuter, 'CrosRunCommand') + @mock.patch.object (command_executer.CommandExecuter, 'CrosRunCommandWOutput') def test_get_highest_static_frequency(self, mock_cros_runcmd): - self.mock_cmd_exec.CrosRunCommand = mock_cros_runcmd + self.mock_cmd_exec.CrosRunCommandWOutput = mock_cros_runcmd mock_cros_runcmd.return_value = [ 0, '1666000 1333000 1000000', ''] freq = self.runner.GetHighestStaticFrequency ('lumpy1.cros', '/tmp/chromeos') self.assertEqual(freq, '1666000') @@ -199,7 +199,8 @@ class SuiteRunnerTest(unittest.TestCase): @mock.patch.object (command_executer.CommandExecuter, 'CrosRunCommand') - @mock.patch.object (command_executer.CommandExecuter, 'ChrootRunCommand') + @mock.patch.object (command_executer.CommandExecuter, + 'ChrootRunCommandWOutput') def test_test_that_run(self, mock_chroot_runcmd, mock_cros_runcmd): def FakeRebootMachine (machine, chroot): @@ -223,7 +224,7 @@ class SuiteRunnerTest(unittest.TestCase): self.assertTrue(raised_exception) mock_chroot_runcmd.return_value = 0 - self.mock_cmd_exec.ChrootRunCommand = mock_chroot_runcmd + self.mock_cmd_exec.ChrootRunCommandWOutput = mock_chroot_runcmd self.mock_cmd_exec.CrosRunCommand = mock_cros_runcmd res = self.runner.Test_That_Run ('lumpy1.cros', self.mock_label, self.test_that_bench, '--iterations=2', @@ -234,25 +235,25 @@ class SuiteRunnerTest(unittest.TestCase): self.assertEqual(mock_cros_runcmd.call_args_list[0][0], ('rm -rf /usr/local/autotest/results/*',)) args_list = mock_chroot_runcmd.call_args_list[0][0] - self.assertEqual(len(args_list), 4) + args_dict = mock_chroot_runcmd.call_args_list[0][1] + self.assertEqual(len(args_list), 2) self.assertEqual(args_list[0], '/tmp/chromeos') self.assertEqual(args_list[1], ('/usr/bin/test_that --autotest_dir ' '~/trunk/src/third_party/autotest/files ' '--fast --board=lumpy ' '--iterations=2 lumpy1.cros octane')) - self.assertTrue(args_list[2]) - self.assertEqual(args_list[3], self.mock_cmd_term) - + self.assertEqual(args_dict['command_terminator'], self.mock_cmd_term) self.real_logger._LogMsg = save_log_msg @mock.patch.object (os.path, 'isdir') - @mock.patch.object (command_executer.CommandExecuter, 'ChrootRunCommand') + @mock.patch.object (command_executer.CommandExecuter, + 'ChrootRunCommandWOutput') def test_telemetry_crosperf_run(self, mock_chroot_runcmd, mock_isdir): mock_isdir.return_value = True mock_chroot_runcmd.return_value = 0 - self.mock_cmd_exec.ChrootRunCommand = mock_chroot_runcmd + self.mock_cmd_exec.ChrootRunCommandWOutput = mock_chroot_runcmd profiler_args = ('--profiler=custom_perf --profiler_args=\'perf_options' '="record -a -e cycles,instructions"\'') res = self.runner.Telemetry_Crosperf_Run ('lumpy1.cros', self.mock_label, @@ -274,13 +275,12 @@ class SuiteRunnerTest(unittest.TestCase): '--chrome_root_mount=/tmp/chrome_root ' 'FEATURES="-usersandbox" CHROME_ROOT=/tmp/chrome_root')) self.assertEqual(args_dict['command_terminator'], self.mock_cmd_term) - self.assertTrue(args_dict['return_output']) - self.assertEqual(len(args_dict), 3) + self.assertEqual(len(args_dict), 2) @mock.patch.object (os.path, 'isdir') @mock.patch.object (os.path, 'exists') - @mock.patch.object (command_executer.CommandExecuter, 'RunCommand') + @mock.patch.object (command_executer.CommandExecuter, 'RunCommandWOutput') def test_telemetry_run(self, mock_runcmd, mock_exists, mock_isdir): def FakeLogMsg (fd, termfd, msg, flush): @@ -290,7 +290,7 @@ class SuiteRunnerTest(unittest.TestCase): self.real_logger._LogMsg = FakeLogMsg mock_runcmd.return_value = 0 - self.mock_cmd_exec.RunCommand = mock_runcmd + self.mock_cmd_exec.RunCommandWOutput = mock_runcmd self.runner._logger = self.real_logger profiler_args = ('--profiler=custom_perf --profiler_args=\'perf_options' diff --git a/dejagnu/gdb_dejagnu.py b/dejagnu/gdb_dejagnu.py index 36afc85a..1b8340b8 100755 --- a/dejagnu/gdb_dejagnu.py +++ b/dejagnu/gdb_dejagnu.py @@ -161,9 +161,9 @@ class DejagnuExecuter(object): self.PrepareGdbDefault() def PrepareGdbDefault(self): - ret = self._executer.ChrootRunCommand( + ret = self._executer.ChrootRunCommandWOutput( self._chromeos_root, - 'equery w cross-%s/gdb' % self._target, return_output=True)[1] + 'equery w cross-%s/gdb' % self._target)[1] ret = path.basename(ret.strip()) matcher = re.match(r'(.*).ebuild', ret) diff --git a/dejagnu/run_dejagnu.py b/dejagnu/run_dejagnu.py index 14bf058d..5506d0c0 100755 --- a/dejagnu/run_dejagnu.py +++ b/dejagnu/run_dejagnu.py @@ -270,9 +270,9 @@ class DejagnuExecuter(object): def PrepareGccDefault(self): """Auto emerging gcc for building purpose only.""" - ret = self._executer.ChrootRunCommand( + ret = self._executer.ChrootRunCommandWOutput( self._chromeos_root, - 'equery w cross-%s/gcc' % self._target, return_output=True)[1] + 'equery w cross-%s/gcc' % self._target)[1] ret = path.basename(ret.strip()) # ret is expected to be something like 'gcc-4.6.2-r11.ebuild' or # 'gcc-9999.ebuild' parse it. @@ -316,8 +316,8 @@ class DejagnuExecuter(object): cmd = 'cd {0} ; {1} --build_dir={0}'.format( self._gcc_top_build_dir, validate_failures_py) self.MountGccSourceAndBuildDir() - ret = self._executer.ChrootRunCommand( - self._chromeos_root, cmd, return_output=True) + ret = self._executer.ChrootRunCommandWOutput( + self._chromeos_root, cmd) if ret[0] != 0: self._l.LogWarning('*** validate_failures.py exited with non-zero code,' 'please run it manually inside chroot - \n' diff --git a/fdo_scripts/vanilla_vs_fdo.py b/fdo_scripts/vanilla_vs_fdo.py index cf80f4a1..f9dc8fd4 100644 --- a/fdo_scripts/vanilla_vs_fdo.py +++ b/fdo_scripts/vanilla_vs_fdo.py @@ -129,8 +129,7 @@ class FDOComparator(object): "build_chrome_browser.py") command = "python %s %s" % (build_chrome_browser, " ".join(build_chrome_browser_args)) - ret, out, err = self._ce.RunCommand(command, - return_output=True) + ret, out, err = self._ce.RunCommandWOutput(command) if "-fprofile-use" in cxxflags: self._ReportMismatches(out) diff --git a/heat_map.py b/heat_map.py index 3a6c7721..3bb7e363 100755 --- a/heat_map.py +++ b/heat_map.py @@ -46,7 +46,7 @@ class HeatMapProducer(object): def getBinaryBaseAddress(self): cmd = 'grep PERF_RECORD_MMAP %s | grep "%s$"' % (self.perf_report, self.binary) - retval, output, _ = self.ce.RunCommand(cmd, return_output=True) + retval, output, _ = self.ce.RunCommandWOutput(cmd) if retval: raise RuntimeError('Failed to run grep to get base address') baseAddresses = Set(); @@ -128,4 +128,3 @@ def main(argv): if __name__ == '__main__': sys.exit(main(sys.argv[1:])) - diff --git a/image_chromeos.py b/image_chromeos.py index 1d977e03..4b764b06 100755 --- a/image_chromeos.py +++ b/image_chromeos.py @@ -141,11 +141,8 @@ def DoImage(argv): image_checksum = FileUtils().Md5File(image, log_level=log_level) command = "cat " + checksum_file - retval, device_checksum, _ = cmd_executer.CrosRunCommand( - command, - return_output=True, - chromeos_root=options.chromeos_root, - machine=options.remote) + retval, device_checksum, _ = cmd_executer.CrosRunCommandWOutput( + command, chromeos_root=options.chromeos_root, machine=options.remote) device_checksum = device_checksum.strip() image_checksum = str(image_checksum) @@ -368,10 +365,8 @@ def VerifyChromeChecksum(chromeos_root, image, remote, log_level): unmount=True) command = "md5sum /opt/google/chrome/chrome" - [_, o, _] = cmd_executer.CrosRunCommand(command, - return_output=True, - chromeos_root=chromeos_root, - machine=remote) + [_, o, _] = cmd_executer.CrosRunCommandWOutput( + command, chromeos_root=chromeos_root, machine=remote) device_chrome_checksum = o.split()[0] if image_chrome_checksum.strip() == device_chrome_checksum.strip(): return True diff --git a/remote_gcc_build.py b/remote_gcc_build.py index 8ed324aa..1862e40f 100755 --- a/remote_gcc_build.py +++ b/remote_gcc_build.py @@ -51,8 +51,7 @@ def FindVersionForToolchain(branch, chromeos_root): major_version = digits.split(".")[0] ce = command_executer.GetCommandExecuter() command = "repo sync . && git branch -a | grep {0}".format(major_version) - _, branches, _ = ce.RunCommand(command, return_output=True, - print_to_console=False) + _, branches, _ = ce.RunCommandWOutput(command, print_to_console=False) m = re.search(r"(R\d+)", branches) if not m: logger.GetLogger().LogFatal("Cannot find version for branch {0}" @@ -89,8 +88,7 @@ def FindBuildIdFromLog(description): "http://chromegw/p/tryserver.chromiumos/" .format(file_dir)) ce = command_executer.GetCommandExecuter() - _, buildinfo, _ = ce.RunCommand(commands, return_output=True, - print_to_console=False) + _, buildinfo, _ = ce.RunCommandWOutput(commands, print_to_console=False) my_info = buildinfo.splitlines() current_line = 1 @@ -143,7 +141,7 @@ def DownloadImage(target, index, dest, version): download_cmd = ("$(which gsutil) cp {0} {1}".format("{0}", dest)) ce = command_executer.GetCommandExecuter() - _, out, _ = ce.RunCommand(ls_cmd, return_output=True, print_to_console=True) + _, out, _ = ce.RunCommandWOutput(ls_cmd, print_to_console=True) lines = out.splitlines() download_files = ["autotest.tar", "chromeos-chrome", "chromiumos_test_image", "debug.tgz", @@ -175,7 +173,7 @@ def RemoveOldBranch(): """Remove the branch with name BRANCH.""" ce = command_executer.GetCommandExecuter() command = "git rev-parse --abbrev-ref HEAD" - _, out, _ = ce.RunCommand(command, return_output=True) + _, out, _ = ce.RunCommandWOutput(command) if BRANCH in out: command = "git checkout -B {0}".format(TMP_BRANCH) ce.RunCommand(command) @@ -228,7 +226,7 @@ def UploadPatch(source): ce.RunCommand(commands) commands = ("yes | repo upload . --cbr --no-verify") - _, _, err = ce.RunCommand(commands, return_output=True) + _, _, err = ce.RunCommandWOutput(commands) return GetPatchNum(err) @@ -264,13 +262,13 @@ def GetGccBranch(branch): """Get the remote branch name from branch or version.""" ce = command_executer.GetCommandExecuter() command = "git branch -a | grep {0}".format(branch) - _, out, _ = ce.RunCommand(command, return_output=True) + _, out, _ = ce.RunCommandWOutput(command) if not out: release_num = re.match(r".*(R\d+)-*", branch) if release_num: release_num = release_num.group(0) command = "git branch -a | grep {0}".format(release_num) - _, out, _ = ce.RunCommand(command, return_output=True) + _, out, _ = ce.RunCommandWOutput(command) if not out: GccBranchForToolchain(branch) if not out: diff --git a/repo_to_repo.py b/repo_to_repo.py index 08d61e9a..487bbbbd 100755 --- a/repo_to_repo.py +++ b/repo_to_repo.py @@ -134,7 +134,7 @@ class P4Repo(Repo): ret = self._ce.RunCommand(command) assert ret == 0, 'Could not setup client.' command = p4client.InCheckoutDir(p4client.SaveCurrentCLNumber()) - ret, o, _ = self._ce.RunCommand(command, return_output=True) + ret, o, _ = self._ce.RunCommandWOutput(command) assert ret == 0, 'Could not get version from client.' self.revision = re.search('^\d+$', o.strip(), re.MULTILINE).group(0) command = p4client.InCheckoutDir(p4client.Remove()) @@ -162,7 +162,7 @@ class SvnRepo(Repo): for mapping in self.mappings: remote_path, local_path = SplitMapping(mapping) command = 'cd %s && svnversion -c .' % (local_path) - ret, o, _ = self._ce.RunCommand(command, return_output=True) + ret, o, _ = self._ce.RunCommandWOutput(command) self.revision += o.strip().split(":")[-1] if ret: return ret return 0 @@ -194,7 +194,7 @@ class GitRepo(Repo): if ret: return ret command = 'git describe --always' - ret, o, _ = self._ce.RunCommand(command, return_output=True) + ret, o, _ = self._ce.RunCommandWOutput(command) self.revision = o.strip() return ret diff --git a/tc_enter_chroot.py b/tc_enter_chroot.py index 85b8a509..c68c48a2 100755 --- a/tc_enter_chroot.py +++ b/tc_enter_chroot.py @@ -48,7 +48,7 @@ class MountPoint: ce = command_executer.GetCommandExecuter() mount_signature = "%s on %s" % (self.external_dir, self.mount_dir) command = "mount" - retval, out, err = ce.RunCommand(command, return_output=True) + retval, out, err = ce.RunCommandWOutput(command) if mount_signature not in out: retval = self.CreateAndOwnDir(self.mount_dir) logger.GetLogger().LogFatalIf(retval, "Cannot create mount_dir!") @@ -239,12 +239,13 @@ def Main(argv, return_output=False): command += " sudo ./" + command_file else: command += " ./" + command_file - retval = command_executer.GetCommandExecuter().RunCommand(command, return_output) + retval = command_executer.GetCommandExecuter().RunCommandGeneric( + command, return_output) return retval else: os.chdir("%s/src/scripts" % chromeos_root) ce = command_executer.GetCommandExecuter() - [ret, out, err] = ce.RunCommand("which cros_sdk", return_output=True) + _, out, _ = ce.RunCommandWOutput("which cros_sdk") cros_sdk_binary = out.split()[0] return os.execv(cros_sdk_binary, ["", "--enter"]) diff --git a/utils/buildbot_utils.py b/utils/buildbot_utils.py index 135347a3..cff30073 100644 --- a/utils/buildbot_utils.py +++ b/utils/buildbot_utils.py @@ -123,8 +123,7 @@ def GetBuildInfo(file_dir, builder): commands += " -b release" else: commands += " -b %s" % builder - _, buildinfo, _ = ce.RunCommand(commands, return_output=True, - print_to_console=False) + _, buildinfo, _ = ce.RunCommandWOutput(commands, print_to_console=False) build_log = buildinfo.splitlines() return build_log @@ -138,9 +137,8 @@ def FindArchiveImage(chromeos_root, build, build_id): ce = command_executer.GetCommandExecuter() command = ("gsutil ls gs://chromeos-image-archive/trybot-%s/*b%s" "/chromiumos_test_image.tar.xz" % (build, build_id)) - retval, out, err = ce.ChrootRunCommand(chromeos_root, command, - return_output=True, - print_to_console=False) + retval, out, err = ce.ChrootRunCommandWOutput(chromeos_root, command, + print_to_console=False) # # If build_id is not unique, there may be multiple archive images # to choose from; sort them & pick the first (newest). @@ -214,7 +212,7 @@ def GetTrybotImage(chromeos_root, buildbot_name, patch_list, build_tag, command = ("./cbuildbot --remote --nochromesdk --notests" " --remote-description=%s %s %s %s" % (description, toolchain_flags, patch_arg, build)) - _, out, _ = ce.RunCommand(command, return_output=True) + _, out, _ = ce.RunCommandWOutput(command) if "Tryjob submitted!" not in out: logger.GetLogger().LogFatal("Error occurred while launching trybot job: " "%s" % command) diff --git a/utils/command_executer.py b/utils/command_executer.py index 5e86d6f1..e13fb3b0 100644 --- a/utils/command_executer.py +++ b/utils/command_executer.py @@ -54,12 +54,15 @@ class CommandExecuter(object): def SetLogLevel(self, log_level): self.log_level = log_level - def RunCommand(self, cmd, return_output=False, machine=None, - username=None, command_terminator=None, - command_timeout=None, - terminated_timeout=10, - print_to_console=True): - """Run a command.""" + def RunCommandGeneric(self, cmd, return_output=False, machine=None, + username=None, command_terminator=None, + command_timeout=None, + terminated_timeout=10, + print_to_console=True): + """Run a command. + + Returns triplet (returncode, stdout, stderr). + """ cmd = str(cmd) @@ -73,10 +76,7 @@ class CommandExecuter(object): if command_terminator and command_terminator.IsTerminated(): if self.logger: self.logger.LogError("Command was terminated!", print_to_console) - if return_output: - return [1, "", ""] - else: - return 1 + return (1, "", "") if machine is not None: user = "" @@ -162,7 +162,31 @@ class CommandExecuter(object): p.wait() if return_output: return (p.returncode, full_stdout, full_stderr) - return p.returncode + return (p.returncode, "", "") + + def RunCommand(self, *args, **kwargs): + """Run a command. + + Takes the same arguments as RunCommandGeneric except for return_output. + Returns a single value returncode. + """ + # Make sure that args does not overwrite 'return_output' + assert len(args) <= 1 + assert 'return_output' not in kwargs + kwargs['return_output'] = False + return self.RunCommandGeneric(*args, **kwargs)[0] + + def RunCommandWOutput(self, *args, **kwargs): + """Run a command. + + Takes the same arguments as RunCommandGeneric except for return_output. + Returns a triplet (returncode, stdout, stderr). + """ + # Make sure that args does not overwrite 'return_output' + assert len(args) <= 1 + assert 'return_output' not in kwargs + kwargs['return_output'] = True + return self.RunCommandGeneric(*args, **kwargs) def RemoteAccessInitCommand(self, chromeos_root, machine): command = "" @@ -187,18 +211,21 @@ class CommandExecuter(object): command = self.RemoteAccessInitCommand(chromeos_root, machine) command += "\nlearn_board" command += "\necho ${FLAGS_board}" - retval, output, _ = self.RunCommand(command, True) + retval, output, _ = self.RunCommandWOutput(command) if self.logger: self.logger.LogFatalIf(retval, "learn_board command failed") elif retval: sys.exit(1) return output.split()[-1] - def CrosRunCommand(self, cmd, return_output=False, machine=None, - command_terminator=None, - chromeos_root=None, command_timeout=None, - terminated_timeout=10, print_to_console=True): - """Run a command on a chromeos box""" + def CrosRunCommandGeneric(self, cmd, return_output=False, machine=None, + command_terminator=None, + chromeos_root=None, command_timeout=None, + terminated_timeout=10, print_to_console=True): + """Run a command on a ChromeOS box. + + Returns triplet (returncode, stdout, stderr). + """ if self.log_level != "verbose": print_to_console = False @@ -225,16 +252,16 @@ class CommandExecuter(object): if self.logger: self.logger.LogError("Could not run remote command on machine." " Is the machine up?") - return retval + return (retval, "", "") command = self.RemoteAccessInitCommand(chromeos_root, machine) command += "\nremote_sh bash %s" % command_file command += "\nl_retval=$?; echo \"$REMOTE_OUT\"; exit $l_retval" - retval = self.RunCommand(command, return_output, - command_terminator=command_terminator, - command_timeout=command_timeout, - terminated_timeout=terminated_timeout, - print_to_console=print_to_console) + retval = self.RunCommandGeneric(command, return_output, + command_terminator=command_terminator, + command_timeout=command_timeout, + terminated_timeout=terminated_timeout, + print_to_console=print_to_console) if return_output: connect_signature = ("Initiating first contact with remote host\n" + "Connection OK\n") @@ -244,11 +271,39 @@ class CommandExecuter(object): return modded_retval return retval - def ChrootRunCommand(self, chromeos_root, command, return_output=False, - command_terminator=None, command_timeout=None, - terminated_timeout=10, - print_to_console=True, - cros_sdk_options=""): + def CrosRunCommand(self, *args, **kwargs): + """Run a command on a ChromeOS box. + + Takes the same arguments as CrosRunCommandGeneric except for return_output. + Returns a single value returncode. + """ + # Make sure that args does not overwrite 'return_output' + assert len(args) <= 1 + assert 'return_output' not in kwargs + kwargs['return_output'] = False + return self.CrosRunCommandGeneric(*args, **kwargs)[0] + + def CrosRunCommandWOutput(self, *args, **kwargs): + """Run a command on a ChromeOS box. + + Takes the same arguments as CrosRunCommandGeneric except for return_output. + Returns a triplet (returncode, stdout, stderr). + """ + # Make sure that args does not overwrite 'return_output' + assert len(args) <= 1 + assert 'return_output' not in kwargs + kwargs['return_output'] = True + return self.CrosRunCommandGeneric(*args, **kwargs) + + def ChrootRunCommandGeneric(self, chromeos_root, command, return_output=False, + command_terminator=None, command_timeout=None, + terminated_timeout=10, print_to_console=True, + cros_sdk_options=""): + """Runs a command within the chroot. + + Returns triplet (returncode, stdout, stderr). + """ + if self.log_level != "verbose": print_to_console = False @@ -283,20 +338,44 @@ class CommandExecuter(object): cros_sdk_options, misc.CHROMEOS_SCRIPTS_DIR, os.path.basename(command_file))) - ret = self.RunCommand(command, return_output, - command_terminator=command_terminator, - command_timeout=command_timeout, - terminated_timeout=terminated_timeout, - print_to_console=print_to_console) + ret = self.RunCommandGeneric(command, return_output, + command_terminator=command_terminator, + command_timeout=command_timeout, + terminated_timeout=terminated_timeout, + print_to_console=print_to_console) os.remove(command_file) return ret + def ChrootRunCommand(self, *args, **kwargs): + """Runs a command within the chroot. - def RunCommands(self, cmdlist, return_output=False, machine=None, + Takes the same arguments as ChrootRunCommandGeneric except for + return_output. + Returns a single value returncode. + """ + # Make sure that args does not overwrite 'return_output' + assert len(args) <= 2 + assert 'return_output' not in kwargs + kwargs['return_output'] = False + return self.ChrootRunCommandGeneric(*args, **kwargs)[0] + + def ChrootRunCommandWOutput(self, *args, **kwargs): + """Runs a command within the chroot. + + Takes the same arguments as ChrootRunCommandGeneric except for + return_output. + Returns a triplet (returncode, stdout, stderr). + """ + # Make sure that args does not overwrite 'return_output' + assert len(args) <= 2 + assert 'return_output' not in kwargs + kwargs['return_output'] = True + return self.ChrootRunCommandGeneric(*args, **kwargs) + + def RunCommands(self, cmdlist, machine=None, username=None, command_terminator=None): cmd = " ;\n" .join(cmdlist) - return self.RunCommand(cmd, return_output, machine, username, - command_terminator) + return self.RunCommand(cmd, machine, username, command_terminator) def CopyFiles(self, src, dest, src_machine=None, dest_machine=None, src_user=None, dest_user=None, recursive=True, @@ -484,10 +563,10 @@ class MockCommandExecuter(CommandExecuter): def __init__(self, log_level, logger_to_set=None): super(MockCommandExecuter, self).__init__(log_level, logger_to_set) - def RunCommand(self, cmd, return_output=False, machine=None, - username=None, command_terminator=None, - command_timeout=None, terminated_timeout=10, - print_to_console=True): + def RunCommandGeneric(self, cmd, return_output=False, machine=None, + username=None, command_terminator=None, + command_timeout=None, terminated_timeout=10, + print_to_console=True): assert not command_timeout cmd = str(cmd) if machine is None: @@ -496,8 +575,17 @@ class MockCommandExecuter(CommandExecuter): username = "current" logger.GetLogger().LogCmd("(Mock) " + cmd, machine, username, print_to_console) - return 0 + return (0, "", "") + + def RunCommand(self, *args, **kwargs): + assert 'return_output' not in kwargs + kwargs['return_output'] = False + return self.RunCommandGeneric(*args, **kwargs)[0] + def RunCommandWOutput(self, *args, **kwargs): + assert 'return_output' not in kwargs + kwargs['return_output'] = True + return self.RunCommandGeneric(*args, **kwargs) class CommandTerminator(object): """Object to request termination of a command in execution.""" diff --git a/utils/file_utils.py b/utils/file_utils.py index 74573344..bb431f19 100644 --- a/utils/file_utils.py +++ b/utils/file_utils.py @@ -31,7 +31,7 @@ class FileUtils(object): def Md5File(self, filename, log_level="verbose", block_size=2 ** 10): command = "md5sum %s" % filename ce = command_executer.GetCommandExecuter(log_level=log_level) - ret, out, err = ce.RunCommand(command, return_output=True) + ret, out, err = ce.RunCommandWOutput(command) if ret: raise Exception("Could not run md5sum on: %s" % filename) diff --git a/utils/misc.py b/utils/misc.py index 05cfffa8..b4f7d4b4 100644 --- a/utils/misc.py +++ b/utils/misc.py @@ -29,8 +29,7 @@ def GetChromeOSVersionFromLSBVersion(lsb_version): ce = command_executer.GetCommandExecuter() command = ("git ls-remote " "https://chromium.googlesource.com/chromiumos/manifest.git") - ret, out, _ = ce.RunCommand(command, return_output=True, - print_to_console=False) + ret, out, _ = ce.RunCommandWOutput(command, print_to_console=False) assert ret == 0, "Command %s failed" % command lower = [] for line in out.splitlines(): @@ -219,9 +218,7 @@ def GetCtargetFromBoard(board, chromeos_root): command = ("source %s; get_ctarget_from_board %s" % (TOOLCHAIN_UTILS_PATH, base_board)) ce = command_executer.GetCommandExecuter() - ret, out, _ = ce.ChrootRunCommand(chromeos_root, - command, - return_output=True) + ret, out, _ = ce.ChrootRunCommandWOutput(chromeos_root, command) if ret != 0: raise ValueError("Board %s is invalid!" % board) # Remove ANSI escape sequences. @@ -235,9 +232,7 @@ def GetArchFromBoard(board, chromeos_root): command = ("source %s; get_board_arch %s" % (TOOLCHAIN_UTILS_PATH, base_board)) ce = command_executer.GetCommandExecuter() - ret, out, _ = ce.ChrootRunCommand(chromeos_root, - command, - return_output=True) + ret, out, _ = ce.ChrootRunCommandWOutput(chromeos_root, command) if ret != 0: raise ValueError("Board %s is invalid!" % board) # Remove ANSI escape sequences. @@ -285,7 +280,7 @@ def MergeEnvStringWithDict(env_string, env_dict, prepend=True): else: new_env = "%s=\"$%s %s\"" % (k, k, v) command = "; ".join([env_string, new_env, "echo $%s" % k]) - ret, out, _ = ce.RunCommand(command, return_output=True) + ret, out, _ = ce.RunCommandWOutput(command) override_env_list.append("%s=%r" % (k, out.strip())) ret = env_string + " " + " ".join(override_env_list) return ret.strip() @@ -295,7 +290,7 @@ def GetAllImages(chromeos_root, board): ce = command_executer.GetCommandExecuter() command = ("find %s/src/build/images/%s -name chromiumos_test_image.bin" % (chromeos_root, board)) - ret, out, _ = ce.RunCommand(command, return_output=True) + ret, out, _ = ce.RunCommandWOutput(command) assert ret == 0, "Could not run command: %s" % command return out.splitlines() @@ -380,8 +375,8 @@ def GitGetCommitHash(git_dir, commit_symbolic_name): command = ('cd {0} && git log -n 1 --pretty="format:%H" {1}').format( git_dir, commit_symbolic_name) - rv, out, _ = command_executer.GetCommandExecuter().RunCommand( - command, return_output=True, print_to_console=False) + rv, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput( + command, print_to_console=False) if rv == 0: return out.strip() return None @@ -422,8 +417,8 @@ def GetGitChangesAsList(git_dir, path=None, staged=False): command += " --cached" if path: command += " -- " + path - _, out, _ = command_executer.GetCommandExecuter().RunCommand( - command, return_output=True, print_to_console=False) + _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput( + command, print_to_console=False) rv = [] for line in out.splitlines(): rv.append(line) @@ -457,7 +452,7 @@ def DeleteChromeOsTree(chromeos_root, dry_run=False): print cmd0 else: if command_executer.GetCommandExecuter().RunCommand( - cmd0, return_output=False, print_to_console=True) != 0: + cmd0, print_to_console=True) != 0: return False cmd1 = ('export CHROMEOSDIRNAME="$(dirname $(cd {0} && pwd))" && ' @@ -469,7 +464,7 @@ def DeleteChromeOsTree(chromeos_root, dry_run=False): return True return command_executer.GetCommandExecuter().RunCommand( - cmd1, return_output=False, print_to_console=True) == 0 + cmd1, print_to_console=True) == 0 def ApplyGerritPatches(chromeos_root, |