def config_set(environment, service_name, service_options): """Set service settings. """ provider = environment.get_machine_provider() client = yield provider.connect() # Get the service and the charm service_manager = ServiceStateManager(client) service = yield service_manager.get_service_state(service_name) charm = yield service.get_charm_state() # Use the charm's ConfigOptions instance to validate the # arguments to config_set. Invalid options passed to this method # will thrown an exception. if isinstance(service_options, dict): options = service_options else: options = parse_keyvalue_pairs(service_options) config = yield charm.get_config() # ignore the output of validate, we run it so it might throw an exception config.validate(options) # Apply the change state = yield service.get_config() state.update(options) yield state.write()
def config_set(environment, service_name, service_options): """Set service options. """ provider = environment.get_machine_provider() client = yield provider.connect() # Get the service and the charm # service_manager = ServiceStateManager(client) service = yield service_manager.get_service_state(service_name) charm = yield service.get_charm_state() # Use the charm's ConfigOptions instance to validate the # arguments to config_set. Invalid options passed to this method # will thrown an exception. options = parse_keyvalue_pairs(service_options) config = yield charm.get_config() # ignore the output of validate, we run it so it might throw an exception config.validate(options) # Apply the change state = yield service.get_config() state.update(options) yield state.write()
def test_parse_keyvalue_pairs(self): sample = self.makeFile("INPUT DATA") # test various styles of options being read options = ["alpha=beta", "content=@%s" % sample] data = parse_keyvalue_pairs(options) self.assertEquals(data["alpha"], "beta") self.assertEquals(data["content"], "INPUT DATA") # and check an error condition options = ["content=@missing"] error = self.assertRaises(JujuError, parse_keyvalue_pairs, options) self.assertEquals( str(error), "No such file or directory: missing (argument:content)") # and check when fed non-kvpairs the error makes sense options = ["foobar"] error = self.assertRaises(JujuError, parse_keyvalue_pairs, options) self.assertEquals(str(error), "Expected `option=value`. Found `foobar`")
def test_parse_keyvalue_pairs(self): sample = self.makeFile("INPUT DATA") # test various styles of options being read options = ["alpha=beta", "content=@%s" % sample] data = parse_keyvalue_pairs(options) self.assertEquals(data["alpha"], "beta") self.assertEquals(data["content"], "INPUT DATA") # and check an error condition options = ["content=@missing"] error = self.assertRaises(JujuError, parse_keyvalue_pairs, options) self.assertEquals( str(error), "No such file or directory: missing (argument:content)") # and check when fed non-kvpairs the error makes sense options = ["foobar"] error = self.assertRaises(JujuError, parse_keyvalue_pairs, options) self.assertEquals( str(error), "Expected `option=value`. Found `foobar`")