示例#1
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)
示例#2
0
    def test_get_environment(self):
        config = {
            "environments": {"firstenv": {"type": "dummy"}}}
        self.write_config(dump(config))

        env_config = EnvironmentsConfig()
        env_config.load_or_write_sample()
        options = FakeOptions()
        options.environment = None
        options.environments = env_config

        environment = get_environment(options)
        self.assertEqual(environment.name, "firstenv")
示例#3
0
    def test_get_nonexistant_environment(self):
        config = {
            "environments": {"firstenv": {"type": "dummy"},
                             "secondenv": {"type": "dummy"}}}
        self.write_config(dump(config))

        env_config = EnvironmentsConfig()
        env_config.load_or_write_sample()
        options = FakeOptions()
        options.environment = "volcano"
        options.environments = env_config

        error = self.assertRaises(
            EnvironmentsConfigError,
            get_environment,
            options)

        self.assertIn("Invalid environment 'volcano'", str(error))
示例#4
0
    def test_get_environment_default_with_multiple(self):
        config = {
            "environments": {"firstenv": {"type": "dummy"},
                             "secondenv": {"type": "dummy"}}}
        self.write_config(dump(config))

        env_config = EnvironmentsConfig()
        env_config.load_or_write_sample()
        options = FakeOptions()
        options.environment = None
        options.environments = env_config

        error = self.assertRaises(
            EnvironmentsConfigError,
            get_environment,
            options)

        self.assertIn(
            "There are multiple environments and no explicit default",
            str(error))
示例#5
0
文件: __init__.py 项目: mcclurmc/juju
def main(args):
    """The main end user cli command for juju users."""
    env_config = EnvironmentsConfig()
    env_config.load_or_write_sample()
    parser = setup_parser(
        subcommands=SUBCOMMANDS,
        prog="juju",
        description="juju cloud orchestration admin")
    parser.set_defaults(environments=env_config, log=log)

    # Some commands, like juju ssh, do a further parse on options by
    # delegating to another command (such as the underlying ssh). But
    # first need to parse nonstrictly all args to even determine what
    # command is even being used.
    options, extra = parser.parse_known_args(args)
    if options.command.passthrough:
        try:
            # Augments options with subparser specific passthrough parsing
            options.command.passthrough(options, extra)
        except ParseError, e:
            options.parser.error(str(e))
示例#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