Beispiel #1
0
    def all_tests(self, key: str,
                  config: Configuration) -> List[TestDefinition]:
        if not config:
            return []

        includes = config.pop_optional(list, 'include') or []
        excludes = config.pop_optional(list, 'exclude') or []
        parameters = config.pop_optional(Configuration,
                                         'parameters') or Configuration()
        all_tests = self.find_python_tests()

        PythonTestsProvider.validate_match_strings(all_tests,
                                                   includes + excludes)

        # Instantiate tests selected
        for test in all_tests:
            test.selected = PythonTestsProvider.test_selected(
                test.name, includes, excludes)

            test_parameters_list = parameters.pop_raw(test.name)
            # If no parameters used, just create one empty set
            if test.selected and not test_parameters_list:
                test_parameters_list = [{}]

            if not isinstance(test_parameters_list, list):
                test_parameters_list = [test_parameters_list]

            for test_parameters in test_parameters_list:
                test.parameter_sets.append(test_parameters)

        parameters.ensure_consumed()
        config.ensure_consumed()
        return all_tests
    def create_consoles(config: Configuration, system: SystemContext) -> List[ConsoleBase]:
        if not config:
            return None, None

        serial = TargetFactory.create_serial(config.pop('serial'), system)
        ssh = TargetFactory.create_ssh(config.pop('ssh'), system)
        config.ensure_consumed()
        return serial, ssh
    def parse_credentials(credentials_config: Configuration) -> Credentials:
        if not credentials_config:
            return Credentials()

        credentials = Credentials(
            credentials_config.pop('login'),
            credentials_config.pop('password'))
        credentials_config.ensure_consumed()
        return credentials
    def parse_system_context(system_config: Configuration) -> SystemContext:
        if not system_config:
            return SystemContext()

        credentials = TargetFactory.parse_credentials(system_config.pop('credentials'))
        system = SystemContext(prompt_regex=system_config.pop('prompt_regex'),
                               credentials=credentials)
        system_config.ensure_consumed()
        return system
    def create_power_control(power_config: Configuration, console: ConsoleBase) -> PowerBase:
        if not power_config:
            power_config = Configuration()

        POWER_SOFT = 'soft'
        POWER_IPPOWER9258 = 'ippower9258'
        POWER_UHUBCTL = 'uhubctl'
        POWER_LIST = [POWER_SOFT, POWER_IPPOWER9258, POWER_UHUBCTL]

        if len(power_config) > 1:
            raise TargetConfigError(
                'Only one power control should be provided in the target configuration,'
                f' but two or more provided:{os.linesep}{power_config}')

        if power_config:
            control_type = power_config.first()
        elif console:
            control_type = POWER_SOFT
        else:
            return None

        if control_type not in POWER_LIST:
            raise TargetConfigError(
                f'Unsupported power control type "{control_type}". Supported types: {POWER_LIST}')

        power_config = power_config.pop(control_type) or Configuration()
        power = None
        if control_type == POWER_SOFT:
            if not console:
                raise TargetConfigError(
                    'No console available for soft power control')

            power = SoftPower(console)

        elif control_type == POWER_IPPOWER9258:
            host = power_config.pop('host')
            outlet = power_config.pop('outlet')
            if not host or not outlet:
                raise TargetConfigError(
                    'IP Power PDU "host" and/or "outlet" attributes are missing')

            port = power_config.pop('port')
            login = power_config.pop('login')
            password = power_config.pop('password')
            power = IPPowerPDU(outlet, host, netport=port,
                               username=login, password=password)
        elif control_type == POWER_UHUBCTL:
            power = Uhubctl(location=power_config.pop('location'),
                            port=power_config.pop('port'))
        else:
            raise Exception('Unreachable, unknown power controller')

        power_config.ensure_consumed()
        return power
Beispiel #6
0
 def create_context(config: Configuration) -> PlumaContext:
     if not isinstance(config, Configuration):
         raise ValueError('Invalid configuration: The configuration passed '
                          'should be a Configuration instance.')
     try:
         context = TargetConfig._create_context(config)
     except ConfigurationError as e:
         raise TargetConfigError(e)
     else:
         TargetConfig.print_context_settings(context)
         config.ensure_consumed()
         return context
    def create_serial(serial_config: Configuration, system: SystemContext) -> ConsoleBase:
        if not serial_config:
            return None

        log.debug(f'Serial config = {serial_config}')

        port = serial_config.pop('port')
        if not port:
            raise TargetConfigError(
                'Missing "port" attributes for serial console in the configuration file')

        serial = SerialConsole(port=port, baud=int(serial_config.pop('baud') or 115200),
                               system=system)
        serial_config.ensure_consumed()
        return serial
    def __init__(self, config: Configuration,
                 test_providers: List[TestsProvider]):
        if not config or not isinstance(config, Configuration):
            raise ValueError(
                f'Null or invalid \'config\', which must be of type \'{Configuration}\''
            )

        if not test_providers:
            raise ValueError('Null test providers passed')

        if not isinstance(test_providers, list):
            test_providers = [test_providers]

        self.settings_config = config.pop(SETTINGS_SECTION, Configuration())
        self.test_providers = test_providers
        self.tests = None

        self.__populate_tests(config)

        config.ensure_consumed()
    def create_ssh(ssh_config: Configuration, system: SystemContext) -> ConsoleBase:
        if not ssh_config:
            return None

        log.debug('SSH config = ' + json.dumps(ssh_config.content()))
        target = ssh_config.pop('target')
        login = ssh_config.pop('login', system.credentials.login)

        if not target or not login:
            raise TargetConfigError(
                'Missing "target" or "login" attributes for SSH console in the configuration file')

        password = ssh_config.pop('password', system.credentials.password)
        ssh_config.ensure_consumed()

        # Create a new system config to override default credentials
        ssh_system = deepcopy(system)
        ssh_system.credentials.login = login
        ssh_system.credentials.password = password

        return SSHConsole(target, system=ssh_system)
    def _create_context(config: Configuration) -> PlumaContext:
        variables = TargetFactory.parse_variables(config.pop('variables'))
        system = TargetFactory.parse_system_context(config.pop('system'))
        serial, ssh = TargetFactory.create_consoles(config.pop('console'), system)

        if not serial and not ssh:
            log.warning("No console defined in the device configuration file")

        power = TargetFactory.create_power_control(
            config.pop('power'), ssh)

        config.ensure_consumed()

        consoles = {}
        if serial:
            consoles['serial'] = serial
        if ssh:
            consoles['ssh'] = ssh

        board = Board('Test board', console=consoles, power=power,
                      system=system)
        return PlumaContext(board, variables=variables)
Beispiel #11
0
    def _create_context(config: Configuration) -> PlumaContext:
        variables = TargetFactory.parse_variables(
            config.pop_optional(Configuration, 'variables'))
        system = TargetFactory.parse_system_context(
            config.pop_optional(Configuration, 'system'))
        consoles = TargetFactory.create_consoles(
            config.pop_optional(Configuration, 'console'), system)

        serial = consoles.get('serial')
        ssh = consoles.get('ssh')
        if not serial and not ssh:
            log.warning("No console defined in the device configuration file")

        power = TargetFactory.create_power_control(
            config.pop_optional(Configuration, 'power'), ssh or serial)

        config.ensure_consumed()

        board = Board('Test board',
                      console=consoles,
                      power=power,
                      system=system)
        return PlumaContext(board, variables=variables)