def TestDeploy(self):
        """Tests the deploy command."""
        packages = ['dev-python/cherrypy', 'app-portage/portage-utils']
        # Set the installation root to /usr/local so that the command does not
        # attempt to remount rootfs (which leads to VM reboot).
        cmd = self.BuildCommand(
            'deploy',
            device=self.device_addr,
            pos_args=packages,
            opt_args=['--log-level=info', '--root=/usr/local'])

        logging.info('Test to uninstall packages on the VM device.')
        with outcap.OutputCapturer() as output:
            result = cros_build_lib.run(cmd + ['--unmerge'],
                                        error_code_ok=True)

        if result.returncode:
            logging.error('Failed to uninstall packages on the VM device.')
            raise CommandError(result.error)

        captured_output = output.GetStdout() + output.GetStderr()
        for event in deploy.BrilloDeployOperation.UNMERGE_EVENTS:
            if event not in captured_output:
                logging.error(
                    'Strings used by deploy.BrilloDeployOperation to update '
                    'the progress bar have been changed. Please update the '
                    'strings in UNMERGE_EVENTS')
                raise CommandError()

        logging.info('Test to install packages on the VM device.')
        with outcap.OutputCapturer() as output:
            result = cros_build_lib.run(cmd, error_code_ok=True)

        if result.returncode:
            logging.error('Failed to install packages on the VM device.')
            raise CommandError(result.error)

        captured_output = output.GetStdout() + output.GetStderr()
        for event in deploy.BrilloDeployOperation.MERGE_EVENTS:
            if event not in captured_output:
                logging.error(
                    'Strings used by deploy.BrilloDeployOperation to update '
                    'the progress bar have been changed. Please update the '
                    'strings in MERGE_EVENTS')
                raise CommandError()

        # Verify that the packages are installed.
        with remote_access.ChromiumOSDeviceHandler(remote_access.LOCALHOST,
                                                   port=self.port) as device:
            try:
                device.RunCommand(['python', '-c', '"import cherrypy"'])
                device.RunCommand(['qmerge', '-h'])
            except cros_build_lib.RunCommandError as e:
                logging.error('Unable to verify packages installed on VM: %s',
                              e)
                raise CommandError()
    def testListTryjobs(self):
        """Test we can generate results for --list."""
        with outcap.OutputCapturer() as output:
            cros_tryjob.PrintKnownConfigs(self.site_config,
                                          production=False,
                                          build_config_fragments=[])

        # We have at least 100 lines of output, and no error out.
        self.assertGreater(len(output.GetStdoutLines()), 100)
        self.assertEqual('', output.GetStderr())
    def testList(self):
        """Test option verification with config list behavior."""
        self.SetupCommandMock([
            '--list',
        ])

        with self.assertRaises(cros_build_lib.DieSystemExit) as cm:
            with outcap.OutputCapturer(quiet_fail=True):  # Hide list output.
                cros_tryjob.VerifyOptions(self.cmd_mock.inst.options,
                                          self.site_config)
        self.assertEqual(cm.exception.code, 0)
    def testListTryjobsEmpty(self):
        """Test we can generate ~empty results for failed --list search."""
        with outcap.OutputCapturer() as output:
            cros_tryjob.PrintKnownConfigs(
                self.site_config,
                production=False,
                build_config_fragments=['this-is-not-a-builder-name'])

        # We have fewer than 6 lines of output, and no error out.
        self.assertLess(len(output.GetStdoutLines()), 6)
        self.assertEqual('', output.GetStderr())
  def testOutsideChrootAutotest(self, check_inside_chroot_mock):
    """Tests running an autotest from outside the chroot."""
    # Checks that mock version has been called.
    check_inside_chroot_mock.assert_called()

    self._tester.autotest = ['accessibility_Sanity']
    # Capture the run command. This is necessary beacuse the mock doesn't
    # capture the cros_sdk wrapper.
    with outcap.OutputCapturer() as output:
      self._tester._RunAutotest()
    # Check that we enter the chroot before running test_that.
    self.assertIn(
        'cros_sdk -- test_that --board amd64-generic --no-quickmerge'
        " --ssh_options '-F /dev/null -i /dev/null' localhost:9222"
        ' accessibility_Sanity', output.GetStderr())
Exemple #6
0
 def testListInstallArgs(self):
     """Check ListInstallArgs behavior."""
     parser = cros_install_debug_syms.GetParser()
     opts = parser.parse_args(['--board', 'betty', 'sys-fs/fuse'])
     self.PatchObject(cros_install_debug_syms,
                      'GetInstallArgs',
                      return_value=[
                          ('a/b-1', 'gs://bucket/b-1.tbz2'),
                          ('c/d-1', 'gs://bucket/d-1.tbz2'),
                      ])
     with outcap.OutputCapturer() as cap:
         cros_install_debug_syms.ListInstallArgs(opts, '/foo')
     self.assertEqual(
         'a/b-1 gs://bucket/b-1.tbz2\nc/d-1 gs://bucket/d-1.tbz2\n',
         cap.GetStdout())
  def CheckParserError(self, args, error_msg):
    """Checks that parser error is raised.

    Args:
      args: List of commandline arguments.
      error_msg: Error message to check for.
    """
    # Recreate args as a list if it is given as a string.
    if isinstance(args, str):
      args = [args]
    # Putting outcap.OutputCapturer() before assertRaises(SystemExit)
    # swallows SystemExit exception check.
    with self.assertRaises(SystemExit):
      with outcap.OutputCapturer() as output:
        cros_test.ParseCommandLine(args)
    self.assertIn(error_msg, output.GetStderr())
    def CaptureOutputInBackground(self, func, *args, **kwargs):
        """Launch func in background and capture its output.

    Args:
      func: Function to execute in the background and whose output is to be
        captured.
      log_level: Logging level to run the func at. By default, it runs at log
        level info.
    """
        log_level = kwargs.pop('log_level', logging.INFO)
        restore_log_level = logging.getLogger().getEffectiveLevel()
        logging.getLogger().setLevel(log_level)
        try:
            with outcap.OutputCapturer(stdout_path=self._stdout_path,
                                       stderr_path=self._stderr_path,
                                       quiet_fail=False):
                func(*args, **kwargs)
        finally:
            self._queue.put(_BackgroundTaskComplete())
            logging.getLogger().setLevel(restore_log_level)
Exemple #9
0
 def __init__(self, vartree, gs_context, sysroot, stdout_to_null):
     self._vartree = vartree
     self._gs_context = gs_context
     self._sysroot = sysroot
     self._stdout_to_null = stdout_to_null
     self._capturer = outcap.OutputCapturer()