Beispiel #1
0
    def setup_web_configuration(cls, router_ids: Union[List[int], None],
                                setup_all: bool, wizard: bool):
        """
        After a systemupgrade, the Router starts in config-mode without the possibility to connect again via SSH.
        Therefore this class uses selenium to parse the given webpage. All options given by the web interface of the
        Router can be set via the 'web_interface_config.yaml', except for the sysupgrade which isn't implemented yet

        :param router_ids: List of unique numbers to identify a Router
        :param setup_all: If True all Routers will be setuped via the webinterface
        :param wizard
        """

        if setup_all:
            for i, router in enumerate(cls.get_routers()):
                cls.start_job(
                    router,
                    RouterWebConfigurationJob(
                        ConfigManager.get_web_interface_list()[i], wizard))
        else:
            for i, router_id in enumerate(router_ids):
                router = cls.get_router_by_id(router_id)
                cls.start_job(
                    router,
                    RouterWebConfigurationJob(
                        ConfigManager.get_web_interface_list()[i], wizard))
Beispiel #2
0
    def start(cls, config_path: str = CONFIG_PATH) -> None:
        """
        Starts the runtime server with all components

        :param config_path: Path to an alternative config directory
        """
        cls.CONFIG_PATH = config_path
        # set the config_path at the manager
        ConfigManager.set_config_path(config_path)

        # read from config the Vlan mode
        vlan_activate = ConfigManager.get_server_property("Vlan_On")
        cls.VLAN = vlan_activate

        # read from config if debug mode is on
        log_level = ConfigManager.get_server_property("Log_Level")
        debug_mode = False
        if log_level is 10:
            debug_mode = True
        cls.DEBUG = debug_mode

        # load Router configs
        cls.__load_configuration()

        if cls.VLAN:
            from util.router_info import RouterInfo
            # TODO: Die Funktion 'cls.update_router_info' sollte verwendet werden
            RouterInfo.update(cls.get_routers()[0])

        print("Runtime Server started")

        cls._ipc_server.start_ipc_server(
            cls, True)  # serves forever - works like a while(true)
Beispiel #3
0
    def start(cls, config_path: str = CONFIG_PATH) -> None:
        """
        Starts the runtime server with all components

        :param config_path: Path to an alternative config directory
        """
        cls.CONFIG_PATH = config_path
        # set the config_path at the manager
        ConfigManager.set_config_path(config_path)

        # read from config the Vlan mode
        vlan_activate = ConfigManager.get_server_property("Vlan_On")
        cls.VLAN = vlan_activate

        # read from config if debug mode is on
        log_level = int(ConfigManager.get_server_property("Log_Level"))
        debug_mode = False
        if log_level is 10:
            debug_mode = True
        cls.DEBUG = debug_mode

        # create instance and give params to the logger object
        Logger().setup(log_level, log_level, log_level)

        # load Router configs
        cls.__load_configuration()

        if cls.VLAN:
            from util.router_info import RouterInfo
            # TODO: Die Funktion 'cls.update_router_info' sollte verwendet werden
            RouterInfo.update(cls.get_routers()[0])

        print("Runtime Server started")

        cls._ipc_server.start_ipc_server(cls, True)  # serves forever - works like a while(true)
Beispiel #4
0
 def test_check(self):
     """
     Test config vs. schema
     :return: Test results
     """
     data = ConfigManager.get_framework_config()
     result = ConfigManager.check(data)
     self.assertEqual(True, result, "Wrong schema or data")
 def test_check(self):
     """
     Test config vs. schema
     :return: Test results
     """
     data = ConfigManager.get_framework_config()
     result = ConfigManager.check(data)
     self.assertEqual(True, result, "Wrong schema or data")
 def run(self):
     """
     Instantiate a NetworkCtrl and copy the firmware via SSH to the Router(/tmp/<firmware_name>.bin).
     """
     logging.info("%sSysupdate Firmware for Router(" + str(self.router.id) + ") ...", LoggerSetup.get_log_deep(1))
     firmware_handler = FirmwareHandler(str(ConfigManager.get_firmware_property('URL')))
     firmware = firmware_handler.get_firmware(self.router.model,
                                              str(ConfigManager.get_firmware_property('Release_Model')),
                                              bool(ConfigManager.get_firmware_property('Download_All')))
     self.router.firmware = firmware
    def test_set_config_path(self):
        """
        Tests to set the config path
        :return: Tests results
        """
        base_dir = path.dirname(path.dirname(__file__))  # This is your Project Root

        config_path = path.join(base_dir, 'framework_unittests/configs/config_no_vlan')
        ConfigManager.set_config_path(config_path)
        self.assertEqual(ConfigManager.CONFIG_PATH, config_path, "Wrong path")

        config_path = path.join(base_dir, 'config')  # Join Project Root with config
        ConfigManager.set_config_path(config_path)
        self.assertEqual(ConfigManager.CONFIG_PATH, config_path, "Wrong path")
Beispiel #8
0
 def run(self):
     """
     Instantiate a NetworkCtrl and copy the firmware via SSH to the Router(/tmp/<firmware_name>.bin).
     """
     logging.info(
         "%sSysupdate Firmware for Router(" + str(self.router.id) + ") ...",
         LoggerSetup.get_log_deep(1))
     firmware_handler = FirmwareHandler(
         str(ConfigManager.get_firmware_property('URL')))
     firmware = firmware_handler.get_firmware(
         self.router.model,
         str(ConfigManager.get_firmware_property('Release_Model')),
         bool(ConfigManager.get_firmware_property('Download_All')))
     self.router.firmware = firmware
Beispiel #9
0
    def test_read_file(self):
        """
        Read a file
        :return: Tests results
        """
        output = ConfigManager.read_file("")
        self.assertEqual(output, None, "Wrong output")

        output = ConfigManager.read_file(ConfigManager.CONFIG_PATH)
        self.assertEqual(output, None, "Wrong output")

        file_path = path.join(ConfigManager.CONFIG_PATH, ConfigManager.FRAMEWORK_CONFIG_FILE)
        output = ConfigManager.read_file(file_path)

        self.assertEqual((output is not None), True, "Wrong output")
Beispiel #10
0
    def sysupdate_firmware(cls, router_ids: List[int], update_all: bool) -> None:
        """
        Downloads and copies the firmware to the :py:class:`Router` given in the List(by a unique id) or to all Routers

        :param router_ids: List of unique numbers to identify a :py:class:`Router`
        :param update_all: Is True if all Routers should be updated
        """
        from util.router_flash_firmware import RouterFlashFirmware
        if update_all:
            for router in cls.get_routers():
                RouterFlashFirmware.sysupdate(router, ConfigManager.get_firmware_dict()[0])
        else:
            for router_id in router_ids:
                router = cls.get_router_by_id(router_id)
                RouterFlashFirmware.sysupdate(router, ConfigManager.get_firmware_dict()[0])
Beispiel #11
0
 def test_web_interface_dict(self):
     """
     Tests the web interface config
     :return: Tests results
     """
     data = ConfigManager.get_web_interface_dict()
     self.assertEqual(len(data), 3, "web_interface: Wrong size of the List")
 def test_test_dict(self):
     """
     Tests the test config
     :return: Tests results
     """
     data = ConfigManager.get_test_dict()
     self.assertEqual(True, data[0], "test: Wrong config")
Beispiel #13
0
 def test_get_config_router_auto(self):
     """
     Tests the router auto config
     :return: Tests results
     """
     data = ConfigManager.get_router_auto_config()
     self.assertEqual(len(data), 10, "test_Yaml: Wrong size of the List")
Beispiel #14
0
 def test_config_router_manual(self):
     """
     Tests the router manual config
     :return: Tests results
     """
     data = ConfigManager.get_router_manual_list()
     self.assertEqual(len(data), 3, "test_Yaml: Wrong size of the List")
 def test_power_strip_dict(self):
     """
     Tests the power strip config
     :return: Tests results
     """
     data = ConfigManager.get_power_strip_dict()
     self.assertEqual(True, data[0], "power_strip: Wrong config")
Beispiel #16
0
 def test_config_router_auto_with_length(self):
     """
     Tests the router auto config with length
     :return: Tests results
     """
     data = ConfigManager.get_router_auto_list(4)
     self.assertEqual(len(data), 4, "test_Yaml: Wrong size of the List")
Beispiel #17
0
 def test_firmware_dict(self):
     """
     Tests the firmware config
     :return: Tests results
     """
     data = ConfigManager.get_firmware_dict()
     self.assertEqual(True, data[0], "Firmware: Wrong config")
    def test_setup_expert(self):
        """
        This UnitTest executes the wca_setup_expert-function with the given config-file.
        It sets the values of all the  from WebInterface of the Router.
        """
        print("Test if the 'wca_setup_wizard'-function is working")
        router = self._create_router()
        # NVAssisten
        nv_assist = NVAssistent("eth0")
        nv_assist.create_namespace_vlan(router)
        # Set netns for the current process
        netns.setns(router.namespace_name)
        try:
            # Config
            config = ConfigManager.get_web_interface_list()[router.id]
            self.assertEqual(len(config), 30, "Wrong size of the Config-Directory")

            print("Set the following configuration: \n" + str(config))

            router_web_config = RouterWebConfiguration(router, config, wizard=True)
            router_web_config.start()
            router_web_config.join()
        except Exception as e:
            nv_assist.close()
            raise e

        assert router.mode == Mode.normal
        nv_assist.close()
Beispiel #19
0
 def test_config_test_list(self):
     """
     Tests the test config
     :return: Tests results
     """
     data = ConfigManager.get_test_list()
     self.assertEqual(len(data), 4, "test_Yaml: Wrong size of the List")
Beispiel #20
0
 def test_config_server_prop(self):
     """
     Tests the server config with a property
     :return: Tests results
     """
     data = ConfigManager.get_server_property("Server_Name")
     self.assertEqual(data, "TestServer", "test_Yaml: Wrong size of the List")
Beispiel #21
0
 def test_get_config_router_auto(self):
     """
     Tests the router auto config
     :return: Tests results
     """
     data = ConfigManager.get_router_auto_config()
     self.assertEqual(len(data), 10, "test_Yaml: Wrong size of the List")
Beispiel #22
0
 def test_config_server_dict(self):
     """
     Tests the server config
     :return: Tests results
     """
     data = ConfigManager.get_server_dict()
     self.assertEqual(len(data), 1, "test_Yaml: Wrong size of the List")
Beispiel #23
0
 def test_config_router_manual(self):
     """
     Tests the router manual config
     :return: Tests results
     """
     data = ConfigManager.get_router_manual_list()
     self.assertEqual(len(data), 3, "test_Yaml: Wrong size of the List")
Beispiel #24
0
 def test_test_dict(self):
     """
     Tests the test config
     :return: Tests results
     """
     data = ConfigManager.get_test_dict()
     self.assertEqual(len(data), 2, "test: Wrong size of the List")
 def test_get_schema_framework(self):
     """
     Tests the framework schema
     :return: Tests results
     """
     schema = ConfigManager.get_framework_schema()
     self.assertEqual(True, (schema is not None), "Wrong schema")
 def test_server_dict(self):
     """
     Tests the server config
     :return: Tests results
     """
     data = ConfigManager.get_server_dict()
     self.assertEqual(True, data[0], "Server: Wrong config")
Beispiel #27
0
 def test_web_interface_dict(self):
     """
     Tests the web interface config
     :return: Tests results
     """
     data = ConfigManager.get_web_interface_dict()
     self.assertEqual(True, data[0], "web_interface: Wrong config")
 def test_get_config_framework(self):
     """
     Tests the framework config
     :return: Tests results
     """
     data = ConfigManager.get_framework_config()
     self.assertEqual(True, (data is not None), "Wrong data")
Beispiel #29
0
 def test_firmware_property(self):
     """
     Tests the firmware config with property
     :return: Tests results
     """
     data = ConfigManager.get_firmware_property("Firmware_Version")
     self.assertEqual(data, "0.7.3", "Firmware: Wrong property")
Beispiel #30
0
 def test_web_interface_dict(self):
     """
     Tests the web interface config
     :return: Tests results
     """
     data = ConfigManager.get_web_interface_dict()
     self.assertEqual(len(data), 3, "web_interface: Wrong size of the List")
Beispiel #31
0
 def test_config_router_auto_with_length(self):
     """
     Tests the router auto config with length
     :return: Tests results
     """
     data = ConfigManager.get_router_auto_list(4)
     self.assertEqual(len(data), 4, "test_Yaml: Wrong size of the List")
Beispiel #32
0
 def test_web_interface_property(self):
     """
     Tests the web interface config with property
     :return: Tests results
     """
     data = ConfigManager.get_web_interface_property("auto_update")
     self.assertEqual(data, False, "web_interface: Wrong property")
Beispiel #33
0
 def test_config_server_list(self):
     """
     Tests the server config
     :return: Tests results
     """
     data = ConfigManager.get_server_list()
     self.assertEqual(len(data), 3, "test_Yaml: Wrong size of the List")
Beispiel #34
0
 def test_power_strip_list(self):
     """
     Tests the power strip config
     :return: Tests results
     """
     data = ConfigManager.get_power_strip_list()
     self.assertEqual(len(data), 1, "power_strip: Wrong size of the List")
    def test_setup_expert(self):
        """
        This UnitTest executes the wca_setup_expert-function with the given config-file.
        It sets the values of all the  from WebInterface of the Router.
        """
        print("Test if the 'wca_setup_expert'-function is working")
        router = self._create_router()
        # NVAssisten
        nv_assist = NVAssistent("eth0")
        nv_assist.create_namespace_vlan(router)
        # Set netns for the current process
        netns.setns(router.namespace_name)

        # Config
        config = ConfigManager().get_web_interface_dict()[router.id]
        self.assertEqual(len(config), 30, "Wrong size of the Config-Directory")

        print("Set the following configuration: \n" + str(config))

        router_web_config = RouterWebConfiguration(router,
                                                   config,
                                                   wizard=False)
        router_web_config.start()
        router_web_config.join()

        assert router.mode == Mode.configuration
        nv_assist.close()
Beispiel #36
0
 def test_test_set(self):
     """
     Tests the test config
     :return: Tests results
     """
     data = ConfigManager.get_test_sets()
     self.assertEqual(len(data), 2, "test: Wrong size of the List")
Beispiel #37
0
 def test_firmware_list(self):
     """
     Tests the firmware config
     :return: Tests results
     """
     data = ConfigManager.get_firmware_list()
     self.assertEqual(len(data), 4, "Firmware: Wrong size of the List")
Beispiel #38
0
 def test_power_strip_dict(self):
     """
     Tests the power strip config
     :return: Tests results
     """
     data = ConfigManager.get_power_strip_dict()
     self.assertEqual(True, data[0], "power_strip: Wrong config")
Beispiel #39
0
 def test_power_strip_list(self):
     """
     Tests the power strip config
     :return: Tests results
     """
     data = ConfigManager.get_power_strip_list()
     self.assertEqual(len(data), 1, "power_strip: Wrong size of the List")
Beispiel #40
0
 def test_test_dict(self):
     """
     Tests the test config
     :return: Tests results
     """
     data = ConfigManager.get_test_dict()
     self.assertEqual(True, data[0], "test: Wrong config")
Beispiel #41
0
 def test_get_routers_list(self):
     """
     Tests the router config
     :return: Tests results
     """
     data = ConfigManager.get_routers_list()
     self.assertEqual(len(data), 2, "Routers: Wrong size of the List")
 def test_get_routers_dict(self):
     """
     Tests the router config
     :return: Tests results
     """
     data = ConfigManager.get_routers_dict()
     self.assertEqual(True, data[0], "Routers: Wrong config")
Beispiel #43
0
 def test_server_prop(self):
     """
     Tests the server config with a property
     :return: Tests results
     """
     data = ConfigManager.get_server_property("Server_Name")
     self.assertEqual(True, type(data) == str, "Server: Wrong property")
Beispiel #44
0
 def test_get_routers_dict(self):
     """
     Tests the router config
     :return: Tests results
     """
     data = ConfigManager.get_routers_dict()
     self.assertEqual(True, data[0], "Routers: Wrong config")
Beispiel #45
0
 def test_firmware_property(self):
     """
     Tests the firmware config with property
     :return: Tests results
     """
     data = ConfigManager.get_firmware_property("Firmware_Version")
     self.assertEqual(True, type(data) == str, "Firmware: Wrong property")
Beispiel #46
0
 def test_server_dict(self):
     """
     Tests the server config
     :return: Tests results
     """
     data = ConfigManager.get_server_dict()
     self.assertEqual(True, data[0], "Server: Wrong config")
Beispiel #47
0
 def test_web_interface_property(self):
     """
     Tests the web interface config with property
     :return: Tests results
     """
     data = ConfigManager.get_web_interface_property("auto_update")
     self.assertEqual(data, False, "web_interface: Wrong property")
Beispiel #48
0
    def test_setup_expert(self):
        """
        This UnitTest executes the wca_setup_expert-function with the given config-file.
        It sets the values of all the  from WebInterface of the Router.
        """
        # Create router
        router = Router(1, "vlan1", 21, "10.223.254.254", 16, "192.168.1.1",
                        24, "root", "root", 1)
        router.model = "TP-LINK TL-WR841N/ND v9"
        router.mac = "e8:de:27:b7:7c:e2"
        router.mode = Mode.configuration
        assert isinstance(router, Router)
        # Config
        config = ConfigManager().get_web_interface_dict()[0]
        self.assertEqual(len(config), 30, "Wrong size of the Config-Directory")
        # Create NetworkCrtl
        network_ctrl = NetworkCtrl(router, 'eth0')
        assert isinstance(network_ctrl, NetworkCtrl)

        try:
            web_config_assist = RouterWebConfiguration(router,
                                                       config,
                                                       wizard=True)
            web_config_assist.start()
            web_config_assist.join()
        except Exception as e:
            Logger().error(str(e))
        finally:
            assert router.mode == Mode.normal
            network_ctrl.exit()
Beispiel #49
0
 def test_get_schema_framework(self):
     """
     Tests the framework schema
     :return: Tests results
     """
     schema = ConfigManager.get_framework_schema()
     self.assertEqual(True, (schema is not None), "Wrong schema")
Beispiel #50
0
 def test_get_routers_list(self):
     """
     Tests the router config
     :return: Tests results
     """
     data = ConfigManager.get_routers_list()
     self.assertEqual(len(data), 2, "Routers: Wrong size of the List")
Beispiel #51
0
 def test_test_set(self):
     """
     Tests the test config
     :return: Tests results
     """
     data = ConfigManager.get_test_sets()
     self.assertEqual(True, len(data) > 0, "test: Wrong size of the List")
Beispiel #52
0
 def test_server_list(self):
     """
     Tests the server config
     :return: Tests results
     """
     data = ConfigManager.get_server_list()
     self.assertEqual(len(data), 3, "Server: Wrong size of the List")
Beispiel #53
0
    def test_read_file(self):
        """
        Read a file
        :return: Tests results
        """
        output = ConfigManager.read_file("")
        self.assertEqual(output, None, "Wrong output")

        output = ConfigManager.read_file(ConfigManager.CONFIG_PATH)
        self.assertEqual(output, None, "Wrong output")

        file_path = path.join(ConfigManager.CONFIG_PATH,
                              ConfigManager.FRAMEWORK_CONFIG_FILE)
        output = ConfigManager.read_file(file_path)

        self.assertEqual((output is not None), True, "Wrong output")
Beispiel #54
0
 def test_get_config_framework(self):
     """
     Tests the framework config
     :return: Tests results
     """
     data = ConfigManager.get_framework_config()
     self.assertEqual(len(data), 6, "framework_config.yml: Wrong size of the List")
Beispiel #55
0
 def test_get_config_framework(self):
     """
     Tests the framework config
     :return: Tests results
     """
     data = ConfigManager.get_framework_config()
     self.assertEqual(True, (data is not None), "Wrong data")
Beispiel #56
0
 def test_server_prop(self):
     """
     Tests the server config with a property
     :return: Tests results
     """
     data = ConfigManager.get_server_property("Server_Name")
     self.assertEqual(data, "TestServer", "Server: Wrong property")
Beispiel #57
0
 def test_server_list(self):
     """
     Tests the server config
     :return: Tests results
     """
     data = ConfigManager.get_server_list()
     self.assertEqual(True, len(data) > 0, "Server: Wrong size of the List")
Beispiel #58
0
 def test_firmware_dict(self):
     """
     Tests the firmware config
     :return: Tests results
     """
     data = ConfigManager.get_firmware_dict()
     self.assertEqual(len(data), 1, "Firmware: Wrong size of the List")
Beispiel #59
0
 def test_firmware_config(self):
     """
     Tests the firmware config
     :return: Tests results
     """
     data = ConfigManager.get_firmware_config()
     self.assertEqual(len(data), 1, "firmware_Yaml: Wrong size of the List")
 def test_web_interface_dict(self):
     """
     Tests the web interface config
     :return: Tests results
     """
     data = ConfigManager.get_web_interface_dict()
     self.assertEqual(True, data[0], "web_interface: Wrong config")