From 033bb4d6b4d6b9d96583f07d9a655e64ece90ad4 Mon Sep 17 00:00:00 2001 From: Mariana Mihova <10135329+marianan@users.noreply.github.com> Date: Tue, 18 May 2021 20:55:37 -0700 Subject: [PATCH] Fix E2E pipeline and increment the version (#17) * Add parameters to script call * fix e2e yml and some output * fix source paths * fix source paths * line endings to Unix * add unit test output + remove setup step for unit test pipeline * Test local files * Add copyrights * Remove empty unit test files from yml * Fix psot install validation bug * Fix e2e cd location * Quote angle brackets * Allow for changes to propagate * Set test result correctly on success * Publish logs as artifacts * Address PR feedback * Remove log publishing * Fix unit test source * Fix unit test source * Ubuntu 20.04 is not supported by this script --- src/azure-iot-edge-installer.sh | 6 +- src/validate-post-install.sh | 4 +- tests/e2e-tests/test-devicestate.sh | 20 ++-- tests/perf_tests.sh | 3 + tests/send_one_message_to_iot_hub_device.py | 3 + tests/test_utils.sh | 3 + tests/track_duration.sh | 3 + tests/unit-tests/test-cmd-parser.sh | 3 + .../test-install-container-management.sh | 2 - tests/unit-tests/test-install-edge-runtime.sh | 2 - tests/unit-tests/test-logger.sh | 3 + .../unit-tests/test-validate-post-install.sh | 13 ++- tests/unit-tests/test-validate-tier1-os.sh | 8 +- vsts_ci/azure-pipelines-e2e.yml | 95 ++++++++-------- vsts_ci/azure-pipelines-perf.yml | 95 ++++++++-------- vsts_ci/azure-pipelines.yml | 102 +++++++++--------- vsts_ci/continuous-e2e.yml | 26 ++--- vsts_ci/continuous-perf.yml | 51 ++++----- vsts_ci/linux/continuous-linux.yml | 7 +- vsts_ci/raspi/continuous-raspi.yml | 6 +- 20 files changed, 250 insertions(+), 205 deletions(-) delete mode 100644 tests/unit-tests/test-install-container-management.sh delete mode 100644 tests/unit-tests/test-install-edge-runtime.sh diff --git a/src/azure-iot-edge-installer.sh b/src/azure-iot-edge-installer.sh index c7672a3..8f5bf5b 100644 --- a/src/azure-iot-edge-installer.sh +++ b/src/azure-iot-edge-installer.sh @@ -63,7 +63,7 @@ function download_bash_script() { } # script -printf "Running azure-iot-edge-installer.sh\n" > /dev/stdout +printf "Welcome to azure-iot-edge-installer\n" > /dev/stdout # if helper scripts dont exist, fetch via wget if [ -d "iot-edge-installer" ]; @@ -102,7 +102,7 @@ if [[ ${#@} > 0 && ${#parsed_cmds[*]} == 0 ]]; then array=("$*") echo Unknown argument "${array[*]}" - echo Usage + echo "Usage: sudo ./azure-iot-edge-installer.sh -s -r -k " exit 1 fi @@ -111,7 +111,7 @@ then echo Missing argument echo defined: "'"${!parsed_cmds[@]}"'" echo given: "'"${parsed_cmds[@]}"'" - echo Usage + echo "Usage: sudo ./azure-iot-edge-installer.sh -s -r -k " exit 1 fi diff --git a/src/validate-post-install.sh b/src/validate-post-install.sh index b77ac9b..f79dc21 100644 --- a/src/validate-post-install.sh +++ b/src/validate-post-install.sh @@ -44,9 +44,9 @@ function validate_post_install() { "aziot-certd" "aziot-tpmd") - for i in "${iotedge_services[@]}" + for service_name in "${iotedge_services[@]}" do - is_service_running ${iotedge_services[$i]} "$status" + is_service_running $service_name "$status" done log_info "Post install validation completed." diff --git a/tests/e2e-tests/test-devicestate.sh b/tests/e2e-tests/test-devicestate.sh index f7a2d32..4b2f074 100644 --- a/tests/e2e-tests/test-devicestate.sh +++ b/tests/e2e-tests/test-devicestate.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash + +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + ###################################### # test-devicestate # @@ -127,10 +131,14 @@ scope_id=$(jq -r '.idScope' <<< "$creds") primary_key=$(jq -r '.symmetricKey.primaryKey' <<< "$creds") echo Run the Azure IoT Edge Installer -wget https://github.com/Azure/iot-edge-config/releases/latest/download/azure-iot-edge-installer.sh \ -&& chmod +x azure-iot-edge-installer.sh \ -&& ./azure-iot-edge-installer.sh \ -&& rm -rf azure-iot-edge-installer.sh +#wget -O azure-iot-edge-installer.sh https://github.com/Azure/iot-edge-config/releases/latest/download/azure-iot-edge-installer.sh \ +cd ./../../src +chmod +x azure-iot-edge-installer.sh +sudo LOCAL_E2E=1 ./azure-iot-edge-installer.sh --scope-id "$scope_id" --registration-id "$device_id" --symmetric-key "$primary_key" +rm -rf azure-iot-edge-installer.sh + +# give 2 mins for changes to propagate to central app +sleep 120 # device state should be provisioned after running the script out=$(curl -X GET -H "Authorization:$apiToken" https://${centralapp_name}.azureiotcentral.com/api/preview/devices/${device_id}) @@ -143,10 +151,10 @@ then echo "Error: Device must be provisioned. Exit."; else echo "Device is provisioned as expected. Success."; - $test_result=0 # success + test_result=0 # success fi; # Clean up cleanup "$armToken" "$apiToken" "$device_id" "$token_id" "$rg" "$centralapp_name" -echo test_result: $test_result + exit $test_result diff --git a/tests/perf_tests.sh b/tests/perf_tests.sh index 0599e1c..90d40a1 100644 --- a/tests/perf_tests.sh +++ b/tests/perf_tests.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + ###################################### # perf_tests # diff --git a/tests/send_one_message_to_iot_hub_device.py b/tests/send_one_message_to_iot_hub_device.py index c1ed405..94305b2 100644 --- a/tests/send_one_message_to_iot_hub_device.py +++ b/tests/send_one_message_to_iot_hub_device.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + import argparse import sys diff --git a/tests/test_utils.sh b/tests/test_utils.sh index 6515e11..cea2f2a 100644 --- a/tests/test_utils.sh +++ b/tests/test_utils.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + if command -v tput &>/dev/null && tty -s; then RED=$(tput setaf 1) GREEN=$(tput setaf 2) diff --git a/tests/track_duration.sh b/tests/track_duration.sh index 738caf5..c7a6b38 100644 --- a/tests/track_duration.sh +++ b/tests/track_duration.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + ###################################### # track_duration # diff --git a/tests/unit-tests/test-cmd-parser.sh b/tests/unit-tests/test-cmd-parser.sh index aa67f17..e551c08 100644 --- a/tests/unit-tests/test-cmd-parser.sh +++ b/tests/unit-tests/test-cmd-parser.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + # import utils.sh source ../../src/utils.sh diff --git a/tests/unit-tests/test-install-container-management.sh b/tests/unit-tests/test-install-container-management.sh deleted file mode 100644 index fa2fcac..0000000 --- a/tests/unit-tests/test-install-container-management.sh +++ /dev/null @@ -1,2 +0,0 @@ -#script -echo "Running test-install-container-management.sh" \ No newline at end of file diff --git a/tests/unit-tests/test-install-edge-runtime.sh b/tests/unit-tests/test-install-edge-runtime.sh deleted file mode 100644 index 472f327..0000000 --- a/tests/unit-tests/test-install-edge-runtime.sh +++ /dev/null @@ -1,2 +0,0 @@ -#script to install edge runtime 1.2 -echo "Running test-install-edge-runtime.sh" \ No newline at end of file diff --git a/tests/unit-tests/test-logger.sh b/tests/unit-tests/test-logger.sh index aa47e8e..7eb92ff 100644 --- a/tests/unit-tests/test-logger.sh +++ b/tests/unit-tests/test-logger.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + exec 3>&1 # bring in the utils library diff --git a/tests/unit-tests/test-validate-post-install.sh b/tests/unit-tests/test-validate-post-install.sh index 341a25e..19f4fe1 100644 --- a/tests/unit-tests/test-validate-post-install.sh +++ b/tests/unit-tests/test-validate-post-install.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash -source src/validate-post-install.sh -source tests/test_utils.sh +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +source ../../src/utils.sh +source ../../src/validate-post-install.sh +source ../test_utils.sh test_service_running() { is_service_running "servicenameA" "servicenameA Running" @@ -28,6 +32,11 @@ test_service_casesensitive() { assert_eq 0 $? } +test_service_casesensitive() { + is_service_running "servicenameA" "servicenameA ruNNing" + assert_eq 0 $? +} + # run tests test_service_running test_service_ready diff --git a/tests/unit-tests/test-validate-tier1-os.sh b/tests/unit-tests/test-validate-tier1-os.sh index 1aa880a..3e10440 100644 --- a/tests/unit-tests/test-validate-tier1-os.sh +++ b/tests/unit-tests/test-validate-tier1-os.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash -source src/validate-tier1-os.sh -source tests/test_utils.sh +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +source ../../src/utils.sh +source ../../src/validate-tier1-os.sh +source ../test_utils.sh test_ubuntu1804() { ID="ubuntu" diff --git a/vsts_ci/azure-pipelines-e2e.yml b/vsts_ci/azure-pipelines-e2e.yml index 0a86011..72734c9 100644 --- a/vsts_ci/azure-pipelines-e2e.yml +++ b/vsts_ci/azure-pipelines-e2e.yml @@ -1,46 +1,49 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- main - -stages: -- stage: E2ETest - displayName: E2E Tests - jobs: - - job: SetupScript - steps: - - script: | - sudo apt update - sudo apt install jq - displayName: 'Install jq' - - task: AzureCLI@2 - inputs: - azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - az upgrade - az extension add --name azure-iot - az --version - az account set -s $(AzureSubscriptionId) - displayName: 'Set Azure resources' - - - job: LinuxE2ETests - pool: - vmImage: ubuntu-18.04 - steps: - - template: continuous-e2e.yml - dependsOn: SetupScript - condition: succeeded() - - - job: RaspberryPiE2ETests - pool: - vmImage: ubuntu-latest - steps: - - template: continuous-e2e.yml - dependsOn: SetupScript - condition: succeeded() - +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +stages: +- stage: E2ETest + displayName: E2E Tests + jobs: + - job: SetupScript + steps: + - script: | + sudo apt update + sudo apt install jq + displayName: 'Install jq' + - task: AzureCLI@2 + inputs: + azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + az upgrade + az extension add --name azure-iot + az --version + az account set -s $(AzureSubscriptionId) + displayName: 'Set Azure resources' + + - job: LinuxE2ETests + pool: + vmImage: ubuntu-18.04 + steps: + - template: continuous-e2e.yml + dependsOn: SetupScript + condition: succeeded() + + - job: RaspberryPiE2ETests + pool: + vmImage: ubuntu-18.04 + steps: + - template: continuous-e2e.yml + dependsOn: SetupScript + condition: succeeded() + diff --git a/vsts_ci/azure-pipelines-perf.yml b/vsts_ci/azure-pipelines-perf.yml index 8ab8c2b..91aa7d4 100644 --- a/vsts_ci/azure-pipelines-perf.yml +++ b/vsts_ci/azure-pipelines-perf.yml @@ -1,46 +1,49 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- main - -stages: -- stage: PERFTests - displayName: Performance Tests - jobs: - - job: SetupScript - steps: - - script: | - sudo apt update - sudo apt install jq - displayName: 'Install jq' - - task: AzureCLI@2 - inputs: - azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - az config set extension.use_dynamic_install=yes_without_prompt - az extension add --name azure-iot - az --version - az account set -s $(AzureSubscriptionId) - displayName: 'Set Azure resources' - - - job: LinuxPerfTests - pool: - vmImage: ubuntu-18.04 - steps: - - template: continuous-perf.yml - dependsOn: SetupScript - condition: succeeded() - - - job: RaspberryPiPerfTests - pool: - vmImage: ubuntu-latest - steps: - - template: continuous-perf.yml - dependsOn: SetupScript - condition: succeeded() - +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +stages: +- stage: PERFTests + displayName: Performance Tests + jobs: + - job: SetupScript + steps: + - script: | + sudo apt update + sudo apt install jq + displayName: 'Install jq' + - task: AzureCLI@2 + inputs: + azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + az config set extension.use_dynamic_install=yes_without_prompt + az extension add --name azure-iot + az --version + az account set -s $(AzureSubscriptionId) + displayName: 'Set Azure resources' + + - job: LinuxPerfTests + pool: + vmImage: ubuntu-18.04 + steps: + - template: continuous-perf.yml + dependsOn: SetupScript + condition: succeeded() + + - job: RaspberryPiPerfTests + pool: + vmImage: ubuntu-latest + steps: + - template: continuous-perf.yml + dependsOn: SetupScript + condition: succeeded() + diff --git a/vsts_ci/azure-pipelines.yml b/vsts_ci/azure-pipelines.yml index 58c5981..92da572 100644 --- a/vsts_ci/azure-pipelines.yml +++ b/vsts_ci/azure-pipelines.yml @@ -1,53 +1,51 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml - -trigger: -- main - -stages: -- stage: UnitTest - displayName: Unit Tests - jobs: - - job: SetupScript - steps: - - script: echo Hello, world! - displayName: 'Run a one-line script' - - - job: LinuxUnitTests - pool: - vmImage: ubuntu-18.04 - steps: - - template: linux/continuous-linux.yml - - - job: RaspberryPiUnitTests - pool: - vmImage: ubuntu-latest - steps: - - template: raspi/continuous-raspi.yml - - - job: GithubRelease - dependsOn: - - LinuxUnitTests - - RaspberryPiUnitTests - condition: and(succeeded('LinuxUnitTests'), succeeded('RaspberryPiUnitTests')) - steps: - - script: | - mkdir dest - cp src/*.sh dest/ - displayName: Create dest/ directory - - task: GitHubRelease@1 - displayName: 'GitHub release (create) RC' - inputs: - gitHubConnection: 'github.com_cindydeng1998' - tagPattern: '^v?[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$' - assets: 'dest/*.sh' - isDraft: true - - task: GitHubRelease@1 - displayName: 'GitHub release (create)' - inputs: - gitHubConnection: 'github.com_cindydeng1998' - tagPattern: '^v?[0-9]+\.[0-9]+\.[0-9]+$' - assets: 'dest/*.sh' +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main + +stages: +- stage: UnitTest + displayName: Unit Tests + jobs: + - job: LinuxUnitTests + pool: + vmImage: ubuntu-18.04 + steps: + - template: linux/continuous-linux.yml + + - job: RaspberryPiUnitTests + pool: + vmImage: ubuntu-latest + steps: + - template: raspi/continuous-raspi.yml + + - job: GithubRelease + dependsOn: + - LinuxUnitTests + - RaspberryPiUnitTests + condition: and(succeeded('LinuxUnitTests'), succeeded('RaspberryPiUnitTests')) + steps: + - script: | + mkdir dest + cp src/*.sh dest/ + displayName: Create dest/ directory + - task: GitHubRelease@1 + displayName: 'GitHub release (create) RC' + inputs: + gitHubConnection: 'github.com_cindydeng1998' + tagPattern: '^v?[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+$' + assets: 'dest/*.sh' + isDraft: true + - task: GitHubRelease@1 + displayName: 'GitHub release (create)' + inputs: + gitHubConnection: 'github.com_cindydeng1998' + tagPattern: '^v?[0-9]+\.[0-9]+\.[0-9]+$' + assets: 'dest/*.sh' isDraft: true \ No newline at end of file diff --git a/vsts_ci/continuous-e2e.yml b/vsts_ci/continuous-e2e.yml index f1acfef..0534f7d 100644 --- a/vsts_ci/continuous-e2e.yml +++ b/vsts_ci/continuous-e2e.yml @@ -1,12 +1,14 @@ -steps: -- task: AzureCLI@2 - inputs: - azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - cd tests/e2e-tests - chmod +x test-devicestate.sh - ./test-devicestate.sh $(AzureSubscriptionId) - displayName: 'Run All E2E Tests' - +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +steps: +- task: AzureCLI@2 + inputs: + azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + cd tests/e2e-tests + chmod +x test-devicestate.sh + ./test-devicestate.sh $(AzureSubscriptionId) + displayName: 'Run All E2E Tests' diff --git a/vsts_ci/continuous-perf.yml b/vsts_ci/continuous-perf.yml index a66fbf6..b3787bc 100644 --- a/vsts_ci/continuous-perf.yml +++ b/vsts_ci/continuous-perf.yml @@ -1,25 +1,28 @@ -steps: -- task: UsePythonVersion@0 - displayName: "Use Python 3.8" - inputs: - versionSpec: 3.8 - -- task: AzureCLI@2 - displayName: 'Run All Performance Tests' - inputs: - azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' - scriptType: 'bash' - scriptLocation: 'inlineScript' - inlineScript: | - cd tests - python3 --version - pip3 --version - pip3 install -r requirements.txt - chmod +x ./track_duration.sh - chmod +x ./perf_tests.sh - chmod +x ./e2e-tests/test-devicestate.sh - az config set extension.use_dynamic_install=yes_without_prompt - az extension add --name azure-iot - az --version - az account set -s $(AzureSubscriptionId) +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +steps: +- task: UsePythonVersion@0 + displayName: "Use Python 3.8" + inputs: + versionSpec: 3.8 + +- task: AzureCLI@2 + displayName: 'Run All Performance Tests' + inputs: + azureSubscription: 'Connection to Pipeline resources for IoT Edge Config' + scriptType: 'bash' + scriptLocation: 'inlineScript' + inlineScript: | + cd tests + python3 --version + pip3 --version + pip3 install -r requirements.txt + chmod +x ./track_duration.sh + chmod +x ./perf_tests.sh + chmod +x ./e2e-tests/test-devicestate.sh + az config set extension.use_dynamic_install=yes_without_prompt + az extension add --name azure-iot + az --version + az account set -s $(AzureSubscriptionId) ./perf_tests.sh $(NumberOfRuns) \ No newline at end of file diff --git a/vsts_ci/linux/continuous-linux.yml b/vsts_ci/linux/continuous-linux.yml index c0e9aa0..1ea8ef5 100644 --- a/vsts_ci/linux/continuous-linux.yml +++ b/vsts_ci/linux/continuous-linux.yml @@ -1,12 +1,13 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + steps: - script: echo Hello Linux! displayName: 'Echo Hello Linux' - script: | cd tests/unit-tests - chmod +x ./*.sh - ./test-install-container-management.sh - ./test-install-edge-runtime.sh + chmod +x ./*.sh ./test-validate-post-install.sh ./test-validate-tier1-os.sh ./test-cmd-parser.sh diff --git a/vsts_ci/raspi/continuous-raspi.yml b/vsts_ci/raspi/continuous-raspi.yml index 411ea54..84b3d1d 100644 --- a/vsts_ci/raspi/continuous-raspi.yml +++ b/vsts_ci/raspi/continuous-raspi.yml @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + steps: - script: echo Hello Raspi! displayName: 'Echo Hello Raspi!' @@ -5,11 +8,8 @@ steps: - script: | cd tests/unit-tests chmod +x ./*.sh - ./test-install-container-management.sh - ./test-install-edge-runtime.sh ./test-validate-post-install.sh ./test-validate-tier1-os.sh ./test-cmd-parser.sh ./test-logger.sh displayName: 'Run All Raspberry Pi Unit Tests' -