diff --git a/automatedtesting/jmeter/Starter.jmx b/automatedtesting/jmeter/PerformanceTestSuite.jmx similarity index 100% rename from automatedtesting/jmeter/Starter.jmx rename to automatedtesting/jmeter/PerformanceTestSuite.jmx diff --git a/automatedtesting/postman/StarterAPIs.json b/automatedtesting/postman/Test.environment.json similarity index 100% rename from automatedtesting/postman/StarterAPIs.json rename to automatedtesting/postman/Test.environment.json diff --git a/automatedtesting/postman/TestSuite.Data-Validation.json b/automatedtesting/postman/TestSuite.Data-Validation.json new file mode 100644 index 000000000..746e86069 --- /dev/null +++ b/automatedtesting/postman/TestSuite.Data-Validation.json @@ -0,0 +1,37 @@ +[ + { + "postId": 1, + "id": 1, + "name": "Labore Laborum", + "salary": "1000", + "age": "34" + }, + { + "postId": 1, + "id": 2, + "name": "Reiciendis Earum", + "salary": "1200", + "age": "26" + }, + { + "postId": 1, + "id": 3, + "name": "Adipisci Animi", + "salary": "3500", + "age": "55" + }, + { + "postId": 1, + "id": 4, + "name": "Alias Sit", + "salary": "2100", + "age": "42" + }, + { + "postId": 1, + "id": 5, + "name": "Vero Eaque", + "salary": "4243", + "age": "47" + } + ] \ No newline at end of file diff --git a/automatedtesting/postman/TestSuite.Regression.json b/automatedtesting/postman/TestSuite.Regression.json new file mode 100644 index 000000000..746e86069 --- /dev/null +++ b/automatedtesting/postman/TestSuite.Regression.json @@ -0,0 +1,37 @@ +[ + { + "postId": 1, + "id": 1, + "name": "Labore Laborum", + "salary": "1000", + "age": "34" + }, + { + "postId": 1, + "id": 2, + "name": "Reiciendis Earum", + "salary": "1200", + "age": "26" + }, + { + "postId": 1, + "id": 3, + "name": "Adipisci Animi", + "salary": "3500", + "age": "55" + }, + { + "postId": 1, + "id": 4, + "name": "Alias Sit", + "salary": "2100", + "age": "42" + }, + { + "postId": 1, + "id": 5, + "name": "Vero Eaque", + "salary": "4243", + "age": "47" + } + ] \ No newline at end of file diff --git a/automatedtesting/selenium/add_remove_from_cart.py b/automatedtesting/selenium/add_remove_from_cart.py new file mode 100644 index 000000000..c7f62b942 --- /dev/null +++ b/automatedtesting/selenium/add_remove_from_cart.py @@ -0,0 +1,8 @@ +# #!/usr/bin/env python +from selenium import webdriver +from selenium.webdriver.chrome.options import Options as ChromeOptions + +# Start the browser and navigate to webpage +driver = webdriver.Chrome() +driver.get('https://wswebapplication-appservice.azurewebsites.net/automatedtesting/selenium/login.py') +#driver.get(https://wswebapplication-appservice.azurewebsites.net/automatedtesting/selenium/login.py') \ No newline at end of file diff --git a/automatedtesting/selenium/login.py b/automatedtesting/selenium/login.py index aca2df148..45d1f6995 100644 --- a/automatedtesting/selenium/login.py +++ b/automatedtesting/selenium/login.py @@ -7,9 +7,9 @@ def login (user, password): print ('Starting the browser...') # --uncomment when running in Azure DevOps. - # options = ChromeOptions() - # options.add_argument("--headless") - # driver = webdriver.Chrome(options=options) + options = ChromeOptions() + options.add_argument("--headless") + driver = webdriver.Chrome(options=options) driver = webdriver.Chrome() print ('Browser started successfully. Navigating to the demo page to login.') driver.get('https://www.saucedemo.com/') diff --git a/automatedtesting/selenium/selenium-output.txt b/automatedtesting/selenium/selenium-output.txt new file mode 100644 index 000000000..e69de29bb diff --git a/automatedtesting/selenium/selenium.log b/automatedtesting/selenium/selenium.log new file mode 100644 index 000000000..e69de29bb diff --git a/azure-pipelines.yaml b/azure-pipelines.yaml index 154906ab8..99ee1920a 100644 --- a/azure-pipelines.yaml +++ b/azure-pipelines.yaml @@ -9,15 +9,16 @@ trigger: # ToDo: Replace the agent pool name, if you are using Udacity Cloud lab. # Otherwise, comment out the line below. pool: myAgentPool +#pool: "Azure Pipelines" variables: python.version: '3.7.6' # ToDo: Replace the service connection name as used in the DevOps project settings - azureServiceConnectionId: 'myServiceConnection' + azureServiceConnectionId: 'AzureRMconn3' #'myServiceConnection' # Project root folder. Point to the folder containing manage.py file. projectRoot: $(System.DefaultWorkingDirectory) # Environment name - environmentName: 'test' + environmentName: 'linux-test3' stages: #--------------------------------------------# @@ -33,7 +34,8 @@ stages: - task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller@0 displayName: 'Terrafom installation' inputs: - terraformVersion: '1.2.9' +# terraformVersion: '1.2.9' + terraformVersion: 'latest' # Run Terraform Init on the pipeline agent # ToDo: Replace the resource group name, storage account name, and container name below @@ -44,9 +46,9 @@ stages: command: 'init' workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/environments/test' backendServiceArm: '$(azureServiceConnectionId)' - backendAzureRmResourceGroupName: '' - backendAzureRmStorageAccountName: '' - backendAzureRmContainerName: '' + backendAzureRmResourceGroupName: 'Azuredevops2' + backendAzureRmStorageAccountName: 'tfstate635024562' + backendAzureRmContainerName: 'tfstate' backendAzureRmKey: 'test.terraform.tfstate' - task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV3@3 @@ -121,9 +123,9 @@ stages: inputs: testResultsFormat: 'JUnit' testResultsFiles: '**/TEST-*.xml' - searchFolder: # ToDo + searchFolder: '$(System.DefaultWorkingDirectory)' # ToDo mergeTestResults: true - testRunTitle: # ToDo + testRunTitle: Test_Demo # ToDo #--------------------------------------------# # Selenium (UI) Test Suite - Archive the package @@ -146,7 +148,7 @@ stages: - task: ArchiveFiles@2 displayName: 'Archive FakeRestAPI' inputs: - rootFolderOrFile: + rootFolderOrFile: includeRootFolder: false archiveType: 'zip' archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)-fakerestapi.zip' @@ -179,8 +181,8 @@ stages: # ToDo: Provide you created in your DevOps project - deployment: FakeRestAPI pool: - vmImage: 'Ubuntu-18.04' - environment: # ToDo + vmImage: 'Ubuntu-20.04' + environment: '$(environmentName)' # ToDo strategy: runOnce: deploy: @@ -188,37 +190,44 @@ stages: - task: AzureWebApp@1 displayName: 'Deploy Azure Web App' inputs: - azureSubscription: '' # ToDo - appName: '' # ToDo + azureSubscription: 'AzureRMconn3' # ToDo + appName: 'wswebApplication-AppService' # ToDo appType: webApp - package: $(Pipeline.Workspace)// # ToDo: Use the published zip artifact. +# package: $(Build.ArtifactStagingDirectory)/$(Build.BuildId)-fakerestapi.zip # ToDo: Use the published zip artifact. + package: $(Pipeline.Workspace)/drop-fakerestapi/$(Build.BuildId)-fakerestapi.zip # ToDo: Use the published zip artifact. +# package: $(Pipeline.Workspace)/a/$(Build.BuildId)-fakerestapi.zip # ToDo: Use the published zip artifact. +# package: $(Pipeline.Workspace)// # ToDo: Use the published zip artifact. #--------------------------------------------# # Run JMeter test suite against the App Service - task: CmdLine@2 inputs: script: | - wget "https://apache.mirrors.lucidnetworks.net//jmeter/binaries/apache-jmeter-5.2.1.tgz" - tar -xf apache-jmeter-5.2.1.tgz + wget "https://dlcdn.apache.org//jmeter/binaries/apache-jmeter-5.6.tgz" + tar -xf apache-jmeter-5.6.tgz unzip -o $(Build.BuildId)-perftests.zip - ./apache-jmeter-5.2.1/bin/jmeter -n -t PerformanceTestSuite.jmx -j jmeter.log -f + ./apache-jmeter-5.6/bin/jmeter -n -t automatedtesting/jmeter/PerformanceTestSuite.jmx -j jmeter.log -f cat jmeter.log # ToDo: Write your commands - workingDirectory: $(Pipeline.Workspace)/ # ToDo: Use the artifact name from the task above + workingDirectory: $(Pipeline.Workspace)/drop-perftests # ToDo: Use the artifact name from the task above +# workingDirectory: $(Pipeline.Workspace)/drop-fakerestapi # ToDo: Use the artifact name from the task above +# workingDirectory: $(Pipeline.Workspace)/ # ToDo: Use the artifact name from the task above #--------------------------------------------# # Selenium | Functional UI Tests # ToDo: - deployment: VMDeploy - displayName: Selenium Tests + displayName: Selenium UI Tests environment: - name: # ToDo: Change/provide a name + name: '$(environmentName)' resourceType: VirtualMachine +# name: "linux-test" # ToDo: Change/provide a name +# resourceType: VirtualMachine tags: selenium strategy: runOnce: deploy: steps: - download: current - artifact: drop-ui-tests # ToDo: Change/provide a name + artifact: drop-uitests # ToDo: Change/provide a name - task: Bash@3 inputs: @@ -232,21 +241,21 @@ stages: sudo apt-get install -y chromium-browser pip3 install selenium cd ~/ - DIR=/home/testuser/app + DIR=/home/adminuser/app if [ ! -d "$DIR" ]; then mkdir app fi - mv /home/testuser/azagent/_work/1/drop-uitests/$(Build.BuildId)-uitests.zip app + mv /home/adminuser/azagent/_work/1/drop-uitests/$(Build.BuildId)-uitests.zip app cd app unzip -o $(Build.BuildId)-uitests.zip - FILE=/home/testuser/app/chromedriver_linux64.zip + FILE=/home/adminuser/app/chromedriver_linux64.zip if [ ! -f "$FILE" ]; then LATEST=$(wget -q -O - http://chromedriver.storage.googleapis.com/LATEST_RELEASE) wget http://chromedriver.storage.googleapis.com/$LATEST/chromedriver_linux64.zip unzip -o chromedriver_linux64.zip sudo ln -s $PWD/chromedriver /usr/local/bin/chromedriver fi - export PATH=$PATH:/home/testuser/app + export PATH=$PATH:/home/adminuser/app echo "Starting Selenium Tests" python3 add_remove_from_cart.py >> selenium.log echo "Completed Selenium Tests. Check selenium.log for results." \ No newline at end of file diff --git a/terraform/environments/test/.terraform.lock.hcl b/terraform/environments/test/.terraform.lock.hcl new file mode 100644 index 000000000..41f6c42fe --- /dev/null +++ b/terraform/environments/test/.terraform.lock.hcl @@ -0,0 +1,21 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/azurerm" { + version = "3.63.0" + hashes = [ + "h1:x5r2Vg60nZa2Q92f/E7og1jNZb6eqsv0vZcWdzWnY3E=", + "zh:0bb8263de0abf1a7457168673f9fcf7e404ae59d03d0e8eda91f1e024f8d9253", + "zh:24dd5883c95801f2d4a88be22b9a3bb4e20de7b6b65e8b7cc90b12a0895d7adf", + "zh:4fe19fe81a68811d09d33aeea05f20987bef84dc7377c4b34782b94dda2c658f", + "zh:673fcd9d15b3f1307a1c41323598678b9a705751851d0f65e6abdf78c9e5361f", + "zh:6c401d348d04436ed891482c3e2151c34d6fbce0a6ee8880c6025de589e22e9a", + "zh:6f6b9909d62e9928d56b1d02c88a514d45022fae72048166e58e288759c73493", + "zh:7de2aa6636ba657166ef992a3b7a822394a2d1f8c319fdbabec69b99950990ea", + "zh:976ca97ab21708f8707c360c18dc64c03a6e497b7a157bb0ff7a8a54c03ebc55", + "zh:af220c20ce6e76c4c072fbc9aa3c02597260117ba7deaa0e0d585fb1957a775b", + "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", + "zh:fb4055762069cf0f58a36110853811f63e52c7077e332d8731a66fade1ba9f15", + "zh:fc95c1c80e98c317ec38fa33d16d55b5a62058dc893fbf578d100fb91401356e", + ] +} diff --git a/terraform/environments/test/configure-tfstate-storage-account.sh_OLD b/terraform/environments/test/configure-tfstate-storage-account.sh_OLD new file mode 100644 index 000000000..ada7fa330 --- /dev/null +++ b/terraform/environments/test/configure-tfstate-storage-account.sh_OLD @@ -0,0 +1,23 @@ +#!/bin/bash +RESOURCE_GROUP_NAME="Azuredevops" +STORAGE_ACCOUNT_NAME="tfstate$RANDOM$RANDOM" +CONTAINER_NAME="tfstate" + +# This command is not needed in the Udacity provided Azure account. +# Create resource group +# az group create --name $RESOURCE_GROUP_NAME --location eastus + +# Create storage account +az storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME --sku Standard_LRS --encryption-services blob + +# Get storage account key +ACCOUNT_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP_NAME --account-name $STORAGE_ACCOUNT_NAME --query '[0].value' -o tsv) +export ARM_ACCESS_KEY=$ACCOUNT_KEY + +# Create blob container +az storage container create --name $CONTAINER_NAME --account-name $STORAGE_ACCOUNT_NAME --account-key $ACCOUNT_KEY +echo "RESOURCE_GROUP_NAME=$RESOURCE_GROUP_NAME" +echo "STORAGE_ACCOUNT_NAME=$STORAGE_ACCOUNT_NAME" +echo "CONTAINER_NAME=$CONTAINER_NAME" +echo "ACCOUNT_KEY=$ACCOUNT_KEY" + diff --git a/terraform/environments/test/input.tf b/terraform/environments/test/input.tf index 071bc0ea6..1d20ef4a4 100644 --- a/terraform/environments/test/input.tf +++ b/terraform/environments/test/input.tf @@ -7,10 +7,14 @@ variable "tenant_id" {} # Resource Group/Location variable "location" {} variable "resource_group" {} +variable "resource_group_name" {} variable "application_type" {} # Network variable virtual_network_name {} variable address_prefix_test {} +variable address_prefixes_test {} variable address_space {} +# VM +#variable subnet_id {} diff --git a/terraform/environments/test/main.tf b/terraform/environments/test/main.tf index 5d94eaaaf..4035535b2 100644 --- a/terraform/environments/test/main.tf +++ b/terraform/environments/test/main.tf @@ -5,19 +5,22 @@ provider "azurerm" { client_secret = "${var.client_secret}" features {} } + terraform { backend "azurerm" { - storage_account_name = "" - container_name = "" - key = "" - access_key = "" + storage_account_name = "tfstate635024562" + container_name = "tfstate" + key = "test.terraform.tfstate" + access_key = "qXly88km6RjjLdisH+W+rvJxRQCqLOjuAGVd1AdZ0SfFvNsjuYJ/mYU2UzpHe2pl6hr0Ncsbu5cg+AStAEYcag==" } } -module "resource_group" { - source = "../../modules/resource_group" - resource_group = "${var.resource_group}" - location = "${var.location}" -} + +#module "resource_group" { +# source = "../../modules/resource_group" +# resource_group = "${var.resource_group}" +# location = "${var.location}" +#} + module "network" { source = "../../modules/network" address_space = "${var.address_space}" @@ -25,8 +28,10 @@ module "network" { virtual_network_name = "${var.virtual_network_name}" application_type = "${var.application_type}" resource_type = "NET" - resource_group = "${module.resource_group.resource_group_name}" +# resource_group = "${module.resource_group.resource_group_name}" + resource_group = "${var.resource_group}" address_prefix_test = "${var.address_prefix_test}" + address_prefixes_test = "${var.address_prefixes_test}" } module "nsg-test" { @@ -34,7 +39,8 @@ module "nsg-test" { location = "${var.location}" application_type = "${var.application_type}" resource_type = "NSG" - resource_group = "${module.resource_group.resource_group_name}" +# resource_group = "${module.resource_group.resource_group_name}" + resource_group = "${var.resource_group}" subnet_id = "${module.network.subnet_id_test}" address_prefix_test = "${var.address_prefix_test}" } @@ -43,12 +49,22 @@ module "appservice" { location = "${var.location}" application_type = "${var.application_type}" resource_type = "AppService" - resource_group = "${module.resource_group.resource_group_name}" + resource_group = "${var.resource_group}" +# resource_group = "${module.resource_group.resource_group_name}" } module "publicip" { source = "../../modules/publicip" location = "${var.location}" application_type = "${var.application_type}" resource_type = "publicip" - resource_group = "${module.resource_group.resource_group_name}" + resource_group = "${var.resource_group}" +} +module "vm" { + source = "../../modules/vm" + location = "${var.location}" + application_type = "${var.application_type}" + resource_type = "VM" + resource_group = "${var.resource_group}" + subnet_id = "${module.network.subnet_id_test}" + public_ip_address_id = "${module.publicip.public_ip_address_id}" } \ No newline at end of file diff --git a/terraform/environments/test/terraform.tfvars b/terraform/environments/test/terraform.tfvars index 83a5d8dbc..84970b27c 100644 --- a/terraform/environments/test/terraform.tfvars +++ b/terraform/environments/test/terraform.tfvars @@ -1,15 +1,17 @@ # Azure subscription vars -subscription_id = "" -client_id = "" -client_secret = "" -tenant_id = "" +subscription_id = "7205ab75-14d1-47f5-9d1b-4a6d61efe05d" +client_id = "fa872483-d4d2-41ce-97f1-606ef9a70b5d" +client_secret = "YNf8Q~K7icfuDFQE~gL1NJ4En~eO32nTARW.2adD" +tenant_id = "514cd75c-be1c-45da-8ad0-46bb2c5e4502" # Resource Group/Location -location = "" -resource_group_name = "" -application_type = "" +location = "West Europe" +resource_group_name = "Azuredevops2" +resource_group = "Azuredevops2" +application_type = "wswebApplication" # Network -virtual_network_name = "" +virtual_network_name = "myVNet" address_space = ["10.5.0.0/16"] +address_prefixes_test = ["10.5.1.0/24"] address_prefix_test = "10.5.1.0/24" diff --git a/terraform/modules/network/input.tf b/terraform/modules/network/input.tf index 4741f2330..edaaad113 100644 --- a/terraform/modules/network/input.tf +++ b/terraform/modules/network/input.tf @@ -7,4 +7,5 @@ variable address_space {} variable "application_type" {} variable "resource_type" {} variable "address_prefix_test" {} +variable "address_prefixes_test" {} diff --git a/terraform/modules/network/network.tf b/terraform/modules/network/network.tf index 391a92f58..04305a83d 100644 --- a/terraform/modules/network/network.tf +++ b/terraform/modules/network/network.tf @@ -8,5 +8,5 @@ resource "azurerm_subnet" "test" { name = "${var.application_type}-${var.resource_type}-sub" resource_group_name = "${var.resource_group}" virtual_network_name = "${azurerm_virtual_network.test.name}" - address_prefix = "${var.address_prefix_test}" -} + address_prefixes = "${var.address_prefixes_test}" +} \ No newline at end of file diff --git a/terraform/modules/publicip/publicip.tf b/terraform/modules/publicip/publicip.tf index 5c3a0eba3..036b429a9 100644 --- a/terraform/modules/publicip/publicip.tf +++ b/terraform/modules/publicip/publicip.tf @@ -3,5 +3,4 @@ resource "azurerm_public_ip" "test" { location = "${var.location}" resource_group_name = "${var.resource_group}" allocation_method = "Dynamic" - } \ No newline at end of file diff --git a/terraform/modules/vm/input.tf b/terraform/modules/vm/input.tf index 8b1378917..9af16f48d 100644 --- a/terraform/modules/vm/input.tf +++ b/terraform/modules/vm/input.tf @@ -1 +1,21 @@ +variable "location" { +# default = "West Europe" +} +variable "application_type" { + # default = "wsApplication" +} +variable "resource_type" { + default = "VM" +} +variable "resource_group" { + default = "Azuredevops" +} + +variable "subnet_id" { +# default = "Azuredevops" +} + +variable "public_ip_address_id" { +# default = "Azuredevops" +} diff --git a/terraform/modules/vm/vm.tf b/terraform/modules/vm/vm.tf index 24da93338..48d628c27 100644 --- a/terraform/modules/vm/vm.tf +++ b/terraform/modules/vm/vm.tf @@ -1,35 +1,45 @@ -resource "azurerm_network_interface" "" { - name = "" - location = "" - resource_group_name = "" + +resource "azurerm_network_interface" "test" { + name = "${var.application_type}-${var.resource_type}" + location = "${var.location}" + resource_group_name = "${var.resource_group}" ip_configuration { name = "internal" - subnet_id = "" + subnet_id = "${var.subnet_id}" private_ip_address_allocation = "Dynamic" - public_ip_address_id = "" + public_ip_address_id = "${var.public_ip_address_id}" } } -resource "azurerm_linux_virtual_machine" "" { - name = "" - location = "" - resource_group_name = "" - size = "Standard_DS2_v2" - admin_username = "" - network_interface_ids = [] +resource "azurerm_linux_virtual_machine" "test" { + name = "${var.application_type}-${var.resource_type}" + location = "${var.location}" + resource_group_name = "${var.resource_group}" + size = "Standard_B1s" + admin_username = "adminuser" + admin_password = "adminuserP@55" + disable_password_authentication = "false" + network_interface_ids = [ + azurerm_network_interface.test.id, + ] +# admin_ssh_key { +# username = "adminuser" +# public_key = "file("~/.ssh/id_rsa.pub")" +# } admin_ssh_key { - username = "" - public_key = "file("~/.ssh/id_rsa.pub")" + username = "adminuser" + public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCe+85RdeEz+9UVLdmToflPtHREOLFpODV/HR1aQoyP+veU4dEYF/gdvHkHOCBNl/x9wNeitr9tzrc0AGjy2hEFGjRdOrT7XG1nZ6a6Mhjd9yTT3ghDk8p8ipYQqbmqyTQphNT9ym4qSOJ1zakCjM6a4M7HB7AyhS8ddI1xGxPH5q2XSh5HC95/1hxrgXFakjNT2Zw//D9LT2gQdIZuuBUPE/8+SjEPa97Qe8m6W9WCkulEFzLzK0TsM6cQ8y0eCrmh30lWfT7XHm2w0kLvj4POL8+2BCCb+dcbBxV/oH4Z9xemBk84psFbixHIVUNIbJuYQORPlWf9wzCD7mjti0C1HFGBjCQyTqDaYjXW91ifIotJiIGILeZ1ZA7XiC9dbiJF8pwPsi3OjT3ehcxrue19/f7mTJ07CJIqTIKF6DL0CLmfZj+ae44jmysihCdJvbia+pRgvwlH5fm9551LL3F3J4O1xRIBIKLSwbiHZqUxEzu8UtwIOyafez0HdWWFRkc= wojsiw@DESKTOP-AVL1658" } + os_disk { caching = "ReadWrite" storage_account_type = "Standard_LRS" } source_image_reference { publisher = "Canonical" - offer = "UbuntuServer" - sku = "18.04-LTS" + offer = "0001-com-ubuntu-server-focal" + sku = "20_04-lts-gen2" version = "latest" } }