Exemple #1
0
    def __init__(self, args, transporter_args):
        self.__args = args
        self.__sender = haplib.Sender(transporter_args)
        self.__rpc_queue = hap.MultiprocessingJoinableQueue()
        self.__dispatcher = haplib.Dispatcher(self.__rpc_queue)
        self.__dispatcher.daemonize("Dispatcher")
        self.__last_info = {"event": "", "trigger": ""}

        self.__handler_map = {
            "exchangeProfile": self.__rpc_exchange_profile,
            "getMonitoringServerInfo": self.__rpc_get_monitoring_server_info,
            "putHosts": self.__rpc_put_hosts,
            "putHostGroups": self.__rpc_put_host_groups,
            "putHostGroupMembership": self.__rpc_put_host_group_membership,
            "putTriggers": self.__rpc_put_triggers,
            "putEvents": self.__rpc_put_events,
            "putItems": self.__rpc_put_items,
            "putHistory": self.__rpc_put_history,
            "getLastInfo": self.__rpc_get_last_info,
            "putArmInfo": self.__rpc_put_arm_info,
        }

        # launch receiver process
        dispatch_queue = self.__dispatcher.get_dispatch_queue()
        self.__receiver = haplib.Receiver(transporter_args, dispatch_queue,
                                          self.__handler_map.keys())
        self.__receiver.daemonize("Receiver")
Exemple #2
0
 def __create_test_instance(self, connector_class=None):
     sender = haplib.Sender({"class": transporter.Transporter})
     obj = haplib.HapiProcessor("test", 0x01, sender)
     obj.set_dispatch_queue(DummyQueue())
     if not connector_class:
         return obj
     connector = connector_class(obj.get_reply_queue())
     sender.set_connector(connector)
     return obj, connector
Exemple #3
0
    def __run(self, args):
        self.enable_handling_sigchld()
        self.enable_handling_terminate_signal()
        logger.info("Transporter: %s" % args.transporter)
        transporter_class = self.__transporter_manager.find(args.transporter)
        if transporter_class is None:
            logger.critical("Not found transporter: %s" % args.transporter)
            raise SystemExit()
        transporter_args = {"class": transporter_class}
        transporter_args.update(transporter_class.parse_arguments(args))

        self.__main_plugin = self.create_main_plugin()
        self.__main_plugin.setup(transporter_args)
        self.__main_plugin.register_callback(
            haplib.BaseMainPlugin.CB_UPDATE_MONITORING_SERVER_INFO,
            self.on_got_monitoring_server_info)
        logger.info("created main plugin.")

        if args.disable_poller:
            logger.info("Disabled: poller plugin.")
        else:
            kwargs = {
                "status_log_interval": args.status_log_interval,
                "polling_targets": args.polling_targets,
            }
            poller_sender = haplib.Sender(transporter_args)
            self.__poller = self.__create_poller(
                                poller_sender,
                                self.__main_plugin.get_dispatcher(),
                                **kwargs)

        self.__main_plugin.start_dispatcher()
        logger.info("started dispatcher process.")
        self.__main_plugin.start_receiver()
        logger.info("started receiver process.")

        self.__main_plugin.exchange_profile()
        logger.info("exchanged profile.")

        ms_info = self.__main_plugin.get_monitoring_server_info()
        logger.info("got monitoring server info.")
        self.on_got_monitoring_server_info(ms_info)

        if self.__poller is not None:
            self.__poller.daemonize("Poller")
            logger.info("started poller plugin.")

        self.__main_plugin()
Exemple #4
0
 def setUpClass(cls):
     transporter_args = {"class": transporter.Transporter}
     cls.sender = haplib.Sender(transporter_args)
     cls.poller = haplib.BasePoller(sender=cls.sender, process_id="test")
Exemple #5
0
 def test_notifiy(self):
     transporter_args = {"class": transporter.Transporter}
     test_sender = haplib.Sender(transporter_args)
     testutils.assertNotRaises(test_sender.notify, "test_notify", 1)
Exemple #6
0
 def test_error(self):
     transporter_args = {"class": transporter.Transporter}
     test_sender = haplib.Sender(transporter_args)
     testutils.assertNotRaises(test_sender.error, -32700, 1)
Exemple #7
0
 def test_response(self):
     transporter_args = {"class": transporter.Transporter}
     test_sender = haplib.Sender(transporter_args)
     testutils.assertNotRaises(test_sender.response, "test_result", 1)
Exemple #8
0
 def test_request(self):
     transporter_args = {"class": transporter.Transporter}
     test_sender = haplib.Sender(transporter_args)
     testutils.assertNotRaises(test_sender.request, "test_procedure_name",
                               "test_param", 1)
Exemple #9
0
 def test_set_connector(self):
     transporter_args = {"class": transporter.Transporter}
     test_sender = haplib.Sender(transporter_args)
     test_sender.set_connector("test")
     self.assertEquals("test", test_sender._Sender__connector)
Exemple #10
0
 def test_get_connector(self):
     transporter_args = {"class": transporter.Transporter}
     test_sender = haplib.Sender(transporter_args)
     result_connector = test_sender.get_connector()
     self.assertEquals(test_sender._Sender__connector, result_connector)