Skip to content

Commit

Permalink
Linting and typing (#141)
Browse files Browse the repository at this point in the history
Linting and type hinting fixes.
  • Loading branch information
Cyclam authored Feb 7, 2024
1 parent f89c939 commit 8694270
Show file tree
Hide file tree
Showing 72 changed files with 676 additions and 6,332 deletions.
3 changes: 2 additions & 1 deletion src/aosm/azext_aosm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ def __init__(self, cli_ctx=None):
super().__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom)

def load_command_table(self, args):
from azext_aosm.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table

from azext_aosm.commands import load_command_table

try:
from . import aaz
except ImportError:
Expand Down
4 changes: 3 additions & 1 deletion src/aosm/azext_aosm/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient:
# By default, get_mgmt_service_client() sets a parameter called 'base_url' when creating
# the client. For us, doing so results in a key error. Setting base_url_bound=False prevents
# that from happening
return get_mgmt_service_client(cli_ctx, HybridNetworkManagementClient, base_url_bound=False)
return get_mgmt_service_client(
cli_ctx, HybridNetworkManagementClient, base_url_bound=False
)


def cf_resources(cli_ctx, subscription_id=None):
Expand Down
8 changes: 4 additions & 4 deletions src/aosm/azext_aosm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from azure.cli.core import AzCommandsLoader

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


Expand Down
37 changes: 25 additions & 12 deletions src/aosm/azext_aosm/build_processors/arm_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@

from azext_aosm.build_processors.base_processor import BaseInputProcessor
from azext_aosm.common.artifact import BaseArtifact, LocalFileACRArtifact
from azext_aosm.common.local_file_builder import LocalFileBuilder
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,
ApplicationEnablement,
ArmResourceDefinitionResourceElementTemplate,
ArmResourceDefinitionResourceElementTemplateDetails,
ArmTemplateArtifactProfile, ArmTemplateMappingRuleProfile,
ArmTemplateArtifactProfile,
ArmTemplateMappingRuleProfile,
AzureCoreArmTemplateArtifactProfile,
AzureCoreArmTemplateDeployMappingRuleProfile, AzureCoreArtifactType,
AzureCoreNetworkFunctionArmTemplateApplication, DependsOnProfile,
ManifestArtifactFormat, NetworkFunctionApplication, NSDArtifactProfile,
ReferencedResource, ResourceElementTemplate, TemplateType)
AzureCoreArmTemplateDeployMappingRuleProfile,
AzureCoreArtifactType,
AzureCoreNetworkFunctionArmTemplateApplication,
DependsOnProfile,
ManifestArtifactFormat,
NetworkFunctionApplication,
NSDArtifactProfile,
ReferencedResource,
ResourceElementTemplate,
TemplateType,
)

logger = get_logger(__name__)

Expand Down Expand Up @@ -56,7 +65,9 @@ def get_artifact_manifest_list(self) -> List[ManifestArtifactFormat]:
:return: A list of artifacts for the artifact manifest.
:rtype: List[ManifestArtifactFormat]
"""
logger.debug("Getting artifact manifest list for ARM template input %s.", self.name)
logger.debug(
"Getting artifact manifest list for ARM template input %s.", self.name
)
return [
ManifestArtifactFormat(
artifact_name=self.input_artifact.artifact_name,
Expand Down Expand Up @@ -122,8 +133,9 @@ def generate_resource_element_template(self) -> ResourceElementTemplate:

return ArmResourceDefinitionResourceElementTemplateDetails(
name=self.name,
depends_on_profile=DependsOnProfile(install_depends_on=[],
uninstall_depends_on=[], update_depends_on=[]),
depends_on_profile=DependsOnProfile(
install_depends_on=[], uninstall_depends_on=[], update_depends_on=[]
),
configuration=ArmResourceDefinitionResourceElementTemplate(
template_type=TemplateType.ARM_TEMPLATE.value,
parameter_values=json.dumps(parameter_values),
Expand All @@ -142,8 +154,9 @@ def generate_nfvi_specific_nf_application(
) -> AzureCoreNetworkFunctionArmTemplateApplication:
return AzureCoreNetworkFunctionArmTemplateApplication(
name=self.name,
depends_on_profile=DependsOnProfile(install_depends_on=[],
uninstall_depends_on=[], update_depends_on=[]),
depends_on_profile=DependsOnProfile(
install_depends_on=[], uninstall_depends_on=[], update_depends_on=[]
),
artifact_type=AzureCoreArtifactType.ARM_TEMPLATE,
artifact_profile=self.generate_artifact_profile(),
deploy_parameters_mapping_rule_profile=self._generate_mapping_rule_profile(),
Expand Down
33 changes: 24 additions & 9 deletions src/aosm/azext_aosm/build_processors/base_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
from knack.log import get_logger

from azext_aosm.common.artifact import BaseArtifact
from azext_aosm.common.local_file_builder import LocalFileBuilder
from azext_aosm.inputs.base_input import BaseInput
from azext_aosm.vendored_sdks.models import (ManifestArtifactFormat,
NetworkFunctionApplication,
ResourceElementTemplate)
from azext_aosm.common.constants import CGS_NAME
from azext_aosm.definition_folder.builder.local_file_builder import LocalFileBuilder
from azext_aosm.inputs.base_input import BaseInput
from azext_aosm.vendored_sdks.models import (
ManifestArtifactFormat,
NetworkFunctionApplication,
ResourceElementTemplate,
)

logger = get_logger(__name__)


Expand Down Expand Up @@ -183,10 +186,16 @@ def generate_values_mappings(
# Loop through each property in the schema.
for subschema_name, subschema in schema["properties"].items():
# If the property is not in the values, and is required, add it to the values.
if "required" in schema and subschema_name not in values and subschema_name in schema["required"]:
if (
"required" in schema
and subschema_name not in values
and subschema_name in schema["required"]
):
print(f"Adding {subschema_name} to values")
if subschema["type"] == "object":
values[subschema_name] = self.generate_values_mappings(subschema, {}, is_ret)
values[subschema_name] = self.generate_values_mappings(
subschema, {}, is_ret
)
else:
values[subschema_name] = (
f"{{configurationparameters('{CGS_NAME}').{self.name}.{subschema_name}}}"
Expand All @@ -198,8 +207,14 @@ def generate_values_mappings(
if subschema_name in values and subschema["type"] == "object":
# Python evaluates {} as False, so we need to explicitly set to {}
default_subschema_values = values[subschema_name] or {}
values[subschema_name] = self.generate_values_mappings(subschema, default_subschema_values, is_ret)
values[subschema_name] = self.generate_values_mappings(
subschema, default_subschema_values, is_ret
)

logger.debug("Output of generate_values_mappings for %s: %s", self.name, json.dumps(values, indent=4))
logger.debug(
"Output of generate_values_mappings for %s: %s",
self.name,
json.dumps(values, indent=4),
)

return values
9 changes: 6 additions & 3 deletions src/aosm/azext_aosm/build_processors/helm_chart_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
LocalFileACRArtifact,
RemoteACRArtifact,
)
from azext_aosm.common.local_file_builder import LocalFileBuilder
from azext_aosm.definition_folder.builder.local_file_builder import LocalFileBuilder
from azext_aosm.inputs.helm_chart_input import HelmChartInput
from azext_aosm.vendored_sdks.models import (
ApplicationEnablement,
Expand Down Expand Up @@ -68,7 +68,9 @@ def get_artifact_manifest_list(self) -> List[ManifestArtifactFormat]:
:return: A list of artifacts for the artifact manifest.
:rtype: List[ManifestArtifactFormat]
"""
logger.debug("Getting artifact manifest list for Helm chart input %s.", self.name)
logger.debug(
"Getting artifact manifest list for Helm chart input %s.", self.name
)
artifact_manifest_list = []
artifact_manifest_list.append(
ManifestArtifactFormat(
Expand Down Expand Up @@ -200,7 +202,8 @@ def _find_chart_images(self) -> Set[Tuple[str, str]]:

return images

def _find_image_lines(self, chart: HelmChartInput, image_lines: Set[str]) -> None:
@staticmethod
def _find_image_lines(chart: HelmChartInput, image_lines: Set[str]) -> None:
"""
Finds the lines containing image references in the given Helm chart and its dependencies.
Expand Down
37 changes: 24 additions & 13 deletions src/aosm/azext_aosm/build_processors/nfd_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,30 @@

import json
from pathlib import Path
from typing import List, Tuple, Any, Dict
from typing import Any, Dict, List, Tuple

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.local_file_builder import LocalFileBuilder
from azext_aosm.common.constants import NSD_OUTPUT_FOLDER_FILENAME
from azext_aosm.definition_folder.builder.local_file_builder import LocalFileBuilder
from azext_aosm.inputs.nfd_input import NFDInput
from azext_aosm.vendored_sdks.models import (
ArmResourceDefinitionResourceElementTemplate, ArtifactType,
DependsOnProfile, ManifestArtifactFormat, NetworkFunctionApplication)
from azext_aosm.vendored_sdks.models import \
NetworkFunctionDefinitionResourceElementTemplateDetails as \
NFDResourceElementTemplate
from azext_aosm.vendored_sdks.models import (NSDArtifactProfile,
ReferencedResource, TemplateType)
from azext_aosm.common.constants import NSD_OUTPUT_FOLDER_FILENAME
ArmResourceDefinitionResourceElementTemplate,
ArtifactType,
DependsOnProfile,
ManifestArtifactFormat,
NetworkFunctionApplication,
)
from azext_aosm.vendored_sdks.models import (
NetworkFunctionDefinitionResourceElementTemplateDetails as NFDResourceElementTemplate,
)
from azext_aosm.vendored_sdks.models import (
NSDArtifactProfile,
ReferencedResource,
TemplateType,
)

logger = get_logger(__name__)

Expand Down Expand Up @@ -79,7 +87,9 @@ def get_artifact_details(
artifact_name=self.input_artifact.artifact_name,
artifact_type=ArtifactType.OCI_ARTIFACT.value,
artifact_version=self.input_artifact.artifact_version,
file_path=self.input_artifact.arm_template_output_path.relative_to(Path(NSD_OUTPUT_FOLDER_FILENAME)),
file_path=self.input_artifact.arm_template_output_path.relative_to(
Path(NSD_OUTPUT_FOLDER_FILENAME)
),
)

# Create a local file builder for the ARM template
Expand Down Expand Up @@ -125,8 +135,9 @@ def generate_resource_element_template(self) -> NFDResourceElementTemplate:
return NFDResourceElementTemplate(
name=self.name,
configuration=configuration,
depends_on_profile=DependsOnProfile(install_depends_on=[],
uninstall_depends_on=[], update_depends_on=[]),
depends_on_profile=DependsOnProfile(
install_depends_on=[], uninstall_depends_on=[], update_depends_on=[]
),
)

def _generate_schema(
Expand Down
36 changes: 24 additions & 12 deletions src/aosm/azext_aosm/build_processors/vhd_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@
from knack.log import get_logger

from azext_aosm.build_processors.base_processor import BaseInputProcessor
from azext_aosm.common.artifact import (BaseArtifact,
BlobStorageAccountArtifact,
LocalFileStorageAccountArtifact)
from azext_aosm.common.local_file_builder import LocalFileBuilder
from azext_aosm.common.artifact import (
BaseArtifact,
BlobStorageAccountArtifact,
LocalFileStorageAccountArtifact,
)
from azext_aosm.definition_folder.builder.local_file_builder import LocalFileBuilder
from azext_aosm.inputs.vhd_file_input import VHDFileInput
from azext_aosm.vendored_sdks.models import (
ApplicationEnablement, ArtifactType,
AzureCoreNetworkFunctionVhdApplication, AzureCoreVhdImageArtifactProfile,
AzureCoreVhdImageDeployMappingRuleProfile, DependsOnProfile,
ManifestArtifactFormat, ReferencedResource, ResourceElementTemplate,
VhdImageArtifactProfile, VhdImageMappingRuleProfile)
ApplicationEnablement,
ArtifactType,
AzureCoreNetworkFunctionVhdApplication,
AzureCoreVhdImageArtifactProfile,
AzureCoreVhdImageDeployMappingRuleProfile,
DependsOnProfile,
ManifestArtifactFormat,
ReferencedResource,
ResourceElementTemplate,
VhdImageArtifactProfile,
VhdImageMappingRuleProfile,
)

logger = get_logger(__name__)

Expand Down Expand Up @@ -85,7 +94,9 @@ def get_artifact_details(
)
artifacts.append(
BlobStorageAccountArtifact(
artifact_manifest=artifact_manifest,
artifact_name=self.input_artifact.artifact_name,
artifact_type=ArtifactType.VHD_IMAGE_FILE.value,
artifact_version=self.input_artifact.artifact_version,
blob_sas_uri=self.input_artifact.blob_sas_uri,
)
)
Expand All @@ -108,8 +119,9 @@ def generate_nf_application(self) -> AzureCoreNetworkFunctionVhdApplication:

return AzureCoreNetworkFunctionVhdApplication(
name=self.name,
depends_on_profile=DependsOnProfile(install_depends_on=[],
uninstall_depends_on=[], update_depends_on=[]),
depends_on_profile=DependsOnProfile(
install_depends_on=[], uninstall_depends_on=[], update_depends_on=[]
),
artifact_profile=self._generate_artifact_profile(),
deploy_parameters_mapping_rule_profile=self._generate_mapping_rule_profile(),
)
Expand Down
Loading

0 comments on commit 8694270

Please sign in to comment.