In this project, you'll develop and demonstrate your skills in using a variety of industry leading tools, especially Microsoft Azure, to create disposable test environments and run a variety of automated tests with the click of a button. Additionally, you'll monitor and provide insight into your application's behavior, and determine root causes by querying the application’s custom log files.
Before starting this walk-through, you will need to have the following resources installed. Please follow the resource guides to install all dependencies if you do not already have them.
- Azure Free account
- Azure Storage account (resource)
- Azure Log Workspace (resource)
- Terraform Service principle (resource)
- Azure DevOps Organization https://azure.microsoft.com/en-us/pricing/details/devops/azure-devops-services/
- Azure CLI (resource)
Scripts can be found in the Resource section
- Terraform resource
- Jmeter https://jmeter.apache.org/download_jmeter.cgi
- Postman https://www.postman.com/downloads/
- Selenium https://sites.google.com/a/chromium.org/chromedriver/getting-started
- Python https://www.python.org/downloads/
Terraform in Azure
Configure the storage account and state backend (https://docs.microsoft.com/en-us/azure/terraform/terraform-backend). Replace the values below in terraform/main.tf with the output from the Azure CLI:
storage_account_name
container_name
access_key
Create a Service Principal for Terraform (https://www.terraform.io/docs/providers/azurerm/guides/service_principal_client_secret.html) Replace the below values in terraform/environments/test/terraform.tfvars with the output from the Azure CLI:
subscription_id
client_id
client_secret
tenant_id
- Clone this repo
git clone https://github.com/subaquatic-pierre/ci-cd-test-automation.git
-
Create AzurePipeLine Project (resource)
-
Link Project to GitHub repo (resource)
-
Update 'terraform.tfvars.example' to include your credentials, update file name to remove '.example' extension.
# Azure subscription vars
subscription_id = "YOUR_CREDENTIALS"
client_id = "YOUR_CREDENTIALS"
client_secret = "YOUR_CREDENTIALS"
tenant_id = "YOUR_CREDENTIALS"
# Resource Group/Location
location = "YOUR_CREDENTIALS"
resource_group = "YOUR_CREDENTIALS"
application_type = "YOUR_CREDENTIALS"
# Network
virtual_network_name = "YOUR_CREDENTIALS"
address_space = ["10.5.0.0/16"]
address_prefix_test = "10.5.1.0/24"
- From the command line, change into terraform directory
cd terraform
- Run Terraform init and apply commands. Enter 'yes' once prompted to run plan
terraform init
terraform apply
-
Add Virtual machine to CITESTING Environment (resource)
-
Create SSH key-pair to be used with GitHub and Azure Pipelines (resource)
-
Create Service Connection in DevOps project
-
Update 'azure-pipelines.yaml' to include your SSH key (resource)
- task: InstallSSHKey@0
inputs:
knownHostsEntry: "GITHUB_HOSTS"
sshPublicKey: "YOUR_PUBLIC_KEY"
sshKeySecureFile: "YOUR_SECURE_FILE"
- Update 'azureSubscription' and 'appName' in Deploy stage in 'azure-pipelines.yaml'
Get Service connection ID to be used in azureSubscription variable below
https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.0-preview.2
azureSubscription: "8946b145-1fad-4823-a128-5f486158f331"
appName: "testautomation-appservice"
-
Create Log Analytics Workspace (resource)
-
Link Virtual Machine to Log Work Space (resource)
-
Create custom log file (resource)
The log path name should be the following:
/var/log/selenium/*.log
-
Connect App Service to Write logs to Azure Log Workspace
-
Create Alert Group for the App Service
-
Change directory into 'jmeter'. Open Jmeter application and open the stress_test_suite.jmx' or 'endurance_test_suite.jmx' to edit the suite. Save the suites with their respective names. Edit URL to point to your WebAppService
-
Write Selenium tests in 'selenium/selenium_test.py'
-
Uncomment line 32 in 'azure-pipelines' to run Postman tests in Build environment
-
Make one last git commit and push for pipeline to trigger the final build
git add .
git commit -m 'Final build'
git push
Change into the directory which you wish to install Jmeter package
cd /usr/lib
Run the below installation script. It will download Jmeter and add a symlink to your PATH
#! /bin/bash
echo "Downloading Jmeter ..."
wget https://downloads.apache.org//jmeter/binaries/apache-jmeter-5.3.tgz
echo "Unpacking jmeter tgz ..."
tar -xzvf apache-jmeter-5.3.tgz
echo "Create symlink to jmeter bin file"
sudo ln -s ./apache-jmeter-5.3/bin/jmeter /usr/bin/jmeter
echo "Removing jmeter tgz ..."
sudo rm -rf apache-jmeter-5.3.tgz
Install selenium and add chrome-driver to PATH e
sudo apt-get upgrade -y
sudo apt-get install python3-pip -y
sudo apt-get install unzip -y
sudo apt-get install -y chromium-browser
pip3 install selenium
export PATH=$PATH:/usr/bin/chromebrowser
sudo apt-get upgrade -y
sudo snap install postman
sudo npm install -g newman reporter
https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml
https://docs.microsoft.com/en-us/azure/developer/terraform/store-state-in-azure-storage
https://www.terraform.io/docs/providers/azurerm/guides/service_principal_client_secret.html
https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-create-workspace
https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-sources-custom-logs
https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-collect-azurevm