}
}
-void ActivePyModules::set_config(const std::string &module_name,
- const std::string &key, const boost::optional<std::string>& val)
+std::pair<int, std::string> ActivePyModules::set_config(
+ const std::string &module_name,
+ const std::string &key,
+ const boost::optional<std::string>& val)
{
- module_config.set_config(&monc, module_name, key, val);
+ return module_config.set_config(&monc, module_name, key, val);
}
std::map<std::string, std::string> ActivePyModules::get_services() const
bool get_config(const std::string &module_name,
const std::string &key, std::string *val) const;
- void set_config(const std::string &module_name,
+ std::pair<int, std::string> set_config(const std::string &module_name,
const std::string &key, const boost::optional<std::string> &val);
PyObject *get_typed_config(const std::string &module_name,
if (value) {
val = value;
}
- without_gil([&] {
- self->py_modules->set_config(module, key, val);
+ auto [ret, msg] = without_gil([&] {
+ return self->py_modules->set_config(module, key, val);
});
+ if (ret) {
+ PyErr_SetString(PyExc_ValueError, msg.c_str());
+ return nullptr;
+ }
Py_RETURN_NONE;
}
PyModuleConfig::~PyModuleConfig() = default;
-void PyModuleConfig::set_config(
+std::pair<int, std::string> PyModuleConfig::set_config(
MonClient *monc,
const std::string &module_name,
const std::string &key, const boost::optional<std::string>& val)
} else {
config.erase(global_key);
}
+ return {0, ""};
} else {
if (val) {
dout(0) << "`config set mgr " << global_key << " " << val << "` failed: "
<< cpp_strerror(set_cmd.r) << dendl;
}
dout(0) << "mon returned " << set_cmd.r << ": " << set_cmd.outs << dendl;
+ return {set_cmd.r, set_cmd.outs};
}
}
~PyModuleConfig();
- void set_config(
+ std::pair<int, std::string> set_config(
MonClient *monc,
const std::string &module_name,
const std::string &key, const boost::optional<std::string>& val);
:param str key:
:type val: str | None
+ :raises ValueError: if `val` cannot be parsed or it is out of the specified range
"""
self._validate_module_option(key)
return self._set_module_option(key, val)
{'name': 'rwoption3', 'type': 'float'},
{'name': 'rwoption4', 'type': 'str'},
{'name': 'rwoption5', 'type': 'bool'},
- {'name': 'rwoption6', 'type': 'bool', 'default': True}
+ {'name': 'rwoption6', 'type': 'bool', 'default': True},
+ {'name': 'rwoption7', 'type': 'int', 'min': 1, 'max': 42},
]
COMMANDS = [
assert isinstance(value, bool)
assert value is False
+ # Option value range is specified
+ try:
+ self.set_module_option("rwoption7", 43)
+ except Exception as e:
+ assert isinstance(e, ValueError)
+ else:
+ message = "should raise if value is not in specified range"
+ assert False, message
+
# Specified module does not exist => return None.
assert self.get_module_option_ex("foo", "bar") is None