Example #1
0
    def repack_shellball(self, hostname):
        """Repack DUT shellball and replace on DUT.

        @param hostname: hostname of DUT.
        """
        extract_dir = tempfile.mkdtemp(prefix='extract', dir='/tmp')

        self.dut_run_cmd('mkdir %s' % extract_dir)
        self.dut_run_cmd('cp %s %s' % (self.SHELLBALL_ORG, self.SHELLBALL_COPY))
        self.dut_run_cmd('%s --sb_extract %s' % (self.SHELLBALL_COPY,
                                                 extract_dir))

        dut_access = remote_access.RemoteDevice(hostname, username='******')
        self.dut_run_cmd('cp %s %s' % (self.SHELLBALL_ORG, self.SHELLBALL_COPY))

        # Replace bin files.
        target_file = '%s/%s' % (extract_dir, 'ec.bin')
        dut_access.CopyToDevice(self.new_ec, target_file, mode='scp')
        target_file = '%s/%s' % (extract_dir, 'bios.bin')
        dut_access.CopyToDevice(self.new_bios, target_file,  mode='scp')

        if self.new_pd:
          target_file = '%s/%s' % (extract_dir, 'pd.bin')
          dut_access.CopyToDevice(self.new_pd, target_file,  mode='scp')

        self.dut_run_cmd('%s --sb_repack %s' % (self.SHELLBALL_COPY,
                                                extract_dir))

        # Call to "shar" in chromeos-firmwareupdate might fail and the repack
        # ignore failure and exit with 0 status (http://crosbug.com/p/33719).
        # Add additional check to ensure the repack is successful.
        command = 'tail -1 %s' % self.SHELLBALL_COPY
        output = self.dut_run_cmd(command)
        if 'exit 0' not in output:
          raise error.TestError('Failed to repack %s' % self.SHELLBALL_COPY)
Example #2
0
def CopyPayload(request_data):
    """Copy a payload file to a target DUT.

  This constructs a `RemoteDevice`, and calls its `CopyToDevice()`
  method to copy a payload file to the target device.  A payload
  file is either the `stateful.tgz` tarball, or a Chrome OS AU
  payload (typically a full payload).

  The `request_data` argument has the following fields:
    * hostname:  Name of the target DUT where the payload will
      be copied.
    * localpath:  Path on this system to the payload file.
    * remotepath:  Path on the DUT where the payload will be copied.
    * kwargs:  Keyword arguments dictionanry to be passed
      to `RemoteDevice.CopyToDevice()`.
    * kwargs['log_stdout_to_file']:  If present, a file to which logger
      output will be written.  The output will typically include the
      command used for the copy, and standard input/output of that copy
      command.
  """
    log_handler = None
    log_file = request_data.kwargs.get('log_stdout_to_file')
    if log_file:
        log_handler = logging.FileHandler(log_file)
        log_handler.setFormatter(LOG_FORMATTER)
        logging.getLogger().addHandler(log_handler)
    try:
        device = remote_access.RemoteDevice(request_data.hostname)
        device.CopyToDevice(request_data.localpath,
                            request_data.remotepath,
                            mode='scp',
                            **request_data.kwargs)
    finally:
        if log_handler:
            logging.getLogger().removeHandler(log_handler)
Example #3
0
  def InitRemote(self):
    """Initialize remote access."""
    self.remote = remote_access.RemoteDevice(
        self.device,
        port=self.ssh_port,
        connect_settings=self._ConnectSettings(),
        private_key=self.private_key)

    self.device_addr = 'ssh://%s' % self.device
    if self.ssh_port:
      self.device_addr += ':%d' % self.ssh_port
 def test_QuickProvision(self, run_command_call, _):
     """Tests launching quick provision."""
     cmd = ('curl -o /tmp/quick-provision foo-static/quick-provision && '
            'bash /tmp/quick-provision --status_url foo-url foo-build-name '
            'foo-static')
     device = remote_access.RemoteDevice('fake-hostname')
     self._cros_update_trigger._QuickProvision(device)
     run_command_call.assert_called_with(cmd,
                                         log_output=True,
                                         shell=True,
                                         capture_output=True,
                                         ssh_error_ok=True,
                                         encoding='utf-8')
Example #5
0
    def __init__(self, opts):
        """Initialize VM.

    Args:
      opts: command line options.
    """
        self.qemu_path = opts.qemu_path
        self.qemu_bios_path = opts.qemu_bios_path
        self.qemu_m = opts.qemu_m
        self.qemu_cpu = opts.qemu_cpu
        self.qemu_smp = opts.qemu_smp
        if self.qemu_smp == 0:
            self.qemu_smp = min(8, multiprocessing.cpu_count)
        self.enable_kvm = opts.enable_kvm
        # We don't need sudo access for software emulation or if /dev/kvm is
        # writeable.
        self.use_sudo = self.enable_kvm and not os.access('/dev/kvm', os.W_OK)
        self.display = opts.display
        self.image_path = opts.image_path
        self.image_format = opts.image_format
        self.board = opts.board
        self.ssh_port = opts.ssh_port
        self.dry_run = opts.dry_run

        self.start = opts.start
        self.stop = opts.stop
        self.cmd = opts.args[1:] if opts.cmd else None

        self.cache_dir = os.path.abspath(opts.cache_dir)
        assert os.path.isdir(self.cache_dir), "Cache directory doesn't exist"

        self.vm_dir = opts.vm_dir
        if not self.vm_dir:
            self.vm_dir = os.path.join(osutils.GetGlobalTempDir(),
                                       'cros_vm_%d' % self.ssh_port)
        self._CreateVMDir()

        self.pidfile = os.path.join(self.vm_dir, 'kvm.pid')
        self.kvm_monitor = os.path.join(self.vm_dir, 'kvm.monitor')
        self.kvm_pipe_in = '%s.in' % self.kvm_monitor  # to KVM
        self.kvm_pipe_out = '%s.out' % self.kvm_monitor  # from KVM
        self.kvm_serial = '%s.serial' % self.kvm_monitor

        self.remote = remote_access.RemoteDevice(remote_access.LOCALHOST,
                                                 port=self.ssh_port)
        self.device_addr = 'ssh://%s:%d' % (remote_access.LOCALHOST,
                                            self.ssh_port)
Example #6
0
    def __init__(self, options, tempdir, staging_dir):
        """Initialize the class.

    Args:
      options: options object.
      tempdir: Scratch space for the class.  Caller has responsibility to clean
        it up.
      staging_dir: Directory to stage the files to.
    """
        self.tempdir = tempdir
        self.options = options
        self.staging_dir = staging_dir
        if not self.options.staging_only:
            self.device = remote.RemoteDevice(options.to,
                                              port=options.port,
                                              ping=options.ping,
                                              private_key=options.private_key)
        self._root_dir_is_still_readonly = multiprocessing.Event()

        self.copy_paths = chrome_util.GetCopyPaths('chrome')
        self.chrome_dir = _CHROME_DIR