Testserver

Class Description

class server.server.Server

The great runtime server for all tests and more. This static class with class methods will be usually run as daemon on the main server. It is used to control the other routers, flash the firmwares and execute such as evaluate the tests. The web server and cli instances are connecting with this class and using its inherit public methods of ServerProxy.

classmethod control_switch(router_ids: typing.List, switch_all: bool, on_or_off: bool)

Switches the power for different routers on or off.

Parameters:
  • router_ids – List of router IDs
  • switch_all – apply to all routers
  • on_or_off – true for on, false for off
classmethod delete_test_results() → int

Remove all test results.

Returns:Number of deleted results
classmethod get_power_strip() → power_strip.power_strip.PowerStrip

Power strip as object, for now only 1.

Returns:Copy of the original object
classmethod get_router_by_id(router_id: int) → router.router.Router

Returns a Router with the given id.

Parameters:router_id
Returns:Router
classmethod get_routers() → typing.List

List of known router.

Returns:List is a copy of the original list
classmethod get_routers_task_queue_size(router_id: int) → int

Returns the size of the task queue including the actual running task.

Parameters:router_id – ID of the router
Returns:queue length
classmethod get_running_task(remote_system: network.remote_system.RemoteSystem) → typing.Union

Returns which task is running on the given RemoteSystem.

Parameters:remote_system – the RemoteSystem
Returns:if no job is running, it returns None
classmethod get_server_version() → str

Returns the server version as a string.

classmethod get_task_errors() → typing.List

Return a list of task errors.

Returns:A list of tuples with error information
classmethod get_task_queue_description(router_id: int=-1) → [(<class 'int'>, <class 'str'>, <class 'bool'>)]

List of waiting and running tasks.

Parameters:router_id – the specific router or all router if id = -1
Returns:List of (router_id, str(Job), job_running)
classmethod get_test_results(router_id: int=-1) → [(<class 'int'>, <class 'str'>, <class 'unittest.result.TestResult'>)]

Returns the firmware test results for the router.

Parameters:router_id – the specific router or all router if id = -1
Returns:List of results
classmethod get_test_sets()
Returns:Dictionary of Test_Sets
classmethod get_waiting_task_queue(remote_system: network.remote_system.RemoteSystem) → collections.deque

Returns the waiting task queue.

Parameters:remote_system – the associated RemoteSystem of the queue
Returns:Returns the queue as a collections.deque, filled with RemoteSystemJobClass and RemoteSystemJob and

there wait objects. Type: deque[Tuple[Union[RemoteSystemJobClass, RemoteSystemJob], DoneEvent]]

classmethod reboot_router(router_ids: typing.Union, reboot_all: bool, configmode: bool)

Reboots the given Routers.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • reboot_all – Reboots all Routers
  • configmode – Reboots Router into configmode
classmethod register_key(router_ids: typing.List, register_all: bool)

Sends the public-key of the given Routers to an email that is specified in the config-file.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • register_all – Register the public-keys of all Routers
register_tty(tty_name: str='') → bool

Register tty from cli in logging.

Parameters:tty_name – Name of the console
Return bool:Success of the register
classmethod router_online(router_ids: typing.Union, update_all: bool, blocked: bool=False) → None

Tries to connect to the Router and updates the Mode of the Router.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • update_all – Is True if all Routers should be updated
  • blocked – blocks until it finished
classmethod set_running_task(remote_system: network.remote_system.RemoteSystem, task: typing.Union) → None

Sets internally which RemoteSystem executes which Task. It doesn’t run or starts the job on the RemoteSystem!

Parameters:
  • remote_system – the RemoteSystem
  • task – the Task
classmethod set_waiting_task(remote_system: network.remote_system.RemoteSystem, task: typing.Union, done_event: threading.Event=<threading.Event object>) → None

Add a task to the waiting Queue of a specific RemoteSystem.

Parameters:
  • remote_system – the associated RemoteSystem of the queue
  • task – task which has to wait
  • done_event – event which will be triggered when the task is finished
classmethod setup_web_configuration(router_ids: typing.Union, 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.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • setup_all – If True all Routers will be setuped via the webinterface

:param wizard

classmethod start(config_path: str='/home/docs/checkouts/readthedocs.org/user_builds/freifunk-testframework/checkouts/master/config') → None

Starts the runtime server with all components.

Parameters:config_path – Path to an alternative config directory
classmethod start_job(remote_sys: network.remote_system.RemoteSystem, remote_job: network.remote_system.RemoteSystemJob, wait: int=-1) → bool

Starts an specific job on a RemoteSystem. The job will be executed asynchronous this means the method is not blocking. It add only the job to the task queue from RemoteSystem. If you want, that this method wait until the job is executed, you have to set the wait param. Think about that your job has maybe to wait in the queue.

Parameters:remote_sys – The RemoteSystem on which the job will run. If none then the job will be executed on all

routers :param remote_job: The name of the test to execute :param wait: -1 for async execution and positive integer for wait in seconds :return: True if job was successful added in the queue

classmethod start_test_set(router_id: int, test_set_name: str, wait: int=-1) → bool

Start an specific test on a router.

Parameters:router_id – The id of the router on which the test will run.

If id is -1 the test will be executed on all routers :param test_set_name: The name of the test set to execute :param wait: -1 for async execution and positive integer for wait in seconds :return: True if test was successful added in the queue

classmethod stop() → None

Stops the server, all running tests and closes all connections.

classmethod stop_all_tasks() → None

Stops all running jobs on the RemoteSystems.

classmethod sysupdate_firmware(router_ids: typing.Union, update_all: bool) → None

Downloads and copies the firmware to the Router given in the List(by a unique id) resp. to all Routers.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • update_all – Is True if all Routers should be updated
classmethod sysupgrade_firmware(router_ids: typing.Union, upgrade_all: bool, n: bool) → None

Upgrades the firmware on the given Router s.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • upgrade_all – If all is True all Routers were upgraded
  • n – If n is True the upgrade discard the last firmware
classmethod update_router_info(router_ids: typing.Union, update_all: bool) → None

Updates all the information about the Router.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • update_all – Is True if all Routers should be updated
classmethod write_in_db(key: str='', test: (<class 'int'>, <class 'str'>, <class 'unittest.result.TestResult'>)=None)

Write new entry in database.

Parameters:
  • key – Database entry key
  • test – Tuple with router id, test name and test

Class Diagram

UML class diagram of the module server

ServerProxy

class server.serverproxy.ServerProxy

A proxy model for inter-process communication between the server runtime and clients like CLI and WebServer. Read the method description carefully! The behaviour may be different as expected. Normally the method will be executed remotely on the server and the return value is given by copy and not by reference!

classmethod control_switch(router_ids: typing.List, switch_all: bool, on_or_off: bool)

Controls the power on the given port

Parameters:
  • router_ids – List of router IDs
  • switch_all – apply to all routers
  • on_or_off – true for on, false for off
classmethod delete_test_results() → int

Remove all test results

Returns:Number of deleted results
classmethod get_router_by_id(router_id: int) → router.router.Router

Returns a Router with the given id.

Parameters:router_id
Returns:Router
classmethod get_routers() → typing.List

List of known routers

Returns:List is a copy of the original list.
classmethod get_routers_task_queue_size(router_id: int) → int

Returns the size of the task queue including the actual running task

Parameters:router_id – ID of the router
Returns:queue length
classmethod get_server_version() → str

Returns the server version as a string

classmethod get_task_errors() → typing.List

Return a list of task errors :return: A list of tuples with error information

classmethod get_task_queue_description(router_id: int=-1) → [(<class 'int'>, <class 'str'>, <class 'bool'>)]

List of waiting and running tasks.

Parameters:router_id – the specific router or all router if id = -1
Returns:List of (router_id, str(Job), job_running)
classmethod get_test_results(router_id: int=-1) → [(<class 'int'>, <class 'str'>, <class 'unittest.result.TestResult'>)]

Returns the firmware test results for the router

Parameters:router_id – the specific router or all router if id = -1
Returns:List of results
classmethod get_test_sets()
Returns:Dictionary of Test_Sets
classmethod reboot_router(router_ids: typing.List, reboot_all: bool, configmode: bool)

Reboots the given Routers.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • reboot_all – Reboots all Routers
  • configmode – Reboots Router into configmode
classmethod register_key(router_ids: typing.List, register_all: bool)

Sends the public-key of the given Routers to an email that is specified in the config-file.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • register_all – Register the public-keys of all Routers
classmethod register_tty(tty_name: str='') → bool

Register tty from cli in logging :param tty_name: Name of the console :return bool: Success of the register

classmethod router_online(router_ids: typing.List, update_all: bool) → None

Tries to connect to the Router and updates the Mode of the Router.

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • update_all – Is True if all Routers should be updated
classmethod setup_web_configuration(router_ids: typing.List, 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

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • setup_all – If True all Routers will be setuped via the webinterface

:param wizard

classmethod start_test_set(router_id: int, test_set_name: str, wait: int=-1) → bool

Start an specific test on a router

Parameters:
  • router_id – The id of the router on which the test will run
  • test_set_name – The name of the test set to execute
  • wait – -1 for async execution and positive integer for wait in seconds
Returns:

True if test was successful added in the queue

classmethod stop() → None

Shutdown the server

classmethod sysupdate_firmware(router_ids: typing.List, update_all: bool) → None

Downloads and copies the firmware to the Router given in the List(by a unique id) resp. to all Routers

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • update_all – Is True if all Routers should be updated
classmethod sysupgrade_firmware(router_ids: typing.List, upgrade_all: bool, n: bool) → None

Upgrades the firmware on the given Router s

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • upgrade_all – If all is True all Routers were upgraded
  • n – If n is True the upgrade discard the last firmware
classmethod update_router_info(router_ids: typing.List, update_all: bool) → None

Updates all the information about the Router

Parameters:
  • router_ids – List of unique numbers to identify a Router
  • update_all – Is True if all Routers should be updated