def __init__(self, dmd, instance): HubService.__init__(self, dmd, instance) self.config = self.dmd.Monitors.Performance._getOb(self.instance) self.methodPriorityMap = { 'sendEvent': 0.0, 'sendEvents': 0.0, }
def __init__(self, dmd, instance, deviceProxyAttributes=()): """ Constructs a new CollectorConfig instance. Subclasses must call this __init__ method but cannot do so with the super() since parents of this class are not new-style classes. @param dmd: the Zenoss DMD reference @param instance: the collector instance name @param deviceProxyAttributes: a tuple of names for device attributes that should be copied to every device proxy created @type deviceProxyAttributes: tuple """ HubService.__init__(self, dmd, instance) self._deviceProxyAttributes = BASE_ATTRIBUTES + deviceProxyAttributes # Get the collector information (eg the 'localhost' collector) self._prefs = self.dmd.Monitors.Performance._getOb(self.instance) self.config = self._prefs # TODO fix me, needed for ThresholdMixin self.configFilter = None # When about to notify daemons about device changes, wait for a little # bit to batch up operations. self._procrastinator = Procrastinate(self._pushConfig) self._reconfigProcrastinator = Procrastinate(self._pushReconfigure) self._notifier = component.getUtility(IBatchNotifier)
def __init__(self, dmd, instance, deviceProxyAttributes=()): """ Constructs a new CollectorConfig instance. Subclasses must call this __init__ method but cannot do so with the super() since parents of this class are not new-style classes. @param dmd: the Zenoss DMD reference @param instance: the collector instance name @param deviceProxyAttributes: a tuple of names for device attributes that should be copied to every device proxy created @type deviceProxyAttributes: tuple """ HubService.__init__(self, dmd, instance) self._deviceProxyAttributes = BASE_ATTRIBUTES + deviceProxyAttributes # Get the collector information (eg the 'localhost' collector) self._prefs = self.dmd.Monitors.Performance._getOb(self.instance) self.config = self._prefs # TODO fix me, needed for ThresholdMixin # When about to notify daemons about device changes, wait for a little # bit to batch up operations. self._procrastinator = Procrastinate(self._pushConfig) self._reconfigProcrastinator = Procrastinate(self._pushReconfigure) self._notifier = component.getUtility(IBatchNotifier)
def __init__(self, dmd, instance): """ Create the service (Called by the hub) param dmd: root db node type instance: string param instance: Perf Monitor (Collector) name for this service """ HubService.__init__(self, dmd, instance) self.log.debug('__init__():initializing AppEngineConfigService') self.config = self.dmd.Monitors.Performance._getOb(self.instance)
def update(self, object): """ This is overridden to forward changes in the AppEngine connection information to the daemons param object: the hook that is called when objects are changed in ZODB """ from Products.ZenModel.DeviceClass import DeviceClass if isinstance(object, DeviceClass): if hasattr( object, 'zAppEngineInstanceApplication') and \ object.__primary_parent__.id == 'AppEngine': procrastinator = Procrastinate( self.updateEndpointConfiguration) procrastinator.doLater(object.id) HubService.update(self, object)
def __init__(self, dmd, instance): HubService.__init__(self, dmd, instance) self.config = self.dmd.Monitors.Performance._getOb(self.instance) self.procrastinator = Procrastinate(self.pushConfig) self._collectorMap = {} self._notifier = component.getUtility(IBatchNotifier)
def __init__(self, dmd, instance): HubService.__init__(self, dmd, instance) self.config = self.dmd.Monitors.Performance._getOb(self.instance)
def setUp(self): self.dmd = Mock(name='dmd') self.instance = Mock(name='instance') self.hub_service = HubService(self.dmd, self.instance)
class TestHubService(TestCase): def setUp(self): self.dmd = Mock(name='dmd') self.instance = Mock(name='instance') self.hub_service = HubService(self.dmd, self.instance) def test_init(self): self.assertIsInstance(self.hub_service, pb.Referenceable) # Validate attributes created by __init__ self.assertEqual(self.hub_service.log, logging.getLogger('zen.hub')) self.assertEqual(self.hub_service.fqdn, socket.getfqdn()) self.assertEqual(self.hub_service.dmd, self.dmd) self.assertEqual(self.hub_service.zem, self.dmd.ZenEventManager) self.assertEqual(self.hub_service.instance, self.instance) self.assertEqual(self.hub_service.listeners, []) self.assertEqual(self.hub_service.listenerOptions, {}) self.assertEqual(self.hub_service.callTime, 0) def test_getPerformanceMonitor(self): out = self.hub_service.getPerformanceMonitor() self.dmd.Monitors.getPerformanceMonitor.assert_called_with( self.instance) self.assertEqual(out, self.dmd.Monitors.getPerformanceMonitor.return_value) @patch( '{HubService}.pb.Referenceable.remoteMessageReceived'.format(**PATH), autospec=True, spec_set=True) @patch('{HubService}.time.time'.format(**PATH), autospec=True, spec_set=True) def test_remoteMessageReceived(self, time, remoteMessageReceived): Broker = Mock(name='pb.Broker') broker = Broker() message = 'message' args = [] kw = {} times = [3, 5] time.side_effect = times out = self.hub_service.remoteMessageReceived(broker, message, args, kw) pb.Referenceable.remoteMessageReceived.assert_called_with( self.hub_service, broker, message, args, kw) self.assertEqual(out, pb.Referenceable.remoteMessageReceived.return_value) self.assertEqual(self.hub_service.callTime, times[1] - times[0]) def test_update_is_deprecated(self): self.hub_service.update('object') # Deprecated function with no output or side-effects def test_deleted_is_deprecated(self): self.hub_service.deleted('object') # Deprecated function with no output or side-effects def test_name(self): out = self.hub_service.name() self.assertEqual(out, self.hub_service.__class__.__name__) def test_addListener(self): remote = Mock(name='remote') options = Mock(name='options') self.hub_service.addListener(remote, options=options) remote.notifyOnDisconnect.assert_called_with( self.hub_service.removeListener) self.assertIn(remote, self.hub_service.listeners) self.assertEqual(self.hub_service.listenerOptions[remote], options) def test_removeListener(self): listener = Mock(name='listener') options = Mock(name='options') self.hub_service.listeners = [listener] self.hub_service.listenerOptions[listener] = options self.hub_service.removeListener(listener) self.assertNotIn(listener, self.hub_service.listeners) self.assertNotIn(listener, self.hub_service.listenerOptions.keys()) def test_sendEvents(self): events = ['evt1', 'evt2', 'evt3'] self.hub_service.sendEvent = create_autospec( self.hub_service.sendEvent, name='HubService.sendEvent') self.hub_service.sendEvents(events) self.hub_service.sendEvent.assert_has_calls([call(x) for x in events]) @patch('Products.ZenEvents.Event.Event', autospec=True, spec_set=True) def test_sendEvent(self, Event): # This should accept an Products.ZenEvents.Event.Event object, but # currently only accepts a dict, which is converted to an Event later event = {} kw = {'kwarg_a': 'kwarg_1', 'kwarg_b': 'kwarg_2'} self.hub_service.sendEvent(event, **kw) sent_event = { 'agent': 'zenhub', 'monitor': self.hub_service.instance, 'manager': self.hub_service.fqdn, 'kwarg_a': kw['kwarg_a'], 'kwarg_b': kw['kwarg_b'], } self.hub_service.zem.sendEvent.assert_called_with(sent_event)
class TestHubService(TestCase): def setUp(self): self.dmd = Mock(name='dmd') self.instance = Mock(name='instance') self.hub_service = HubService(self.dmd, self.instance) def test_init(self): self.assertIsInstance(self.hub_service, pb.Referenceable) # Validate attributes created by __init__ self.assertEqual(self.hub_service.log, logging.getLogger('zen.hub')) self.assertEqual(self.hub_service.fqdn, socket.getfqdn()) self.assertEqual(self.hub_service.dmd, self.dmd) self.assertEqual(self.hub_service.zem, self.dmd.ZenEventManager) self.assertEqual(self.hub_service.instance, self.instance) self.assertEqual(self.hub_service.listeners, []) self.assertEqual(self.hub_service.listenerOptions, {}) self.assertEqual(self.hub_service.callTime, 0) def test_getPerformanceMonitor(self): out = self.hub_service.getPerformanceMonitor() self.dmd.Monitors.getPerformanceMonitor.assert_called_with( self.instance ) self.assertEqual( out, self.dmd.Monitors.getPerformanceMonitor.return_value ) @patch( '{HubService}.pb.Referenceable.remoteMessageReceived'.format(**PATH), autospec=True, spec_set=True ) @patch( '{HubService}.time.time'.format(**PATH), autospec=True, spec_set=True ) def test_remoteMessageReceived(self, time, remoteMessageReceived): Broker = Mock(name='pb.Broker') broker = Broker() message = 'message' args = [] kw = {} times = [3, 5] time.side_effect = times out = self.hub_service.remoteMessageReceived(broker, message, args, kw) pb.Referenceable.remoteMessageReceived.assert_called_with( self.hub_service, broker, message, args, kw ) self.assertEqual( out, pb.Referenceable.remoteMessageReceived.return_value ) self.assertEqual( self.hub_service.callTime, times[1] - times[0] ) def test_update_is_deprecated(self): self.hub_service.update('object') # Deprecated function with no output or side-effects def test_deleted_is_deprecated(self): self.hub_service.deleted('object') # Deprecated function with no output or side-effects def test_name(self): out = self.hub_service.name() self.assertEqual(out, self.hub_service.__class__.__name__) def test_addListener(self): remote = Mock(name='remote') options = Mock(name='options') self.hub_service.addListener(remote, options=options) remote.notifyOnDisconnect.assert_called_with( self.hub_service.removeListener ) self.assertIn(remote, self.hub_service.listeners) self.assertEqual(self.hub_service.listenerOptions[remote], options) def test_removeListener(self): listener = Mock(name='listener') options = Mock(name='options') self.hub_service.listeners = [listener] self.hub_service.listenerOptions[listener] = options self.hub_service.removeListener(listener) self.assertNotIn(listener, self.hub_service.listeners) self.assertNotIn(listener, self.hub_service.listenerOptions.keys()) def test_sendEvents(self): events = ['evt1', 'evt2', 'evt3'] self.hub_service.sendEvent = create_autospec( self.hub_service.sendEvent, name='HubService.sendEvent' ) self.hub_service.sendEvents(events) self.hub_service.sendEvent.assert_has_calls([call(x) for x in events]) @patch('Products.ZenEvents.Event.Event', autospec=True, spec_set=True) def test_sendEvent(self, Event): # This should accept an Products.ZenEvents.Event.Event object, but # currently only accepts a dict, which is converted to an Event later event = {} kw = {'kwarg_a': 'kwarg_1', 'kwarg_b': 'kwarg_2'} self.hub_service.sendEvent(event, **kw) sent_event = { 'agent': 'zenhub', 'monitor': self.hub_service.instance, 'manager': self.hub_service.fqdn, 'kwarg_a': kw['kwarg_a'], 'kwarg_b': kw['kwarg_b'], } self.hub_service.zem.sendEvent.assert_called_with(sent_event)