summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhiQiang Fan <aji.zqfan@gmail.com>2016-02-26 03:40:13 +0800
committergordon chung <gord@live.ca>2016-03-23 18:18:41 +0000
commit098ae2805a7692a59643db5253cfc398bff7e243 (patch)
treeb290b3c48b89781f245fa9bb5d7f6f99d8ed18ff
parent9404e73f6c24bc72e25ead7338ce536bb7d86346 (diff)
downloadceilometer-098ae2805a7692a59643db5253cfc398bff7e243.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 (cherry picked from commit 55afd4fa763f62e75fb00e0622df9862811365b8)
-rw-r--r--ceilometer/cmd/eventlet/polling.py19
-rw-r--r--ceilometer/tests/functional/test_bin.py43
2 files changed, 46 insertions, 16 deletions
diff --git a/ceilometer/cmd/eventlet/polling.py b/ceilometer/cmd/eventlet/polling.py
index 1055711e..e4bb583f 100644
--- a/ceilometer/cmd/eventlet/polling.py
+++ b/ceilometer/cmd/eventlet/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
diff --git a/ceilometer/tests/functional/test_bin.py b/ceilometer/tests/functional/test_bin.py
index 817c0e52..3f365aa8 100644
--- a/ceilometer/tests/functional/test_bin.py
+++ b/ceilometer/tests/functional/test_bin.py
@@ -269,6 +269,19 @@ class BinApiTestCase(base.BaseTestCase):
class BinCeilometerPollingServiceTestCase(base.BaseTestCase):
def setUp(self):
super(BinCeilometerPollingServiceTestCase, self).setUp()
+ self.tempfile = None
+ self.subp = None
+
+ def tearDown(self):
+ if self.subp:
+ try:
+ self.subp.kill()
+ except OSError:
+ pass
+ os.remove(self.tempfile)
+ super(BinCeilometerPollingServiceTestCase, self).tearDown()
+
+ def test_starting_with_duplication_namespaces(self):
content = ("[DEFAULT]\n"
"rpc_backend=fake\n"
"[database]\n"
@@ -278,15 +291,6 @@ class BinCeilometerPollingServiceTestCase(base.BaseTestCase):
self.tempfile = fileutils.write_to_tempfile(content=content,
prefix='ceilometer',
suffix='.conf')
- self.subp = None
-
- def tearDown(self):
- super(BinCeilometerPollingServiceTestCase, self).tearDown()
- if self.subp:
- self.subp.kill()
- os.remove(self.tempfile)
-
- def test_starting_with_duplication_namespaces(self):
self.subp = subprocess.Popen(['ceilometer-polling',
"--config-file=%s" % self.tempfile,
"--polling-namespaces",
@@ -295,4 +299,23 @@ class BinCeilometerPollingServiceTestCase(base.BaseTestCase):
stderr=subprocess.PIPE)
out = self.subp.stderr.read(1024)
self.assertIn(b'Duplicated values: [\'compute\', \'compute\'] '
- b'found in CLI options, auto de-duplidated', out)
+ b'found in CLI options, auto de-duplicated', out)
+
+ def test_polling_namespaces_invalid_value_in_config(self):
+ content = ("[DEFAULT]\n"
+ "rpc_backend=fake\n"
+ "polling_namespaces = ['central']\n"
+ "[database]\n"
+ "connection=log://localhost\n")
+ if six.PY3:
+ content = content.encode('utf-8')
+ self.tempfile = fileutils.write_to_tempfile(content=content,
+ prefix='ceilometer',
+ suffix='.conf')
+ self.subp = subprocess.Popen(
+ ["ceilometer-polling", "--config-file=%s" % self.tempfile],
+ stderr=subprocess.PIPE)
+ __, err = self.subp.communicate()
+ expected = ("Exception: Valid values are ['compute', 'central', "
+ "'ipmi'], but found [\"['central']\"]")
+ self.assertIn(expected, err)