Skip to content

Commit

Permalink
Merge pull request Azure#20 from jddarby/JDP/bug-735056
Browse files Browse the repository at this point in the history
Name uploaded VHD correctly
  • Loading branch information
jamiedparsons authored Jun 6, 2023
2 parents 6ed8ffa + e38d425 commit 6cda523
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 31 deletions.
20 changes: 6 additions & 14 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.",
"location": "Azure location to use when creating resources.",
"blob_artifact_store_name": "Name of the storage account Artifact Store resource. Will be created if it does not exist.",
"artifact_name": "Name of the artifact",
"file_path": (
"Optional. File path of the artifact you wish to upload from your "
"local disk. Delete if not required."
Expand Down Expand Up @@ -67,7 +66,6 @@

@dataclass
class ArtifactConfig:
artifact_name: str = DESCRIPTION_MAP["artifact_name"]
# artifact.py checks for the presence of the default descriptions, change there if
# you change the descriptions.
file_path: Optional[str] = DESCRIPTION_MAP["file_path"]
Expand Down Expand Up @@ -118,15 +116,6 @@ class NSConfiguration:
nsd_version: str = DESCRIPTION_MAP["nsd_version"]
nsdv_description: str = DESCRIPTION_MAP["nsdv_description"]

def __post_init__(self):
"""
Cope with deserializing subclasses from dicts to ArtifactConfig.
Used when creating VNFConfiguration object from a loaded json config file.
"""
if isinstance(self.arm_template, dict):
self.arm_template = ArtifactConfig(**self.arm_template)

def validate(self):
## validate that all of the configuration parameters are set

Expand Down Expand Up @@ -179,8 +168,7 @@ def build_output_folder_name(self) -> str:
@property
def resource_element_name(self) -> str:
"""Return the name of the resource element."""
artifact_name = self.arm_template.artifact_name
return f"{artifact_name}-resource-element"
return f"{self.nsdg_name.lower()}-resource-element"

@property
def network_function_name(self) -> str:
Expand All @@ -206,12 +194,16 @@ def cg_schema_name(self) -> str:
def arm_template(self) -> ArtifactConfig:
"""Return the parameters of the ARM template to be uploaded as part of the NSDV."""
artifact = ArtifactConfig()
artifact.artifact_name = f"{self.nsdg_name.lower()}_nf_artifact"
artifact.version = self.nsd_version
artifact.file_path = os.path.join(
self.build_output_folder_name, NF_DEFINITION_JSON_FILE
)
return artifact

@property
def arm_template_artifact_name(self) -> str:
"""Return the artifact name for the ARM template"""
return f"{self.network_function_definition_group_name}_nfd_artifact"


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions src/aosm/azext_aosm/deploy/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass
from typing import Union

from azure.storage.blob import BlobClient
from azure.storage.blob import BlobClient, BlobType
from azext_aosm._configuration import ArtifactConfig
from oras.client import OrasClient

Expand Down Expand Up @@ -68,7 +68,7 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None:
if artifact_config.file_path:
logger.info("Upload to blob store")
with open(artifact_config.file_path, "rb") as artifact:
self.artifact_client.upload_blob(artifact, overwrite=True)
self.artifact_client.upload_blob(artifact, overwrite=True, blob_type=BlobType.PAGEBLOB)
logger.info(
f"Successfully uploaded {artifact_config.file_path} to {self.artifact_client.account_name}"
)
Expand Down
23 changes: 18 additions & 5 deletions src/aosm/azext_aosm/deploy/artifact_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,37 @@ def _get_artifact_client(
)

container_basename = artifact.artifact_name.replace("-", "")
blob_url = self._get_blob_url(
f"{container_basename}-{artifact.artifact_version}"
)
container_name = f"{container_basename}-{artifact.artifact_version}"

# For AOSM to work VHD blobs must have the suffix .vhd
if artifact.artifact_name.endswith("-vhd"):
blob_name = f"{artifact.artifact_name[:-4].replace('-', '')}-{artifact.artifact_version}.vhd"
else:
blob_name = container_name

logger.debug("container name: %s, blob name: %s", container_name, blob_name)

blob_url = self._get_blob_url(container_name, blob_name)
return BlobClient.from_blob_url(blob_url)
else:
return self._oras_client(self._manifest_credentials["acr_server_url"])

def _get_blob_url(self, container_name: str) -> str:
def _get_blob_url(self, container_name: str, blob_name: str) -> str:
"""
Get the URL for the blob to be uploaded to the storage account artifact store.
:param container_name: name of the container
:param blob_name: the name that the blob will get uploaded with
"""
for container_credential in self._manifest_credentials["container_credentials"]:
if container_credential["container_name"] == container_name:
sas_uri = str(container_credential["container_sas_uri"])
sas_uri_prefix = sas_uri.split("?")[0]
sas_uri_token = sas_uri.split("?")[1]

blob_url = f"{sas_uri_prefix}/{blob_name}?{sas_uri_token}"

logger.debug("Blob URL: %s", blob_url)

return f"{sas_uri_prefix}/{container_name}?{sas_uri_token}"
return blob_url
raise KeyError(f"Manifest does not include a credential for {container_name}.")
5 changes: 2 additions & 3 deletions src/aosm/azext_aosm/deploy/deploy_with_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ def construct_manifest_parameters(self) -> Dict[str, Any]:
"saArtifactStoreName": {"value": self.config.blob_artifact_store_name},
"acrManifestName": {"value": self.config.acr_manifest_name},
"saManifestName": {"value": self.config.sa_manifest_name},
"vhdName": {"value": self.config.vhd.artifact_name},
'nfName': {"value": self.config.nf_name},
"vhdVersion": {"value": self.config.vhd.version},
"armTemplateName": {"value": self.config.arm_template.artifact_name},
"armTemplateVersion": {"value": self.config.arm_template.version},
}
elif isinstance(self.config, NSConfiguration):
Expand All @@ -208,7 +207,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]:
"publisherName": {"value": self.config.publisher_name},
"acrArtifactStoreName": {"value": self.config.acr_artifact_store_name},
"acrManifestName": {"value": self.config.acr_manifest_name},
"armTemplateName": {"value": self.config.arm_template.artifact_name},
"armTemplateName": {"value": self.config.arm_template_artifact_name},
"armTemplateVersion": {"value": self.config.arm_template.version},
}
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ param saArtifactStoreName string
param acrManifestName string
@description('Name of the manifest to deploy for the Storage Account-backed Artifact Store')
param saManifestName string
@description('The name under which to store the VHD')
param vhdName string
@description('Name of Network Function. Used predominantly as a prefix for other variable names')
param nfName string
@description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0')
param vhdVersion string
@description('The name under which to store the ARM template')
param armTemplateName string
@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.')
param armTemplateVersion string

// Created by the az aosm definition publish command before the template is deployed
Expand Down Expand Up @@ -46,7 +44,7 @@ resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/a
properties: {
artifacts: [
{
artifactName: '${vhdName}'
artifactName: '${nfName}-vhd'
artifactType: 'VhdImageFile'
artifactVersion: vhdVersion
}
Expand All @@ -61,7 +59,7 @@ resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/
properties: {
artifacts: [
{
artifactName: '${armTemplateName}'
artifactName: '${nfName}-arm-template'
artifactType: 'ArmTemplate'
artifactVersion: armTemplateVersion
}
Expand Down
2 changes: 1 addition & 1 deletion src/aosm/azext_aosm/generate_nsd/nsd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def write_nsd_bicep(self) -> None:
"""Write out the NSD bicep file."""
params = {
"nfvi_site_name": self.config.nfvi_site_name,
"armTemplateName": self.config.arm_template.artifact_name,
"armTemplateName": self.config.arm_template_artifact_name,
"armTemplateVersion": self.config.arm_template.version,
"cg_schema_name": self.config.cg_schema_name,
"nsdv_description": self.config.nsdv_description,
Expand Down

0 comments on commit 6cda523

Please sign in to comment.