Skip to content

v0.4.0 Lab 5 Extend test coverage

CARMLPipelinePrincipal edited this page Oct 25, 2022 · 1 revision

In this lab you will enhance an existing module by adding additional tests.

For this lab, we will use another simple and quick to deploy module: availabilitySets.

Navigation


Step 1 - Examine the module

  1. In your VSCode, navigate to the path arm/Microsoft.Compute/availabilitySets. You will notice the readme.md file describes several parameters and only one of them, name, is marked as Required.

    AVS Readme
  2. Navigate to .parameters/parameters.json in the availability set module. This file is currently used to validate the actual deployment of the module in Azure. It specifies only the name and roleAssignments parameters. In this lab you will perform the following tasks:

    • Update the existing parameters.json file to test an additional parameter
    • Integrate one additional parameter file to test the minimum set of input parameters required by the availability set module

Step 2 - Update existing parameter file

Ensure that the dependency pipeline you run in Lab 3 deployed a Proximity Placement Group in your lab environment.

Note: In case the pipeline failed for any reason you can create the dependency manually by following the steps described here. Once the dependency is available, proceed with the follow steps:

Now lets update the existing parameter file.

  1. If not already open, navigate back to the parameters.json file in path arm/Microsoft.Compute/availabilitySets/.parameters/parameters.json in your local VSCode.

  2. Add the below snippet as a new parameter to the parameter file and ensure the name of the proximity placement group matches the one you deployed as a dependency. The <<subscriptionId>> & <<namePrefix>> tokens will be automatically replaced with their correct values by the pipeline

    "proximityPlacementGroupId": {
        "value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.Compute/proximityPlacementGroups/adp-<<namePrefix>>-az-ppg-x-001"
    }
  3. By adding the new parameter, the deployment in the pipeline will pick it up and validate that the template uses it successfully and as intended. The full parameter file should look like

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "name": {
                "value": "<<namePrefix>>-az-avs-x-001"
            },
            "roleAssignments": {
                "value": [
                    {
                        "roleDefinitionIdOrName": "Reader",
                        "principalIds": [
                            "<<deploymentSpId>>"
                        ]
                    }
                ]
            },
            "proximityPlacementGroupId": {
                "value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.Compute/proximityPlacementGroups/adp-<<namePrefix>>-az-ppg-x-001"
            }
        }
    }

Step 3 - Add a new parameter file

Now you will create a new parameter file that will test that the template's default values work as intended by providing only the minimum set of parameters.

  1. If not already, navigate again to the arm/Microsoft.Compute/availabilitySets/.parameters folder

  2. Create a new file and name it min.parameters.json

  3. As you examined earlier, the template only requires you to provide the name parameter. To this end, add the follow content to the created parameter file:

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "name": {
                "value": "<<namePrefix>>-az-avs-min-001"
            }
        }
    }

    Note: The name value is different from the previous parameters.json file. As both resources are deployed in parallel, they must have different names to not interfere with one another.

Step 4 - Add the new file to the workflow

Now you have to modify the workflow file to make sure it also uses the new parameter file during the tests.

  1. Navigate to the availability sets validation pipeline in .github/workflows/ms.compute.availabilitysets.yml.

  2. In line 84 you should see the parameters matrix where you will need to add the min.parameters.json

    Parameters matrix

    Note: If this was a direct contribution to the main CARML repository, we'd also ask you to update the corresponding Azure DevOps template file with the analogous changes.

Step 5 - Upload your changes to GitHub

Now that the tests are implemented and the pipeline updated, you can upload your changes to GitHub. You can do this in two ways

Alternative 1: Via VSCode's terminal
  1. If a Terminal is not in sight, you can alternatively open it by expanding the Terminal-dropdown on the top, and selecting New Terminal

  2. Now, execute the following PowerShell commands:

    git add .
    git commit -m 'Added new minimum parameter test file and proximity placement group test to availability set module'
    git push
Alternative 2: Via VSCode's UI
  1. Add your changes: If not already there, navigate to the source control menu to the left and add the changed files to the commit. To do so, select the + icon next to Changes (appears when hovering)

    Open source control
  2. Commit your changes: Next, you should give the commit a meaningful message such as 'Added new minimum parameter test file and proximity placement group test to availability set module' and can then click the checkmark symbol on the top to create the commit

    Git commit
  3. Push your changes: Finally, you can push the changes to the repository by selecting the blue Publish Branch button

    Git push

Step 6 - Test the deployment

You will now manually test the deployment, verifying its template is using both parameter files.

  1. On GitHub, go to Actions

  2. Find the Compute: AvailabilitySets workflow and select Run workflow

  3. Further select your branch from the Branch: dropdown (e.g. carmlLab)

    Select branch
  4. Unflag the Remove deployed module and execute the workflow by selecting Run workflow

    Execute the workflow

    Note: The pipeline will take about 5-6 minutes to complete

  5. You can click on the running workflow and verify that you have a separate job for each specified parameter file.

    Note: The separate jobs will only be visible once the Deployment tests stage starts

    Run with 2 parameters
  6. Once the jobs are completed, go to the Azure portal and open the validation-rg resource group. Verify that both availability groups have been deployed to Azure and that they have been configured with the settings specified in their corresponding parameter files.

    2 availability sets

If ready, proceed to the next lab: Lab 6 - Publishing

Optional Appendix

Proximity Placement Group dependency

In case the dependency pipeline of Lab 3 failed to deploy the required proximity placement group for any reason, you can use the below instructions to create it manually from the Azure portal:

  1. Navigate to the Azure portal and search for proximity placement groups

    Search for Proximity Placement
  2. Next, select the + Create button in the Proximity placement groups view

    Init Proximity Placement Creation
  3. Select the validation-rg resource group, a location and a name for the resource (e.g. adp-<<YourNamePrefix>>-az-ppg-x-001) and create the resource

    Note: The name you give the resource must exactly match the one specified in the availability set's parameter file (excluding the token).

    Create Proximity Placement


If ready, proceed to the next lab: Lab 6 - Publishing