def test_import_firmware(self): """ Try's to get the firmware-image two times. At least the second try the firmware should be stored on the device and imported. """ Logger().debug("Test FirmwareHandler: import_firmware ...") # 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" assert isinstance(router, Router) # Create firmware_handler release_model = "stable" url = "https://firmware.darmstadt.freifunk.net" download_all = False firmware_handler = FirmwareHandler(url) assert isinstance(firmware_handler, FirmwareHandler) # Downlaods the firmware-image firmware_handler.download_firmware(router.model, release_model) # Imports the firmware-image from the local storage firmware = firmware_handler.get_firmware(router.model, release_model, download_all) assert isinstance(firmware, Firmware) assert firmware.name == "gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin" assert firmware.version == "0.7.3" assert firmware.freifunk_verein == "ffda" assert firmware.release_model == "stable" assert firmware.file == (firmware_handler.FIRMWARE_PATH + '/stable/sysupgrade/gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin')
def test_get_single_firmware(self): """ Downloads a single firmware-image. """ Logger().debug("Test FirmwareHandler: get_single_firmware ...") # 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" assert isinstance(router, Router) # Create firmware_handler release_model = "stable" url = "https://firmware.darmstadt.freifunk.net" download_all = False firmware_handler = FirmwareHandler(url) assert isinstance(firmware_handler, FirmwareHandler) # Imports the Firmware if already existing or downlaods it firmware = firmware_handler.get_firmware(router.model, release_model, download_all) assert isinstance(firmware, Firmware) assert firmware.name == "gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin" assert firmware.version == "0.7.3" assert firmware.freifunk_verein == "ffda" assert firmware.release_model == "stable" assert firmware.file == (firmware_handler.FIRMWARE_PATH + '/stable/sysupgrade/gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin')
def test_router_wget(self): # 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" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) # Create NetworkCrtl network_ctrl = NetworkCtrl(router, 'eth0') assert isinstance(network_ctrl, NetworkCtrl) self.assertRaises(Exception, network_ctrl.connect_with_remote_system()) # Create test file 'test_wget.txt' path = os.path.dirname(__file__) file = open(path + '/test_wget.txt', 'w+') # The Router downloads this file via wget from the raspberryPi network_ctrl.remote_system_wget(path + '/test_wget.txt', '/tmp/') # Tests if the file has successful downloaded output = network_ctrl.send_command( "test -f '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") # Test output = network_ctrl.send_command( "rm '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") file.close() network_ctrl.exit()
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()
def test_router_wget(self): # 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" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) # Create NetworkCrtl network_ctrl = NetworkCtrl(router, 'eth0') assert isinstance(network_ctrl, NetworkCtrl) self.assertRaises(Exception, network_ctrl.connect_with_remote_system()) # Create test file 'test_wget.txt' path = os.path.dirname(__file__) file = open(path + '/test_wget.txt', 'w+') # The Router downloads this file via wget from the raspberryPi network_ctrl.remote_system_wget(path + '/test_wget.txt', '/tmp/') # Tests if the file has successful downloaded output = network_ctrl.send_command("test -f '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") # Test output = network_ctrl.send_command("rm '/tmp/test_wget.txt' && echo True") self.assertEqual(output, "['True\\n']") file.close() network_ctrl.exit()
def _test_import_firmware(self): """ Try's to get the firmware-image two times. At least the second try the firmware should be stored on the device and imported. """ print("Test FirmwareHandler: import_firmware ...") # 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" assert isinstance(router, Router) # Create firmware_handler release_model = "stable" url = "https://firmware.darmstadt.freifunk.net" download_all = False firmware_handler = FirmwareHandler(url) assert isinstance(firmware_handler, FirmwareHandler) # Downloads the firmware-image firmware_handler.download_firmware(router.model, release_model) # Imports the firmware-image from the local storage firmware = firmware_handler.get_firmware(router.model, release_model, download_all) assert isinstance(firmware, Firmware) assert firmware.name == "gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin" assert firmware.version == "0.7.3" assert firmware.freifunk_verein == "ffda" assert firmware.release_model == "stable" assert firmware.file == ( FIRMWARE_PATH + '/stable/sysupgrade/gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin' )
def _test_get_single_firmware(self): """ Downloads a single firmware-image. """ print("Test FirmwareHandler: get_single_firmware ...") # 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" assert isinstance(router, Router) # Create firmware_handler release_model = "stable" url = "https://firmware.darmstadt.freifunk.net" download_all = False firmware_handler = FirmwareHandler(url) assert isinstance(firmware_handler, FirmwareHandler) # Imports the Firmware if already existing or downlaods it firmware = firmware_handler.get_firmware(router.model, release_model, download_all) assert isinstance(firmware, Firmware) assert firmware.name == "gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin" assert firmware.version == "0.7.3" assert firmware.freifunk_verein == "ffda" assert firmware.release_model == "stable" assert firmware.file == ( FIRMWARE_PATH + '/stable/sysupgrade/gluon-ffda-0.7.3-tp-link-tl-wr841n-nd-v9-sysupgrade.bin' )
def _test_check_hash_firmware(self): """ Downloads a single firmware-image. """ print("Test FirmwareHandler: check_hash_firmware ...") # 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" assert isinstance(router, Router) # Create firmware_handler release_model = "stable" url = "https://firmware.darmstadt.freifunk.net" download_all = False firmware_handler = FirmwareHandler(url) assert isinstance(firmware_handler, FirmwareHandler) # Imports the Firmware if already existing or downloads it firmware = firmware_handler.get_firmware(router.model, release_model, download_all) assert isinstance(firmware, Firmware) incorrect_hash = "2b83a03e961f2e0a7fe1817e86e9caf248fbe440d12acda5a5c78de8a7d4f25ec48282cb8562d4b3b5e3c0" assert not firmware.check_hash(incorrect_hash) assert firmware.check_hash(firmware.hash)
def test_check_hash_firmware(self): """ Downloads a single firmware-image. """ Logger().debug("Test FirmwareHandler: check_hash_firmware ...") # 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" assert isinstance(router, Router) # Create firmware_handler release_model = "stable" url = "https://firmware.darmstadt.freifunk.net" download_all = False firmware_handler = FirmwareHandler(url) assert isinstance(firmware_handler, FirmwareHandler) # Imports the Firmware if already existing or downloads it firmware = firmware_handler.get_firmware(router.model, release_model, download_all) assert isinstance(firmware, Firmware) incorrect_hash = "2b83a03e961f2e0a7fe1817e86e9caf248fbe440d12acda5a5c78de8a7d4f25ec48282cb8562d4b3b5e3c0" assert not firmware.check_hash(incorrect_hash) assert firmware.check_hash(firmware.hash)
def _create_router(self): # Create router router = Router(0, "vlan21", 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" assert isinstance(router, Router) return router
def _create_router(self): # Create router router = Router(0, "vlan21", 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" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.normal assert isinstance(router, Router) return router
def _create_router(self): # Create router router = Router(0, "vlan21", 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.node_name = "64293-testframework1" router.public_key = "483938492329bc12aa1212d1b" assert isinstance(router, Router) return router
def _create_router(self): # Create router router = Router(0, "vlan21", 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" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) return router
def test_router_info(self): # 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.normal router_info = RouterInfo(router) router_info.start() router_info.join()
def test_reboot_into_config(self): # 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.normal assert isinstance(router, Router) RouterReboot().configmode(router) assert router.mode == Mode.configuration
def test_optional_getter_setter(self): router = Router(0, "vlan21", 21, "10.223.254.254", 16, "192.168.1.1", 24, "root", "root", 1) assert isinstance(router, Router) router.mode = Mode.configuration router.model = "TP-LINK TL-WR841N/ND v9" router.mac = "e8:de:27:b7:7c:e2" router.node_name = "64293-testframework1" router.public_key = "1234567890abcdef16171819" network_interface = NetworkInterface(0, "eth0") assert isinstance(network_interface, NetworkInterface) router.network_interfaces[network_interface.name] = network_interface cpu_process = CPUProcess(11, "root", 1.1, 11.2, "echo") assert isinstance(cpu_process, CPUProcess) router.cpu_processes.append(cpu_process) socket = InternetSocket() assert isinstance(socket, InternetSocket) router.sockets.append(socket) ram = RAM(8000, 4000, 4000, 0, 0) assert isinstance(ram, RAM) router.ram = ram flash_driver = Flashdriver(8000, 2000, 6000) assert isinstance(flash_driver, Flashdriver) router.flashdriver = flash_driver router.uci["autoupdater.settings.enabled"] = "1" bat_originator = BatOriginator( "00:00:00:00:00:00", 12.2, "01:00:01:00:01:00", "mesh0", ["01:00:01:00:01:00", "21:00:21:00:21:00", "03:00:03:00:03:00"]) assert isinstance(bat_originator, BatOriginator) router.bat_originators.append(bat_originator) self.assertEqual(Mode.configuration, router.mode) self.assertEqual("TP-LINK TL-WR841N/ND v9", router.model) self.assertEqual("e8:de:27:b7:7c:e2", router.mac) self.assertEqual("64293-testframework1", router.node_name) self.assertEqual("1234567890abcdef16171819", router.public_key) self.assertEqual(network_interface, router.network_interfaces[network_interface.name]) self.assertEqual(cpu_process, router.cpu_processes.pop()) self.assertEqual(socket, router.sockets.pop()) self.assertEqual(ram, router.ram) self.assertEqual(flash_driver, router.flashdriver) self.assertEqual('Firmware not known', router.firmware.name) self.assertEqual("1", router.uci["autoupdater.settings.enabled"]) self.assertEqual(bat_originator, router.bat_originators.pop())
def test_connection(self): # 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" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) # Create NetworkCrtl network_ctrl = NetworkCtrl(router, 'eth0') assert isinstance(network_ctrl, NetworkCtrl) # network_ctrl.connect_with_router() network_ctrl.exit()
def test_optional_getter_setter(self): router = Router(0, "vlan21", 21, "10.223.254.254", 16, "192.168.1.1", 24, "root", "root", 1) assert isinstance(router, Router) router.mode = Mode.configuration router.model = "TP-LINK TL-WR841N/ND v9" router.mac = "e8:de:27:b7:7c:e2" router.node_name = "64293-testframework1" router.public_key = "1234567890abcdef16171819" network_interface = NetworkInterface(0, "eth0") assert isinstance(network_interface, NetworkInterface) router.network_interfaces[network_interface.name] = network_interface cpu_process = CPUProcess(11, "root", 1.1, 11.2, "echo") assert isinstance(cpu_process, CPUProcess) router.cpu_processes.append(cpu_process) socket = InternetSocket() assert isinstance(socket, InternetSocket) router.sockets.append(socket) ram = RAM(8000, 4000, 4000, 0, 0) assert isinstance(ram, RAM) router.ram = ram flash_driver = Flashdriver(8000, 2000, 6000) assert isinstance(flash_driver, Flashdriver) router.flashdriver = flash_driver router.uci["autoupdater.settings.enabled"] = "1" bat_originator = BatOriginator("00:00:00:00:00:00", 12.2, "01:00:01:00:01:00", "mesh0", ["01:00:01:00:01:00", "21:00:21:00:21:00", "03:00:03:00:03:00"]) assert isinstance(bat_originator, BatOriginator) router.bat_originators.append(bat_originator) self.assertEqual(Mode.configuration, router.mode) self.assertEqual("TP-LINK TL-WR841N/ND v9", router.model) self.assertEqual("e8:de:27:b7:7c:e2", router.mac) self.assertEqual("64293-testframework1", router.node_name) self.assertEqual("1234567890abcdef16171819", router.public_key) self.assertEqual(network_interface, router.network_interfaces[network_interface.name]) self.assertEqual(cpu_process, router.cpu_processes.pop()) self.assertEqual(socket, router.sockets.pop()) self.assertEqual(ram, router.ram) self.assertEqual(flash_driver, router.flashdriver) self.assertEqual('Firmware not known', router.firmware.name) self.assertEqual("1", router.uci["autoupdater.settings.enabled"]) self.assertEqual(bat_originator, router.bat_originators.pop())
def test_send_command(self): # 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" # Has to be matched with the current mode (normal, configuration) router.mode = Mode.configuration assert isinstance(router, Router) # Create NetworkCrtl network_ctrl = NetworkCtrl(router, 'eth0') assert isinstance(network_ctrl, NetworkCtrl) # Test if the command 'uname' could be send via ssh self.assertRaises(Exception, network_ctrl.connect_with_remote_system()) output = network_ctrl.send_command("uname") self.assertEqual(output, "['Linux\\n']") network_ctrl.exit()
from util.router_flash_firmware import RouterFlashFirmware from router.router import Router, Mode from config.configmanager import ConfigManager # 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 # Create firware configuration firmware_config = ConfigManager.get_firmware_dict()[0] RouterFlashFirmware.sysupdate(router, firmware_config) RouterFlashFirmware.sysupgrade(router, n=True)