Skip to content

Commit

Permalink
Temp 16feb wheel (#145)
Browse files Browse the repository at this point in the history
* added nexus arm processor; added nfvi type to vnfinput.json; added condition for calling each arm processor

* pipe through nfvi type from vnf input to template; added nexus input; fixed mistakes in armprocessor

* initial commit for children vnf handlers

* added core and nexus config logic

* fixed nexus input and nexus processor; fixed templates

* generalised render manifest and render definition bicep functions to use one

* added incorrect config error handling

* added nexus flag to publish; added error handling for incorrect vnf type (if forgot to put nexus flag case); tidied nexus inputs

* added vnf nexus base bicep; fixed vnf definition template; temp fix for image versions

* moved render bicep to common/utils; replaced build base bicep with render bicep

* general tidyup: removed prints, added return types

* added nfvi type to nsds

* removed old todos

* refactored nexus handler, moved generate params code into processor

* moved logic to base vnf handler; moved more logic to processor

* fix template name in vnf j2

* fixed nexus image file

* added nfvitype to nsd nf template by making new j2 + changing how nfd processor works

* added nfvitype to nsd nf template by making new j2 + changing how nfd processor works

* minor formatting

* made vnfnexus a definition type; slight refactor of custom.py

* removed nexus param, removed prints, added commented out test file

* fixed flake8 + pylint issues

* Base handler treats command inputs separately (#143)

* refactored base handler init to treat inputs from different commands separately; added better validation

* fixed error handling in base handler

* fixed error typing

---------

Co-authored-by: Jordan <[email protected]>

* mypy fixes

* fixed customLocation id for vnf nexus

* markups from review inc moving build manifest to parent vnf handler

* added better docstrings

* updated history.rst

* Achurchard/fix helm chart upload (#144)

* Use helm push for Helm charts (not oras push)

* Logging

---------

Co-authored-by: Andy Churchard <[email protected]>
Co-authored-by: Jordan <[email protected]>

* bumped version

* Bug: No type in schema (#148)

* first fix for anyOf logic error msg

* Update src/aosm/azext_aosm/build_processors/base_processor.py

Co-authored-by: Cyclam <[email protected]>

* Update src/aosm/azext_aosm/build_processors/base_processor.py

Co-authored-by: Cyclam <[email protected]>

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Cyclam <[email protected]>

* Bug: Nexus Image Version Must be Semver (#149)

* added semver checking to input config validation; moved split image path to utils

* changed semver regex; renamed function

* fixed typo

* markups

* fix typo

---------

Co-authored-by: Jordan <[email protected]>

* Create RG if it doesn't exist (#150)

* add validation resource group exists function

* tidied up code

* Update src/aosm/azext_aosm/definition_folder/reader/definition_folder.py

Co-authored-by: Cyclam <[email protected]>

* renaming from markups

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Cyclam <[email protected]>

* Bug Fix: NFD and NSD Manifest Names Clash (#147)

* added sa_manifest and acr_manifest property, added sa and acr to manifest names; added nsd to nsd manifest name

* create manifest name from nf/nsd name instead of acr/sa; fixed docs strings

---------

Co-authored-by: Jordan <[email protected]>

* Fix Nexus Linting + Add Unit Tests (#146)

* fixed pylint + flake8 errors

* fix mypy errors

* fixed artifact builder tests

* temp commit for unit testing

* temp push of broken tests

* added new mocks (not perfect) for vnfs£

* fixed artifact write failure

* More mypy fixes

* fixed style issues

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Andy Churchard <[email protected]>

* Use ephemeral tempdir for generated helm package .tgz file. (#151)

* Use ephemeral tempdir for generated helm package .tgz file.

* Fix file_path bug if .tgz file was provided by user.

---------

Co-authored-by: Andy Churchard <[email protected]>

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Andy Churchard <[email protected]>
Co-authored-by: Cyclam <[email protected]>
  • Loading branch information
4 people authored Feb 28, 2024
1 parent 8694270 commit ca3d8d0
Show file tree
Hide file tree
Showing 53 changed files with 2,083 additions and 531 deletions.
12 changes: 12 additions & 0 deletions src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ Release History
===============

Unreleased

1.0.0b8
++++++++

1.0.0b7
++++++++
* Fixed: customLocation missing from Nexus
* Fixed: helm charts not uploading correctly

++++++++
1.0.0b6
++++++++
* Added Nexus support

1.0.0b5
++++++++
Expand Down
11 changes: 6 additions & 5 deletions src/aosm/azext_aosm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from azure.cli.core import AzCommandsLoader

from .common.constants import (
ARTIFACT_UPLOAD,
BICEP_PUBLISH,
CNF,
VNF,
VNF_NEXUS,
BICEP_PUBLISH,
ARTIFACT_UPLOAD,
HELM_TEMPLATE,
IMAGE_UPLOAD,
VNF,
)


Expand All @@ -23,7 +24,7 @@ def load_arguments(self: AzCommandsLoader, _):
get_three_state_flag,
)

definition_type = get_enum_type([VNF, CNF])
definition_type = get_enum_type([VNF, CNF, VNF_NEXUS])
nf_skip_steps = get_enum_type(
[BICEP_PUBLISH, ARTIFACT_UPLOAD, IMAGE_UPLOAD, HELM_TEMPLATE]
)
Expand All @@ -36,7 +37,7 @@ def load_arguments(self: AzCommandsLoader, _):
c.argument(
"definition_type",
arg_type=definition_type,
help="Type of AOSM definition.",
help="Type of AOSM definition to be published.",
required=True,
)
c.argument(
Expand Down
118 changes: 91 additions & 27 deletions src/aosm/azext_aosm/build_processors/arm_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,41 @@
# --------------------------------------------------------------------------------------------

import json
from pathlib import Path
from abc import abstractmethod
from typing import List, Tuple, final

from knack.log import get_logger

from azext_aosm.build_processors.base_processor import BaseInputProcessor
from azext_aosm.common.artifact import BaseArtifact, LocalFileACRArtifact
from azext_aosm.common.artifact import (BaseArtifact, LocalFileACRArtifact)
from azext_aosm.definition_folder.builder.local_file_builder import LocalFileBuilder
from azext_aosm.inputs.arm_template_input import ArmTemplateInput
from azext_aosm.vendored_sdks.models import (
ApplicationEnablement,
ArmResourceDefinitionResourceElementTemplate,
ArtifactType,
AzureOperatorNexusNetworkFunctionArmTemplateApplication,
ApplicationEnablement, ArmResourceDefinitionResourceElementTemplate,
ArmResourceDefinitionResourceElementTemplateDetails,
ArmTemplateArtifactProfile,
ArmTemplateMappingRuleProfile,
AzureCoreArmTemplateArtifactProfile,
NetworkFunctionApplication, NSDArtifactProfile,
ResourceElementTemplate, TemplateType, AzureOperatorNexusArtifactType,
AzureOperatorNexusArmTemplateDeployMappingRuleProfile, AzureOperatorNexusArmTemplateArtifactProfile,
AzureCoreArmTemplateDeployMappingRuleProfile,
AzureCoreArtifactType,
AzureCoreNetworkFunctionArmTemplateApplication,
DependsOnProfile,
ManifestArtifactFormat,
NetworkFunctionApplication,
NSDArtifactProfile,
ReferencedResource,
ResourceElementTemplate,
TemplateType,
)

from azext_aosm.common.constants import (
VNF_OUTPUT_FOLDER_FILENAME,
NF_DEFINITION_FOLDER_NAME,
TEMPLATE_PARAMETERS_FILENAME)


logger = get_logger(__name__)


Expand Down Expand Up @@ -71,7 +78,7 @@ def get_artifact_manifest_list(self) -> List[ManifestArtifactFormat]:
return [
ManifestArtifactFormat(
artifact_name=self.input_artifact.artifact_name,
artifact_type=AzureCoreArtifactType.ARM_TEMPLATE.value,
artifact_type=ArtifactType.ARM_TEMPLATE.value,
artifact_version=self.input_artifact.artifact_version,
)
]
Expand All @@ -93,7 +100,7 @@ def get_artifact_details(
[
LocalFileACRArtifact(
artifact_name=self.input_artifact.artifact_name,
artifact_type=AzureCoreArtifactType.ARM_TEMPLATE.value,
artifact_type=ArtifactType.ARM_TEMPLATE.value,
artifact_version=self.input_artifact.artifact_version,
file_path=self.input_artifact.template_path,
)
Expand All @@ -105,22 +112,15 @@ def get_artifact_details(
def generate_nf_application(self) -> NetworkFunctionApplication:
return self.generate_nfvi_specific_nf_application()

def generate_artifact_profile(self) -> AzureCoreArmTemplateArtifactProfile:
artifact_profile = ArmTemplateArtifactProfile(
template_name=self.input_artifact.artifact_name,
template_version=self.input_artifact.artifact_version,
)
return AzureCoreArmTemplateArtifactProfile(
artifact_store=ReferencedResource(id=""),
template_artifact_profile=artifact_profile,
)

@abstractmethod
def generate_nfvi_specific_nf_application(self):
pass

def generate_resource_element_template(self) -> ResourceElementTemplate:
"""Generate the resource element template."""
"""Generate the resource element template.
Note: There is no Nexus specific RET
"""
parameter_values = self.generate_values_mappings(
self.input_artifact.get_schema(), self.input_artifact.get_defaults(), True
)
Expand All @@ -143,11 +143,31 @@ def generate_resource_element_template(self) -> ResourceElementTemplate:
),
)

def generate_parameters_file(self) -> LocalFileBuilder:
"""Generate parameters file."""
mapping_rule_profile = self._generate_mapping_rule_profile()
params = (
mapping_rule_profile.template_mapping_rule_profile.template_parameters
)
logger.info(
"Created parameters file for arm template."
)
return LocalFileBuilder(
Path(
VNF_OUTPUT_FOLDER_FILENAME,
NF_DEFINITION_FOLDER_NAME,
self.input_artifact.artifact_name + '-' + TEMPLATE_PARAMETERS_FILENAME,
),
json.dumps(json.loads(params), indent=4),
)

@abstractmethod
def _generate_mapping_rule_profile(self):
pass


class AzureCoreArmBuildProcessor(BaseArmBuildProcessor):
"""
This class represents an ARM template processor for Azure Core.
"""
"""This class represents an ARM template processor for Azure Core."""

def generate_nfvi_specific_nf_application(
self,
Expand All @@ -158,7 +178,7 @@ def generate_nfvi_specific_nf_application(
install_depends_on=[], uninstall_depends_on=[], update_depends_on=[]
),
artifact_type=AzureCoreArtifactType.ARM_TEMPLATE,
artifact_profile=self.generate_artifact_profile(),
artifact_profile=self._generate_artifact_profile(),
deploy_parameters_mapping_rule_profile=self._generate_mapping_rule_profile(),
)

Expand All @@ -178,11 +198,55 @@ def _generate_mapping_rule_profile(
template_mapping_rule_profile=mapping_profile,
)

def _generate_artifact_profile(self) -> AzureCoreArmTemplateArtifactProfile:
artifact_profile = ArmTemplateArtifactProfile(
template_name=self.input_artifact.artifact_name,
template_version=self.input_artifact.artifact_version,
)
return AzureCoreArmTemplateArtifactProfile(
artifact_store=ReferencedResource(id=""),
template_artifact_profile=artifact_profile,
)


class NexusArmBuildProcessor(BaseArmBuildProcessor):
"""
Not implemented yet. This class represents a processor for generating ARM templates specific to Nexus.
This class represents a processor for generating ARM templates specific to Nexus.
"""
def generate_nfvi_specific_nf_application(
self,
) -> AzureOperatorNexusNetworkFunctionArmTemplateApplication:
return AzureOperatorNexusNetworkFunctionArmTemplateApplication(
name=self.name,
depends_on_profile=DependsOnProfile(install_depends_on=[],
uninstall_depends_on=[], update_depends_on=[]),
artifact_type=AzureOperatorNexusArtifactType.ARM_TEMPLATE,
artifact_profile=self._generate_artifact_profile(),
deploy_parameters_mapping_rule_profile=self._generate_mapping_rule_profile(),
)

def generate_nfvi_specific_nf_application(self):
return NotImplementedError
def _generate_mapping_rule_profile(
self,
) -> AzureOperatorNexusArmTemplateDeployMappingRuleProfile:
template_parameters = self.generate_values_mappings(
self.input_artifact.get_schema(), self.input_artifact.get_defaults()
)

mapping_profile = ArmTemplateMappingRuleProfile(
template_parameters=json.dumps(template_parameters)
)

return AzureOperatorNexusArmTemplateDeployMappingRuleProfile(
application_enablement=ApplicationEnablement.ENABLED,
template_mapping_rule_profile=mapping_profile,
)

def _generate_artifact_profile(self) -> AzureOperatorNexusArmTemplateArtifactProfile:
artifact_profile = ArmTemplateArtifactProfile(
template_name=self.input_artifact.artifact_name,
template_version=self.input_artifact.artifact_version,
)
return AzureOperatorNexusArmTemplateArtifactProfile(
artifact_store=ReferencedResource(id=""),
template_artifact_profile=artifact_profile,
)
19 changes: 16 additions & 3 deletions src/aosm/azext_aosm/build_processors/base_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from typing import Any, Dict, List, Tuple

from knack.log import get_logger

from azure.cli.core.azclierror import InvalidArgumentValueError
from azext_aosm.common.artifact import BaseArtifact
from azext_aosm.common.constants import CGS_NAME
from azext_aosm.definition_folder.builder.local_file_builder import LocalFileBuilder
Expand Down Expand Up @@ -98,8 +98,7 @@ def generate_params_schema(self) -> Dict[str, Any]:
)

params_schema = json.loads(base_params_schema)
# print(json.dumps(self.input_artifact.get_schema(), indent=4))
# print(json.dumps(self.input_artifact.get_defaults(), indent=4))

self._generate_schema(
params_schema[self.name],
self.input_artifact.get_schema(),
Expand Down Expand Up @@ -185,6 +184,20 @@ def generate_values_mappings(

# Loop through each property in the schema.
for subschema_name, subschema in schema["properties"].items():

if "type" not in subschema:
if ["oneOf", "anyOf"] in subschema:
raise InvalidArgumentValueError(
f"The subschema '{subschema_name}' does not contain a type.\n"
"It contains 'anyOf' or 'oneOf' logic, which is not valid for AOSM.\n"
"Please remove this from your values.schema.json and provide a concrete type "
"or remove the schema and the CLI will generate a generic schema."
)
raise InvalidArgumentValueError(
f"The subschema {subschema_name} does not contain a type. This is a required field.\n"
"Please fix your values.schema.json or remove the schema and the CLI will generate a "
"generic schema."
)
# If the property is not in the values, and is required, add it to the values.
if (
"required" in schema
Expand Down
Loading

0 comments on commit ca3d8d0

Please sign in to comment.