Skip to content

Commit

Permalink
move artifact upload to before nfd/nsd deploy (#62) (#70)
Browse files Browse the repository at this point in the history
* move artifact upload to before nfd/nsd deploy

* markups

* check in new test recording
  • Loading branch information
sunnycarter committed Aug 25, 2023
1 parent d0aadff commit 60ace56
Show file tree
Hide file tree
Showing 3 changed files with 2,624 additions and 2,711 deletions.
1 change: 1 addition & 0 deletions src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ upcoming
* Take Oras 0.1.19 to fix NSD Artifact upload on Windows
* Support deploying multiple instances of the same NF in an SNS
* Fix CNF publish on Windows by using Linux style paths in rendered NFD bicep templates (bicep always requires Linux style paths).
* Re-order publish steps so that artifacts are uploaded before the NFD/NSD is published.
* Add progress information for VHD upload
* Change optional argument from `manifest_parameters_json_file` to `manifest_params_file` to appease linter.

Expand Down
156 changes: 87 additions & 69 deletions src/aosm/azext_aosm/deploy/deploy_with_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,9 @@ def deploy_nfd_from_bicep(self) -> None:
"""
assert isinstance(self.config, NFConfiguration)
if self.skip == BICEP_PUBLISH:
print("Skipping bicep publish")
print("Skipping bicep manifest publish")
else:
if not self.bicep_path:
# User has not passed in a bicep template, so we are deploying the default
# one produced from building the NFDV using this CLI
if self.resource_type == VNF:
file_name = VNF_DEFINITION_BICEP_TEMPLATE_FILENAME
if self.resource_type == CNF:
file_name = CNF_DEFINITION_BICEP_TEMPLATE_FILENAME
bicep_path = os.path.join(
self.config.output_directory_for_build, file_name
)

# 1) Deploy Artifact manifest bicep
# Create or check required resources
deploy_manifest_template = not self.nfd_predeploy()
if deploy_manifest_template:
Expand All @@ -120,33 +110,46 @@ def deploy_nfd_from_bicep(self) -> None:
f"Artifact manifests exist for NFD {self.config.nf_name} "
f"version {self.config.version}"
)
message = (
f"Deploy bicep template for NFD {self.config.nf_name} version"
f" {self.config.version} into"
f" {self.config.publisher_resource_group_name} under publisher"
f" {self.config.publisher_name}"
)
print(message)
logger.info(message)
logger.debug(
"Parameters used for NF definition bicep deployment: %s",
self.parameters,
)

self.deploy_bicep_template(bicep_path, self.parameters)
print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.")

if self.skip == ARTIFACT_UPLOAD:
print("Skipping artifact upload")
else:
# 2) Upload artifacts - must be done before nfd deployment
if self.resource_type == VNF:
self._vnfd_artifact_upload()
if self.resource_type == CNF:
self._cnfd_artifact_upload()

if self.skip == BICEP_PUBLISH:
print("Skipping bicep nfd publish")
print("Done")
return

if self.resource_type == VNF:
self._vnfd_artifact_upload()
if self.resource_type == CNF:
self._cnfd_artifact_upload()

print("Done")
# 3) Deploy NFD bicep
if not self.bicep_path:
# User has not passed in a bicep template, so we are deploying the default
# one produced from building the NFDV using this CLI
if self.resource_type == VNF:
file_name = VNF_DEFINITION_BICEP_TEMPLATE_FILENAME
if self.resource_type == CNF:
file_name = CNF_DEFINITION_BICEP_TEMPLATE_FILENAME
bicep_path = os.path.join(
self.config.output_directory_for_build, file_name
)
message = (
f"Deploy bicep template for NFD {self.config.nf_name} version"
f" {self.config.version} into"
f" {self.config.publisher_resource_group_name} under publisher"
f" {self.config.publisher_name}"
)
print(message)
logger.info(message)
logger.debug(
"Parameters used for NF definition bicep deployment: %s",
self.parameters,
)
self.deploy_bicep_template(bicep_path, self.parameters)
print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.")

def _vnfd_artifact_upload(self) -> None:
"""Uploads the VHD and ARM template artifacts."""
Expand Down Expand Up @@ -381,6 +384,7 @@ def deploy_nsd_from_bicep(self) -> None:
"""
assert isinstance(self.config, NSConfiguration)
if not self.skip == BICEP_PUBLISH:
# 1) Deploy Artifact manifest bicep
if not self.bicep_path:
# User has not passed in a bicep template, so we are deploying the default
# one produced from building the NSDV using this CLI
Expand All @@ -403,50 +407,64 @@ def deploy_nsd_from_bicep(self) -> None:
)
print("Artifact manifests already exist")

message = (
f"Deploy bicep template for NSDV {self.config.nsd_version} "
f"into {self.config.publisher_resource_group_name} under publisher "
f"{self.config.publisher_name}"
)
print(message)
logger.info(message)
self.deploy_bicep_template(bicep_path, self.parameters)
print(
f"Deployed NSD {self.config.nsdg_name} "
f"version {self.config.nsd_version}."
)
if self.skip == ARTIFACT_UPLOAD:
print("Skipping artifact upload")
print("Done")
return

for manifest, nf in zip(
self.config.acr_manifest_names, self.config.network_functions
):
acr_manifest = ArtifactManifestOperator(
self.config,
self.api_clients,
self.config.acr_artifact_store_name,
manifest,
)
else:
# 2) Upload artifacts - must be done before nsd deployment
for manifest, nf in zip(
self.config.acr_manifest_names, self.config.network_functions
):
acr_manifest = ArtifactManifestOperator(
self.config,
self.api_clients,
self.config.acr_artifact_store_name,
manifest,
)

# Convert the NF bicep to ARM
arm_template_artifact_json = self.convert_bicep_to_arm(
os.path.join(
self.config.output_directory_for_build, nf.nf_bicep_filename
# Convert the NF bicep to ARM
arm_template_artifact_json = self.convert_bicep_to_arm(
os.path.join(
self.config.output_directory_for_build, nf.nf_bicep_filename
)
)
)

arm_template_artifact = acr_manifest.artifacts[0]
arm_template_artifact = acr_manifest.artifacts[0]

# appease mypy
assert nf.arm_template.file_path, "Config missing ARM template file path"
with open(nf.arm_template.file_path, "w", encoding="utf-8") as file:
file.write(json.dumps(arm_template_artifact_json, indent=4))
# appease mypy
assert (
nf.arm_template.file_path
), "Config missing ARM template file path"
with open(nf.arm_template.file_path, "w", encoding="utf-8") as file:
file.write(json.dumps(arm_template_artifact_json, indent=4))

print(f"Uploading ARM template artifact: {nf.arm_template.file_path}")
arm_template_artifact.upload(nf.arm_template)
print(f"Uploading ARM template artifact: {nf.arm_template.file_path}")
arm_template_artifact.upload(nf.arm_template)

if self.skip == BICEP_PUBLISH:
print("Skipping bicep nsd publish")
print("Done")
return

# 3) Deploy NSD bicep
if not self.bicep_path:
# User has not passed in a bicep template, so we are deploying the default
# one produced from building the NSDV using this CLI
bicep_path = os.path.join(
self.config.output_directory_for_build,
NSD_BICEP_FILENAME,
)
message = (
f"Deploy bicep template for NSDV {self.config.nsd_version} "
f"into {self.config.publisher_resource_group_name} under publisher "
f"{self.config.publisher_name}"
)
print(message)
logger.info(message)
self.deploy_bicep_template(bicep_path, self.parameters)
print(
f"Deployed NSD {self.config.nsdg_name} "
f"version {self.config.nsd_version}."
)

def deploy_manifest_template(self) -> None:
"""Deploy the bicep template defining the manifest."""
Expand Down
Loading

0 comments on commit 60ace56

Please sign in to comment.