Ejemplo n.º 1
0
    def load_module(self, module_name):
        """
        Dynamically load the modules specified in the config file. Allow model
        specific module implementations to override the default by attempting
        to load them first.
        """
        if self.model:
            if os.path.isfile("controller/modules/{0}/{1}.py".format(
                    self.model, module_name)):
                module = importlib.import_module(
                    "controller.modules.{0}.{1}".format(
                        self.model, module_name))
            else:
                module = importlib.import_module(
                    "controller.modules.{0}".format(module_name))

        # get the class with name key from module
        module_class = getattr(module, module_name)

        # create a CFxHandle object for each module
        handle = CFxHandle(self)
        self._config[module_name]["NodeId"] = self._node_id
        instance = module_class(handle, self._config[module_name], module_name)

        handle._cm_instance = instance
        handle._cm_config = self._config[module_name]

        # store the CFxHandle object references in the
        # dict with module name as the key
        self._cfx_handle_dict[module_name] = handle
Ejemplo n.º 2
0
    def load_module(self, module_name):
        if 'enabled' in self.json_data[module_name]:
            module_enabled = self.json_data[module_name]['enabled']
        else:
            module_enabled = True

        if (module_name not in self.loaded_modules) and module_enabled:
            # load the dependencies of the module
            self.load_dependencies(module_name)

            # import the modules dynamically
            try:
                module = importlib.import_module("controller.modules.{0}".format(module_name))
            except ImportError:
                if self.vpn_type == "GroupVPN":
                    module = importlib.import_module("controller.modules.gvpn.{0}".format(module_name))
                elif self.vpn_type == "SocialVPN":
                    module = importlib.import_module("controller.modules.svpn.{0}".format(module_name))
                else:
                    module = importlib.import_module("controller.modules.{0}.{1}".format(self.vpn_type, module_name))

            # get the class with name key from module
            module_class = getattr(module, module_name)

            # create a CFxHandle object for each module
            handle = CFxHandle(self)

            # instantiate the class with the CFxHandle reference and the
            # configuration parameter (additionally, pass the list of sockets to
            # the TincanListener and TincanSender modules
            if module_name in ['TincanListener', 'TincanSender']:
                instance = module_class(self.sock_list,
                                        handle,
                                        self.CONFIG[module_name],
                                        module_name)
            else:
                instance = module_class(handle, self.CONFIG[module_name], module_name)

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)
Ejemplo n.º 3
0
 def testsignal_scavenge_pending_cbts(self):
     """
     Test to check if scavenge of pending CBT works with one above the request timeout.
     """
     cfxObject = Mock()
     cfx_handle = CFxHandle(cfxObject)
     module = importlib.import_module(
         "controller.modules.{0}".format("Signal"))
     module_class = getattr(module, "Signal")
     sig_dict = {
         "Signal": {
             "Enabled": True,
             "Overlays": {
                 "A0FB389": {
                     "HostAddress": "1.1.1.1",
                     "Port": "5222",
                     "Username": "******",
                     "Password": "******",
                     "AuthenticationMethod": "PASSWORD"
                 }
             }
         },
         "NodeId": "1234434323"
     }
     signal = module_class(cfx_handle, sig_dict, "Signal")
     cfx_handle._cm_instance = signal
     cfx_handle._cm_config = sig_dict
     cbt1 = CBT()
     cbt1.tag = "1"
     cbt1.time_submit = time.time() - 5
     signal.request_timeout = 5
     cbt2 = CBT()
     cbt2.tag = "2"
     cbt2.time_submit = time.time() - 1
     signal.complete_cbt = MagicMock()
     signal._cfx_handle._pending_cbts.update({"0": cbt1})
     signal._cfx_handle._pending_cbts.update({"1": cbt2})
     assert len(signal._cfx_handle._pending_cbts.items()) == 2
     signal.scavenge_pending_cbts()
     assert len(signal._cfx_handle._pending_cbts.items()) == 1
     items = {}
     items.update({"1": cbt2})
     assert signal._cfx_handle._pending_cbts == items
     print("Passed : testsignal_scavenge_pending_cbts")
Ejemplo n.º 4
0
    def load_module(self, module_name):
        if 'Enabled' in self.CONFIG[module_name]:
            module_enabled = self.CONFIG[module_name]['Enabled']
        else:
            module_enabled = True

        if (module_name not in self.loaded_modules) and module_enabled and module_name != "Tincan":
            # load the dependencies of the module
            self.load_dependencies(module_name)

            # import the modules dynamically
            try:
                module = importlib.import_module("controller.modules.{0}".format(module_name))
            except ImportError as error:
                if self.vpn_type == "GroupVPN":
                    module = importlib.import_module("controller.modules.gvpn.{0}".format(module_name))
                elif self.vpn_type == "SocialVPN":
                    module = importlib.import_module("controller.modules.svpn.{0}".format(module_name))
                else:
                    module = importlib.import_module("controller.modules.{0}.{1}".format(self.vpn_type, module_name))

            # get the class with name key from module
            module_class = getattr(module, module_name)

            # create a CFxHandle object for each module
            handle = CFxHandle(self)
            instance = module_class(handle, self.CONFIG[module_name], module_name)

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)
Ejemplo n.º 5
0
    def load_module(self, module_name):
        if 'Enabled' in self.json_data[module_name]:
            module_enabled = self.json_data[module_name]['Enabled']
        else:
            module_enabled = True

        if (module_name not in self.loaded_modules
            ) and module_enabled and module_name != "Tincan":
            # load the dependencies of the module
            self.load_dependencies(module_name)

            # import the modules dynamically
            try:
                module = importlib.import_module(
                    "controller.modules.{0}".format(module_name))
            except ImportError:
                if self.vpn_type == "GroupVPN":
                    module = importlib.import_module(
                        "controller.modules.gvpn.{0}".format(module_name))
                elif self.vpn_type == "SocialVPN":
                    module = importlib.import_module(
                        "controller.modules.svpn.{0}".format(module_name))
                else:
                    module = importlib.import_module(
                        "controller.modules.{0}.{1}".format(
                            self.vpn_type, module_name))

            # get the class with name key from module
            module_class = getattr(module, module_name)

            # create a CFxHandle object for each module
            handle = CFxHandle(self)

            # instantiate the class with the CFxHandle reference and the
            # configuration parameter (additionally, pass the list of sockets to
            # the TincanListener and TincanSender modules
            if module_name in ['TincanListener']:
                instance = module_class([self.sock, self.sock_svr], handle,
                                        self.CONFIG[module_name], module_name)
            elif module_name in ['TincanSender']:
                instance = module_class([self.sock], handle,
                                        self.CONFIG[module_name], module_name)
            else:
                instance = module_class(handle, self.CONFIG[module_name],
                                        module_name)

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)
Ejemplo n.º 6
0
    def load_module(self, module_name):
        if 'Enabled' in self.CONFIG[module_name]:
            module_enabled = self.CONFIG[module_name]['Enabled']
        else:
            module_enabled = True

        if (module_name not in self.loaded_modules) and module_enabled and module_name != "Tincan":
            # load the dependencies of the module
            self.load_dependencies(module_name)

            # import the modules dynamically
            try:
                module = importlib.import_module("controller.modules.{0}".format(module_name))
            except ImportError as error:
                if self.vpn_type == "GroupVPN":
                    module = importlib.import_module("controller.modules.gvpn.{0}".format(module_name))
                elif self.vpn_type == "SocialVPN":
                    module = importlib.import_module("controller.modules.svpn.{0}".format(module_name))
                else:
                    module = importlib.import_module("controller.modules.{0}.{1}".format(self.vpn_type, module_name))

            # get the class with name key from module
            module_class = getattr(module, module_name)

            # create a CFxHandle object for each module
            handle = CFxHandle(self)
            instance = module_class(handle, self.CONFIG[module_name], module_name)

            handle.CMInstance = instance
            handle.CMConfig = self.CONFIG[module_name]

            # store the CFxHandle object references in the
            # dict with module name as the key
            self.CFxHandleDict[module_name] = handle

            # intialize all the CFxHandles which in turn initialize the CMs
            handle.initialize()

            self.loaded_modules.append(module_name)