Exemplo n.º 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())
Exemplo n.º 2
0
 def test_replicate_private_config_wrong_git_ref_path(self):
     """An error is thrown if the git ref doesn't point to a private overlay."""
     with self.assertRaisesRegex(ValueError,
                                 'ref.path must match the pattern'):
         refs = [GitRef(path='a/b/c', ref='master', revision='123')]
         packages.replicate_private_config(_build_targets=None,
                                           refs=refs,
                                           chroot=None)
Exemplo n.º 3
0
 def test_replicate_private_config_replication_config_missing(self):
   """An error is thrown if there is not a replication config."""
   os.remove(self.replication_config_path)
   with self.assertRaisesRegex(
       ValueError, 'Expected ReplicationConfig missing at %s' %
       self.replication_config_path):
     refs = [
         GitRef(path='overlay-coral-private', ref='master', revision='123')
     ]
     packages.replicate_private_config(
         _build_targets=None, refs=refs, _chroot=None)
Exemplo n.º 4
0
  def test_replicate_private_config_wrong_number_of_refs(self):
    """An error is thrown if there is not exactly one ref."""
    with self.assertRaisesRegex(ValueError, 'Expected exactly one ref'):
      packages.replicate_private_config(
          _build_targets=None, refs=[], _chroot=None)

    with self.assertRaisesRegex(ValueError, 'Expected exactly one ref'):
      refs = [
          GitRef(path='a', ref='master', revision='1'),
          GitRef(path='a', ref='master', revision='2')
      ]
      packages.replicate_private_config(
          _build_targets=None, refs=refs, _chroot=None)
Exemplo n.º 5
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)])
Exemplo n.º 6
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)
Exemplo n.º 7
0
  def test_replicate_private_config(self):
    """Basic replication test."""
    refs = [GitRef(path='overlay-coral-private', ref='master', revision='123')]
    result = packages.replicate_private_config(
        _build_targets=None, refs=refs, _chroot=None)

    self.assertEqual(len(result.modified), 1)
    # The public build_config.json was modified.
    self.assertEqual(result.modified[0].files, [self.public_config_path])
    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.
    with open(self.public_config_path, 'r') as f:
      self.assertEqual(json.load(f), {'chromeos': {'configs': [{'a': 3}]}})
Exemplo n.º 8
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
                }]
            }})