コード例 #1
0
  def testRun(self):
    """Basic test of the 'run' command."""
    audio_dst_path = os.path.join(self.tempdir, 'dst', 'audio_file')

    replication_config = ReplicationConfig(file_replication_rules=[
        FileReplicationRule(
            source_path=self.audio_path,
            destination_path=audio_dst_path,
            file_type=FILE_TYPE_OTHER,
            replication_type=REPLICATION_TYPE_COPY,
        ),
    ])

    replication_config_path = os.path.join(self.tempdir,
                                           'replication_config.jsonpb')
    osutils.WriteFile(replication_config_path,
                      json_format.MessageToJson(replication_config))

    replication_util.main(['run', replication_config_path])

    expected_file_layout = (
        D('src', ['audio_file']),
        D('dst', ['audio_file']),
        'replication_config.jsonpb',
    )

    cros_test_lib.VerifyOnDiskHierarchy(self.tempdir, expected_file_layout)

    self.assertFileContents(audio_dst_path, '[Speaker A Settings]')
コード例 #2
0
    def testReplicateDestinationExists(self):
        """Test existing files are overwritten."""
        file_layout = (D('dst', ['audio_file']), )
        cros_test_lib.CreateOnDiskHierarchy(self.tempdir, file_layout)

        audio_dst_path = os.path.join('dst', 'audio_file')
        self.WriteTempFile(audio_dst_path, 'Original audio data')

        replication_config = ReplicationConfig(file_replication_rules=[
            FileReplicationRule(
                source_path=self.audio_path,
                destination_path=audio_dst_path,
                file_type=FILE_TYPE_OTHER,
                replication_type=REPLICATION_TYPE_COPY,
            ),
        ])

        replication_lib.Replicate(replication_config)

        expected_file_layout = (
            D('src', ['build_config.json', 'audio_file', 'firmware.bin']),
            D('dst', ['audio_file']),
        )

        cros_test_lib.VerifyOnDiskHierarchy(self.tempdir, expected_file_layout)

        self.assertTempFileContents(audio_dst_path, '[Speaker A Settings]')
コード例 #3
0
    def testReplicate(self):
        """Test basic Replication functionality.

    - destination_fields used to filter JSON payload.
    - firmware.bin not copied.
    """
        build_config_dst_path = os.path.join(self.tempdir, 'dst',
                                             'build_config.json')
        audio_dst_path = os.path.join(self.tempdir, 'dst', 'audio_file')

        replication_config = ReplicationConfig(file_replication_rules=[
            FileReplicationRule(source_path=self.build_config_path,
                                destination_path=build_config_dst_path,
                                file_type=FILE_TYPE_JSON,
                                replication_type=REPLICATION_TYPE_FILTER,
                                destination_fields=FieldMask(
                                    paths=['name', 'field2'])),
            FileReplicationRule(
                source_path=self.audio_path,
                destination_path=audio_dst_path,
                file_type=FILE_TYPE_OTHER,
                replication_type=REPLICATION_TYPE_COPY,
            ),
        ])

        replication_lib.Replicate(replication_config)

        expected_file_layout = (
            D('src', ['build_config.json', 'audio_file', 'firmware.bin']),
            D('dst', ['build_config.json', 'audio_file']),
        )

        cros_test_lib.VerifyOnDiskHierarchy(self.tempdir, expected_file_layout)

        build_config_dst = json.loads(osutils.ReadFile(build_config_dst_path))
        expected_build_config_dst = {
            'chromeos': {
                'configs': [
                    {
                        'name': 'A',
                        'field2': 2,
                    },
                    {
                        'name': 'B',
                        'field2': 4,
                    },
                ]
            }
        }
        self.assertDictEqual(expected_build_config_dst, build_config_dst)

        self.assertFileContents(audio_dst_path, '[Speaker A Settings]')
コード例 #4
0
    def _CopyAndVerify(self,
                       path,
                       src_struct,
                       dest_struct,
                       error=None,
                       strict=False,
                       sloppy=False):
        cros_test_lib.CreateOnDiskHierarchy(self.src_base, src_struct)
        if error:
            self.assertRaises(error, path.Copy, self.src_base, self.dest_base,
                              None, strict, sloppy)
            return

        path.Copy(self.src_base, self.dest_base, self.copier, strict, sloppy)
        cros_test_lib.VerifyOnDiskHierarchy(self.dest_base, dest_struct)