Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pk5/add integration tests #51

Merged
merged 4 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -201,6 +204,7 @@ def delete_published_definition(
definition_type,
config_file,
clean=False,
force=False
):
"""
Delete a published definition.
Expand All @@ -221,9 +225,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 @@ -277,7 +281,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 @@ -302,13 +306,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 @@ -325,7 +331,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 @@ -377,15 +383,16 @@ def publish_design(
)


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 @@ -626,7 +626,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
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