Skip to content

Commit

Permalink
Pk5/add integration tests (#51)
Browse files Browse the repository at this point in the history
* Somewhat working example

* Cleanups

* Update recording

* fix minor linting error
  • Loading branch information
patrykkulik-microsoft authored Jul 26, 2023
1 parent 55a2320 commit 9483466
Show file tree
Hide file tree
Showing 14 changed files with 5,337 additions and 60 deletions.
43 changes: 25 additions & 18 deletions src/aosm/azext_aosm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def build_definition(
config_file: str,
order_params: bool = False,
interactive: bool = False,
force: bool = False,
):
"""
Build a definition.
Expand All @@ -66,6 +67,7 @@ def build_definition(
config=config,
order_params=order_params,
interactive=interactive,
force=force,
)


Expand Down Expand Up @@ -100,7 +102,7 @@ def _get_config_from_file(config_file: str, configuration_type: str) -> Configur


def _generate_nfd(
definition_type: str, config: NFConfiguration, order_params: bool, interactive: bool
definition_type: str, config: NFConfiguration, order_params: bool, interactive: bool, force: bool = False
):
"""Generate a Network Function Definition for the given type and config."""
nfd_generator: NFDGenerator
Expand All @@ -116,12 +118,13 @@ def _generate_nfd(
" have been implemented."
)
if nfd_generator.nfd_bicep_path:
carry_on = input(
f"The {nfd_generator.nfd_bicep_path.parent} directory already exists -"
" delete it and continue? (y/n)"
)
if carry_on != "y":
raise UnclassifiedUserFault("User aborted!")
if not force:
carry_on = input(
f"The {nfd_generator.nfd_bicep_path.parent} directory already exists -"
" delete it and continue? (y/n)"
)
if carry_on != "y":
raise UnclassifiedUserFault("User aborted!")

shutil.rmtree(nfd_generator.nfd_bicep_path.parent)
nfd_generator.generate_nfd()
Expand Down Expand Up @@ -195,6 +198,7 @@ def delete_published_definition(
definition_type,
config_file,
clean=False,
force=False
):
"""
Delete a published definition.
Expand All @@ -215,9 +219,9 @@ def delete_published_definition(

delly = ResourceDeleter(api_clients, config)
if definition_type == VNF:
delly.delete_nfd(clean=clean)
delly.delete_nfd(clean=clean, force=force)
elif definition_type == CNF:
delly.delete_nfd(clean=clean)
delly.delete_nfd(clean=clean, force=force)
else:
raise ValueError(
"Definition type must be either 'vnf' or 'cnf'. Definition type"
Expand Down Expand Up @@ -271,7 +275,7 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"):
)


def build_design(cmd, client: HybridNetworkManagementClient, config_file: str):
def build_design(cmd, client: HybridNetworkManagementClient, config_file: str, force: bool = False):
"""
Build a Network Service Design.
Expand All @@ -296,13 +300,15 @@ def build_design(cmd, client: HybridNetworkManagementClient, config_file: str):
_generate_nsd(
config=config,
api_clients=api_clients,
force=force,
)


def delete_published_design(
cmd,
client: HybridNetworkManagementClient,
config_file,
force=False,
):
"""
Delete a published NSD.
Expand All @@ -319,7 +325,7 @@ def delete_published_design(
)

destroyer = ResourceDeleter(api_clients, config)
destroyer.delete_nsd()
destroyer.delete_nsd(force=force)


def publish_design(
Expand Down Expand Up @@ -373,15 +379,16 @@ def publish_design(

deployer.deploy_nsd_from_bicep()

def _generate_nsd(config: NSConfiguration, api_clients: ApiClients):
def _generate_nsd(config: NSConfiguration, api_clients: ApiClients, force: bool = False):
"""Generate a Network Service Design for the given config."""
if os.path.exists(config.output_directory_for_build):
carry_on = input(
f"The folder {config.output_directory_for_build} already exists - delete it"
" and continue? (y/n)"
)
if carry_on != "y":
raise UnclassifiedUserFault("User aborted! ")
if not force:
carry_on = input(
f"The folder {config.output_directory_for_build} already exists - delete it"
" and continue? (y/n)"
)
if carry_on != "y":
raise UnclassifiedUserFault("User aborted! ")

shutil.rmtree(config.output_directory_for_build)
nsd_generator = NSDGenerator(api_clients, config)
Expand Down
80 changes: 41 additions & 39 deletions src/aosm/azext_aosm/delete/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
self.api_clients = api_clients
self.config = config

def delete_nfd(self, clean: bool = False):
def delete_nfd(self, clean: bool = False, force: bool = False) -> None:
"""
Delete the NFDV and manifests. If they don't exist it still reports them as deleted.
Expand All @@ -44,33 +44,34 @@ def delete_nfd(self, clean: bool = False):
"""
assert isinstance(self.config, NFConfiguration)

if clean:
print(
"Are you sure you want to delete all resources associated with NFD"
f" {self.config.nf_name} including the artifact stores and publisher"
f" {self.config.publisher_name}?"
)
logger.warning(
"This command will fail if other NFD versions exist in the NFD group."
)
logger.warning(
"Only do this if you are SURE you are not sharing the publisher and"
" artifact stores with other NFDs"
)
print("There is no undo. Type the publisher name to confirm.")
if not input_ack(self.config.publisher_name.lower(), "Confirm delete:"):
print("Not proceeding with delete")
return
else:
print(
"Are you sure you want to delete the NFD Version"
f" {self.config.version} and associated manifests from group"
f" {self.config.nfdg_name} and publisher {self.config.publisher_name}?"
)
print("There is no undo. Type 'delete' to confirm")
if not input_ack("delete", "Confirm delete:"):
print("Not proceeding with delete")
return
if not force:
if clean:
print(
"Are you sure you want to delete all resources associated with NFD"
f" {self.config.nf_name} including the artifact stores and publisher"
f" {self.config.publisher_name}?"
)
logger.warning(
"This command will fail if other NFD versions exist in the NFD group."
)
logger.warning(
"Only do this if you are SURE you are not sharing the publisher and"
" artifact stores with other NFDs"
)
print("There is no undo. Type the publisher name to confirm.")
if not input_ack(self.config.publisher_name.lower(), "Confirm delete:"):
print("Not proceeding with delete")
return
else:
print(
"Are you sure you want to delete the NFD Version"
f" {self.config.version} and associated manifests from group"
f" {self.config.nfdg_name} and publisher {self.config.publisher_name}?"
)
print("There is no undo. Type 'delete' to confirm")
if not input_ack("delete", "Confirm delete:"):
print("Not proceeding with delete")
return

self.delete_nfdv()

Expand All @@ -86,24 +87,25 @@ def delete_nfd(self, clean: bool = False):
self.delete_artifact_store("sa")
self.delete_publisher()

def delete_nsd(self):
def delete_nsd(self, force: bool = False) -> None:
"""
Delete the NSDV and manifests.
If they don't exist it still reports them as deleted.
"""
assert isinstance(self.config, NSConfiguration)

print(
"Are you sure you want to delete the NSD Version"
f" {self.config.nsd_version}, the associated manifest"
f" {self.config.acr_manifest_name} and configuration group schema"
f" {self.config.cg_schema_name}?"
)
print("There is no undo. Type 'delete' to confirm")
if not input_ack("delete", "Confirm delete:"):
print("Not proceeding with delete")
return
if not force:
print(
"Are you sure you want to delete the NSD Version"
f" {self.config.nsd_version}, the associated manifest"
f" {self.config.acr_manifest_name} and configuration group schema"
f" {self.config.cg_schema_name}?"
)
print("There is no undo. Type 'delete' to confirm")
if not input_ack("delete", "Confirm delete:"):
print("Not proceeding with delete")
return

self.delete_nsdv()
self.delete_artifact_manifest("acr")
Expand Down
2 changes: 1 addition & 1 deletion src/aosm/azext_aosm/deploy/deploy_with_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def validate_and_deploy_arm_template(
current_time = str(time.time()).split(".", maxsplit=1)[0]

# Add a timestamp to the deployment name to ensure it is unique
deployment_name = f"AOSM_CLI_deployment_into_{resource_group}_{current_time}"
deployment_name = f"AOSM_CLI_deployment_{current_time}"

validation = self.api_clients.resource_client.deployments.begin_validate(
resource_group_name=resource_group,
Expand Down
4 changes: 3 additions & 1 deletion src/aosm/azext_aosm/generate_nsd/nsd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def write_config_mappings(self, folder_path: str) -> None:

config_mappings = {
"deploymentParameters": deployment_parameters,
self.nfdv_parameter_name: f"{{configurationparameters('{self.config.cg_schema_name}').{nf}.{self.nfdv_parameter_name}}}",
self.nfdv_parameter_name: (
f"{{configurationparameters('{self.config.cg_schema_name}').{nf}.{self.nfdv_parameter_name}}}"
),
"managedIdentity": f"{{configurationparameters('{self.config.cg_schema_name}').managedIdentity}}",
}

Expand Down
3 changes: 2 additions & 1 deletion src/aosm/azext_aosm/tests/latest/mock_nsd/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"network_function_type": "vnf",
"nsdg_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
"nsdv_description": "Plain ubuntu VM",
"multiple_instances": false
}
Loading

0 comments on commit 9483466

Please sign in to comment.