Пример #1
0
    def registerController(self, module, start_services=True):
        """Registers a controller module for a test run.

        This declares a controller dependency of this test class. If the target
        module exists and matches the controller interface, the controller
        module will be instantiated with corresponding configs in the test
        config file. The module should be imported first.

        Params:
            module: A module that follows the controller module interface.
            start_services: boolean, controls whether services (e.g VTS agent)
                            are started on the target.

        Returns:
            A list of controller objects instantiated from controller_module.

        Raises:
            ControllerError is raised if no corresponding config can be found,
            or if the controller module has already been registered.
        """
        logging.info("cwd: %s", os.getcwd())
        logging.info("adb devices: %s", module.list_adb_devices())
        self.verifyControllerModule(module)
        module_ref_name = module.__name__.split('.')[-1]
        if module_ref_name in self.controller_registry:
            raise signals.ControllerError(
                ("Controller module %s has already "
                 "been registered. It can not be "
                 "registered again.") % module_ref_name)
        # Create controller objects.
        create = module.create
        module_config_name = module.VTS_CONTROLLER_CONFIG_NAME
        if module_config_name not in self.testbed_configs:
            raise signals.ControllerError(("No corresponding config found for"
                                           " %s") % module_config_name)
        try:
            # Make a deep copy of the config to pass to the controller module,
            # in case the controller module modifies the config internally.
            original_config = self.testbed_configs[module_config_name]
            controller_config = copy.deepcopy(original_config)
            logging.info("controller_config: %s", controller_config)
            if "use_vts_agent" not in self.testbed_configs:
                objects = create(controller_config, start_services)
            else:
                objects = create(controller_config,
                                 self.testbed_configs["use_vts_agent"])
        except:
            logging.exception(("Failed to initialize objects for controller "
                               "%s, abort!"), module_config_name)
            raise
        if not isinstance(objects, list):
            raise ControllerError(("Controller module %s did not return a list"
                                   " of objects, abort.") % module_ref_name)
        self.controller_registry[module_ref_name] = objects
        logging.debug("Found %d objects for controller %s", len(objects),
                      module_config_name)
        destroy_func = module.destroy
        self.controller_destructors[module_ref_name] = destroy_func
        return objects
Пример #2
0
    def verifyControllerModule(self, module):
        """Verifies a module object follows the required interface for
        controllers.

        Args:
            module: An object that is a controller module. This is usually
                    imported with import statements or loaded by importlib.

        Raises:
            ControllerError is raised if the module does not match the vts.runners.host
            controller interface, or one of the required members is null.
        """
        required_attributes = ("create", "destroy",
                               "VTS_CONTROLLER_CONFIG_NAME")
        for attr in required_attributes:
            if not hasattr(module, attr):
                raise signals.ControllerError(
                    ("Module %s missing required "
                     "controller module attribute %s.") %
                    (module.__name__, attr))
            if not getattr(module, attr):
                raise signals.ControllerError(
                    ("Controller interface %s in %s "
                     "cannot be null.") % (attr, module.__name__))