예제 #1
0
    def test_replicate_private_config_multiple_build_configs(self):
        """An error is thrown if there is more than one build config."""
        replication_config = ReplicationConfig(file_replication_rules=[
            FileReplicationRule(source_path=self.private_config_path,
                                destination_path=self.public_config_path,
                                file_type=FILE_TYPE_JSON,
                                replication_type=REPLICATION_TYPE_FILTER,
                                destination_fields=FieldMask(paths=['a'])),
            FileReplicationRule(source_path=self.private_config_path,
                                destination_path=self.public_config_path,
                                file_type=FILE_TYPE_JSON,
                                replication_type=REPLICATION_TYPE_FILTER,
                                destination_fields=FieldMask(paths=['a']))
        ])

        osutils.WriteFile(self.replication_config_path,
                          json_format.MessageToJson(replication_config))

        refs = [
            GitRef(path='/chromeos/overlays/overlay-coral-private',
                   ref='master',
                   revision='123')
        ]
        with self.assertRaisesRegex(
                ValueError,
                'Expected at most one build_config.json destination path.'):
            packages.replicate_private_config(_build_targets=None,
                                              refs=refs,
                                              chroot=Chroot())
예제 #2
0
    def test_replicate_private_config_no_build_config(self):
        """If there is no build config, don't generate C files."""
        # Modify the replication config to write to "other_config.json" instead of
        # "build_config.json"
        modified_destination_path = self.public_config_path.replace(
            'build_config', 'other_config')
        replication_config = ReplicationConfig(file_replication_rules=[
            FileReplicationRule(source_path=self.private_config_path,
                                destination_path=modified_destination_path,
                                file_type=FILE_TYPE_JSON,
                                replication_type=REPLICATION_TYPE_FILTER,
                                destination_fields=FieldMask(paths=['a']))
        ])
        osutils.WriteFile(self.replication_config_path,
                          json_format.MessageToJson(replication_config))

        refs = [
            GitRef(path='/chromeos/overlays/overlay-coral-private',
                   ref='master',
                   revision='123')
        ]
        result = packages.replicate_private_config(_build_targets=None,
                                                   refs=refs,
                                                   chroot=Chroot())

        self.assertEqual(len(result.modified), 1)
        self.assertEqual(
            result.modified[0].files,
            [os.path.join(self.tempdir, modified_destination_path)])
예제 #3
0
    def test_uprev_ebuild(self):
        """Tests uprev of ebuild with version path"""
        file_layout = (D(self.package,
                         [self.ebuild, self.unstable_ebuild, self.manifest]), )
        cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout)

        package_path = os.path.join(self.tempdir, self.package)

        ebuild_path = os.path.join(package_path, self.ebuild)
        self.WriteTempFile(ebuild_path, 'KEYWORDS="*"\n')

        result = packages.uprev_ebuild_from_pin(package_path,
                                                self.new_version,
                                                chroot=Chroot())
        self.assertEqual(
            len(result.modified), 1,
            'unexpected number of results: %s' % len(result.modified))

        mod = result.modified[0]
        self.assertEqual(mod.new_version, self.new_version + '-r1',
                         'unexpected version number: %s' % mod.new_version)

        old_ebuild_path = os.path.join(package_path,
                                       self.ebuild_template % self.version)
        new_ebuild_path = os.path.join(package_path,
                                       self.ebuild_template % self.new_version)
        manifest_path = os.path.join(package_path, 'Manifest')

        expected_modified_files = [
            old_ebuild_path, new_ebuild_path, manifest_path
        ]
        self.assertCountEqual(mod.files, expected_modified_files)

        self.assertCommandContains(['ebuild', 'manifest'])
예제 #4
0
    def testSuccess(self):
        """Test successful handling case."""
        path = '/chroot/path'
        cache_dir = '/cache/dir'
        chrome_root = '/chrome/root'
        use_flags = [{'flag': 'useflag1'}, {'flag': 'useflag2'}]
        features = [{'feature': 'feature1'}, {'feature': 'feature2'}]
        expected_env = {
            'USE': 'useflag1 useflag2',
            'FEATURES': 'feature1 feature2',
            'CHROME_ORIGIN': 'LOCAL_SOURCE'
        }

        chroot_message = common_pb2.Chroot(path=path,
                                           cache_dir=cache_dir,
                                           chrome_dir=chrome_root,
                                           env={
                                               'use_flags': use_flags,
                                               'features': features
                                           })

        expected = Chroot(path=path,
                          cache_dir=cache_dir,
                          chrome_root=chrome_root,
                          env=expected_env)
        result = controller_util.ParseChroot(chroot_message)

        self.assertEqual(expected, result)
예제 #5
0
  def test_calls_function(self):
    """Test calling a registered function."""
    patch = self.PatchObject(self, 'uprev_category_package')

    cpv = portage_util.SplitCPV('category/package', strict=False)
    packages.uprev_versioned_package(cpv, [], [], Chroot())

    patch.assert_called()
예제 #6
0
    def test_replicate_private_config(self):
        """Basic replication test."""
        refs = [
            GitRef(path='/chromeos/overlays/overlay-coral-private',
                   ref='master',
                   revision='123')
        ]
        chroot = Chroot()
        result = packages.replicate_private_config(_build_targets=None,
                                                   refs=refs,
                                                   chroot=chroot)

        self.assertCommandContains([
            'cros_config_schema', '-m',
            os.path.join(constants.CHROOT_SOURCE_ROOT,
                         self.public_config_path), '-g',
            os.path.join(constants.CHROOT_SOURCE_ROOT,
                         self.public_package_root, 'files'), '-f', '"TRUE"'
        ],
                                   enter_chroot=True,
                                   chroot_args=chroot.get_enter_args())

        self.assertEqual(len(result.modified), 1)
        # The public build_config.json and generated C files were modified.
        expected_modified_files = [
            os.path.join(self.tempdir, self.public_config_path),
            os.path.join(self.tempdir, self.public_package_root, 'files',
                         'config.c'),
            os.path.join(self.tempdir, self.public_package_root, 'files',
                         'ec_config.c'),
            os.path.join(self.tempdir, self.public_package_root, 'files',
                         'ec_config.h'),
        ]
        self.assertEqual(result.modified[0].files, expected_modified_files)
        self.assertEqual(result.modified[0].new_version, '123')

        # The update from the private build_config.json was copied to the public.
        # Note that only the 'a' field is present, as per destination_fields.
        self.assertEqual(
            json.loads(self.ReadTempFile(self.public_config_path)),
            {'chromeos': {
                'configs': [{
                    'a': 3
                }]
            }})
    def test_clean_stale_packages_chroot_not_exists(self):
        """Cannot run the commands when the chroot does not exist."""
        chroot = Chroot()
        self.PatchObject(chroot, 'exists', return_value=False)
        manager = uprev_lib.UprevOverlayManager([], None, chroot=chroot)
        self.PatchObject(parallel, 'RunTasksInProcessPool')

        # pylint: disable=protected-access
        manager._clean_stale_packages()
예제 #8
0
    def test_no_ebuild(self):
        """Tests assertion is raised if package has no ebuilds"""
        file_layout = (D(self.package, [self.manifest]), )
        cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout)

        package_path = os.path.join(self.tempdir, self.package)

        with self.assertRaises(packages.UprevError):
            packages.uprev_ebuild_from_pin(package_path,
                                           self.new_version,
                                           chroot=Chroot())
예제 #9
0
  def test_no_uprev(self):
    """Test no uprev handling."""
    self.PatchObject(packages, '_parse_android_atom', return_value=None)
    build_targets = [build_target_util.BuildTarget(t) for t in ['foo', 'bar']]
    packages.uprev_android('refs/tracking-branch', 'android/package',
                           'refs/android-build-branch', Chroot(),
                           build_targets=build_targets)

    self.assertCommandContains(['cros_mark_android_as_stable',
                                '--boards=foo:bar'])
    self.assertCommandContains(['emerge-foo'], expected=False)
    self.assertCommandContains(['emerge-bar'], expected=False)
예제 #10
0
    def test_clean_stale_packages_no_build_targets(self):
        """Make sure it behaves as expected with no build targets provided."""
        chroot = Chroot()
        self.PatchObject(chroot, 'exists', return_value=True)
        manager = uprev_lib.UprevOverlayManager([], None, chroot=chroot)
        patch = self.PatchObject(parallel, 'RunTasksInProcessPool')

        # pylint: disable=protected-access
        manager._clean_stale_packages()

        # Make sure we aren't doing any work.
        patch.assert_called_once_with(mock.ANY, [[None]])
예제 #11
0
 def setUp(self):
     self.board = 'test-board'
     # Create cheets-fingerprints.txt based on tempdir/src...
     self.fingerprint_contents = (
         'google/test-board/test-board_cheets'
         ':9/R99-12345.0.9999/123456:user/release-keys')
     fingerprint_path = os.path.join(
         self.tempdir,
         'src/build/images/test-board/latest/cheets-fingerprint.txt')
     self.chroot = Chroot(self.tempdir)
     osutils.WriteFile(fingerprint_path,
                       self.fingerprint_contents,
                       makedirs=True)
예제 #12
0
    def test_multiple_unstable_ebuilds(self):
        """Tests assertion is raised if multiple unstable ebuilds are present"""
        file_layout = (D(
            self.package,
            [self.ebuild, self.ebuild_template % '1.2.1', self.manifest]), )
        cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout)

        package_path = os.path.join(self.tempdir, self.package)

        with self.assertRaises(packages.UprevError):
            packages.uprev_ebuild_from_pin(package_path,
                                           self.new_version,
                                           chroot=Chroot())
예제 #13
0
def clean_stale_packages(new_package_atoms, build_targets, chroot=None):
    """Cleans up stale package info from a previous build."""
    if new_package_atoms:
        logging.info('Cleaning up stale packages %s.', new_package_atoms)

    chroot = chroot or Chroot()

    if cros_build_lib.IsOutsideChroot() and not chroot.exists():
        logging.warning('Unable to clean packages. No chroot to enter.')
        return

    # First unmerge all the packages for a board, then eclean it.
    # We need these two steps to run in order (unmerge/eclean),
    # but we can let all the boards run in parallel.
    def _do_clean_stale_packages(board):
        if board:
            suffix = '-' + board
            runcmd = cros_build_lib.run
        else:
            suffix = ''
            runcmd = cros_build_lib.sudo_run

        if cros_build_lib.IsOutsideChroot():
            # Setup runcmd with the chroot arguments once.
            runcmd = functools.partial(runcmd,
                                       enter_chroot=True,
                                       chroot_args=chroot.get_enter_args())

        emerge, eclean = 'emerge' + suffix, 'eclean' + suffix
        if not osutils.FindMissingBinaries([emerge, eclean]):
            if new_package_atoms:
                # If nothing was found to be unmerged, emerge will exit(1).
                result = runcmd([emerge, '-q', '--unmerge'] +
                                new_package_atoms,
                                extra_env={'CLEAN_DELAY': '0'},
                                check=False,
                                cwd=constants.SOURCE_ROOT)
                if result.returncode not in (0, 1):
                    raise cros_build_lib.RunCommandError(
                        'unexpected error', result)

            runcmd([eclean, '-d', 'packages'],
                   cwd=constants.SOURCE_ROOT,
                   capture_output=True)

    tasks = []
    for build_target in build_targets:
        tasks.append([build_target.name])
    tasks.append([None])

    parallel.RunTasksInProcessPool(_do_clean_stale_packages, tasks)
예제 #14
0
  def test_success(self):
    """Test successful run handling."""
    self.PatchObject(packages, '_parse_android_atom',
                     return_value='ANDROID_ATOM=android/android-1.0')

    build_targets = [build_target_util.BuildTarget(t) for t in ['foo', 'bar']]

    packages.uprev_android('refs/tracking-branch', 'android/package',
                           'refs/android-build-branch', Chroot(),
                           build_targets=build_targets)
    self.assertCommandContains(['cros_mark_android_as_stable',
                                '--boards=foo:bar'])
    self.assertCommandContains(['emerge-foo'])
    self.assertCommandContains(['emerge-bar'])
예제 #15
0
    def test_clean_stale_packages_with_boards(self):
        """Test it cleans all boards as well as the chroot."""
        targets = ['board1', 'board2']
        build_targets = [BuildTarget(t) for t in targets]
        chroot = Chroot()
        self.PatchObject(chroot, 'exists', return_value=True)
        manager = uprev_lib.UprevOverlayManager([],
                                                None,
                                                chroot=chroot,
                                                build_targets=build_targets)
        patch = self.PatchObject(parallel, 'RunTasksInProcessPool')

        # pylint: disable=protected-access
        manager._clean_stale_packages()

        patch.assert_called_once_with(mock.ANY,
                                      [[t] for t in targets + [None]])
예제 #16
0
    def test_no_uprev(self):
        """Test no uprev handling."""
        self.rc.AddCmdResult(partial_mock.In('cros_mark_android_as_stable'),
                             stdout='')
        build_targets = [
            build_target_lib.BuildTarget(t) for t in ['foo', 'bar']
        ]
        packages.uprev_android('refs/tracking-branch',
                               'android/package',
                               'refs/android-build-branch',
                               Chroot(),
                               build_targets=build_targets)

        self.assertCommandContains(
            ['cros_mark_android_as_stable', '--boards=foo:bar'])
        self.assertCommandContains(['emerge-foo'], expected=False)
        self.assertCommandContains(['emerge-bar'], expected=False)
예제 #17
0
    def test_replicate_private_config_generated_files_incorrect(self):
        """An error is thrown if generated C files are missing."""
        self.rc.SetDefaultCmdResult(
            side_effect=self._write_incorrect_generated_c_files)

        refs = [
            GitRef(path='/chromeos/overlays/overlay-coral-private',
                   ref='master',
                   revision='123')
        ]
        chroot = Chroot()

        with self.assertRaisesRegex(packages.GeneratedCrosConfigFilesError,
                                    'Expected to find generated C files'):
            packages.replicate_private_config(_build_targets=None,
                                              refs=refs,
                                              chroot=chroot)
예제 #18
0
    def test_success(self):
        """Test successful run handling."""
        self.rc.AddCmdResult(partial_mock.In('cros_mark_android_as_stable'),
                             stdout='ANDROID_ATOM=android/android-1.0\n')
        build_targets = [
            build_target_lib.BuildTarget(t) for t in ['foo', 'bar']
        ]

        packages.uprev_android('refs/tracking-branch',
                               'android/package',
                               'refs/android-build-branch',
                               Chroot(),
                               build_targets=build_targets)
        self.assertCommandContains(
            ['cros_mark_android_as_stable', '--boards=foo:bar'])
        self.assertCommandContains(['emerge-foo'])
        self.assertCommandContains(['emerge-bar'])
def ParseChroot(chroot_message):
  """Create a chroot object from the chroot message.

  Args:
    chroot_message (common_pb2.Chroot): The chroot message.

  Returns:
    Chroot: The parsed chroot object.

  Raises:
    AssertionError: When the message is not a Chroot message.
  """
  assert isinstance(chroot_message, common_pb2.Chroot)

  path = chroot_message.path or constants.DEFAULT_CHROOT_PATH
  cache_dir = chroot_message.cache_dir
  chrome_root = chroot_message.chrome_dir

  use_flags = [u.flag for u in chroot_message.env.use_flags]
  features = [f.feature for f in chroot_message.env.features]

  env = {}
  if use_flags:
    env['USE'] = ' '.join(use_flags)

  # Make sure it'll use the local source to build chrome when we have it.
  if chrome_root:
    env['CHROME_ORIGIN'] = 'LOCAL_SOURCE'

  if features:
    env['FEATURES'] = ' '.join(features)

  chroot = Chroot(
      path=path, cache_dir=cache_dir, chrome_root=chrome_root, env=env)

  return chroot
예제 #20
0
    def test_unregistered_package(self):
        """Test calling with an unregistered package."""
        cpv = package_info.SplitCPV('does-not/exist', strict=False)

        with self.assertRaises(packages.UnknownPackageError):
            packages.uprev_versioned_package(cpv, [], [], Chroot())