def _validate_test_config(test_config): """Validates the raw configuration loaded from the config file. Making sure all the required fields exist. """ for k in Config.reserved_keys.value: if k not in test_config: raise USERError(("Required key {} missing in test " "config.").format(k))
def _validate_testbed_name(name): """Validates the name of a test bed. Since test bed names are used as part of the test run id, it needs to meet certain requirements. Args: name: The test bed's name specified in config file. Raises: If the name does not meet any criteria, USERError is raised. """ if not name: raise USERError("Test bed names can't be empty.") if not isinstance(name, str): raise USERError("Test bed names have to be string.") for l in name: if l not in valid_filename_chars: raise USERError("Char '%s' is not allowed in test bed names." % l)
def _parse_one_test_specifier(item): """Parse one test specifier from command line input. This also verifies that the test class name and test case names follow ACTS's naming conventions. A test class name has to end with "Test"; a test case name has to start with "test". Args: item: A string that specifies a test class or test cases in one test class to run. Returns: A tuple of a string and a list of strings. The string is the test class name, the list of strings is a list of test case names. The list can be None. """ tokens = item.split(':') if len(tokens) > 2: raise USERError("Syntax error in test specifier %s" % item) if len(tokens) == 1: # This should be considered a test class name test_cls_name = tokens[0] _verify_test_class_name(test_cls_name) return (test_cls_name, None) elif len(tokens) == 2: # This should be considered a test class name followed by # a list of test case names. test_cls_name, test_case_names = tokens clean_names = [] _verify_test_class_name(test_cls_name) for elem in test_case_names.split(','): test_case_name = elem.strip() if not test_case_name.startswith("test_"): raise USERError(("Requested test case '%s' in test class " "'%s' does not follow the test case " "naming convention test_*.") % (test_case_name, test_cls_name)) clean_names.append(test_case_name) return (test_cls_name, clean_names)
def _validate_testbed_configs(testbed_configs): """Validates the testbed configurations. Args: testbed_configs: A list of testbed configuration json objects. Raises: If any part of the configuration is invalid, USERError is raised. """ seen_names = set() # Cross checks testbed configs for resource conflicts. for config in testbed_configs: # Check for conflicts between multiple concurrent testbed configs. # No need to call it if there's only one testbed config. name = config[Config.key_testbed_name.value] _validate_testbed_name(name) # Test bed names should be unique. if name in seen_names: raise USERError("Duplicate testbed name {} found.".format(name)) seen_names.add(name)
def _verify_test_class_name(test_cls_name): if not test_cls_name.endswith("Test"): raise USERError(("Requested test class '%s' does not follow the test " "class naming convention *Test.") % test_cls_name)