Beispiel #1
0
def _process_wrapper(return_queue: multiprocessing.Queue,
                     error_queue: multiprocessing.Queue,
                     logging_queue: multiprocessing.Queue, process_id: str,
                     extension_package_import_paths: Sequence[str],
                     call_spec: CallSpec) -> None:
    """Executes the provided function in a parallel process."""
    gdm_logger.initialize_child_process_logging(logging_queue)
    short_description = f"{call_spec.function.__name__} in process {os.getpid()}"
    logger = gdm_logger.get_logger()
    logger.debug(f"{short_description}: starting execution of {call_spec}...")
    # The state of the main process (such as registered extension packages) is not
    # copied over when using "forkserver" or "spawn" as the process start method.
    for import_path in extension_package_import_paths:
        try:
            package_registrar.register(importlib.import_module(import_path))
        except (ImportError, errors.PackageRegistrationError) as e:
            logger.debug(
                f"{short_description}: failed to import and register GDM "
                f"extension package with import path {import_path}. "
                f"Error: {e!r}. Proceeding despite the failure.")

    manager_inst = manager.Manager()
    try:
        return_value = call_spec.function(manager_inst, *call_spec.args,
                                          **call_spec.kwargs)
        logger.debug(f"{short_description}: execution succeeded. "
                     f"Return value: {return_value}.")
        return_queue.put((process_id, return_value))
    except Exception as e:  # pylint: disable=broad-except
        logger.warning(
            f"{short_description}: execution raised an error: {e!r}.")
        error_queue.put((process_id, (type(e).__name__, str(e))))
    finally:
        manager_inst.close()
Beispiel #2
0
 def check_properties_set(cls, device_name, property_list):
     mgr = manager.Manager()
     for property_name in property_list:
         value = mgr.get_device_prop(device_name, property_name)
         if value is None or str(value).startswith("Exception"):
             return False
     return True
Beispiel #3
0
def _extract_testbed_device_info(config):
    """Extracts the device type and name from the first testbed and checks testbed validity.

    Args:
        config (str): path to the testbed config

    Raises:
        RuntimeError: the testbed doesn't have any devices or has more than 1 device in it.

    Returns:
        tuple: (testbed device type, testbed device name)
    """
    file_name = config
    with open(file_name) as open_file:
        file_content = yaml.load(open_file)
    controllers = file_content["TestBeds"][0]["Controllers"]

    devices = controllers.get("GazooDevice", [])
    if not devices:
        raise RuntimeError(
            "No valid devices available in testbed in {}".format(file_name))
    if len(devices) > 2:
        raise RuntimeError("Please use a testbed with just one device. "
                           "{} devices in first testbed in {}".format(
                               len(devices), file_name))

    device_id = devices[0]
    if isinstance(device_id, dict):
        device_id = device_id["id"]
    manager_instance = manager.Manager()
    device_type = manager_instance.get_device_prop(device_id, "device_type")
    manager_instance.close()
    return device_type, device_id
 def setup_class(self):
     super().setup_class()
     logging.getLogger().setLevel(logging.INFO)
     self.manager = manager.Manager(
         log_directory=self.log_path,
         gdm_log_file=os.path.join(self.log_path, "gdm.log"),
         stdout_logging=False
     )  # Avoid log duplication with Mobly's stdout log handler
Beispiel #5
0
 def check_properties_set(cls, device_name: str,
                          property_list: Collection[str]) -> bool:
     """Returns True if all of the properties are set."""
     mgr = manager.Manager()
     for property_name in property_list:
         value = mgr.get_device_prop(device_name, property_name)
         if value is None or str(value).startswith("Exception"):
             return False
     return True
Beispiel #6
0
 def setup_class(self):
     """Aborts the test suite if all tests have been filtered out by self.filter_tests()."""
     super().setup_class()
     self.manager = manager.Manager(log_directory=self.log_path,
                                    gdm_log_file=os.path.join(self.log_path, "gdm.log"),
                                    stdout_logging=False)
     self.check_test_config_keys()
     if self._abort_in_setup_class:
         asserts.abort_class("All tests in test suite {} have been skipped. "
                             "Aborting the test suite.".format(type(self).__name__))
Beispiel #7
0
def create(configs: List[Dict[str, Any]]) -> List[custom_types.Device]:
    """Creates gazoo device instances and returns them."""
    # log_path is set by mobly on logging in base_test
    log_path_directory = getattr(logging, "log_path", "/tmp/logs")
    gdm_log_file = os.path.join(log_path_directory, "gdm.txt")
    global _MANAGER_INSTANCE
    _MANAGER_INSTANCE = manager.Manager(log_directory=log_path_directory,
                                        gdm_log_file=gdm_log_file,
                                        stdout_logging=False)
    devices = []
    for entry in configs:
        name = entry["id"]
        _set_auxiliary_props(entry, name)
        device = _MANAGER_INSTANCE.create_device(name)
        devices.append(device)
    return devices
Beispiel #8
0
 def setUpClass(cls):
     super().setUpClass()
     logging.getLogger().setLevel(logging.INFO)
     cls.manager = manager.Manager()