diff --git a/src/bos/common/utils.py b/src/bos/common/utils.py index 315a5297..946ca021 100644 --- a/src/bos/common/utils.py +++ b/src/bos/common/utils.py @@ -132,11 +132,7 @@ def using_sbps_check_kernel_parameters(kernel_parameters: str) -> bool: Return True if it is and False if it is not. """ # Check for the 'root=sbps-s3' string. - pattern = re.compile("root=sbps-s3") - match = pattern.search(kernel_parameters) - if match: - return True - return False + return "root=sbps-s3" in kernel_parameters def components_by_id(components: List[dict]) -> dict: """ @@ -149,12 +145,7 @@ def components_by_id(components: List[dict]) -> dict: Purpose: It makes searching more efficient because you can index by component name. """ - components_by_id = {} - for component in components: - id = component["id"] - components_by_id[id] = component - - return components_by_id + return { component["id"]: component for component in components } def reverse_components_by_id(components_by_id: dict) -> List[dict]: """ @@ -166,5 +157,4 @@ def reverse_components_by_id(components_by_id: dict) -> List[dict]: Purpose: Reverse the effect of components_by_id. """ - components = [component for component in components_by_id.values()] - return components \ No newline at end of file + return list(components_by_id.values()) diff --git a/src/bos/operators/utils/clients/ims.py b/src/bos/operators/utils/clients/ims.py index 10d7f2bf..d192aec0 100644 --- a/src/bos/operators/utils/clients/ims.py +++ b/src/bos/operators/utils/clients/ims.py @@ -66,9 +66,9 @@ def tag_image(image_id: str, operation: str, key: str, value: str = None, sessio raise TagFailure(msg) if value: - LOGGER.debug(f"Patching image {image_id} {operation}ing key: {key} value: {value}") + LOGGER.debug("Patching image %s %sing key: %s value: %s", image_id, operation, key, value) else: - LOGGER.debug(f"Patching image {image_id} {operation}ing key: {key}") + LOGGER.debug("Patching image %s %sing key: %s", image_id, operation, key) if not session: session = requests_retry_session() @@ -81,4 +81,3 @@ def tag_image(image_id: str, operation: str, key: str, value: str = None, sessio } } patch_image(image_id=image_id, data=data, session=session) - diff --git a/utils/convert_oas/convert_oas.py b/utils/convert_oas/convert_oas.py index 5acc8cc6..0d04710a 100644 --- a/utils/convert_oas/convert_oas.py +++ b/utils/convert_oas/convert_oas.py @@ -45,7 +45,8 @@ class ConversionException(Exception): def _cleanse_schema(schema): if not isinstance(schema, dict): - raise ConversionException(f"Expecting schema to be type dict, but found type {type(schema).__name__}: {schema}") + raise ConversionException( + f"Expecting schema to be type dict, but found type {type(schema).__name__}: {schema}") if len(schema) == 1: key = list(schema.keys())[0] match key: @@ -60,7 +61,8 @@ def _cleanse_schema(schema): # If this is oneOf, anyOf, or allOf, then it should map to a list, and we need to # parse each element of that list if not isinstance(schema[key], list): - raise ConversionException(f"Expecting '{key}' to map to a list, but it does not: {schema}") + raise ConversionException( + f"Expecting '{key}' to map to a list, but it does not: {schema}") for v in schema[key]: _cleanse_schema(v) return @@ -88,9 +90,10 @@ def _cleanse_generic_schema(schema): if schema.pop("nullable", False): schema["type"] = [ schema["type"], "null" ] - # Remove keywords that are not part of JSON schema, as well - # as ones which are not needed for validation, and have different meanings between OAS and JSON schema - for k in ["deprecated", "discriminator", "example", "externalDocs", "readOnly", "writeOnly", "xml", "description"]: + # Remove keywords that are not part of JSON schema, as well as ones which are not needed for + # validation, and have different meanings between OAS and JSON schema + for k in ["deprecated", "discriminator", "example", "externalDocs", "readOnly", "writeOnly", + "xml", "description"]: schema.pop(k, None) @@ -99,37 +102,42 @@ def _cleanse_array_schema(schema): try: items_schema = schema["items"] except KeyError as exc: - raise ConversionException(f"Array schema is missing required 'items' field: {schema}") from exc + raise ConversionException( + f"Array schema is missing required 'items' field: {schema}") from exc _cleanse_schema(items_schema) def _cleanse_numeric_schema(schema): _cleanse_generic_schema(schema) if any(field in schema for field in [ "exclusiveMinimum", "exclusiveMaximum" ]): - # Rather than worry about dealing with this programmatically, we should just fail. This is run at build time, - # so if it fails, the API spec can be fixed before this gets checked in. - raise ConversionException(f"Integer/Number schema has exclusiveMinimum/Maximum field. Cannot handle automatically. Schema: {schema}") + # Rather than worry about dealing with this programmatically, we should just fail. + # This is run at build time, so if it fails, the API spec can be fixed before this + # gets checked in. + raise ConversionException( + f"Integer/Number schema has exclusiveMinimum/Maximum field. Schema: {schema}") def _cleanse_object_schema(schema): _cleanse_generic_schema(schema) object_properties = schema.get("properties", {}) if not isinstance(object_properties, dict): - raise ConversionException(f"Object schema has non-dict 'properties' value. Schema: {schema}") + raise ConversionException( + f"Object schema has non-dict 'properties' value. Schema: {schema}") for v in object_properties.values(): _cleanse_schema(v) - # additionalProperties is allowed to map to a schema dict. But it's also allowed to map to a boolean. Or to be absent. - # If it is present and mapped to a non-empty dict, then we need to cleanse it. + # additionalProperties is allowed to map to a schema dict. But it's also allowed to map + # to a boolean. Or to be absent. If it is present and mapped to a non-empty dict, then we + # need to cleanse it. try: - additionalProperties = schema['additionalProperties'] + additional_properties = schema['additionalProperties'] except KeyError: return - if not isinstance(additionalProperties, dict): + if not isinstance(additional_properties, dict): return - if not additionalProperties: + if not additional_properties: return - _cleanse_schema(additionalProperties) + _cleanse_schema(additional_properties) def convert_oas(input_file: TextIO, output_file: TextIO|None=None) -> dict: