def test___dumpStats(t): ZenHub._ZenHub__dumpStats(t.zh) t.zh._service_manager.getStatusReport.assert_called_once_with() t.zh.log.info.assert_called_once_with( "\n%s\n", t.zh._service_manager.getStatusReport.return_value ) t.zh._service_manager.reportWorkerStatus.assert_called_once_with()
def test_sighandler_USR2(t, _notify, _ReportWorkerStatus): ZenHub.sighandler_USR2(t.zh, signum="unused", frame="unused") t.zh._status_reporter.getReport.assert_called_once_with() t.zh.log.info.assert_called_once_with( "\n%s\n", t.zh._status_reporter.getReport.return_value, ) _notify.assert_called_once_with(_ReportWorkerStatus.return_value) _ReportWorkerStatus.assert_called_once_with()
def test_sighandler_USR1(t, signal, _super): t.zh.profiler = Mock(name='profiler', spec_set=['dump_stats']) t.zh.options = Mock(name='options', profiling=True) signum = sentinel.signum frame = sentinel.frame ZenHub.sighandler_USR1(t.zh, signum=signum, frame=frame) t.zh.profiler.dump_stats.assert_called_with() _super.assert_called_with(ZenHub, t.zh) _super.return_value.sighandler_USR1.assert_called_with(signum, frame)
def test_sighandler_USR1(t, signal, super): '''Daemon function when signal USR1 is recieved, broadcast it to all worker processes ''' t.zh.profiler = Mock(name='profiler', spec_set=['dump_stats']) t.zh.options = Mock(name='options', profiling=True) signum = sentinel.signum frame = sentinel.frame ZenHub.sighandler_USR1(t.zh, signum=signum, frame=frame) t.zh.profiler.dump_stats.assert_called_with() super.assert_called_with(ZenHub, t.zh) super.return_value.sighandler_USR1.assert_called_with( signum, frame )
def setUp(t): # Patch out the ZenHub __init__ method, due to excessive side-effects t.init_patcher = patch.object( ZCmdBase, '__init__', autospec=True, return_value=None, ) t.init_patcher.start() t.addCleanup(t.init_patcher.stop) # Mock out attributes set by ZCmdBase t.zcmdbase_patchers = [ patch.object(ZenHub, 'dmd', create=True), patch.object(ZenHub, 'log', create=True), patch.object(ZenHub, 'options', create=True), patch.object(ZenHub, 'niceDoggie', create=True), patch.object( ZenHub, 'storage', create=True, set_spec=['poll_invalidations'], ), ] for patcher in t.zcmdbase_patchers: patcher.start() t.addCleanup(patcher.stop) # Patch external dependencies needs_patching = [ "reactor", "XmlRpcManager", "make_server_factory", "getCredentialCheckers", "make_service_manager", "make_pools", "ZenHubStatusReporter", "StatsMonitor", "InvalidationManager", "MetricManager", "notify", "ContinuousProfiler", "load_config_override", "load_config", "IHubConfProvider", "provideUtility", "register_legacy_worklist_metrics", ] t.patchers = {} for target in needs_patching: patched = patch( "{src}.{target}".format(target=target, **PATH), autospec=True, ) t.patchers[target] = patched setattr(t, target, patched.start()) t.addCleanup(patched.stop) t.zh = ZenHub()
class TestZenHub(BaseTestCase): layer = ZenossTestCaseLayer base = 7000 xbase = 8000 def afterSetUp(self): super(TestZenHub, self).afterSetUp() global count count += 1 base = self.base + count xbase = self.xbase + count self.before, sys.argv = sys.argv, [ 'run', '--pbport=%d' % base, '--xmlrpcport=%d' % xbase, '--workers=0' ] self.zenhub = ZenHub() from zope.component import getGlobalSiteManager # The call to zenhub above overrides the queue so we need to # re-override it gsm = getGlobalSiteManager() queue = DummyQueuePublisher() gsm.registerUtility(queue, IQueuePublisher) def beforeTearDown(self): sys.argv = self.before super(TestZenHub, self).beforeTearDown() def testPbRegistration(self): from twisted.spread.jelly import unjellyableRegistry self.assertTrue(unjellyableRegistry.has_key('DataMaps.ObjectMap')) self.assertTrue( unjellyableRegistry.has_key( 'Products.DataCollector.plugins.DataMaps.ObjectMap')) def testGetService(self): client = TestClient(self, self.base + count) self.zenhub.main() self.assertTrue(client.success) def testSendEvent(self): client = SendEventClient(self, self.base + count) self.zenhub.main() self.assertTrue(client.success)
def afterSetUp(self): super(TestZenHub, self).afterSetUp() global count count += 1 base = self.base + count xbase = self.xbase + count self.before, sys.argv = sys.argv, [ 'run', '--pbport=%d' % base, '--xmlrpcport=%d' % xbase, '--workers=0' ] self.zenhub = ZenHub() from zope.component import getGlobalSiteManager # The call to zenhub above overrides the queue so we need to # re-override it gsm = getGlobalSiteManager() queue = DummyQueuePublisher() gsm.registerUtility(queue, IQueuePublisher)
class TestZenHub(BaseTestCase): layer = ZenossTestCaseLayer base = 7000 xbase = 8000 def afterSetUp(self): super(TestZenHub, self).afterSetUp() global count count += 1 base = self.base + count xbase = self.xbase + count self.before, sys.argv = sys.argv, ['run', '--pbport=%d' % base, '--xmlrpcport=%d' % xbase, '--workers=0'] self.zenhub = ZenHub() from zope.component import getGlobalSiteManager # The call to zenhub above overrides the queue so we need to # re-override it gsm = getGlobalSiteManager() queue = DummyQueuePublisher() gsm.registerUtility(queue, IQueuePublisher) def beforeTearDown(self): sys.argv = self.before super(TestZenHub, self).beforeTearDown() def testPbRegistration(self): from twisted.spread.jelly import unjellyableRegistry self.assertTrue(unjellyableRegistry.has_key('DataMaps.ObjectMap')) self.assertTrue(unjellyableRegistry.has_key('Products.DataCollector.plugins.DataMaps.ObjectMap')) def testGetService(self): client = TestClient(self, self.base + count) self.zenhub.main() self.assertTrue(client.success) def testSendEvent(self): client = SendEventClient(self, self.base + count) self.zenhub.main() self.assertTrue(client.success)
def afterSetUp(self): super(TestZenHub, self).afterSetUp() global count count += 1 base = self.base + count xbase = self.xbase + count self.before, sys.argv = sys.argv, ['run', '--pbport=%d' % base, '--xmlrpcport=%d' % xbase, '--workers=0'] self.zenhub = ZenHub() from zope.component import getGlobalSiteManager # The call to zenhub above overrides the queue so we need to # re-override it gsm = getGlobalSiteManager() queue = DummyQueuePublisher() gsm.registerUtility(queue, IQueuePublisher)
def test_sighandler_USR2(t, reactor): '''Daemon function when signal USR2 is recieved, broadcast it to all worker processes ''' ZenHub.sighandler_USR2(t.zh, signum='unused', frame='unused') reactor.callLater.assert_called_once_with(0, t.zh._ZenHub__dumpStats)
def test___init__( t, _super, load_config, notify, HubWillBeCreatedEvent, ContinuousProfiler, reactor, zenPath, HubCreatedEvent, App_Start, signal, load_config_override, XmlRpcManager, make_server_factory, getCredentialCheckers, make_service_manager, make_pools, ZenHubStatusReporter, StatsMonitor, MetricManager, InvalidationManager, provideUtility, register_legacy_worklist_metrics, ): # Mock out attributes set by the parent class # Because these changes are made on the class, they must be reversable t.zenhub_patchers = [ patch.object(ZenHub, 'dmd', create=True), patch.object(ZenHub, 'log', create=True), patch.object(ZenHub, 'options', create=True), patch.object(ZenHub, 'getRRDStats', autospec=True), patch.object(ZenHub, '_getConf', autospec=True), patch.object(ZenHub, 'sendEvent', autospec=True), patch.object(ZenHub, 'storage', create=True), ] for patcher in t.zenhub_patchers: patcher.start() t.addCleanup(patcher.stop) ZenHub._getConf.return_value.id = 'config_id' ZenHub.storage.mock_add_spec(['poll_invalidations']) zh = ZenHub() t.assertIsInstance(zh, ZenHub) # Skip Metrology validation for now due to complexity _super.return_value.__init__assert_called_with(ZenHub, zh) load_config.assert_called_with("hub.zcml", ZENHUB_MODULE) HubWillBeCreatedEvent.assert_called_with(zh) notify.assert_has_calls([call(HubWillBeCreatedEvent.return_value)]) # Performance Profiling ContinuousProfiler.assert_called_with('zenhub', log=zh.log) zh.profiler.start.assert_called_with() # 'counters' is a ZenHub API. t.assertIs(zh.counters, StatsMonitor.return_value.counters) t.assertIsInstance(zh.shutdown, bool) t.assertFalse(zh.shutdown) t.assertIs(zh._monitor, StatsMonitor.return_value) t.assertIs(zh._status_reporter, ZenHubStatusReporter.return_value) t.assertIs(zh._pools, make_pools.return_value) t.assertIs(zh._service_manager, make_service_manager.return_value) t.assertIs(zh._server_factory, make_server_factory.return_value) t.assertIs(zh._xmlrpc_manager, XmlRpcManager.return_value) register_legacy_worklist_metrics.assert_called_once_with() # Event Handler shortcut t.assertEqual(zh.zem, zh.dmd.ZenEventManager) # Messageing config, including work and invalidations # Patched internal import of Products.ZenMessaging.queuemessaging load_config_override.assert_called_with( 'twistedpublisher.zcml', QUEUEMESSAGING_MODULE, ) HubCreatedEvent.assert_called_with(zh) notify.assert_called_with(HubCreatedEvent.return_value) zh.sendEvent.assert_called_with( zh, eventClass=App_Start, summary='zenhub started', severity=0, ) StatsMonitor.assert_called_once_with() ZenHubStatusReporter.assert_called_once_with( StatsMonitor.return_value, ) make_pools.assert_called_once_with() make_service_manager.assert_called_once_with(make_pools.return_value) getCredentialCheckers.assert_called_once_with( zh.options.passwordfile, ) make_server_factory.assert_called_once_with( make_pools.return_value, make_service_manager.return_value, getCredentialCheckers.return_value, ) XmlRpcManager.assert_called_once_with( zh.dmd, getCredentialCheckers.return_value[0], ) MetricManager.assert_called_with(daemon_tags={ 'zenoss_daemon': 'zenhub', 'zenoss_monitor': zh.options.monitor, 'internal': True, }, ) t.assertEqual(zh._metric_manager, MetricManager.return_value) t.assertEqual( zh._invalidation_manager, InvalidationManager.return_value, ) provideUtility.assert_called_once_with(zh._metric_manager) signal.signal.assert_called_with(signal.SIGUSR2, zh.sighandler_USR2)
self._zenhub = zenhub def check(self): pass class HubWillBeCreatedEvent(object): # noqa: D101 implements(IHubWillBeCreatedEvent) def __init__(self, hub): self.hub = hub class HubCreatedEvent(object): # noqa: D101 implements(IHubCreatedEvent) def __init__(self, hub): self.hub = hub class ParserReadyForOptionsEvent(object): # noqa: D101 implements(IParserReadyForOptionsEvent) def __init__(self, parser): self.parser = parser if __name__ == '__main__': from Products.ZenHub.zenhub import ZenHub ZenHub().main()