Make interval optional in pipeline

Make interval in pipeline yaml file optional. If interval is not
provided, a default value should be given.

Change-Id: I557e66902c272331bd1e2c72d03d495f0924d573
Closes-Bug: #1423957
This commit is contained in:
leizhang 2015-05-04 16:05:16 +08:00
parent 9f76e5b580
commit e27b11ae74
2 changed files with 10 additions and 5 deletions

View File

@ -278,15 +278,16 @@ class SampleSource(Source):
def __init__(self, cfg):
super(SampleSource, self).__init__(cfg)
try:
try:
self.interval = int(cfg['interval'])
except ValueError:
raise PipelineException("Invalid interval value", cfg)
# Support 'counters' for backward compatibility
self.meters = cfg.get('meters', cfg.get('counters'))
except KeyError as err:
raise PipelineException(
"Required field %s not specified" % err.args[0], cfg)
try:
self.interval = int(cfg.get('interval', 600))
except ValueError:
raise PipelineException("Invalid interval value", cfg)
if self.interval <= 0:
raise PipelineException("Interval value should > 0", cfg)

View File

@ -210,7 +210,11 @@ class BasePipelineTestCase(base.BaseTestCase):
def test_no_interval(self):
self._unset_pipeline_cfg('interval')
self._exception_create_pipelinemanager()
pipeline_manager = pipeline.PipelineManager(self.pipeline_cfg,
self.transformer_manager)
pipe = pipeline_manager.pipelines[0]
self.assertEqual(600, pipe.get_interval())
def test_no_publishers(self):
self._unset_pipeline_cfg('publishers')