Controllers Base Module
This module implements th controller base class with clean-up functionality.
- class mtf.network_port.controllers_base.ControllerBase
Base class for controllers that need to be cleaned up.
This class is designed to support managing the automatic cleanup of controller instances. - All controllers that need to be cleaned up should
inherit from this base class.
The controllers that are added in the list of controllers will be automatically cleaned up when
the cleanup_controllers() method is called. - The list of controllers will not be cleaned throughout the entire test series or other scenarios where cleanup is needed. - Any new controller class should inherit from the ControllerBase class to ensure automatic cleanup. - Any new controller class that inherit from the ControllerBase should not override __new__() method to be sure that any new instance is added to the controllers list.
- static __new__(cls, *args, **kwargs)
Creates a new instance.
- Args:
*args: The variable arguments list. **wargs: The keyword arguments list.
- Returns:
ControllersBase: The newly created instance.
Note:
Note
The instance will be automatically added to the list of controllers to be cleaned up later. It guarantees that all the controller instances are followed up and cleaned up when the associate method ‘controllers_cleanup(cls)’ is called.
Important
Do not override this method in subclasses to maintain this functionality.
- classmethod controllers_cleanup()
Cleans up all controller instances.
It calls clean_up() for each controller in the list. If a cleanup fails, an error is raised, but the method continues processing the remaining controllers.
- Returns:
- bool: True indicating that all controllers were cleaned up successfully.
Otherwise, False is returned when an error occurs during the cleanup process.
- clean_up() bool
Cleans up the controller instance.
This method should be overridden to provide the specific cleanup logic. If an instance does not override it,a default message is shown to indicate that no cleanup logic is implemented.
- Returns:
bool: True on success, False otherwise.
Note:
Important
This method must be overridden to implement the proper clean-up process for the respective instance/subclass.