Best Python code snippet using tempest_python
config.py
Source:config.py  
...1097            # service clients.1098            # NOTE(andreaf) This has to be done at the time the first1099            # attribute is accessed, to ensure all plugins have been already1100            # loaded, options registered, and _config is set.1101            _register_tempest_service_clients()1102        return getattr(self._config, attr)1103    def set_config_path(self, path):1104        self._path = path1105CONF = TempestConfigProxy()1106def skip_unless_config(*args):1107    """Decorator to raise a skip if a config opt doesn't exist or is False1108    :param str group: The first arg, the option group to check1109    :param str name: The second arg, the option name to check1110    :param str msg: Optional third arg, the skip msg to use if a skip is raised1111    :raises testtools.TestCaseskipException: If the specified config option1112        doesn't exist or it exists and evaluates to False1113    """1114    def decorator(f):1115        group = args[0]1116        name = args[1]1117        @functools.wraps(f)1118        def wrapper(self, *func_args, **func_kwargs):1119            if not hasattr(CONF, group):1120                msg = "Config group %s doesn't exist" % group1121                raise testtools.TestCase.skipException(msg)1122            conf_group = getattr(CONF, group)1123            if not hasattr(conf_group, name):1124                msg = "Config option %s.%s doesn't exist" % (group,1125                                                             name)1126                raise testtools.TestCase.skipException(msg)1127            value = getattr(conf_group, name)1128            if not value:1129                if len(args) == 3:1130                    msg = args[2]1131                else:1132                    msg = "Config option %s.%s is false" % (group,1133                                                            name)1134                raise testtools.TestCase.skipException(msg)1135            return f(self, *func_args, **func_kwargs)1136        return wrapper1137    return decorator1138def skip_if_config(*args):1139    """Raise a skipException if a config exists and is True1140    :param str group: The first arg, the option group to check1141    :param str name: The second arg, the option name to check1142    :param str msg: Optional third arg, the skip msg to use if a skip is raised1143    :raises testtools.TestCase.skipException: If the specified config option1144        exists and evaluates to True1145    """1146    def decorator(f):1147        group = args[0]1148        name = args[1]1149        @functools.wraps(f)1150        def wrapper(self, *func_args, **func_kwargs):1151            if hasattr(CONF, group):1152                conf_group = getattr(CONF, group)1153                if hasattr(conf_group, name):1154                    value = getattr(conf_group, name)1155                    if value:1156                        if len(args) == 3:1157                            msg = args[2]1158                        else:1159                            msg = "Config option %s.%s is false" % (group,1160                                                                    name)1161                        raise testtools.TestCase.skipException(msg)1162            return f(self, *func_args, **func_kwargs)1163        return wrapper1164    return decorator1165def service_client_config(service_client_name=None):1166    """Return a dict with the parameters to init service clients1167    Extracts from CONF the settings specific to the service_client_name and1168    api_version, and formats them as dict ready to be passed to the service1169    clients __init__:1170        * `region` (default to identity)1171        * `catalog_type`1172        * `endpoint_type`1173        * `build_timeout` (object-storage and identity default to compute)1174        * `build_interval` (object-storage and identity default to compute)1175    The following common settings are always returned, even if1176    `service_client_name` is None:1177        * `disable_ssl_certificate_validation`1178        * `ca_certs`1179        * `trace_requests`1180        * `http_timeout`1181    The dict returned by this does not fit a few service clients:1182        * The endpoint type is not returned for identity client, since it takes1183          three different values for v2 admin, v2 public and v31184        * The `ServersClient` from compute accepts an optional1185          `enable_instance_password` parameter, which is not returned.1186        * The `VolumesClient` for both v1 and v2 volume accept an optional1187          `default_volume_size` parameter, which is not returned.1188        * The `TokenClient` and `V3TokenClient` have a very different1189          interface, only auth_url is needed for them.1190    :param service_client_name: str Name of the service. Supported values are1191        'compute', 'identity', 'image', 'network', 'object-storage', 'volume'1192    :return: dictionary of __init__ parameters for the service clients1193    :rtype: dict1194    """1195    _parameters = {1196        'disable_ssl_certificate_validation':1197            CONF.identity.disable_ssl_certificate_validation,1198        'ca_certs': CONF.identity.ca_certificates_file,1199        'trace_requests': CONF.debug.trace_requests,1200        'http_timeout': CONF.service_clients.http_timeout1201    }1202    if service_client_name is None:1203        return _parameters1204    # Get the group of options first, by normalising the service_group_name1205    # Services with a '-' in the name have an '_' in the option group name1206    config_group = service_client_name.replace('-', '_')1207    # NOTE(andreaf) Check if the config group exists. This allows for this1208    # helper to be used for settings from registered plugins as well1209    try:1210        options = getattr(CONF, config_group)1211    except cfg.NoSuchOptError:1212        # Option group not defined1213        raise exceptions.UnknownServiceClient(services=service_client_name)1214    # Set endpoint_type1215    # Identity uses different settings depending on API version, so do not1216    # return the endpoint at all.1217    if service_client_name != 'identity':1218        _parameters['endpoint_type'] = getattr(options, 'endpoint_type')1219    # Set build_*1220    # Object storage and identity groups do not have conf settings for1221    # build_* parameters, and we default to compute in any case1222    for setting in ['build_timeout', 'build_interval']:1223        if not hasattr(options, setting) or not getattr(options, setting):1224            _parameters[setting] = getattr(CONF.compute, setting)1225        else:1226            _parameters[setting] = getattr(options, setting)1227    # Set region1228    # If a service client does not define region or region is not set1229    # default to the identity region1230    if not hasattr(options, 'region') or not getattr(options, 'region'):1231        _parameters['region'] = CONF.identity.region1232    else:1233        _parameters['region'] = getattr(options, 'region')1234    # Set service1235    _parameters['service'] = getattr(options, 'catalog_type')1236    return _parameters1237def _register_tempest_service_clients():1238    # Register tempest own service clients using the same mechanism used1239    # for external plugins.1240    # The configuration data is pushed to the registry so that automatic1241    # configuration of tempest own service clients is possible both for1242    # tempest as well as for the plugins.1243    service_clients = clients.tempest_modules()1244    registry = clients.ClientsRegistry()1245    all_clients = []1246    for service_client in service_clients:1247        module = service_clients[service_client]1248        configs = service_client.split('.')[0]1249        service_client_data = dict(1250            name=service_client.replace('.', '_'),1251            service_version=service_client,...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
