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")
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")
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))
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))
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))
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))
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))
def main(args): """The main end user cli command for juju users.""" parser = setup_parser( subcommands=SUBCOMMANDS, prog="juju", description="juju cloud orchestration admin") # 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)) else: # Otherwise, do be strict options = parser.parse_args(args) env_config = EnvironmentsConfig() env_config.load_or_write_sample() options.environments = env_config options.log = log setup_logging(options) options.command(options)