Skip to content

Commit

Permalink
Fix integration tests (#163)
Browse files Browse the repository at this point in the history
* Initial stab at making the multiple registry support work

* Update TODO

* update TODO

* merge fixes

* add logic to find registry credentials

* Code cleanup and adding unit tests

* updates to the registry class

* In Progress work

* Working publish

* Move _push_image_from_local_registry and copy_image into the registry class

* tidy up changes

* Namespace and style fixes

* Minor input config change

* unit tests

* Do not push image namespace to target ACR

* Make sure not to break the nexus part of the code

* Update CHANGELOG

* initial commit for integration tests

* Fix error not being caught correctly

* Minor comment change

* Fix integration tests

* Moving files around

* Working vnf integration test

* Comment out test that is not working

* Clean up the structure of the integration tests

* Delete unnecessary tests

* Fix CNF test and move a util function

* fix other integration tests

* Delete the broken tests folder

* Fix the vnf test

* move files around

* Improve the update_input_file function

* improve the nsd test

* Move files around and improve the nsd output

* remove unnecessary line

* Update recording processors and recordings

* Fix linting issues

* bad merge change

* Update the nsd output with Open CGVs

* Fix few unit tests broken by merge

* Markups

---------

Co-authored-by: Andy Churchard <[email protected]>
Co-authored-by: Jordan <[email protected]>
  • Loading branch information
3 people authored Mar 27, 2024
1 parent 0c90032 commit 6ed34e0
Show file tree
Hide file tree
Showing 85 changed files with 7,788 additions and 2,090 deletions.
3 changes: 1 addition & 2 deletions src/aosm/azext_aosm/common/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
clean_registry_name,
push_image_from_local_registry_to_acr,
call_subprocess_raise_output,
check_tool_installed,
)
from azext_aosm.configuration_models.common_parameters_config import (
BaseCommonParametersConfig,
Expand All @@ -31,8 +32,6 @@
from azext_aosm.common.registry import ContainerRegistry, AzureContainerRegistry
from azext_aosm.vendored_sdks.models import ArtifactType
from azext_aosm.vendored_sdks import HybridNetworkManagementClient
from azext_aosm.common.command_context import CommandContext
from azext_aosm.common.utils import check_tool_installed, convert_bicep_to_arm
from knack.util import CLIError
from knack.log import get_logger
from oras.client import OrasClient
Expand Down
11 changes: 4 additions & 7 deletions src/aosm/azext_aosm/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import json
import re
import os
import tarfile
from typing import Tuple
from pathlib import Path
from jinja2 import StrictUndefined, Template
import json
import shutil
import subprocess
from time import sleep
import tarfile
import tempfile
from typing import Tuple
from time import sleep
from pathlib import Path
from typing import Union
from jinja2 import StrictUndefined, Template

from knack.log import get_logger
from knack.util import CLIError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ def write(self):
self.path.mkdir(exist_ok=True)
artifacts_list = []
for artifact in self.artifacts:
artifact_dict = artifact.to_dict()
logger.debug(
"Writing artifact %s as: %s", artifact.artifact_name, artifact.to_dict()
"Writing artifact %s as: %s", artifact.artifact_name, artifact_dict
)
artifacts_list.append(artifact.to_dict())
artifacts_list.append(artifact_dict)
(self.path / "artifacts.json").write_text(json.dumps(artifacts_list, indent=4))
self._write_supporting_files()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Azure location to use when creating resources.
"location": "uksouth",
// Name of the Publisher resource you want your definition published to.
// Will be created if it does not exist.
"publisher_name": "automated-cli-tests-nginx-publisher",
// Optional. Resource group for the Publisher resource.
// Will be created if it does not exist (with a default name if none is supplied).
"publisher_resource_group_name": "{{publisher_resource_group_name}}",
// Optional. Name of the ACR Artifact Store resource.
// Will be created if it does not exist (with a default name if none is supplied).
"acr_artifact_store_name": "nginx-acr",
// Name of NF definition.
"nf_name": "nginx",
// Version of the NF definition in A.B.C format.
"version": "1.0.0",
// List of registries from which to pull the image(s).
// For example [sourceacr.azurecr.io/test, myacr2.azurecr.io].
"image_sources": ["docker.io"],

// List of Helm packages to be included in the CNF.
"helm_packages": [
{
"name": "nginxdemo",
"path_to_chart": "{{path_to_chart}}",
"default_values": "",
"depends_on": []
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"publisher_name": "automated-cli-tests-nginx-publisher",
"publisher_resource_group_name": "{{publisher_resource_group_name}}",
"acr_artifact_store_name": "nginx-nsd-acr",
"location": "uksouth",
"network_functions": [
{
"publisher": "automated-cli-tests-nginx-publisher",
"publisher_resource_group": "{{publisher_resource_group_name}}",
"name": "nginx-nfdg",
"version": "1.0.0",
"publisher_offering_location": "uksouth",
"type": "cnf",
"multiple_instances": false
}
],
"nsd_name": "nginx-nsdg",
"nsd_version": "1.0.0",
"nsdv_description": "Deploys a basic NGINX CNF"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"location": "uksouth",
"publisher_name": "automated-cli-tests-ubuntu-publisher",
"publisher_resource_group_name": "cli_test_nsd",
"acr_artifact_store_name": "ubuntu-acr",
"resource_element_templates": [
{
"resource_element_type": "NF",
"properties": {
// The name of the existing publisher for the NSD.
"publisher": "automated-cli-tests-ubuntu-publisher",
// The resource group that the publisher is hosted in.
"publisher_resource_group": "cli_test_nsd",
// The name of the existing Network Function Definition Group to deploy using this NSD.
"name": "ubuntu-vm",
// The version of the existing Network Function Definition to base this NSD on.
// This NSD will be able to deploy any NFDV with deployment parameters compatible with this version.
"version": "1.0.0",
// The region that the NFDV is published to.
"publisher_offering_location": "uksouth",
// Type of Network Function. Valid values are 'cnf' or 'vnf'.
"type": "vnf",
// Set to true or false. Whether the NSD should allow arbitrary numbers of this type of NF. If false only a single instance will be allowed. Only supported on VNFs, must be set to false on CNFs.
"multiple_instances": "false"
}
},
{
"resource_element_type": "NF",
"properties": {
// The name of the existing publisher for the NSD.
"publisher": "automated-cli-tests-ubuntu-publisher",
// The resource group that the publisher is hosted in.
"publisher_resource_group": "cli_test_nsd",
// The name of the existing Network Function Definition Group to deploy using this NSD.
"name": "nginx",
// The version of the existing Network Function Definition to base this NSD on.
// This NSD will be able to deploy any NFDV with deployment parameters compatible with this version.
"version": "1.0.0",
// The region that the NFDV is published to.
"publisher_offering_location": "uksouth",
// Type of Network Function. Valid values are 'cnf' or 'vnf'.
"type": "cnf",
// Set to true or false. Whether the NSD should allow arbitrary numbers of this type of NF. If false only a single instance will be allowed. Only supported on VNFs, must be set to false on CNFs.
"multiple_instances": "false"
}
}
],
"nfvi_type": "AzureCore",
"nsd_name": "multi-nf",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"location": "uksouth",
"publisher_name": "automated-cli-tests-ubuntu-publisher",
"publisher_resource_group_name": "cli_test_nsd",
"acr_artifact_store_name": "ubuntu-acr",
"resource_element_templates": [
{
"resource_element_type": "NF",
"properties": {
// The name of the existing publisher for the NSD.
"publisher": "automated-cli-tests-ubuntu-publisher",
// The resource group that the publisher is hosted in.
"publisher_resource_group": "cli_test_nsd",
// The name of the existing Network Function Definition Group to deploy using this NSD.
"name": "ubuntu-vm",
// The version of the existing Network Function Definition to base this NSD on.
// This NSD will be able to deploy any NFDV with deployment parameters compatible with this version.
"version": "1.0.0",
// The region that the NFDV is published to.
"publisher_offering_location": "uksouth",
// Type of Network Function. Valid values are 'cnf' or 'vnf'.
"type": "vnf",
// Set to true or false. Whether the NSD should allow arbitrary numbers of this type of NF. If false only a single instance will be allowed. Only supported on VNFs, must be set to false on CNFs.
"multiple_instances": "true"
}
}
],
"nfvi_type": "AzureCore",
"nsd_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"location": "uksouth",
"publisher_name": "automated-cli-tests-ubuntu-publisher",
"publisher_resource_group_name": "test_publisher_name",
"acr_artifact_store_name": "ubuntu-acr",
"resource_element_templates": [
{
"resource_element_type": "NF",
"properties": {
// The name of the existing publisher for the NSD.
"publisher": "automated-cli-tests-ubuntu-publisher",
// The resource group that the publisher is hosted in.
"publisher_resource_group": "test_publisher_name",
// The name of the existing Network Function Definition Group to deploy using this NSD.
"name": "ubuntu-vm",
// The version of the existing Network Function Definition to base this NSD on.
// This NSD will be able to deploy any NFDV with deployment parameters compatible with this version.
"version": "1.0.0",
// The region that the NFDV is published to.
"publisher_offering_location": "uksouth",
// Type of Network Function. Valid values are 'cnf' or 'vnf'.
"type": "vnf",
// Set to true or false. Whether the NSD should allow arbitrary numbers of this type of NF. If false only a single instance will be allowed. Only supported on VNFs, must be set to false on CNFs.
"multiple_instances": "false"
}
}
],
"nfvi_type": "AzureCore",
"nsd_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Azure location to use when creating resources.
"location": "uksouth",
// Name of the Publisher resource you want your definition published to.
// Will be created if it does not exist.
"publisher_name": "automated-cli-tests-ubuntu-publisher",
// Optional. Resource group for the Publisher resource.
// Will be created if it does not exist (with a default name if none is supplied).
"publisher_resource_group_name": "{{publisher_resource_group_name}}",
// Optional. Name of the ACR Artifact Store resource.
// Will be created if it does not exist (with a default name if none is supplied).
"acr_artifact_store_name": "ubuntu-acr",
// Name of NF definition.
"nf_name": "ubuntu-vm",
// Version of the NF definition in A.B.C format.
"version": "1.0.0",
// Optional. Name of the storage account Artifact Store resource.
// Will be created if it does not exist (with a default name if none is supplied).
"blob_artifact_store_name": "ubuntu-blob-store",
// ARM template configuration.
"arm_templates": [
{
"artifact_name": "automated-cli-tests-artifact",
"file_path": "{{arm_template_path}}",
"version": "1.0.0"
}
],
"vhd": {
"artifact_name": "automated-cli-tests-vhd",
"file_path": "{{vhd_path}}",
"version": "1-0-0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
// Azure location to use when creating resources.
"location": "uksouth",
// Name of the Publisher resource you want your definition published to.
// Will be created if it does not exist.
"publisher_name": "automated-cli-tests-ubuntu-publisher",
// Optional. Resource group for the Publisher resource.
// Will be created if it does not exist (with a default name if none is supplied).
"publisher_resource_group_name": "{{publisher_resource_group_name}}",
// Optional. Name of the ACR Artifact Store resource.
// Will be created if it does not exist (with a default name if none is supplied).
"acr_artifact_store_name": "ubuntu-acr",
// Name of NF definition.
"nf_name": "ubuntu-vm",
// Version of the NF definition in A.B.C format.
"version": "1.0.0",
// Optional. Name of the storage account Artifact Store resource.
// Will be created if it does not exist (with a default name if none is supplied).
"blob_artifact_store_name": "ubuntu-blob-store",
// ARM template configuration.
"arm_templates": [
{
"artifact_name": "automated-cli-tests-artifact",
"file_path": "{{arm_template_path}}",
"version": "1.0.0"
}
],
// VHD image configuration.
"vhd": {
// Version of the artifact in A-B-C format. Note the '-' (dash) not '.' (dot).
"version": "1-0-0",
// Supply either file_path or blob_sas_url, not both.
// SAS URL of the blob artifact you wish to copy to your Artifact Store.
// Leave as empty string if not required. Use Linux slash (/) file separator even if running on Windows.
"blob_sas_url": "https://a/dummy/sas-url",
// Optional. Specifies the size of empty data disks in gigabytes.
// This value cannot be larger than 1023 GB. Delete if not required.
"image_disk_size_GB": "30",
// Optional. Specifies the HyperVGenerationType of the VirtualMachine created from the image.
// Valid values are V1 and V2. V1 is the default if not specified. Delete if not required.
"image_hyper_v_generation": "V1",
// Optional. The ARM API version used to create the Microsoft.Compute/images resource.
// Delete if not required.
"image_api_version": "2023-03-01"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"location": "uksouth",
"publisher_name": "automated-cli-tests-ubuntu-publisher",
"publisher_resource_group_name": "{{publisher_resource_group_name}}",
"acr_artifact_store_name": "ubuntu-acr",
"resource_element_templates": [
{
"resource_element_type": "NF",
"properties": {
// The name of the existing publisher for the NSD.
"publisher": "automated-cli-tests-ubuntu-publisher",
// The resource group that the publisher is hosted in.
"publisher_resource_group": "{{publisher_resource_group_name}}",
// The name of the existing Network Function Definition Group to deploy using this NSD.
"name": "ubuntu-vm",
// The version of the existing Network Function Definition to base this NSD on.
// This NSD will be able to deploy any NFDV with deployment parameters compatible with this version.
"version": "1.0.0",
// The region that the NFDV is published to.
"publisher_offering_location": "uksouth",
// Type of Network Function. Valid values are 'cnf' or 'vnf'.
"type": "vnf",
// Set to true or false. Whether the NSD should allow arbitrary numbers of this type of NF. If false only a single instance will be allowed. Only supported on VNFs, must be set to false on CNFs.
"multiple_instances": "false"
}
}
],
"nfvi_type": "AzureCore",
"nsd_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"location": "uksouth",
"publisherName": "automated-cli-tests-ubuntu-publisher",
"publisherResourceGroupName": "test_publisher_name",
"acrArtifactStoreName": "ubuntu-acr",
"acrManifestName": "ubuntu-nsd-manifest-1-0-0",
"nsDesignGroup": "ubuntu",
"nsDesignVersion": "1.0.0",
"nfviSiteName": "ubuntu_NFVI"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.

// This file creates an Artifact Manifest for a NSD
param location string
@description('Name of an existing publisher, expected to be in the resource group where you deploy the template')
param publisherName string
@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.')
param acrArtifactStoreName string
@description('Name of the Artifact Manifest to create')
param acrManifestName string

// The publisher resource is the top level AOSM resource under which all other designer resources
// are created.
// If using publish command, this is created from deploying the nsdbase.bicep
resource publisher 'Microsoft.HybridNetwork/publishers@2023-09-01' existing = {
name: publisherName
}

// The artifact store is the resource in which all the artifacts required to deploy the NF are stored.
// If using publish command, this is created from deploying the nsdbase.bicep
resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-09-01' existing = {
parent: publisher
name: acrArtifactStoreName
}

// Artifact manifest from ARMTemplate and NF RET artifacts
resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-09-01' = {
parent: acrArtifactStore
name: acrManifestName
location: location
properties: {
artifacts: [
{
artifactName: 'ubuntu'
artifactType: 'OCIArtifact'
artifactVersion: '1.0.0'
}
]
}
}
Loading

0 comments on commit 6ed34e0

Please sign in to comment.