예제 #1
0
    def startPoller(self):
        "Start the poller"

        self._startTime = time.time()
        self._plugin_number = 0

        # Poller enable ?
        if not self._enable:
            self._logger.warning(
                "Poller disable, configuration enable = false")
            exit(2)
        # Test du dernier poller
        if not self.pollerTimeToGo():
            return False

        if not self._myInfo_hostID:
            self._logger.warning(
                "Poller disable, configuration host_id = None")
            exit(2)

        # load cache for DERIVE and store and forward message
        with CacheLastValue(cache_file='/dev/shm/numeter_poller_cache.json',
                               logger='numeter') as self._cache, \
             StoreAndForward(cache_file='/dev/shm/numeter_poller_storeandforward.json',
                               logger='numeter') as self._store_and_forward:
            self.loadModules()

        # End log time execution
        self._logger.warning("---- End : numeter_poller, " +
                             str(self._plugin_number) + " Plugins in " +
                             str(time.time() - self._startTime) + ", seconds.")
예제 #2
0
class CacheLastValueTestCase(test_base.TestCase):

    def setUp(self):
        super(CacheLastValueTestCase, self).setUp()
        self.cache = CacheLastValue()

    def tearDown(self):
        super(CacheLastValueTestCase, self).tearDown()

    def test_dump_cache(self):
        # dump need write _cache default {}
        with mock.patch('__builtin__.open', mock.mock_open(), create=True) as file_mock:
            handle = file_mock()
            self.cache._dump_cache()
            handle.write.assert_called_once_with('{}')

    def test_load_cache(self):
        # load cache from file
        with mock.patch('__builtin__.open', mock.mock_open(), create=True) as file_mock:
            file_mock.return_value.read.return_value = '{"foo": "bar"}'
            self.cache._load_cache()
            self.assertEquals(self.cache._cache, {'foo':'bar'})

    def test_save_value(self):
        # save value
        key = 'foo'; timestamp = '000000000'; value = 42;
        self.cache.save_value(key, timestamp, value)
        self.assertEquals(self.cache._cache, {key: {'timestamp': timestamp,
                                                    'value': value}})

    def test_get_value(self):
        self.cache._cache = {'foo': 'bar'}
        result = self.cache.get_value('foo')
        self.assertEquals(result, 'bar')
예제 #3
0
class CacheLastValueTestCase(test_base.TestCase):
    def setUp(self):
        super(CacheLastValueTestCase, self).setUp()
        self.cache = CacheLastValue()

    def tearDown(self):
        super(CacheLastValueTestCase, self).tearDown()

    def test_dump_cache(self):
        # dump need write _cache default {}
        with mock.patch('__builtin__.open', mock.mock_open(),
                        create=True) as file_mock:
            handle = file_mock()
            self.cache._dump_cache()
            handle.write.assert_called_once_with('{}')

    def test_load_cache(self):
        # load cache from file
        with mock.patch('__builtin__.open', mock.mock_open(),
                        create=True) as file_mock:
            file_mock.return_value.read.return_value = '{"foo": "bar"}'
            self.cache._load_cache()
            self.assertEquals(self.cache._cache, {'foo': 'bar'})

    def test_save_value(self):
        # save value
        key = 'foo'
        timestamp = '000000000'
        value = 42
        self.cache.save_value(key, timestamp, value)
        self.assertEquals(self.cache._cache,
                          {key: {
                              'timestamp': timestamp,
                              'value': value
                          }})

    def test_get_value(self):
        self.cache._cache = {'foo': 'bar'}
        result = self.cache.get_value('foo')
        self.assertEquals(result, 'bar')
예제 #4
0
 def setUp(self):
     super(CacheLastValueTestCase, self).setUp()
     self.cache = CacheLastValue()
예제 #5
0
 def setUp(self):
     super(CacheLastValueTestCase, self).setUp()
     self.cache = CacheLastValue()