Check the namespaces duplication for ceilometer-polling
This change add validation for the namespaces duplication when launch a ceilometer-polling service with duplicated namespaces specified by --polling-namespaces option. Change-Id: Iacd80b77bda4ae16d0307ebed6aa9903204c94d2 Closes-Bug: #1428476
This commit is contained in:
parent
0ca53a61a4
commit
b795b755ae
@ -17,16 +17,20 @@
|
||||
from oslo_config import cfg
|
||||
|
||||
from ceilometer.agent import manager
|
||||
from ceilometer.i18n import _LW
|
||||
from ceilometer.openstack.common import log
|
||||
from ceilometer.openstack.common import service as os_service
|
||||
from ceilometer import service
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class MultiChoicesOpt(cfg.Opt):
|
||||
def __init__(self, name, choices=None, **kwargs):
|
||||
super(MultiChoicesOpt, self).__init__(name,
|
||||
type=cfg.types.List(),
|
||||
type=DeduplicatedCfgList(),
|
||||
**kwargs)
|
||||
self.choices = choices
|
||||
|
||||
@ -39,6 +43,17 @@ class MultiChoicesOpt(cfg.Opt):
|
||||
kwargs['choices'] = choices
|
||||
return kwargs
|
||||
|
||||
|
||||
class DeduplicatedCfgList(cfg.types.List):
|
||||
def __call__(self, *args, **kwargs):
|
||||
result = super(DeduplicatedCfgList, self).__call__(*args, **kwargs)
|
||||
if len(result) != len(set(result)):
|
||||
LOG.warning(_LW("Duplicated values: %s found in CLI options, "
|
||||
"auto de-duplidated"), result)
|
||||
result = list(set(result))
|
||||
return result
|
||||
|
||||
|
||||
CLI_OPTS = [
|
||||
MultiChoicesOpt('polling-namespaces',
|
||||
default=['compute', 'central'],
|
||||
|
@ -211,3 +211,33 @@ class BinApiTestCase(base.BaseTestCase):
|
||||
response, content = self.get_response('v2/meters')
|
||||
self.assertEqual(200, response.status)
|
||||
self.assertEqual([], json.loads(content))
|
||||
|
||||
|
||||
class BinCeilometerPollingServiceTestCase(base.BaseTestCase):
|
||||
def setUp(self):
|
||||
super(BinCeilometerPollingServiceTestCase, self).setUp()
|
||||
content = ("[DEFAULT]\n"
|
||||
"rpc_backend=fake\n"
|
||||
"[database]\n"
|
||||
"connection=log://localhost\n")
|
||||
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",
|
||||
"compute",
|
||||
"compute"],
|
||||
stderr=subprocess.PIPE)
|
||||
out = self.subp.stderr.read(1024)
|
||||
self.assertIn('Duplicated values: [\'compute\', \'compute\'] '
|
||||
'found in CLI options, auto de-duplidated', out)
|
||||
|
Loading…
Reference in New Issue
Block a user