Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source_local_docker_image defaults to placeholder text (#79) #80

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 40 additions & 28 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,28 @@ class HelmPackageConfig:
class CNFImageConfig:
"""CNF Image config settings."""

source_registry: str = DESCRIPTION_MAP["source_registry"]
source_registry_namespace: str = DESCRIPTION_MAP["source_registry_namespace"]
source_local_docker_image: str = DESCRIPTION_MAP["source_local_docker_image"]
source_registry: str = ""
source_registry_namespace: str = ""
source_local_docker_image: str = ""

def __post_init__(self):
"""
Cope with optional parameters being omitted in the loaded json config file.

If param is set to placeholder text, it is not in the config file and should be unset.
"""
if self.source_registry == DESCRIPTION_MAP["source_registry"]:
self.source_registry = ""
if (
self.source_registry_namespace
== DESCRIPTION_MAP["source_registry_namespace"]
):
self.source_registry_namespace = ""
if (
self.source_local_docker_image
== DESCRIPTION_MAP["source_local_docker_image"]
):
self.source_local_docker_image = ""


@dataclass
Expand Down Expand Up @@ -329,33 +348,22 @@ def validate(self):

:raises ValidationError: If source registry ID doesn't match the regex
"""
source_reg_set = (
self.images.source_registry
and self.images.source_registry != DESCRIPTION_MAP["source_registry"]
)
source_local_set = (
self.images.source_local_docker_image
and self.images.source_local_docker_image
!= DESCRIPTION_MAP["source_local_docker_image"]
)
source_reg_namespace_set = (
self.images.source_registry_namespace
and self.images.source_registry_namespace
!= DESCRIPTION_MAP["source_registry_namespace"]
)

# If these are the same, either neither is set or both are, both of which are errors
if source_reg_set == source_local_set:
raise ValidationError(
"Config validation error. Images config must have either a local docker image"
" or a source registry, but not both."
)
source_reg_set = self.images.source_registry != ""
source_local_set = self.images.source_local_docker_image != ""
source_reg_namespace_set = self.images.source_registry_namespace != ""

if source_reg_namespace_set and not source_reg_set:
raise ValidationError(
"Config validation error. The image source registry namespace should "
"only be configured if a source registry is configured."
)
# If these are the same, either neither is set or both are, both of which are errors
if source_reg_set == source_local_set:
raise ValidationError(
"Config validation error. Images config must have either a local docker image"
" or a source registry, but not both."
)


NFD_NAME = "The name of the existing Network Function Definition Group to deploy using this NSD"
Expand All @@ -367,7 +375,9 @@ def validate(self):
NFD_LOCATION = "The region that the NFDV is published to."
PUBLISHER_RESOURCE_GROUP = "The resource group that the publisher is hosted in."
PUBLISHER_NAME = "The name of the publisher that this NFDV is published under."
PUBLISHER_SCOPE = "The scope that the publisher is published under. Currently, only 'private' is supported."
PUBLISHER_SCOPE = (
"The scope that the publisher is published under. Only 'private' is supported."
)
NFD_TYPE = "Type of Network Function. Valid values are 'cnf' or 'vnf'"
MULTIPLE_INSTANCES = (
"Set to true or false. Whether the NSD should allow arbitrary numbers of this "
Expand Down Expand Up @@ -423,9 +433,7 @@ def validate(self) -> None:

# Temporary validation while only private publishers exist
if self.publisher_scope not in ["private", "Private"]:
raise ValidationError(
"Only private publishers are currently supported"
)
raise ValidationError("Only private publishers are currently supported")

if self.type not in [CNF, VNF]:
raise ValueError(
Expand Down Expand Up @@ -503,7 +511,11 @@ def __post_init__(self):
self.network_functions = nf_ret_list

def validate(self):
# validate that all of the configuration parameters are set
"""
Validate the configuration passed in.

:raises ValueError for any invalid config
"""

if self.location in (DESCRIPTION_MAP["location"], ""):
raise ValueError("Location must be set")
Expand Down
Loading