Ejemplo n.º 1
0
    def configure_environment(self):
        """The provisioning agent configure its environment on start or change.

        The environment contains the configuration th agent needs to interact
        with its machine provider, in order to do its work. This configuration
        data is deployed lazily over an encrypted connection upon first usage.

        The agent waits for this data to exist before completing its startup.
        """
        try:
            get_d, watch_d = self.client.get_and_watch("/environment")
            environment_data, stat = yield get_d
            watch_d.addCallback(self._on_environment_changed)
        except NoNodeException:
            # Wait till the environment node appears. play twisted gymnastics
            exists_d, watch_d = self.client.exists_and_watch("/environment")
            stat = yield exists_d
            if stat:
                environment = yield self.configure_environment()
            else:
                watch_d.addCallback(
                    lambda result: self.configure_environment())
            if not stat:
                environment = yield watch_d
            returnValue(environment)

        config = EnvironmentsConfig()
        config.parse(environment_data)
        returnValue(config.get_default())
Ejemplo n.º 2
0
    def test_serialize_custom_variables_outside_environment(self):
        """Serializing captures custom variables out of the environment."""
        data = yaml.load(SAMPLE_ENV)
        data["default"] = "myfirstenv"
        self.write_config(yaml.dump(data))
        self.config.load()
        serialized = self.config.serialize()

        config = EnvironmentsConfig()
        config.parse(serialized)
        environment = config.get_default()
        self.assertEqual(environment.name, "myfirstenv")