Ejemplo n.º 1
0
def GetClientConfig(filename):
    """Write client config to filename."""
    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()
    context = list(grr_config.CONFIG.context)
    context.append("Client Context")
    deployer = build.ClientRepacker()
    # Disable timestamping so we can get a reproducible and cachable config file.
    config_data = deployer.GetClientConfig(context,
                                           validate=True,
                                           deploy_timestamp=False)
    builder = build.ClientBuilder()
    with open(filename, "w") as fd:
        fd.write(config_data)
        builder.WriteBuildYaml(fd, build_timestamp=False)
Ejemplo n.º 2
0
    def testWriteBuildYaml(self):
        """Test build.yaml is output correctly."""
        context = [
            "Target:LinuxDeb", "Platform:Linux", "Target:Linux", "Arch:amd64"
        ]
        expected = {
            "Client.build_environment":
            "cp27-cp27mu-linux_x86_64",
            "Client.build_time":
            "2016-05-24 20:04:25",
            "Template.build_type":
            "Release",
            "Template.build_context": ["ClientBuilder Context"] + context,
            "Template.version_major":
            str(config.CONFIG.Get("Source.version_major")),
            "Template.version_minor":
            str(config.CONFIG.Get("Source.version_minor")),
            "Template.version_revision":
            str(config.CONFIG.Get("Source.version_revision")),
            "Template.version_release":
            str(config.CONFIG.Get("Source.version_release")),
            "Template.arch":
            u"amd64"
        }

        # TODO(hanuszczak): YAML, consider using `StringIO` instead.
        fd = io.BytesIO()
        builder = build.ClientBuilder(context=context)

        with mock.patch.object(rdf_client.Uname, "FromCurrentSystem") as fcs:
            fcs.return_value.signature.return_value = "cp27-cp27mu-linux_x86_64"
            with test_lib.FakeTime(1464120265):
                builder.WriteBuildYaml(fd)

        fd.seek(0)
        self.assertEqual(yaml.Parse(fd.getvalue().decode("utf-8")), expected)