diff options
author | ZhiQiang Fan <aji.zqfan@gmail.com> | 2016-02-26 03:40:13 +0800 |
---|---|---|
committer | ZhiQiang Fan <aji.zqfan@gmail.com> | 2016-03-07 20:15:09 +0800 |
commit | 55afd4fa763f62e75fb00e0622df9862811365b8 (patch) | |
tree | 1e622fd335ef8d0be6e69971c0ed35b7a2651f2b /ceilometer/cmd | |
parent | ec4848b9f0db227fdd03afd7e711d4c50d4af1fd (diff) | |
download | ceilometer-55afd4fa763f62e75fb00e0622df9862811365b8.tar.gz |
Add validation for polling_namespaces option
We find that if polling_namespaces is specified by config file
instead of in command line args, the validation doesn't work at all,
which cause the agent still running but in a wrong state.
This patch fixes it.
Change-Id: I34a268da18549961eb1a3ccd862def5145725cd5
Closes-Bug: #1553013
Diffstat (limited to 'ceilometer/cmd')
-rw-r--r-- | ceilometer/cmd/polling.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/ceilometer/cmd/polling.py b/ceilometer/cmd/polling.py index 1055711e..e4bb583f 100644 --- a/ceilometer/cmd/polling.py +++ b/ceilometer/cmd/polling.py @@ -29,9 +29,8 @@ CONF = cfg.CONF class MultiChoicesOpt(cfg.Opt): def __init__(self, name, choices=None, **kwargs): - super(MultiChoicesOpt, self).__init__(name, - type=DeduplicatedCfgList(), - **kwargs) + super(MultiChoicesOpt, self).__init__( + name, type=DeduplicatedCfgList(choices), **kwargs) self.choices = choices def _get_argparse_kwargs(self, group, **kwargs): @@ -45,12 +44,20 @@ class MultiChoicesOpt(cfg.Opt): class DeduplicatedCfgList(cfg.types.List): + def __init__(self, choices=None, **kwargs): + super(DeduplicatedCfgList, self).__init__(**kwargs) + self.choices = choices or [] + def __call__(self, *args, **kwargs): result = super(DeduplicatedCfgList, self).__call__(*args, **kwargs) - if len(result) != len(set(result)): + result_set = set(result) + if len(result) != len(result_set): LOG.warning(_LW("Duplicated values: %s found in CLI options, " - "auto de-duplidated"), result) - result = list(set(result)) + "auto de-duplicated"), result) + result = list(result_set) + if self.choices and not (result_set <= set(self.choices)): + raise Exception('Valid values are %s, but found %s' + % (self.choices, result)) return result |