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

Bug: Nexus Image Version Must be Semver #149

Merged
merged 5 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 2 additions & 9 deletions src/aosm/azext_aosm/cli_handlers/onboarding_nexus_vnf_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from azext_aosm.inputs.arm_template_input import ArmTemplateInput
from azext_aosm.inputs.nexus_image_input import NexusImageFileInput
from .onboarding_vnf_handler import OnboardingVNFCLIHandler
from azext_aosm.common.utils import render_bicep_contents_from_j2, get_template_path
from azext_aosm.common.utils import render_bicep_contents_from_j2, get_template_path, split_image_path

logger = get_logger(__name__)

Expand Down Expand Up @@ -79,8 +79,7 @@ def _get_processor_list(self) -> [BaseInputProcessor]:
)
# For each image, instantiate image processor
for image in self.config.images:
(source_acr_registry, name, version) = self._split_image_path(image)

(source_acr_registry, name, version) = split_image_path(image)
image_input = NexusImageFileInput(
artifact_name=name,
artifact_version=version,
Expand Down Expand Up @@ -122,12 +121,6 @@ def build_all_parameters_json(self) -> JSONDefinitionElementBuilder:
)
return base_file

def _split_image_path(self, image) -> "tuple[str, str, str]":
"""Split the image path into source acr registry, name and version."""
(source_acr_registry, name_and_version) = image.split("/", 2)
(name, version) = name_and_version.split(":", 2)
return (source_acr_registry, name, version)

def _generate_type_specific_nf_application(self, processor) -> "tuple[list, list]":
"""Generate the type specific nf application."""
arm_nf = []
Expand Down
1 change: 1 addition & 0 deletions src/aosm/azext_aosm/common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ManifestsExist(str, Enum):
CNF_VALUES_SCHEMA_FILENAME = "values.schema.json"
CNF_TEMPLATE_FOLDER_NAME = "cnf"

SEMVER_REGEX = r"^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$"
#################
# OLD CONSTANTS #
#################
Expand Down
13 changes: 11 additions & 2 deletions src/aosm/azext_aosm/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import re
import os
import tarfile
from pathlib import Path
Expand All @@ -13,7 +13,7 @@
import tempfile

from knack.log import get_logger

from azext_aosm.common.constants import SEMVER_REGEX
from azext_aosm.common.exceptions import InvalidFileTypeError, MissingDependency

logger = get_logger(__name__)
Expand Down Expand Up @@ -123,3 +123,12 @@ def check_tool_installed(tool_name: str) -> None:
"""
if shutil.which(tool_name) is None:
raise MissingDependency(f"You must install {tool_name} to use this command.")

def split_image_path(image) -> "tuple[str, str, str]":
"""Split the image path into source acr registry, name and version."""
(source_acr_registry, name_and_version) = image.split("/", 2)
(name, version) = name_and_version.split(":", 2)
return (source_acr_registry, name, version)

def is_semver(string):
return re.match(SEMVER_REGEX, string) is not None
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
from __future__ import annotations

from dataclasses import dataclass, field
from typing import List

Expand All @@ -13,6 +12,7 @@
from azext_aosm.configuration_models.onboarding_nfd_base_input_config import (
OnboardingNFDBaseInputConfig,
)
from azext_aosm.common.utils import split_image_path, is_semver


@dataclass
Expand Down Expand Up @@ -231,6 +231,11 @@ def validate(self):
raise ValidationError("arm_template must be set")
if not self.images:
raise ValidationError("You must include at least one image")
for image in self.images:
(_, _, version) = split_image_path(image)
if not is_semver(version):
raise ValidationError(f"{image} has invalid version '{version}'.\n"
"Allowed formats are major.minor.patch")
jordlay marked this conversation as resolved.
Show resolved Hide resolved
jordlay marked this conversation as resolved.
Show resolved Hide resolved
if not self.arm_templates:
raise ValidationError("You must include at least one arm template")
for arm_template in self.arm_templates:
Expand Down
Loading