예제 #1
0
    def __init__(self,
                 output_dir,
                 target_cpu,
                 host=None,
                 port=None,
                 ssh_config=None,
                 system_log_file=None):
        """output_dir: The directory which will contain the files that are
                   generated to support the deployment.
    target_cpu: The CPU architecture of the deployment target. Can be
                "x64" or "arm64".
    host: The address of the deployment target device.
    port: The port of the SSH service on the deployment target device.
    ssh_config: The path to SSH configuration data."""

        super(DeviceTarget, self).__init__(output_dir, target_cpu)

        self._port = 22
        self._auto = not host or not ssh_config
        self._new_instance = True
        self._system_log_file = system_log_file
        self._loglistener = None

        if self._auto:
            boot_data.ProvisionSSH(output_dir)
            self._ssh_config_path = boot_data.GetSSHConfigPath(output_dir)
        else:
            self._ssh_config_path = os.path.expanduser(ssh_config)
            self._host = host
            if port:
                self._port = port
            self._new_instance = False
예제 #2
0
 def testProvisionSSHGeneratesFiles(self):
     fuchsia_authorized_keys_path = _GetAuthorizedKeysPath()
     fuchsia_id_key_path = os.path.join(_SSH_DIR, 'fuchsia_ed25519')
     fuchsia_pub_key_path = os.path.join(_SSH_DIR, 'fuchsia_ed25519.pub')
     ssh_config_path = GetSSHConfigPath()
     # Check if the keys exists before generating. If they do, delete them
     # afterwards before asserting if ProvisionSSH works.
     authorized_key_before = os.path.exists(fuchsia_authorized_keys_path)
     id_keys_before = os.path.exists(fuchsia_id_key_path)
     pub_keys_before = os.path.exists(fuchsia_pub_key_path)
     ssh_config_before = os.path.exists(ssh_config_path)
     ssh_dir_before = os.path.exists(_SSH_CONFIG_DIR)
     boot_data.ProvisionSSH()
     authorized_key_after = os.path.exists(fuchsia_authorized_keys_path)
     id_keys_after = os.path.exists(fuchsia_id_key_path)
     ssh_config_after = os.path.exists(ssh_config_path)
     if not authorized_key_before:
         os.remove(fuchsia_authorized_keys_path)
     if not id_keys_before:
         os.remove(fuchsia_id_key_path)
     if not pub_keys_before:
         os.remove(fuchsia_pub_key_path)
     if not ssh_config_before:
         os.remove(ssh_config_path)
     if not ssh_dir_before:
         os.rmdir(_SSH_CONFIG_DIR)
     self.assertTrue(os.path.exists(authorized_key_after))
     self.assertTrue(os.path.exists(id_keys_after))
     self.assertTrue(os.path.exists(ssh_config_after))
예제 #3
0
    def __init__(self,
                 output_dir,
                 target_cpu,
                 host=None,
                 node_name=None,
                 port=None,
                 ssh_config=None,
                 fuchsia_out_dir=None,
                 os_check='update',
                 system_log_file=None):
        """output_dir: The directory which will contain the files that are
                   generated to support the deployment.
    target_cpu: The CPU architecture of the deployment target. Can be
                "x64" or "arm64".
    host: The address of the deployment target device.
    node_name: The node name of the deployment target device.
    port: The port of the SSH service on the deployment target device.
    ssh_config: The path to SSH configuration data.
    fuchsia_out_dir: The path to a Fuchsia build output directory, for
                     deployments to devices paved with local Fuchsia builds.
    os_check: If 'check', the target's SDK version must match.
              If 'update', the target will be repaved if the SDK versions
                  mismatch.
              If 'ignore', the target's SDK version is ignored."""

        super(DeviceTarget, self).__init__(output_dir, target_cpu)

        self._port = port if port else 22
        self._system_log_file = system_log_file
        self._host = host
        self._fuchsia_out_dir = fuchsia_out_dir
        self._node_name = node_name
        self._os_check = os_check
        self._amber_repo = None

        if self._host and self._node_name:
            raise Exception(
                'Only one of "--host" or "--name" can be specified.')

        if self._fuchsia_out_dir:
            if ssh_config:
                raise Exception(
                    'Only one of "--fuchsia-out-dir" or "--ssh_config" can '
                    'be specified.')

            self._fuchsia_out_dir = os.path.expanduser(fuchsia_out_dir)
            # Use SSH keys from the Fuchsia output directory.
            self._ssh_config_path = os.path.join(self._fuchsia_out_dir,
                                                 'ssh-keys', 'ssh_config')
            self._os_check = 'ignore'

        elif ssh_config:
            # Use the SSH config provided via the commandline.
            self._ssh_config_path = os.path.expanduser(ssh_config)

        else:
            # Default to using an automatically generated SSH config and keys.
            boot_data.ProvisionSSH(output_dir)
            self._ssh_config_path = boot_data.GetSSHConfigPath(output_dir)
예제 #4
0
  def _BuildCommand(self):
    boot_data.ProvisionSSH()
    self._host_ssh_port = common.GetAvailableTcpPort()
    kernel_image = common.EnsurePathExists(
        boot_data.GetTargetFile('qemu-kernel.kernel', self._image_arch,
                                self._image_type))
    zbi_image = common.EnsurePathExists(
        boot_data.GetTargetFile('zircon-a.zbi', self._image_arch,
                                self._image_type))
    fvm_image = common.EnsurePathExists(
        boot_data.GetTargetFile('storage-full.blk', self._image_arch,
                                self._image_type))
    aemu_path = common.EnsurePathExists(
        os.path.join(common.GetEmuRootForPlatform(self.EMULATOR_NAME),
                     'emulator'))

    emu_command = [
        self._FVDL_PATH,
        '--sdk',
        'start',
        '--nointeractive',

        # Host port mapping for user-networking mode.
        '--port-map',
        'hostfwd=tcp::{}-:22'.format(self._host_ssh_port),

        # no-interactive requires a --vdl-output flag to shutdown the emulator.
        '--vdl-output',
        self._vdl_output_file.name,
        '-c',
        ' '.join(boot_data.GetKernelArgs()),

        # Use existing images instead of downloading new ones.
        '--kernel-image',
        kernel_image,
        '--zbi-image',
        zbi_image,
        '--fvm-image',
        fvm_image,
        '--image-architecture',
        self._target_cpu,

        # Use an existing emulator checked out by Chromium.
        '--aemu-path',
        aemu_path,

        # Use this flag and temp file to define ram size.
        '--device-proto',
        self._device_proto_file.name,
        '--cpu-count',
        str(self._cpu_cores)
    ]
    self._ConfigureEmulatorLog(emu_command)

    if not self._require_kvm:
      emu_command.append('--noacceleration')
    if not self._enable_graphics:
      emu_command.append('--headless')
    if self._hardware_gpu:
      emu_command.append('--host-gpu')
    if self._with_network:
      emu_command.append('-N')

    return emu_command