def setUpClass(cls): load_plugins(CONFIG) if hasattr(cls, 'fixture_class'): cls.fixture_class() if not hasattr(TestCase, 'assertIsNotNone'): def _assertIsNotNone(cls, val): cls.assertNotEqual(val, None) TestCase.assertIsNotNone = _assertIsNotNone if not hasattr(TestCase, 'assertIsNone'): def _assertIsNone(cls, val): cls.assertEqual(val, None) TestCase.assertIsNone = _assertIsNone
def setUpClass(cls): cls.module_patcher = patch.dict('sys.modules', cls.modules) cls.module_patcher.start() load_plugins(CONFIG) if hasattr(cls, 'fixture_class'): cls.fixture_class() if not hasattr(TestCase, 'assertIsNotNone'): def _assertIsNotNone(cls, val): cls.assertNotEqual(val, None) TestCase.assertIsNotNone = _assertIsNotNone if not hasattr(TestCase, 'assertIsNone'): def _assertIsNone(cls, val): cls.assertEqual(val, None) TestCase.assertIsNone = _assertIsNone
def __init__(self): super(Daemon, self).__init__() self._parser = _parser() try: argcomplete.autocomplete(self._parser) except: pass self.args = self._parser.parse_args() if 'NO_COLORS' in os.environ or os.name == 'nt': colors.disable() self.load_transport_class() load_plugins(CONFIG)
def _setup(self): """ Perform initial confiiguration """ self._create_backend() self.backend.prepare() self.queue = self.backend.publish_queue('requests') self.renderer = ResultPrinter(self.queue) load_plugins(CONFIG) if 'timeout' in self.args: # override timeout from args? try: self.timeout = int(self.args.timeout) except: # invalid timeout self.timeout = DEFAULT_TIMEOUT
def from_config(cls, config, **kwargs): transport_str = config.transport_class or cls.default_transport transport_class = local_plugin_loader(transport_str) transport = transport_class.from_config(config, **kwargs) plugins = load_plugins(config) if not plugins: # load defaults from cloudrunner.util.loader import load_plugins_from load_plugins_from('cloudrunner.plugins.state.functions', [StatePluginBase]) return cls(transport=transport, plugins=plugins, **kwargs)
def __init__(self): super(Daemon, self).__init__() self._parser = _parser() try: argcomplete.autocomplete(self._parser) except: pass self.args = self._parser.parse_args() if 'NO_COLORS' in os.environ: colors.disable() # Defaults to Single-user transport transport_class = CONFIG.transport or \ 'cloudrunner.plugins.transport.node_transport.NodeTransport' (mod, _, klass) = transport_class.rpartition('.') self.transport_class = None transport_module = load_plugins_from(mod, [TransportBackend]) if not transport_module: print colors.red("Cannot find module for transport plugin: %s" % mod) exit(1) for _klass in transport_module: if _klass.__name__ == klass: self.transport_class = _klass break if not self.transport_class: print colors.red("Cannot find transport class %s from module %s" % (klass, mod)) exit(1) assert self.transport_class load_plugins(CONFIG)
def run(self): """ Main method of CloudRunner node. It tries to register if not registered yet. """ self.node_id = CONFIG.node_id self.running = Event() if not CONFIG.master_pub or not CONFIG.master_repl: print colors.yellow("Master IP:port is not set in config file (%s)" % CONFIG._fn) master_pub = raw_input("Enter Master PUB uri (IP or IP:port):") if ":" in master_pub: ip, _, port = master_pub.rpartition(":") else: ip = master_pub port = 5551 CONFIG.update("General", "master_pub", "%s:%s" % (ip, port)) master_repl = raw_input("Enter Master REPLY uri (IP or IP:port), " "hit ENTER for default(%s:5552):" % ip) if not master_repl: port = 5552 elif ":" in master_repl: ip, _, port = master_repl.rpartition(":") else: ip = master_repl port = 5552 CONFIG.update("General", "master_repl", "%s:%s" % (ip, port)) CONFIG.reload() if not validate_address(CONFIG.master_pub) or \ not validate_address(CONFIG.master_repl): LOG.error('Server IP not present in config or is not valid.\n' 'Check your config') exit(1) if not self.node_id: LOG.error("The node id not set in config. " "Run program with config option first") exit(1) self.backend = self.transport_class.from_config( CONFIG, **vars(self.args)) load_plugins(CONFIG) self.sessions = {} self.matcher = Matcher(self.node_id, self.backend.meta()) LOG.info("Starting node") self.details() self._sig_int = signal.getsignal(signal.SIGINT) self._sig_term = signal.getsignal(signal.SIGTERM) if os.name == 'nt': # Use Ctrl+C to invoke clean on Windows import win32api win32api.SetConsoleCtrlHandler(self.clean, True) else: signal.signal(signal.SIGINT, self._handle_terminate) signal.signal(signal.SIGTERM, self._handle_terminate) # Invoke clean for sessions signal.signal(signal.SIGHUP, self.clean) if not self.backend.prepare(): LOG.info("Cannot start transport backend") self._handle_terminate() exit(1) def request_processor(): req_queue = self.backend.consume_queue('requests', ident="DISPATCHER") poller = self.backend.create_poller(req_queue) while not self.running.is_set(): try: ready = poller.poll(200) if not ready: continue if req_queue in ready: message = req_queue.recv()[0] if not message: continue job = JobTarget.build(message) if job: self.target_match(job) except ConnectionError: break except Exception: continue req_queue.close() Thread(target=request_processor).start() self.backend.loop() LOG.info("Node exited")
def run(self): """ Main method of CloudRunner node. It tries to register if not registered yet. """ self.node_id = CONFIG.node_id self.running = Event() if not CONFIG.master_pub or not CONFIG.master_repl: print colors.yellow( "Master IP:port is not set in config file (%s)" % CONFIG._fn) master_pub = raw_input("Enter Master PUB uri (IP or IP:port):") if ":" in master_pub: ip, _, port = master_pub.rpartition(":") else: ip = master_pub port = 5551 CONFIG.update("General", "master_pub", "%s:%s" % (ip, port)) master_repl = raw_input("Enter Master REPLY uri (IP or IP:port), " "hit ENTER for default(%s:5552):" % ip) if not master_repl: port = 5552 elif ":" in master_repl: ip, _, port = master_repl.rpartition(":") else: ip = master_repl port = 5552 CONFIG.update("General", "master_repl", "%s:%s" % (ip, port)) CONFIG.reload() if not validate_address(CONFIG.master_pub) or \ not validate_address(CONFIG.master_repl): LOG.error('Server IP not present in config or is not valid.\n' 'Check your config') exit(1) if not self.node_id: LOG.error("The node id not set in config. " "Run program with config option first") exit(1) self.backend = self.transport_class.from_config( CONFIG, **vars(self.args)) load_plugins(CONFIG) self.sessions = {} self.matcher = Matcher(self.node_id, self.backend.meta()) LOG.info("Starting node") self.details() self._sig_int = signal.getsignal(signal.SIGINT) self._sig_term = signal.getsignal(signal.SIGTERM) if os.name == 'nt': # Use Ctrl+C to invoke clean on Windows import win32api win32api.SetConsoleCtrlHandler(self.clean, True) else: signal.signal(signal.SIGINT, self._handle_terminate) signal.signal(signal.SIGTERM, self._handle_terminate) # Invoke clean for sessions signal.signal(signal.SIGHUP, self.clean) if not self.backend.prepare(): LOG.info("Cannot start transport backend") self._handle_terminate() exit(1) def request_processor(): req_queue = self.backend.consume_queue('requests', ident="DISPATCHER") poller = self.backend.create_poller(req_queue) while not self.running.is_set(): try: ready = poller.poll(200) if not ready: continue if req_queue in ready: message = req_queue.recv()[0] if not message: continue job = JobTarget.build(message) if job: self.target_match(job) except ConnectionError: break except Exception: continue req_queue.close() Thread(target=request_processor).start() self.backend.loop() LOG.info("Node exited")