예제 #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())
예제 #2
0
 def get_config(self):
     try:
         content, stat = yield self._client.get("/environment")
     except zookeeper.NoNodeException:
         raise EnvironmentStateNotFound()
     config = EnvironmentsConfig()
     config.parse(content)
     returnValue(config)
예제 #3
0
 def get_config(self):
     try:
         content, stat = yield self._client.get("/environment")
     except zookeeper.NoNodeException:
         raise EnvironmentStateNotFound()
     config = EnvironmentsConfig()
     config.parse(content)
     returnValue(config)
예제 #4
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")
예제 #5
0
 def test_load_serialized_environment(self):
     """
     Serialize an environment, and then load it again
     via an EnvironmentsConfig.
     """
     self.write_config(SAMPLE_ENV)
     self.config.load()
     serialized = self.config.serialize("myfirstenv")
     config = EnvironmentsConfig()
     config.parse(serialized)
     self.assertTrue(
         isinstance(config.get("myfirstenv"), Environment))
     self.assertFalse(
         isinstance(config.get("mysecondenv"), Environment))
예제 #6
0
 def get_serialized_environment(self):
     config = EnvironmentsConfig()
     config.parse(SAMPLE_ENV)
     return config.serialize("myfirstenv")
예제 #7
0
 def get_test_environment_config(self):
     sample_config = SAMPLE_ENV % self.makeDir()
     config = EnvironmentsConfig()
     config.parse(sample_config)
     return config
예제 #8
0
파일: test_charm.py 프로젝트: mcclurmc/juju
 def get_test_environment_config(self):
     sample_config = SAMPLE_ENV % self.makeDir()
     config = EnvironmentsConfig()
     config.parse(sample_config)
     return config
예제 #9
0
 def get_serialized_environment(self):
     config = EnvironmentsConfig()
     config.parse(SAMPLE_ENV)
     return config.serialize("myfirstenv")