From ede9d738e04dfafa28e167008dcd43454a9fc7bd Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Mon, 9 Oct 2023 16:14:38 +0100 Subject: [PATCH] Pre release lower case acr (#113) * Lower case acr names (#112) * Lower case ACR names and fix interactive mode for lists * lint * remove duplicate else branch * history --- src/aosm/HISTORY.rst | 2 ++ src/aosm/azext_aosm/_configuration.py | 13 ++++++++ .../generate_nfd/cnf_nfd_generator.py | 32 ++++++++----------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index a68f73c042c..266a9ab8b95 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -39,6 +39,8 @@ upcoming * Fix CNF image import from cross-subscription ACR * Fix unexpected bracket symbol added to list deployParameters during list parsing * Format helm names according to RP validation rules +* Always force ACR names to be lower-case +* Fix interactive mode for lists of deployParameters 0.2.0 ++++++ diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 7671abcdaa5..dee64aafb66 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -338,6 +338,19 @@ class CNFImageConfig: source_registry_namespace: str = "" source_local_docker_image: str = "" + def __post_init__(self): + """ + Ensure that all config is lower case. + + ACR names can be uppercase but the login server is always lower case and docker + and az acr import commands require lower case. Might as well do the namespace + and docker image too although much less likely that the user has accidentally + pasted these with upper case. + """ + self.source_registry = self.source_registry.lower() + self.source_registry_namespace = self.source_registry_namespace.lower() + self.source_local_docker_image = self.source_local_docker_image.lower() + @classmethod def helptext(cls) -> "CNFImageConfig": """ diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index f3e14f6c8c3..036773eb6e0 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -731,24 +731,11 @@ def _replace_values_with_deploy_params( """ logger.debug("Replacing values with deploy parameters") final_values_mapping_dict: Dict[Any, Any] = {} - for k, v in values_yaml_dict.items(): + for k, v in values_yaml_dict.items(): # pylint: disable=too-many-nested-blocks # if value is a string and contains deployParameters. logger.debug("Processing key %s", k) param_name = k if param_prefix is None else f"{param_prefix}_{k}" - if isinstance(v, (str, int, bool)): - # Replace the parameter with {deploymentParameter.keyname} - if self.interactive: - # Interactive mode. Prompt user to include or exclude parameters - # This requires the enter key after the y/n input which isn't ideal - if not input_ack("y", f"Expose parameter {param_name}? y/n "): - logger.debug("Excluding parameter %s", param_name) - final_values_mapping_dict.update({k: v}) - continue - replacement_value = f"{{deployParameters.{param_name}}}" - - # add the schema for k (from the big schema) to the (smaller) schema - final_values_mapping_dict.update({k: replacement_value}) - elif isinstance(v, dict): + if isinstance(v, dict): final_values_mapping_dict[k] = self._replace_values_with_deploy_params( v, param_name ) @@ -764,7 +751,14 @@ def _replace_values_with_deploy_params( final_values_mapping_dict[k].append( self._replace_values_with_deploy_params(item, param_name) ) - elif isinstance(item, (str, int, bool)) or not v: + elif isinstance(item, (str, int, bool)) or not item: + if self.interactive: + if not input_ack( + "y", f"Expose parameter {param_name}? y/n " + ): + logger.debug("Excluding parameter %s", param_name) + final_values_mapping_dict[k].append(item) + continue replacement_value = f"{{deployParameters.{param_name}}}" final_values_mapping_dict[k].append(replacement_value) else: @@ -772,10 +766,10 @@ def _replace_values_with_deploy_params( f"Found an unexpected type {type(item)} of key {k} in " "values.yaml, cannot generate values mapping file." ) - elif not v: - # V is blank so we don't know what type it is. Assuming it is an - # empty string (but do this after checking for dict and list) + elif isinstance(v, (str, int, bool)) or not v: # Replace the parameter with {deploymentParameter.keyname} + # If v is blank we don't know what type it is. Assuming it is an + # empty string (but do this after checking for dict and list) if self.interactive: # Interactive mode. Prompt user to include or exclude parameters # This requires the enter key after the y/n input which isn't ideal