def test_make_service(self): """Test makeService""" opt = dict(config='config', messages='messages', freq=5) before = time.time() masterService = beatcheck.makeService(opt) service = masterService.getServiceNamed("beatcheck") after = time.time() self.assertIsInstance(service, tainternet.TimerService) self.assertEquals(service.step, 5) callableThing, args, kwargs = service.call self.assertIs(callableThing, beatcheck.run) self.assertFalse(kwargs) restarter, checker, timer = args self.assertIs(timer, time.time) self.assertIs(restarter.func, ctllib.restart) self.assertFalse(restarter.keywords) places, = restarter.args self.assertEquals(places, ctllib.Places(config='config', messages='messages')) self.assertIs(checker.func, beatcheck.check) self.assertFalse(checker.keywords) path, start = checker.args self.assertEquals(path.basename(), 'config') self.assertLessEqual(before, start) self.assertLessEqual(start, after)
def test_make_service(self): """Test makeService""" opt = dict(config='config', messages='messages', freq=5) masterService = httpcheck.makeService(opt) service = masterService.getServiceNamed("httpcheck") self.assertIsInstance(service, tainternet.TimerService) self.assertEquals(service.step, 5) callableThing, args, kwargs = service.call self.assertIs(callableThing, httpcheck.run) self.assertFalse(kwargs) restarter, checker = args self.assertIs(restarter.func, ctllib.restart) self.assertFalse(restarter.keywords) places, = restarter.args self.assertEquals(places, ctllib.Places(config='config', messages='messages')) self.assertIs(checker.func, httpcheck.check) self.assertFalse(checker.keywords) settings, states, location = checker.args self.assertEquals(location, filepath.FilePath(opt['config'])) self.assertEquals(states, {}) self.assertIs(settings.reactor, reactor) agent = settings.agent self.assertIsInstance(agent, client.Agent) ## pylint: disable=protected-access self.assertTrue(agent._pool.persistent)
def parseConfig(opt): """Parse configuration :params opt: dict-like object with config and messages keys :returns: restarter, path """ places = ctllib.Places(config=opt['config'], messages=opt['messages']) restarter = functools.partial(ctllib.restart, places) path = filepath.FilePath(opt['config']) return restarter, path
def setUp(self): """Set up configuration and build/cleanup directories""" self.places = ctllib.Places(config='config', messages='messages') def _cleanup(): for d in self.places: if os.path.exists(d): shutil.rmtree(d) _cleanup() self.addCleanup(_cleanup) for d in self.places: os.mkdir(d)
def test_call(self): """Check the 'call' function""" ns = argparse.Namespace() results = [] def _func(places, **kwargs): results.append((places, kwargs)) ns.func = _func ns.config = 'config1' ns.messages = 'messages1' ns.foo = 'bar' ns.baz = 'quux' ctllib.call(ns) self.assertEquals( results, [(ctllib.Places(config='config1', messages='messages1'), dict(foo='bar', baz='quux'))])
def mkconfig(dirname): """create an NColony configuration :param dirname: directory in which to create the configuration :type dirname: string :rettype: ncolony.ctllib.Places """ place = os.path.abspath(dirname) if os.path.exists(place): shutil.rmtree(place) os.mkdir(place) config = os.path.join(place, 'config') messages = os.path.join(place, 'messages') places = ctllib.Places(config=config, messages=messages) for dr in places: os.mkdir(dr) return places
metadata = base.child('metadata') store = base.child('store') logs = base.child('log') if tempDir.child('twistd.pid').exists(): sys.exit("Running twistd, aborting") reset(store) reset(tempDir) reset(metadata) reset(logs) config = metadata.child('config') messages = metadata.child('messages') status = metadata.child('status') for subd in (config, messages, status): subd.createDirectory() places = ctllib.Places(config=config.path, messages=messages.path) twistd = os.path.join(binLocation, 'twistd') def getBaseArgs(name): return [ '--pidfile', tempDir.child(name + '.pid').path, '--logfile', logs.child(name + '.log').path, '--nodaemon' ] def addService(name, serviceName, args, extras=None): baseArgs = getBaseArgs(name) args = baseArgs + [serviceName] + args ctllib.add(places, name=name, cmd=twistd, args=args, extras=extras)