Example #1
0
  def _CheckDependencies(self):
    """Verify emerge dependencies.

    Verify all board packages can be emerged from scratch, without any
    backtracking. This ensures that no updates are skipped by Portage due to
    the fallback behavior enabled by the backtrack option, and helps catch
    cases where Portage skips an update due to a typo in the ebuild.

    Only print the output if this step fails or if we're in debug mode.
    """
    if self.options.deps and not self.host:
      cmd = chroot_util.GetEmergeCommand(sysroot=self.sysroot)
      cmd += ['-pe', '--backtrack=0'] + self.build_pkgs
      try:
        cros_build_lib.RunCommand(cmd, combine_stdout_stderr=True,
                                  debug_level=logging.DEBUG)
      except cros_build_lib.RunCommandError as ex:
        ex.msg += self._BAD_DEPEND_MSG
        raise
Example #2
0
def CreateChroot(chroot_path, sdk_tarball, toolchains_overlay_tarball,
                 cache_dir, nousepkg=False):
  """Creates a new chroot from a given SDK"""

  cmd = MAKE_CHROOT + ['--stage3_path', sdk_tarball,
                       '--chroot', chroot_path,
                       '--cache_dir', cache_dir]

  if toolchains_overlay_tarball:
    cmd.extend(['--toolchains_overlay_path', toolchains_overlay_tarball])

  if nousepkg:
    cmd.append('--nousepkg')

  logging.notice('Creating chroot. This may take a few minutes...')
  try:
    cros_build_lib.RunCommand(cmd, print_cmd=False)
  except cros_build_lib.RunCommandError:
    raise SystemExit('Running %r failed!' % cmd)
Example #3
0
def _GetDefaultClangFormatPath():
    """Gets the default clang-format binary path.

  This also ensures that the binary itself is up-to-date.
  """

    clang_format_path = os.path.join(BUILDTOOLS_PATH, 'linux64/clang-format')
    hash_file_path = os.path.join(BUILDTOOLS_PATH, 'linux64/clang-format.sha1')
    with open(hash_file_path, 'r') as f:
        expected_hash = f.read().strip()
    if expected_hash != _GetSha1Hash(clang_format_path):
        # See chromium/src/buildtools/clang_format/README.txt for more details.
        cmd = [
            os.path.join(constants.DEPOT_TOOLS_DIR,
                         'download_from_google_storage.py'), '-b',
            'chromium-clang-format', '-s', hash_file_path
        ]
        cros_build_lib.RunCommand(cmd=cmd, print_cmd=False)
    return clang_format_path
Example #4
0
def GenConfigsForBoard(board, regen, error_code_ok):
  """Set up the configs for the specified board.

  This must be run from within the chroot. It sets up the board but does not
  fully initialize it (it skips the initialization of the toolchain and the
  board packages)

  Args:
    board: Board to set up.
    regen: Whether to regen configs if the board already exists.
    error_code_ok: Whether errors are acceptable. We set this to True in some
      tests for configs that are not on the waterfall.
  """
  assert cros_build_lib.IsInsideChroot()
  if regen or not os.path.exists('/build/%s' % board):
    cmd = ['%s/src/scripts/setup_board' % constants.CHROOT_SOURCE_ROOT,
           '--board=%s' % board, '--regen_configs', '--skip_toolchain_update',
           '--skip_chroot_upgrade', '--skip_board_pkg_init', '--quiet']
    cros_build_lib.RunCommand(cmd, error_code_ok=error_code_ok)
Example #5
0
def CleanTargets(targets, root='/'):
  """Unmerges old packages that are assumed unnecessary.

  Args:
    targets: The list of targets to clean up.
    root: The install root in which we want packages cleaned up.
  """
  unmergemap = {}
  for target in targets:
    for package in GetTargetPackages(target):
      if IsPackageDisabled(target, package):
        continue
      pkg = GetPortagePackage(target, package)
      current = GetInstalledPackageVersions(pkg, root=root)
      desired = GetDesiredPackageVersions(target, package)
      # NOTE: This refers to installed packages (vartree) rather than the
      # Portage version (porttree and/or bintree) when determining the current
      # version. While this isn't the most accurate thing to do, it is probably
      # a good simple compromise, which should have the desired result of
      # uninstalling everything but the latest installed version. In
      # particular, using the bintree (--usebinpkg) requires a non-trivial
      # binhost sync and is probably more complex than useful.
      desired_num = VersionListToNumeric(target, package, desired, True)
      if not set(desired_num).issubset(current):
        print('Error detecting stable version for %s, skipping clean!' % pkg)
        return
      unmergemap[pkg] = set(current).difference(desired_num)

  # Cleaning doesn't care about consistency and rebuilding package.* files.
  packages = []
  for pkg, vers in unmergemap.iteritems():
    packages.extend('=%s-%s' % (pkg, ver) for ver in vers if ver != '9999')

  if packages:
    print('Cleaning packages:')
    print(packages)
    cmd = [EMERGE_CMD, '--unmerge']
    if root != '/':
      cmd.extend(['--sysroot=%s' % root, '--root=%s' % root])
    cmd.extend(packages)
    cros_build_lib.RunCommand(cmd)
  else:
    print('Nothing to clean!')
Example #6
0
  def _UpdateGnArgsIfStale(self, out_dir, build_label, gn_args, board):
    """Runs 'gn gen' if gn args are stale or logs a warning."""
    gn_args_file_path = os.path.join(
        self.options.chrome_src, out_dir, build_label, 'args.gn')

    if not self._StaleGnArgs(gn_args, gn_args_file_path):
      return

    if not self.options.gn_gen:
      logging.warning('To update gn args run:')
      logging.warning('gn gen out_$SDK_BOARD/Release --args="$GN_ARGS"')
      return

    logging.warning('Running gn gen')
    cros_build_lib.RunCommand(
        ['gn', 'gen', 'out_%s/Release' % board,
         '--args=%s' % gn_helpers.ToGNString(gn_args)],
        print_cmd=logging.getLogger().isEnabledFor(logging.DEBUG),
        cwd=self.options.chrome_src)
Example #7
0
 def _RunCommand(self, cmd, **kwargs):
     kwargs.setdefault('redirect_stderr', True)
     try:
         return cros_build_lib.RunCommand(cmd, **kwargs)
     # gsutil uses the same exit code for any failure, so we are left to
     # parse the output as needed.
     except cros_build_lib.RunCommandError as e:
         error = e.result.error
         if error:
             if 'GSResponseError' in error:
                 if 'code=PreconditionFailed' in error:
                     raise GSContextPreconditionFailed(e)
                 if 'code=NoSuchKey' in error:
                     raise GSNoSuchKey(e)
             # If the file does not exist, one of the following errors occurs.
             if (error.startswith('InvalidUriError:') or
                     error.startswith('CommandException: No URIs matched')):
                 raise GSNoSuchKey(e)
         raise
Example #8
0
def _PrepareAppFolder(options):
    """Copies this folder and its symlink'd dependencies into a temporary dir.

  Returns:
    A contextmanager that yields a temporary directory and cleans up afterward.
  """
    with osutils.TempDir() as tempdir:
        # This is rsync in 'archive' mode, but symlinks are followed to copy actual
        # files/directories.
        rsync_cmd = [
            'rsync', '-qrLgotD', '--exclude', '*.pyc', '--exclude',
            '__pycache__', '--exclude', '*.git'
        ]
        for path in options.skip_paths:
            rsync_cmd.extend(['--exclude', path])

        cros_build_lib.RunCommand(rsync_cmd + ['.', tempdir],
                                  cwd=options.project_path)
        yield tempdir
Example #9
0
def CreateAndUploadPayload(payload,
                           cache,
                           work_dir,
                           sign=True,
                           verify=True,
                           dry_run=False,
                           au_generator_uri=None):
    """Helper to create a PaygenPayloadLib instance and use it.

  Args:
    payload: An instance of utils.Payload describing the payload to generate.
    cache: An instance of DownloadCache for retrieving files.
    work_dir: A working directory that can hold scratch files. Will be cleaned
              up when done, and won't interfere with other users. None for /tmp.
    sign: Boolean saying if the payload should be signed (normally, you do).
    verify: whether the payload should be verified (default: True)
    dry_run: don't perform actual work
    au_generator_uri: URI to override standard au_generator.zip rules.
  """
    # We need to create a temp directory inside the chroot so be able to access
    # from both inside and outside the chroot.
    temp_dir = path_util.FromChrootPath(
        cros_build_lib.RunCommand(['mktemp', '-d'],
                                  capture_output=True,
                                  enter_chroot=True).output.strip())

    with osutils.TempDir(prefix='paygen_payload.',
                         base_dir=temp_dir) as gen_dir:
        logging.info('* Starting payload generation')
        start_time = datetime.datetime.now()

        _PaygenPayload(payload,
                       cache,
                       gen_dir,
                       sign,
                       verify,
                       au_generator_uri,
                       dry_run=dry_run).Run()

        end_time = datetime.datetime.now()
        logging.info('* Finished payload generation in %s',
                     end_time - start_time)
Example #10
0
def Cbuildbot(buildroot, depot_tools_path, argv):
    """Start cbuildbot in specified directory with all arguments.

  Args:
    buildroot: Directory to be passed to cbuildbot with --buildroot.
    depot_tools_path: Directory for depot_tools to be used by cbuildbot.
    argv: Command line options passed to cbuildbot_launch.

  Returns:
    Return code of cbuildbot as an integer.
  """
    logging.info('Bootstrap cbuildbot in: %s', buildroot)

    # Fixup buildroot parameter.
    argv = argv[:]
    for i in xrange(len(argv)):
        if argv[i] in ('-r', '--buildroot'):
            argv[i + 1] = buildroot

    # This filters out command line arguments not supported by older versions
    # of cbuildbot.
    parser = cbuildbot.CreateParser()
    options = cbuildbot.ParseCommandLine(parser, argv)
    cbuildbot_path = os.path.join(buildroot, 'chromite', 'bin', 'cbuildbot')
    cmd = sync_stages.BootstrapStage.FilterArgsForTargetCbuildbot(
        buildroot, cbuildbot_path, options)

    # We want cbuildbot to use branched depot_tools scripts from our manifest,
    # so that depot_tools is branched to match cbuildbot.
    logging.info('Adding depot_tools into PATH: %s', depot_tools_path)
    extra_env = {'PATH': PrependPath(depot_tools_path)}

    # TODO(crbug.com/845304): Remove once underlying boto issues are resolved.
    fix_boto = ShouldFixBotoCerts(options)

    with boto_compat.FixBotoCerts(activate=fix_boto):
        result = cros_build_lib.RunCommand(cmd,
                                           extra_env=extra_env,
                                           error_code_ok=True,
                                           cwd=buildroot)

    return result.returncode
Example #11
0
  def _EnsureMirroring(self, post_sync=False):
    """Ensure git is usable from w/in the chroot if --references is enabled

    repo init --references hardcodes the abspath to parent; this pathway
    however isn't usable from the chroot (it doesn't exist).  As such the
    pathway is rewritten to use relative pathways pointing at the root of
    the repo, which via I84988630 enter_chroot sets up a helper bind mount
    allowing git/repo to access the actual referenced repo.

    This has to be invoked prior to a repo sync of the target trybot to
    fix any pathways that may have been broken by the parent repo moving
    on disk, and needs to be invoked after the sync has completed to rewrite
    any new project's abspath to relative.
    """

    if not self._referenced_repo:
      return

    proj_root = os.path.join(self.directory, '.repo', 'projects')
    if not os.path.exists(proj_root):
      # Not yet synced, nothing to be done.
      return

    rewrite_git_alternates.RebuildRepoCheckout(self.directory,
                                               self._referenced_repo)

    if post_sync:
      chroot_path = os.path.join(self._referenced_repo, '.repo', 'chroot',
                                 'external')
      chroot_path = git.ReinterpretPathForChroot(chroot_path)
      rewrite_git_alternates.RebuildRepoCheckout(
          self.directory, self._referenced_repo, chroot_path)

    # Finally, force the git config marker that enter_chroot looks for
    # to know when to do bind mounting trickery; this normally will exist,
    # but if we're converting a pre-existing repo checkout, it's possible
    # that it was invoked w/out the reference arg.  Note this must be
    # an absolute path to the source repo- enter_chroot uses that to know
    # what to bind mount into the chroot.
    cros_build_lib.RunCommand(
        ['git', 'config', '--file', self._ManifestConfig, 'repo.reference',
         self._referenced_repo])
Example #12
0
def main(argv):
    """The main function."""
    parser = GetParser()
    options, args = parser.parse_args(argv)

    # Verify the project is there.
    if len(args) < 1:
        parser.error('Please specify a project')
    if len(args) > 1:
        parser.error('Too many arguments')

    # Verify the project and calculate the hostname.
    name, = args
    if name.startswith('chromeos/'):
        host, port = constants.GERRIT_INT_HOST, constants.GERRIT_INT_PORT
    elif name.startswith('chromiumos/'):
        host, port = constants.GERRIT_HOST, constants.GERRIT_PORT
    else:
        parser.error('Project must be a chromeos/ or chromiumos/ project.')

    # If no parent was specified, search for a parent.
    if options.parent is None:
        options.parent = FindParent(host, port, name)

    cmd = ['ssh', host, '-p', port, 'gerrit', 'create-project', '--name', name]

    # --submit-type has to be in caps for gerrit to be happy; we do the
    # conversion on the user's behalf; same for converting '-' to '_'.
    options.submit_type = options.submit_type.upper().replace('-', '_')
    for option in parser.option_list:
        if option.dest and option.dest not in LOCAL_OPTIONS:
            val = getattr(options, option.dest)
            if val:
                cmd.append('--%s' % option.dest.replace('_', '-'))
                if isinstance(val, basestring):
                    cmd.append(val)

    print 'Command is:\n  %s' % ' '.join(map(repr, cmd))
    if not options.dry_run:
        cros_build_lib.RunCommand(cmd, shell=False)
        print 'Created %s' % (name, )
    return 0
    def _TestCmd(self, cmd, real_cmd, sp_kv=dict(), rc_kv=dict(), sudo=False):
        """Factor out common setup logic for testing RunCommand().

    Args:
      cmd: a string or an array of strings that will be passed to RunCommand.
      real_cmd: the real command we expect RunCommand to call (might be
          modified to have enter_chroot).
      sp_kv: key-value pairs passed to subprocess.Popen().
      rc_kv: key-value pairs passed to RunCommand().
      sudo: use SudoRunCommand() rather than RunCommand().
    """
        expected_result = cros_build_lib.CommandResult()
        expected_result.cmd = real_cmd
        expected_result.error = self.error
        expected_result.output = self.output
        expected_result.returncode = self.proc_mock.returncode

        arg_dict = dict()
        for attr in 'close_fds cwd env stdin stdout stderr shell'.split():
            if attr in sp_kv:
                arg_dict[attr] = sp_kv[attr]
            else:
                if attr == 'close_fds':
                    arg_dict[attr] = True
                elif attr == 'shell':
                    arg_dict[attr] = False
                else:
                    arg_dict[attr] = None

        with self._SetupPopen(real_cmd,
                              ignore_sigint=rc_kv.get('ignore_sigint'),
                              **sp_kv) as proc:
            proc.communicate(None).AndReturn((self.output, self.error))

        self.mox.ReplayAll()
        if sudo:
            actual_result = cros_build_lib.SudoRunCommand(cmd, **rc_kv)
        else:
            actual_result = cros_build_lib.RunCommand(cmd, **rc_kv)
        self.mox.VerifyAll()

        self._AssertCrEqual(expected_result, actual_result)
Example #14
0
def CreateValidationFiles(validationdir, crxdir, identifier):
  """Create validationfiles for all extensions in |crxdir|."""

  verified_files = []

  # Discover all extensions to be validated (but not JSON files).
  for directory, _, filenames in os.walk(os.path.join(crxdir, 'extensions')):

    # Make directory relative to output dir by removing crxdir and /.
    for filename in filenames:
      verified_files.append(os.path.join(directory[len(crxdir) + 1:],
                                         filename))

  validation_file = os.path.join(validationdir, '%s.validation' % identifier)

  osutils.SafeMakedirs(validationdir)
  cros_build_lib.RunCommand(['sha256sum'] + verified_files,
                            log_stdout_to_file=validation_file,
                            cwd=crxdir, print_cmd=False)
  logging.info('Hashes created.')
Example #15
0
    def _InstallBuildDependencies(self):
        # Calculate buildtime deps that are not runtime deps.
        raw_sysroot = cros_build_lib.GetSysroot(board=self.options.board)
        cmd = ['qdepends', '-q', '-C', self.options.package]
        output = cros_build_lib.RunCommand(cmd,
                                           extra_env={
                                               'ROOT': raw_sysroot
                                           },
                                           capture_output=True).output

        if output.count('\n') > 1:
            raise AssertionError(
                'Too many packages matched given package pattern')

        # qdepend outputs "package: deps", so only grab the deps.
        atoms = output.partition(':')[2].split()

        # Install the buildtime deps.
        if atoms:
            self._Emerge(*atoms)
Example #16
0
    def _GetPortageEnvVar(self, envvar, board):
        """Get a portage environment variable for the configuration's board.

    envvar: The environment variable to get. E.g. 'PORTAGE_BINHOST'.

    Returns:
      The value of the environment variable, as a string. If no such variable
      can be found, return the empty string.
    """
        cwd = os.path.join(self._build_root, 'src', 'scripts')
        if board:
            portageq = 'portageq-%s' % board
        else:
            portageq = 'portageq'
        binhost = cros_build_lib.RunCommand([portageq, 'envvar', envvar],
                                            cwd=cwd,
                                            redirect_stdout=True,
                                            enter_chroot=True,
                                            error_code_ok=True)
        return binhost.output.rstrip('\n')
Example #17
0
  def RemoteCommand(self, cmd):
    """Run a remote command in the VM.

    Args:
      cmd: command to run, of list type.
    """
    if not isinstance(cmd, list):
      raise VMError('cmd must be a list.')

    args = ['ssh', '-o', 'UserKnownHostsFile=/dev/null',
            '-o', 'StrictHostKeyChecking=no',
            '-i', remote_access.TEST_PRIVATE_KEY,
            '-p', str(self.ssh_port), 'root@localhost']
    args.extend(cmd)

    if not self.dry_run:
      return cros_build_lib.RunCommand(args, redirect_stdout=True,
                                       combine_stdout_stderr=True,
                                       log_output=True,
                                       error_code_ok=True)
Example #18
0
def CreateChroot(chroot_path,
                 sdk_tarball,
                 cache_dir,
                 nousepkg=False,
                 nogetbinpkg=False):
    """Creates a new chroot from a given SDK"""

    cmd = MAKE_CHROOT + [
        '--stage3_path', sdk_tarball, '--chroot', chroot_path, '--cache_dir',
        cache_dir
    ]
    if nousepkg:
        cmd.append('--nousepkg')
    elif nogetbinpkg:
        cmd.append('--nogetbinpkg')

    try:
        cros_build_lib.RunCommand(cmd, print_cmd=False)
    except cros_build_lib.RunCommandError:
        raise SystemExit('Running %r failed!' % cmd)
Example #19
0
def GrabRemotePackageIndex(binhost_url):
    """Grab the latest binary package database from the specified URL.

  Args:
    binhost_url: Base URL of remote packages (PORTAGE_BINHOST).

  Returns:
    A PackageIndex object, if the Packages file can be retrieved. If the
    packages file cannot be retrieved, then None is returned.
  """
    url = '%s/Packages' % binhost_url.rstrip('/')
    pkgindex = PackageIndex()
    if binhost_url.startswith('http'):
        try:
            f = _RetryUrlOpen(url)
        except urllib2.HTTPError as e:
            if e.code in HTTP_FORBIDDEN_CODES:
                cros_build_lib.PrintBuildbotStepWarnings()
                cros_build_lib.Error('Cannot GET %s: %s' % (url, str(e)))
                return None
            # Not found errors are normal if old prebuilts were cleaned out.
            if e.code in HTTP_NOT_FOUND_CODES:
                return None
            raise
    elif binhost_url.startswith('gs://'):
        cmd = [gs.GSUTIL_BIN, 'cat', url]
        try:
            output = cros_build_lib.RunCommand(cmd,
                                               redirect_stdout=True,
                                               print_cmd=False).output
        except cros_build_lib.RunCommandError as e:
            cros_build_lib.PrintBuildbotStepWarnings()
            cros_build_lib.Error('Cannot GET %s: %s' % (url, str(e)))
            return None
        f = cStringIO.StringIO(output)
    else:
        return None
    pkgindex.Read(f)
    pkgindex.header.setdefault('URI', binhost_url)
    f.close()
    return pkgindex
Example #20
0
    def testMD5SumAccessOK(self):
        gs_uri = 'gs://bucket/foo/bar/somefile'
        crc32c = 'c96fd51e'
        crc32c_64 = base64.b64encode(base64.b16decode(crc32c, casefold=True))
        md5_sum = 'b026324c6904b2a9cb4b88d6d61c81d1'
        md5_sum_64 = base64.b64encode(base64.b16decode(md5_sum, casefold=True))
        output = '\n'.join([
            '%s:' % gs_uri,
            '        Creation time:          Tue, 04 Mar 2014 19:55:26 GMT',
            '        Content-Language:       en',
            '        Content-Length:         2',
            '        Content-Type:           application/octet-stream',
            '        Hash (crc32c):          %s' % crc32c_64,
            '        Hash (md5):             %s' % md5_sum_64,
            '        ETag:                   CMi938jU+bwCEAE=',
            '        Generation:             1393962926989000',
            '        Metageneration:         1',
            '        ACL:            [',
            '  {',
            '    "entity": "project-owners-134157665460",',
            '    "projectTeam": {',
            '      "projectNumber": "134157665460",',
            '      "team": "owners"',
            '    },',
            '    "role": "OWNER"',
            '  }',
            ']',
        ])
        # Set up the test replay script.
        cmd = [self.gsutil, 'ls', '-L', gs_uri]
        cros_build_lib.RunCommand(cmd,
                                  redirect_stdout=True,
                                  redirect_stderr=True,
                                  error_code_ok=True).AndReturn(
                                      cros_test_lib.EasyAttr(output=output))
        self.mox.ReplayAll()

        # Run the test verification.
        result = gslib.MD5Sum(gs_uri)
        self.assertEqual(md5_sum, result)
        self.mox.VerifyAll()
Example #21
0
def EnterChroot(chroot_path, cache_dir, chrome_root, chrome_root_mount,
                additional_args):
    """Enters an existing SDK chroot"""
    cmd = ENTER_CHROOT + ['--chroot', chroot_path, '--cache_dir', cache_dir]
    if chrome_root:
        cmd.extend(['--chrome_root', chrome_root])
    if chrome_root_mount:
        cmd.extend(['--chrome_root_mount', chrome_root_mount])
    if len(additional_args) > 0:
        cmd.append('--')
        cmd.extend(additional_args)

    ret = cros_build_lib.RunCommand(cmd, print_cmd=False, error_code_ok=True)
    # If we were in interactive mode, ignore the exit code; it'll be whatever
    # they last ran w/in the chroot and won't matter to us one way or another.
    # Note this does allow chroot entrance to fail and be ignored during
    # interactive; this is however a rare case and the user will immediately
    # see it (nor will they be checking the exit code manually).
    if ret.returncode != 0 and additional_args:
        raise SystemExit('Running %r failed with exit code %i' %
                         (cmd, ret.returncode))
Example #22
0
  def _CreatePS1(board, version, chroot=None):
    """Returns PS1 string that sets commandline and xterm window caption.

    If a chroot path is set, then indicate we are using the sysroot from there
    instead of the stock sysroot by prepending an asterisk to the version.

    Args:
      board: The SDK board.
      version: The SDK version.
      chroot: The path to the chroot, if set.
    """
    current_ps1 = cros_build_lib.RunCommand(
        ['bash', '-l', '-c', 'echo "$PS1"'], print_cmd=False,
        capture_output=True).output.splitlines()
    if current_ps1:
      current_ps1 = current_ps1[-1]
    if not current_ps1:
      # Something went wrong, so use a fallback value.
      current_ps1 = r'\u@\h \w $ '
    ps1_prefix = ChromeSDKCommand._PS1Prefix(board, version, chroot)
    return '%s %s' % (ps1_prefix, current_ps1)
Example #23
0
    def VerifyImage(self, unittest, percent_required_to_pass=100, test=''):
        """Verifies an image using test_that with verification suite."""
        test_directory, _ = self.GetNextResultsPath('autotest_tests')
        if not test: test = self.verify_suite

        cmd = [
            'test_that', '--no-quickmerge',
            '--results_dir=%s' % test_directory, self.remote, test
        ]
        if self.ssh_private_key is not None:
            cmd.append('--ssh_private_key=%s' %
                       path_util.ToChrootPath(self.ssh_private_key))

        result = cros_build_lib.RunCommand(cmd,
                                           error_code_ok=True,
                                           enter_chroot=True,
                                           redirect_stdout=True,
                                           cwd=constants.CROSUTILS_DIR)

        return self.AssertEnoughTestsPassed(unittest, result.output,
                                            percent_required_to_pass)
  def testFileSize(self):
    gs_uri = '%s/%s' % (self.bucket_uri, 'some/file/path')

    # Set up the test replay script.
    cmd = [self.gsutil, '-d', 'stat', gs_uri]
    size = 96
    output = '\n'.join(['header: x-goog-generation: 1386322968237000',
                        'header: x-goog-metageneration: 1',
                        'header: x-goog-stored-content-encoding: identity',
                        'header: x-goog-stored-content-length: %d' % size,
                        'header: Content-Type: application/octet-stream'])

    cros_build_lib.RunCommand(
        cmd, redirect_stdout=True, redirect_stderr=True).AndReturn(
            cros_test_lib.EasyAttr(output=output))
    self.mox.ReplayAll()

    # Run the test verification.
    result = gslib.FileSize(gs_uri)
    self.assertEqual(size, result)
    self.mox.VerifyAll()
Example #25
0
    def RunAlertsDispatcher(self, db_credentials_dir, tree):
        """Submit alerts summary to Sheriff-o-Matic.

    Args:
      db_credentials_dir: Path to CIDB database credentials.
      tree: Sheriff-o-Matic tree to submit alerts to.
    """
        dispatcher_cmd = [
            os.path.join(self._build_root, 'chromite', 'scripts',
                         'som_alerts_dispatcher'), '--som_tree', tree
        ]
        if buildbucket_lib.GetServiceAccount(
                constants.CHROMEOS_SERVICE_ACCOUNT):
            # User the service account file if it exists.
            dispatcher_cmd.extend(
                ['--service_acct_json', constants.CHROMEOS_SERVICE_ACCOUNT])
        if tree != constants.SOM_TREE:
            dispatcher_cmd.append('--allow_experimental')
        dispatcher_cmd.append(db_credentials_dir)

        cros_build_lib.RunCommand(dispatcher_cmd)
Example #26
0
    def test012ApprovalTime(self):
        """Approval timestamp should be reset when a new patchset is created."""
        # Create a change.
        project = self.createProject('test013')
        helper = self._GetHelper()
        clone_path = self.cloneProject(project, 'p1')
        gpatch = self.createPatch(clone_path, project, msg='Init')
        helper.SetReview(gpatch.gerrit_number, labels={'Code-Review': '+2'})

        # Update the change.
        new_msg = 'New %s' % gpatch.commit_message
        cros_build_lib.RunCommand(['git', 'commit', '--amend', '-m', new_msg],
                                  cwd=clone_path,
                                  quiet=True)
        self.uploadChange(clone_path)
        gpatch2 = self._GetHelper().QuerySingleRecord(change=gpatch.change_id,
                                                      project=gpatch.project,
                                                      branch='master')
        self.assertNotEqual(gpatch2.approval_timestamp, 0)
        self.assertNotEqual(gpatch2.commit_timestamp, 0)
        self.assertEqual(gpatch2.approval_timestamp, gpatch2.commit_timestamp)
Example #27
0
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()
    return CompatId(arch, useflags, cflags_split)
Example #28
0
    def UpdateToolchain(self):
        """Updates the toolchain packages.

    This will install both the toolchains and the packages that are implicitly
    needed (gcc-libs, linux-headers).
    """
        cros_build_lib.RunCommand([
            os.path.join(constants.CROSUTILS_DIR, 'install_toolchain'),
            '--sysroot', self.path
        ])

        if not self.GetCachedField(_IMPLICIT_SYSROOT_DEPS):
            emerge = [
                os.path.join(constants.CHROMITE_BIN_DIR, 'parallel_emerge'),
                '--sysroot=%s' % self.path
            ]
            cros_build_lib.SudoRunCommand(emerge + [
                '--root-deps=rdeps', '--usepkg', '--getbinpkg', '--select',
                'gcc-libs', 'linux-headers'
            ])
            self.SetCachedField(_IMPLICIT_SYSROOT_DEPS, 'yes')
Example #29
0
def UpdateChromeEbuildAFDOFile(board, profiles):
    """Update chrome ebuild with the dictionary of {arch: afdo_file} pairs.

  Modifies the Chrome ebuild to set the appropriate AFDO file for each
  given architecture. Regenerates the associated Manifest file and
  commits the new ebuild and Manifest.

  Args:
    board: board we are building Chrome for.
    profiles: {arch: afdo_file} pairs to put into the ebuild.
              These are profiles from selected benchmarks.
  """
    # Find the Chrome ebuild file.
    equery_prog = 'equery'
    ebuild_prog = 'ebuild'
    if board:
        equery_prog += '-%s' % board
        ebuild_prog += '-%s' % board

    equery_cmd = [equery_prog, 'w', 'chromeos-chrome']
    ebuild_file = cros_build_lib.RunCommand(
        equery_cmd, enter_chroot=True, redirect_stdout=True).output.rstrip()

    # Patch the ebuild file with the names of the available afdo_files.
    PatchChromeEbuildAFDOFile(ebuild_file, profiles)

    # Also patch the 9999 ebuild. This is necessary because the uprev
    # process starts from the 9999 ebuild file and then compares to the
    # current version to see if the uprev is really necessary. We dont
    # want the names of the available afdo_files to show as differences.
    # It also allows developers to do USE=afdo_use when using the 9999
    # ebuild.
    ebuild_9999 = os.path.join(os.path.dirname(ebuild_file),
                               'chromeos-chrome-9999.ebuild')
    PatchChromeEbuildAFDOFile(ebuild_9999, profiles)

    UpdateManifest(ebuild_9999, ebuild_prog)

    ebuild_dir = path_util.FromChrootPath(os.path.dirname(ebuild_file))
    CommitIfChanged(ebuild_dir, 'Update profiles and manifests for Chrome.')
Example #30
0
    def testCreateArchive(self):
        """Test that we can correctly archive up hash values for the signer."""

        client = self.createStandardClient()

        tmp_dir = None
        hashes = ['Hash 1', 'Hash 2', 'Hash 3']

        try:
            with tempfile.NamedTemporaryFile() as archive_file:
                client._CreateArchive(archive_file.name, hashes,
                                      self.hash_names)

                # Make sure the archive file created exists
                self.assertExists(archive_file.name)

                tmp_dir = tempfile.mkdtemp()

                cmd = ['tar', '-xjf', archive_file.name]
                cros_build_lib.RunCommand(cmd,
                                          redirect_stdout=True,
                                          redirect_stderr=True,
                                          cwd=tmp_dir)

                # Check that the expected (and only the expected) contents are present
                extracted_file_names = os.listdir(tmp_dir)
                self.assertEquals(len(extracted_file_names),
                                  len(self.hash_names))
                for name in self.hash_names:
                    self.assertTrue(name in extracted_file_names)

                # Make sure each file has the expected contents
                for h, hash_name in zip(hashes, self.hash_names):
                    with open(os.path.join(tmp_dir, hash_name), 'r') as f:
                        self.assertEqual([h], f.readlines())

        finally:
            # Clean up at the end of the test
            if tmp_dir:
                shutil.rmtree(tmp_dir)