예제 #1
0
def BuildTestSets(tests, chroot_available, network, jobs=1):
    """Build the tests to execute.

  Take care of special test handling like whether it needs to be inside or
  outside of the sdk, whether the test should be skipped, etc...

  Args:
    tests: List of tests to execute.
    chroot_available: Whether we can execute tests inside the sdk.
    network: Whether to execute network tests.
    jobs: How many jobs will we run in parallel.

  Returns:
    List of tests to execute and their full command line.
  """
    testsets = []
    for test in SortTests(tests, jobs=jobs):
        cmd = [test]

        # See if this test requires special consideration.
        status = SPECIAL_TESTS.get(test)
        if status is SKIP:
            logging.info('Skipping %s', test)
            continue
        elif status is INSIDE:
            if not cros_build_lib.IsInsideChroot():
                if not chroot_available:
                    logging.info('Skipping %s: chroot not available', test)
                    continue
                cmd = [
                    'cros_sdk', '--',
                    os.path.join('..', '..', 'chromite', test)
                ]
        elif status is OUTSIDE:
            if cros_build_lib.IsInsideChroot():
                logging.info('Skipping %s: must be outside the chroot', test)
                continue
        else:
            mode = os.stat(test).st_mode
            if stat.S_ISREG(mode):
                if not mode & 0o111:
                    logging.debug('Skipping %s: not executable', test)
                    continue
            else:
                logging.debug('Skipping %s: not a regular file', test)
                continue

        # Build up the final test command.
        cmd.append('--verbose')
        if network:
            cmd.append('--network')
        cmd = [
            'timeout', '--preserve-status', '-k',
            '%sm' % TEST_SIG_TIMEOUT,
            '%sm' % TEST_TIMEOUT
        ] + cmd

        testsets.append((test, cmd, tempfile.TemporaryFile()))

    return testsets
예제 #2
0
def main(argv):
  parser = GetParser()
  opts = parser.parse_args(argv)
  opts.Freeze()

  # Process list output quickly as it takes no privileges.
  if opts.list:
    print('\n'.join(sorted(opts.tests or FindTests((constants.CHROMITE_DIR,)))))
    return

  # Many of our tests require a valid chroot to run. Make sure it's created
  # before we block network access.
  chroot = os.path.join(constants.SOURCE_ROOT, constants.DEFAULT_CHROOT_DIR)
  if (not os.path.exists(chroot) and
      ChrootAvailable() and
      not cros_build_lib.IsInsideChroot()):
    cros_build_lib.RunCommand(['cros_sdk', '--create'])

  # This is a cheesy hack to make sure gsutil is populated in the cache before
  # we run tests. This is a partial workaround for crbug.com/468838.
  gs.GSContext.GetDefaultGSUtilBin()

  # Now let's run some tests.
  _ReExecuteIfNeeded([sys.argv[0]] + argv, opts.network)
  # A lot of pieces here expect to be run in the root of the chromite tree.
  # Make them happy.
  os.chdir(constants.CHROMITE_DIR)
  tests = opts.tests or FindTests()

  if opts.quick:
    SPECIAL_TESTS.update(SLOW_TESTS)

  global TIMING_CACHE_FILE  # pylint: disable=global-statement
  TIMING_CACHE_FILE = os.path.join(
      path_util.GetCacheDir(), constants.COMMON_CACHE, 'run_tests.cache.json')

  jobs = opts.jobs or multiprocessing.cpu_count()

  with cros_build_lib.ContextManagerStack() as stack:
    # If we're running outside the chroot, try to contain ourselves.
    if cgroups.Cgroup.IsSupported() and not cros_build_lib.IsInsideChroot():
      stack.Add(cgroups.SimpleContainChildren, 'run_tests')

    # Throw all the tests into a custom tempdir so that if we do CTRL+C, we can
    # quickly clean up all the files they might have left behind.
    stack.Add(osutils.TempDir, prefix='chromite.run_tests.', set_global=True,
              sudo_rm=True)

    with cros_build_lib.TimedSection() as timer:
      result = RunTests(
          tests, jobs=jobs, chroot_available=ChrootAvailable(),
          network=opts.network, dryrun=opts.dryrun, failfast=opts.failfast)

    if result:
      logging.info('All tests succeeded! (%s total)', timer.delta)
    else:
      return 1

  if not opts.network:
    logging.warning('Network tests skipped; use --network to run them')
예제 #3
0
def main(argv):
    parser = get_parser()
    opts, pytest_args = parser.parse_known_args()
    if opts.quick:
        if not cros_build_lib.IsInsideChroot() and opts.chroot:
            logging.warning(
                'Tests start up faster when run from inside the chroot.')

    if opts.chroot:
        ensure_chroot_exists()
        re_execute_inside_chroot(argv)
    else:
        os.chdir(constants.CHROMITE_DIR)
        pytest_args += ['--no-chroot']

    # This is a cheesy hack to make sure gsutil is populated in the cache before
    # we run tests. This is a partial workaround for crbug.com/468838.
    gs.GSContext.GetDefaultGSUtilBin()

    if opts.quick:
        logging.info('Skipping test namespacing due to --quickstart.')
        # Default to running in a single process under --quickstart. User args can
        # still override this.
        pytest_args = ['-n', '0'] + pytest_args
    else:
        # Namespacing is enabled by default because tests may break each other or
        # interfere with parts of the running system if not isolated in a namespace.
        # Disabling namespaces is not recommended for general use.
        re_execute_with_namespace([sys.argv[0]] + argv)

    sys.exit(pytest.main(pytest_args))
예제 #4
0
def RunCbuildbot(options):
  """Run a cbuildbot build.

  Args:
    options: Parsed cros tryjob tryjob arguments.

  Returns:
    Exit code of build as an int.
  """
  if cros_build_lib.IsInsideChroot():
    cros_build_lib.Die('cbuildbot tryjobs cannot be started inside the chroot.')

  args = CbuildbotArgs(options)

  if not CreateBuildrootIfNeeded(options.buildroot):
    return 1

  # Define the command to run.
  cbuildbot = os.path.join(constants.CHROMITE_BIN_DIR, 'cbuildbot')
  cmd = [cbuildbot] + args + options.build_configs

  # Run the tryjob.
  result = cros_build_lib.run(cmd, debug_level=logging.CRITICAL,
                              check=False, cwd=options.buildroot)
  return result.returncode
예제 #5
0
    def _RunAutotest(self):
        """Run an autotest using test_that.

    Returns:
      cros_build_lib.CommandResult object.
    """
        cmd = ['test_that']
        if self._device.board:
            cmd += ['--board', self._device.board]
        if self.results_dir:
            cmd += ['--results_dir', path_util.ToChrootPath(self.results_dir)]
        if self._device.private_key:
            cmd += [
                '--ssh_private_key',
                path_util.ToChrootPath(self._device.private_key)
            ]
        if self._device.log_level == 'debug':
            cmd += ['--debug']
        if self.test_that_args:
            cmd += self.test_that_args[1:]
        cmd += [
            '--no-quickmerge',
            '--ssh_options',
            '-F /dev/null -i /dev/null',
        ]
        if self._device.ssh_port:
            cmd += ['%s:%d' % (self._device.device, self._device.ssh_port)]
        else:
            cmd += [self._device.device]
        cmd += self.autotest
        return self._device.RunCommand(
            cmd, enter_chroot=not cros_build_lib.IsInsideChroot())
예제 #6
0
    def __init__(self, source_path=None, source_from_path_repo=True):
        self._inside_chroot = cros_build_lib.IsInsideChroot()
        self._source_path = (constants.SOURCE_ROOT
                             if source_path is None else source_path)
        self._source_from_path_repo = source_from_path_repo

        # The following are only needed if outside the chroot.
        if self._inside_chroot:
            self._chroot_path = None
            self._chroot_link = None
            self._chroot_to_host_roots = None
        else:
            self._chroot_path = self._GetSourcePathChroot(self._source_path)
            # The chroot link allows us to resolve paths when the chroot is symlinked
            # to the default location. This is generally not used, but it is useful
            # for CI for optimization purposes. We will trust them not to do something
            # dumb, like symlink to /, but this doesn't enable that kind of behavior
            # anyway, just allows resolving paths correctly from outside the chroot.
            self._chroot_link = self._ReadChrootLink(self._chroot_path)

            # Initialize mapping of known root bind mounts.
            self._chroot_to_host_roots = (
                (constants.CHROOT_SOURCE_ROOT, self._source_path),
                (constants.CHROOT_CACHE_ROOT, self._GetCachePath),
            )
예제 #7
0
def RunInsideChroot(command=None, chroot_args=None):
    """Restart the current command inside the chroot.

  This method is only valid for any code that is run via ScriptWrapperMain.
  It allows proper cleanup of the local context by raising an exception handled
  in ScriptWrapperMain.

  Args:
    command: An instance of CliCommand to be restarted inside the chroot.
             |command| can be None if you do not wish to modify the log_level.
    chroot_args: List of command-line arguments to pass to cros_sdk, if invoked.
  """
    if cros_build_lib.IsInsideChroot():
        return

    # Produce the command line to execute inside the chroot.
    argv = sys.argv[:]
    argv[0] = path_util.ToChrootPath(argv[0])

    # Set log-level of cros_sdk to be same as log-level of command entering the
    # chroot.
    if chroot_args is None:
        chroot_args = []
    if command is not None:
        chroot_args += ['--log-level', command.options.log_level]

    raise ChrootRequiredError(argv, chroot_args)
예제 #8
0
    def setUp(self):
        self.root = self.tempdir
        self.buildroot = self.MakeTestRootDir('build_root')
        self.sourceroot = self.MakeTestRootDir('source_root')
        self.trybot_root = self.MakeTestRootDir('trybot')
        self.trybot_internal_root = self.MakeTestRootDir('trybot-internal')
        self.external_marker = os.path.join(self.trybot_root, '.trybot')
        self.internal_marker = os.path.join(self.trybot_internal_root,
                                            '.trybot')

        os.makedirs(os.path.join(self.sourceroot, '.repo', 'manifests'))
        os.makedirs(os.path.join(self.sourceroot, '.repo', 'repo'))

        # Create the parser before we stub out os.path.exists() - which the parser
        # creation code actually uses.
        parser = cbuildbot._CreateParser()

        # Stub out all relevant methods regardless of whether they are called in the
        # specific test case.  We can do this because we don't run VerifyAll() at
        # the end of every test.
        self.mox.StubOutWithMock(optparse.OptionParser, 'error')
        self.mox.StubOutWithMock(cros_build_lib, 'IsInsideChroot')
        self.mox.StubOutWithMock(cbuildbot, '_CreateParser')
        self.mox.StubOutWithMock(sys, 'exit')
        self.mox.StubOutWithMock(cros_build_lib, 'GetInput')
        self.mox.StubOutWithMock(cbuildbot, '_RunBuildStagesWrapper')

        parser.error(mox.IgnoreArg()).InAnyOrder().AndRaise(
            TestExitedException())
        cros_build_lib.IsInsideChroot().InAnyOrder().AndReturn(False)
        cbuildbot._CreateParser().InAnyOrder().AndReturn(parser)
        sys.exit(mox.IgnoreArg()).InAnyOrder().AndRaise(TestExitedException())
        cbuildbot._RunBuildStagesWrapper(
            mox.IgnoreArg(), mox.IgnoreArg()).InAnyOrder().AndReturn(True)
예제 #9
0
def SetupBoard(target, accept_licenses=None, run_configs=None):
  """Run the full process to setup a board's sysroot.

  This is the entry point to run the setup_board script.

  Args:
    target (build_target_lib.BuildTarget): The build target configuration.
    accept_licenses (str|None): The additional licenses to accept.
    run_configs (SetupBoardRunConfig): The run configs.

  Raises:
    sysroot_lib.ToolchainInstallError when the toolchain fails to install.
  """
  if not cros_build_lib.IsInsideChroot():
    # TODO(saklein) switch to build out command and run inside chroot.
    raise NotInChrootError('SetupBoard must be run from inside the chroot')

  # Make sure we have valid run configs setup.
  run_configs = run_configs or SetupBoardRunConfig()

  sysroot = Create(target, run_configs, accept_licenses)

  if run_configs.regen_configs:
    # We're now done if we're only regenerating the configs.
    return

  InstallToolchain(target, sysroot, run_configs)
예제 #10
0
파일: binhost.py 프로젝트: sjg20/chromite
def CalculateCompatId(board, extra_useflags):
    """Calculate the CompatId for board with the specified extra useflags.

  This function requires that the board has been set up first (e.g. using
  GenConfigsForBoard)

  Args:
    board: The board to use.
    extra_useflags: A sequence of use flags to enable or disable.

  Returns:
    A CompatId object for the board with the specified extra_useflags.
  """
    assert cros_build_lib.IsInsideChroot()
    useflags = GetChromeUseFlags(board, extra_useflags)
    cmd = ['portageq-%s' % board, 'envvar', 'ARCH', 'CFLAGS']
    arch_cflags = cros_build_lib.RunCommand(
        cmd, print_cmd=False, capture_output=True).output.rstrip()
    arch, cflags = arch_cflags.split('\n', 1)
    cflags_split = cflags.split()

    # We will add -clang-syntax to falco and nyan board. So we need to
    # filter out -clang-syntax to make the flags from PFQ are the same as
    # the release-board. See crbug.com/499115
    # TODO(yunlian): Remove this when all the boards are build with -clang-syntax
    if '-clang-syntax' in cflags_split:
        cflags_split.remove('-clang-syntax')
    return CompatId(arch, useflags, cflags_split)
예제 #11
0
  def _ChrootCheck(self, service_options, method_options):
    """Check the chroot options, and execute assertion or note reexec as needed.

    Args:
      service_options (google.protobuf.Message): The service options.
      method_options (google.protobuf.Message): The method options.

    Returns:
      bool - True iff it needs to be reexeced inside the chroot.

    Raises:
      cros_build_lib.DieSystemExit when the chroot setting cannot be satisfied.
    """
    chroot_assert = build_api_pb2.NO_ASSERTION
    if method_options.HasField('method_chroot_assert'):
      # Prefer the method option when set.
      chroot_assert = method_options.method_chroot_assert
    elif service_options.HasField('service_chroot_assert'):
      # Fall back to the service option.
      chroot_assert = service_options.service_chroot_assert

    if chroot_assert == build_api_pb2.INSIDE:
      return not cros_build_lib.IsInsideChroot()
    elif chroot_assert == build_api_pb2.OUTSIDE:
      # If it must be run outside we have to already be outside.
      cros_build_lib.AssertOutsideChroot()

    return False
예제 #12
0
def CreateTmpGitRepo(project, project_url):
    """Create a temporary git repo locally.

  Args:
    project: git project name to clone.
    project_url: git project url to clone.

  Returns:
    project_dir: local project directory.
  """

    work_dir = GetWorkDir(project)

    if not cros_build_lib.IsInsideChroot():
        work_dir = os.path.join(constants.SOURCE_ROOT,
                                constants.DEFAULT_CHROOT_DIR, work_dir)

    # Delete the work_dir built by previous runs.
    osutils.RmDir(work_dir, ignore_missing=True, sudo=True)

    # Safely create work_dir
    osutils.SafeMakedirs(work_dir)

    project_dir = os.path.join(work_dir, project)
    ref = os.path.join(constants.SOURCE_ROOT, project)

    logging.info('Cloning %s %s to %s', project_url, ref, project_dir)
    repository.CloneWorkingRepo(dest=project_dir,
                                url=project_url,
                                reference=ref)
    return project_dir
예제 #13
0
def main(argv):
    opts = ParseArgs(argv)
    if not cros_build_lib.IsInsideChroot():
        raise commandline.ChrootRequiredError()

    if os.geteuid() != 0:
        cros_build_lib.SudoRunCommand(sys.argv, print_cmd=False)
        return

    output = sys.stdout
    if opts.out_file:
        output = open(opts.out_file, 'w')

    sysroot = sysroot_lib.Sysroot(opts.sysroot)
    if opts.command == 'create-wrappers':
        sysroot.CreateAllWrappers(opts.friendlyname)
    elif opts.command == 'generate-config':
        config = sysroot.GenerateBoardConfig(opts.board)

        output.write('\n' + config)
    elif opts.command == 'generate-make-conf':
        output.write('\n' + sysroot.GenerateMakeConf(opts.accepted_licenses))
    elif opts.command == 'generate-binhosts':
        output.write(
            '\n' +
            sysroot.GenerateBinhostConf(opts.chrome_only, opts.local_only))
예제 #14
0
def RunLocal(options):
    """Run a local tryjob.

  Args:
    options: Parsed cros tryjob tryjob arguments.

  Returns:
    Exit code of build as an int.
  """
    if cros_build_lib.IsInsideChroot():
        cros_build_lib.Die(
            'Local tryjobs cannot be started inside the chroot.')

    args = CbuildbotArgs(options)

    if not CreateBuildrootIfNeeded(options.buildroot):
        return 1

    # Define the command to run.
    launcher = os.path.join(constants.CHROMITE_DIR, 'scripts',
                            'cbuildbot_launch')
    cmd = [launcher] + args + options.build_configs

    # Run the tryjob.
    result = cros_build_lib.RunCommand(cmd,
                                       debug_level=logging.CRITICAL,
                                       error_code_ok=True,
                                       cwd=options.buildroot)
    return result.returncode
예제 #15
0
def main(argv):
  options = ParseArgs(argv)

  if not cros_build_lib.IsInsideChroot():
    raise commandline.ChrootRequiredError()

  if os.geteuid() != 0:
    cros_build_lib.SudoRunCommand(sys.argv)
    return

  # sysroot must have a trailing / as the tree dictionary produced by
  # create_trees in indexed with a trailing /.
  sysroot = cros_build_lib.GetSysroot(options.board) + '/'
  trees = create_trees(target_root=sysroot, config_root=sysroot)

  vartree = trees[sysroot]['vartree']

  cache_dir = os.path.join(path_util.FindCacheDir(),
                           'cros_install_debug_syms-v' + CACHE_VERSION)

  if options.clearcache:
    osutils.RmDir(cache_dir, ignore_missing=True)

  binhost_cache = None
  if options.cachebinhost:
    binhost_cache = cache.DiskCache(cache_dir)

  boto_file = vartree.settings['BOTO_CONFIG']
  if boto_file:
    os.environ['BOTO_CONFIG'] = boto_file

  gs_context = gs.GSContext()
  symbols_mapping = RemoteSymbols(vartree, binhost_cache)

  if options.all:
    to_install = vartree.dbapi.cpv_all()
  else:
    to_install = [GetMatchingCPV(p, vartree.dbapi) for p in options.packages]

  to_install = [p for p in to_install
                if ShouldGetSymbols(p, vartree.dbapi, symbols_mapping)]

  if not to_install:
    logging.info('nothing to do, exit')
    return

  with DebugSymbolsInstaller(vartree, gs_context, sysroot,
                             not options.debug) as installer:
    args = [(p, symbols_mapping[p]) for p in to_install]
    parallel.RunTasksInProcessPool(installer.Install, args,
                                   processes=options.jobs)

  logging.debug('installation done, updating packages index file')
  packages_dir = os.path.join(sysroot, 'packages')
  packages_file = os.path.join(packages_dir, 'Packages')
  # binpkg will set DEBUG_SYMBOLS automatically if it detects the debug symbols
  # in the packages dir.
  pkgindex = binpkg.GrabLocalPackageIndex(packages_dir)
  with open(packages_file, 'w') as p:
    pkgindex.Write(p)
예제 #16
0
 def _AssertGclientConfigSpec(self, expected_spec, use_cache=True):
     if cros_build_lib.HostIsCIBuilder() and use_cache:
         if cros_build_lib.IsInsideChroot():
             expected_spec += "cache_dir = '/tmp/b/git-cache'\n"
         else:
             expected_spec += "cache_dir = '/b/git-cache'\n"
     self.rc.assertCommandContains(
         ('gclient', 'config', '--spec', expected_spec), cwd=self._TEST_CWD)
 def testReturnCodeZeroWithArrayCmdEnterChroot(self):
     """--enter_chroot=True and --cmd is an array of strings."""
     self.proc_mock.returncode = 0
     cmd_list = ['foo', 'bar', 'roger']
     real_cmd = cmd_list
     if not cros_build_lib.IsInsideChroot():
         real_cmd = ['cros_sdk', '--'] + cmd_list
     self._TestCmd(cmd_list, real_cmd, rc_kv=dict(enter_chroot=True))
예제 #18
0
def CreateMakeConfUser():
  """Create default make.conf.user file in the chroot if it does not exist."""
  path = '/etc/make.conf.user'
  if not cros_build_lib.IsInsideChroot():
    path = path_util.FromChrootPath(path)

  if not os.path.exists(path):
    osutils.WriteFile(path, _DEFAULT_MAKE_CONF_USER, sudo=True)
예제 #19
0
def RunChrootVersionHooks(version_file=None, hooks_dir=None):
    """Run the chroot version hooks to bring the chroot up to date."""
    if not cros_build_lib.IsInsideChroot():
        command = ['run_chroot_version_hooks']
        cros_build_lib.run(command, enter_chroot=True)
    else:
        chroot = ChrootUpdater(version_file=version_file, hooks_dir=hooks_dir)
        chroot.ApplyUpdates()
예제 #20
0
 def setUpClass(cls):
     assert cros_build_lib.IsInsideChroot()
     logging.info('Generating board configs.')
     board_keys = binhost.GetAllImportantBoardKeys(cls.site_config)
     boards = set(key.board for key in board_keys)
     inputs = [[board, not cls.CACHING, False] for board in boards]
     parallel.RunTasksInProcessPool(binhost.GenConfigsForBoard, inputs)
     fetcher = binhost.CompatIdFetcher(caching=cls.CACHING)
     cls.COMPAT_IDS = fetcher.FetchCompatIds(list(board_keys))
예제 #21
0
def main(argv):
    """Main function."""
    # No actual options used, but --help is still supported.
    parser = GetParser()
    _opts = parser.parse_args(argv)

    if build_lib.IsInsideChroot():
        InsideChroot().Run()
    else:
        OutsideChroot(argv).Run()
예제 #22
0
def is_inside_chroot():
    """Check if the process is running inside chroot.

    This is a wrapper around chromite.lib.cros_build_lib.IsInsideChroot(). The
    method checks if cros_build_lib can be imported first.

    @return: True if the process is running inside chroot or cros_build_lib
             cannot be imported.

    """
    return not cros_build_lib or cros_build_lib.IsInsideChroot()
예제 #23
0
def re_execute_inside_chroot(argv):
    """Re-execute the test wrapper inside the chroot."""
    cmd = [
        'cros_sdk',
        '--',
        os.path.join('..', '..', 'chromite', 'run_pytest'),
    ]
    if not cros_build_lib.IsInsideChroot():
        os.execvp(cmd[0], cmd + argv)
    else:
        os.chdir(constants.CHROMITE_DIR)
예제 #24
0
 def setUpClass(cls):
     assert cros_build_lib.IsInsideChroot()
     logging.info('Generating board configs. This takes about 30m...')
     board_keys = binhost.GetAllImportantBoardKeys(cls.site_config)
     boards = set(key.board for key in board_keys)
     for board in sorted(boards):
         binhost.GenConfigsForBoard(board,
                                    regen=not cls.CACHING,
                                    error_code_ok=False)
     fetcher = binhost.CompatIdFetcher(caching=cls.CACHING)
     cls.COMPAT_IDS = fetcher.FetchCompatIds(list(board_keys))
예제 #25
0
def is_inside_chroot():
    """Check if the process is running inside the chroot.

    @return: True if the process is running inside the chroot, False otherwise.
    """
    try:
        # chromite may not be setup, e.g., in vm, therefore the ImportError
        # needs to be handled.
        from chromite.lib import cros_build_lib
        return cros_build_lib.IsInsideChroot()
    except ImportError:
        return False
def GetProjectWorkDir(project):
    """Return the project work directory.

  Args:
    project: The name of the project to create work dir.
  """
    project_work_dir = GetProjectTmpDir(project)

    if not cros_build_lib.IsInsideChroot():
        project_work_dir = os.path.join(constants.SOURCE_ROOT,
                                        constants.DEFAULT_CHROOT_DIR,
                                        project_work_dir)

    return project_work_dir
예제 #27
0
def InitLatestVersion(version_file=None, hooks_dir=None):
    """Initialize the chroot version to the latest version."""
    if not cros_build_lib.IsInsideChroot():
        # Run the command in the chroot.
        command = ['run_chroot_version_hooks', '--init-latest']
        cros_build_lib.run(command, enter_chroot=True)
    else:
        # Initialize the version.
        chroot = ChrootUpdater(version_file=version_file, hooks_dir=hooks_dir)
        if chroot.IsInitialized():
            logging.info('Chroot is already initialized to %s.',
                         chroot.GetVersion())
        else:
            logging.info('Initializing chroot to version %s.',
                         chroot.latest_version)
            chroot.SetVersion(chroot.latest_version)
def is_moblab(lsb_release_content=None):
    """Return if we are running on a Moblab system or not.

    @param lsb_release_content: A string represents the content of lsb-release.
            If the caller is from drone, it can pass in the file content here.

    @return the board string if this is a Moblab device or None if it is not.
    """
    if os.path.exists(constants.LSB_RELEASE):
        return _lsbrelease_search(r'.*moblab',
                                  lsb_release_content=lsb_release_content)
    try:
        from chromite.lib import cros_build_lib
        if cros_build_lib.IsInsideChroot():
            return None
    except ImportError as e:
        logging.error('Unable to determine if this is a moblab system: %s', e)
예제 #29
0
 def Run(self):
     """Run cros pinchrome."""
     self.options.Freeze()
     chroot_tmp = os.path.join(constants.SOURCE_ROOT,
                               constants.DEFAULT_CHROOT_DIR, 'tmp')
     tmp_override = None if cros_build_lib.IsInsideChroot() else chroot_tmp
     work_dir = tempfile.mkdtemp(prefix='pinchrome_', dir=tmp_override)
     try:
         if self.options.unpin:
             self.unpin(work_dir)
         else:
             self.pin(work_dir)
     finally:
         if self.options.wipe:
             osutils.RmDir(work_dir)
         else:
             print('Leaving working directory at %s.' % work_dir)
예제 #30
0
def GetChrootVersion(chroot_path=None):
    """Get the chroot version.

  Args:
    chroot_path (str|None): The chroot path.

  Returns:
    int|None - The version of the chroot if the chroot is valid, else None.
  """
    if chroot_path:
        path = chroot_path
    elif cros_build_lib.IsInsideChroot():
        path = None
    else:
        path = constants.DEFAULT_CHROOT_PATH

    return cros_sdk_lib.GetChrootVersion(path)