示例#1
0
  def Start(self):
    if self._auto:
      logging.debug('Starting automatic device deployment.')
      node_name = boot_data.GetNodeName(self._output_dir)
      self._host = self.__Discover(node_name)
      if self._host and self._WaitUntilReady(retries=0):
        if not self._SDKHashMatches():
          logging.info('SDK hash does not match, rebooting.')
          self.RunCommand(['dm', 'reboot'])
          self._started = False
        else:
          logging.info('Connected to an already booted device.')
          self._new_instance = False
          return

      logging.info('Netbooting Fuchsia. ' +
                   'Please ensure that your device is in bootloader mode.')
      bootserver_path = os.path.join(SDK_ROOT, 'tools', 'bootserver')
      bootserver_command = [
          bootserver_path,
          '-1',
          '--efi',
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'local.esp.blk')),
          '--fvm',
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'fvm.sparse.blk')),
          '--fvm',
          EnsurePathExists(
              boot_data.ConfigureDataFVM(self._output_dir,
                                         boot_data.FVM_TYPE_SPARSE)),
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'fuchsia.zbi')),
          '--'] + boot_data.GetKernelArgs(self._output_dir)
      logging.debug(' '.join(bootserver_command))
      subprocess.check_call(bootserver_command)

      # Start loglistener to save system logs.
      if self._system_log_file:
        loglistener_path = os.path.join(SDK_ROOT, 'tools', 'loglistener')
        self._loglistener = subprocess.Popen(
            [loglistener_path, node_name],
            stdout=self._system_log_file,
            stderr=subprocess.STDOUT, stdin=open(os.devnull))

      logging.debug('Waiting for device to join network.')
      for retry in xrange(CONNECT_RETRY_COUNT):
        self._host = self.__Discover(node_name)
        if self._host:
          break
        time.sleep(CONNECT_RETRY_WAIT_SECS)
      if not self._host:
        raise Exception('Couldn\'t connect to device.')

      logging.debug('host=%s, port=%d' % (self._host, self._port))

    self._WaitUntilReady();

    # Update the target's hash to match the current tree's.
    self.PutFile(os.path.join(SDK_ROOT, '.hash'), TARGET_HASH_FILE_PATH)
示例#2
0
    def _WaitUntilReady(self, retries=_ATTACH_MAX_RETRIES):
        logging.info('Connecting to Fuchsia using SSH.')
        loglistener_path = os.path.join(common.SDK_ROOT, 'tools',
                                        'loglistener')
        instance_id = boot_data.GetNodeName(self._output_dir)
        process = subprocess.Popen([loglistener_path, instance_id],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT,
                                   stdin=open(os.devnull))
        with LoglistenerReader(process) as loglistener_reader:
            for retry in xrange(retries + 1):
                if retry > 2:
                    # Log loglistener output after 2 failed SSH connection attempt.
                    loglistener_reader.dump_logs()

                host, port = self._GetEndpoint()
                if remote_cmd.RunSsh(self._GetSshConfigPath(), host, port,
                                     ['true'], True) == 0:
                    logging.info('Connected!')
                    self._started = True
                    return True
                time.sleep(_ATTACH_RETRY_INTERVAL)
            logging.error('Timeout limit reached.')

        raise FuchsiaTargetException('Couldn\'t connect using SSH.')
示例#3
0
    def Start(self):
        if self._auto:
            logging.debug('Starting automatic device deployment.')
            node_name = boot_data.GetNodeName(self._output_dir)
            self._host = self.__Discover(node_name)
            if self._host and self._WaitUntilReady(retries=0):
                logging.info('Connected to an already booted device.')
                return

            logging.info(
                'Netbooting Fuchsia. ' +
                'Please ensure that your device is in bootloader mode.')
            boot_data_path = boot_data.CreateBootdata(self._output_dir,
                                                      self._GetTargetSdkArch())
            bootserver_path = os.path.join(common.SDK_ROOT, 'tools',
                                           'bootserver')
            bootserver_command = [bootserver_path, '-1',
                                  boot_data.GetKernelPath(self._GetTargetSdkArch()),
                                  boot_data_path, '--'] + \
                                  boot_data.GetKernelArgs(self._output_dir)
            logging.debug(' '.join(bootserver_command))
            subprocess.check_call(bootserver_command)

            logging.debug('Waiting for device to join network.')
            for _ in xrange(CONNECT_RETRY_COUNT):
                self._host = self.__Discover(node_name)
                if self._host:
                    break
                time.sleep(CONNECT_RETRY_WAIT_SECS)
            if not self._host:
                raise Exception('Couldn\'t connect to device.')

            logging.debug('host=%s, port=%d' % (self._host, self._port))

        self._WaitUntilReady()
示例#4
0
    def Start(self):
        if self._auto:
            logging.debug('Starting automatic device deployment.')
            node_name = boot_data.GetNodeName(self._output_dir)
            self._host = self.__Discover(node_name)
            if self._host and self._WaitUntilReady(retries=0):
                if not self._SDKHashMatches():
                    logging.info('SDK hash does not match, rebooting.')
                    self.RunCommand(['dm', 'reboot'])
                    self._started = False
                else:
                    logging.info('Connected to an already booted device.')
                    self._new_instance = False
                    return

            self.__ProvisionDevice(node_name)

        else:
            if not self._host:
                self._host = self.__Discover(node_name=None)
                if not self._host:
                    raise Exception('No Fuchsia devices found.')

            if not self._WaitUntilReady(retries=0):
                raise Exception('Could not conenct to %s' % self._host)
示例#5
0
  def Start(self):
    if self._auto:
      logging.debug('Starting automatic device deployment.')
      node_name = boot_data.GetNodeName(self._output_dir)
      self._host = self.__Discover(node_name)
      if self._host and self._WaitUntilReady(retries=0):
        logging.info('Connected to an already booted device.')
        self._new_instance = False
        return

      logging.info('Netbooting Fuchsia. ' +
                   'Please ensure that your device is in bootloader mode.')
      bootserver_path = os.path.join(SDK_ROOT, 'tools', 'bootserver')
      bootserver_command = [
          bootserver_path,
          '-1',
          '--efi',
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'local.esp.blk')),
          '--fvm',
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'fvm.sparse.blk')),
          '--fvm',
          EnsurePathExists(
              boot_data.ConfigureDataFVM(self._output_dir,
                                         boot_data.FVM_TYPE_SPARSE)),
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'zircon.bin')),
          EnsurePathExists(boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                   'bootdata-blob.bin')),
          '--'] + boot_data.GetKernelArgs(self._output_dir)
      logging.debug(' '.join(bootserver_command))
      subprocess.check_call(bootserver_command)

      # Setup loglistener. Logs will be redirected to stdout if the device takes
      # longer than expected to boot.
      loglistener_path = os.path.join(SDK_ROOT, 'tools', 'loglistener')
      loglistener = subprocess.Popen([loglistener_path, node_name],
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT,
                                     stdin=open(os.devnull))
      self._SetSystemLogsReader(
          log_reader.LogReader(loglistener, loglistener.stdout))

      logging.debug('Waiting for device to join network.')
      for retry in xrange(CONNECT_RETRY_COUNT):
        if retry == CONNECT_RETRY_COUNT_BEFORE_LOGGING:
          self._system_logs_reader.RedirectTo(sys.stdout);
        self._host = self.__Discover(node_name)
        if self._host:
          break
        time.sleep(CONNECT_RETRY_WAIT_SECS)
      if not self._host:
        raise Exception('Couldn\'t connect to device.')

      logging.debug('host=%s, port=%d' % (self._host, self._port))

    self._WaitUntilReady();
示例#6
0
    def Start(self):
        if self._auto:
            logging.debug('Starting automatic device deployment.')
            node_name = boot_data.GetNodeName(self._output_dir)
            self._host = self.__Discover(node_name)
            if self._host and self._WaitUntilReady(retries=0):
                logging.info('Connected to an already booted device.')
                self._new_instance = False
                return

            logging.info(
                'Netbooting Fuchsia. ' +
                'Please ensure that your device is in bootloader mode.')
            bootserver_path = os.path.join(common.SDK_ROOT, 'tools',
                                           'bootserver')
            data_fvm_path = boot_data.ConfigureDataFVM(
                self._output_dir, boot_data.FVM_TYPE_SPARSE)
            bootserver_command = [bootserver_path,
                                  '-1',
                                  '--efi',
                                  boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                          'local.esp.blk'),
                                  '--fvm',
                                  boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                          'fvm.sparse.blk'),
                                  '--fvm',
                                  data_fvm_path,
                                  boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                          'zircon.bin'),
                                  boot_data.GetTargetFile(self._GetTargetSdkArch(),
                                                          'bootdata-blob.bin'),
                                  '--'] + \
                                  boot_data.GetKernelArgs(self._output_dir)
            logging.debug(' '.join(bootserver_command))
            subprocess.check_call(bootserver_command)

            logging.debug('Waiting for device to join network.')
            for _ in xrange(CONNECT_RETRY_COUNT):
                self._host = self.__Discover(node_name)
                if self._host:
                    break
                time.sleep(CONNECT_RETRY_WAIT_SECS)
            if not self._host:
                raise Exception('Couldn\'t connect to device.')

            logging.debug('host=%s, port=%d' % (self._host, self._port))

        self._WaitUntilReady()