From c4eaaefe949f06af30c7b6f412efb7913e667e3d Mon Sep 17 00:00:00 2001 From: Haitham Shami Date: Fri, 28 May 2021 11:18:09 -0700 Subject: [PATCH] User/hshami/client unique (#32) * code * print errors from run * use redirect output * collect more info on e2e failures * fg install for edge-runtime * more logging * desperation * desperation - 2 * nm * use existing sources list? * PR feedback - pass 1 * latest PR comments * the quiet choice --- src/azure-iot-edge-installer.sh | 6 ++-- src/install-edge-runtime.sh | 2 +- src/utils.sh | 63 +++++++++++++++++++++------------ vsts_ci/azure-pipelines-e2e.yml | 6 ++-- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/azure-iot-edge-installer.sh b/src/azure-iot-edge-installer.sh index b1f6e52..f16e08d 100644 --- a/src/azure-iot-edge-installer.sh +++ b/src/azure-iot-edge-installer.sh @@ -111,8 +111,6 @@ add_option_args "CORRELATION_VECTOR" -cv --correlation-vector # parse command line inputs and fetch output from parser declare -A parsed_cmds="$(cmd_parser $@)" -set_opt_out_selection ${parsed_cmds["TELEMETRY_OPT_OUT"]} $parsed_cmds["CORRELATION_VECTOR"] - # validate that all arguments are acceptable / known if [[ ${#@} > 0 && ${#parsed_cmds[*]} == 0 ]]; then @@ -131,6 +129,8 @@ then exit ${EXIT_CODES[2]} fi +set_opt_out_selection ${parsed_cmds["TELEMETRY_OPT_OUT"]} ${parsed_cmds["CORRELATION_VECTOR"]} ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} + # check if current OS is Tier 1 source validate-tier1-os.sh is_os_tier1 @@ -148,7 +148,7 @@ source install-container-management.sh install_container_management source install-edge-runtime.sh -install_edge_runtime ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} ${parsed_cmds["SYMMETRIC_KEY"]} +install_edge_runtime ${parsed_cmds["SCOPE_ID"]} ${parsed_cmds["REGISTRATION_ID"]} ${parsed_cmds["SYMMETRIC_KEY"]} source validate-post-install.sh validate_post_install diff --git a/src/install-edge-runtime.sh b/src/install-edge-runtime.sh index f568cfc..3e54364 100644 --- a/src/install-edge-runtime.sh +++ b/src/install-edge-runtime.sh @@ -49,7 +49,7 @@ function install_edge_runtime() { # create .toml from template log_info "Create instance configuration .toml from template." - cp /etc/aziot/config.toml.edge.template /etc/aziot/config.toml &>/dev/null + cp /etc/aziot/config.toml.edge.template /etc/aziot/config.toml 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT exit_code=$? if [[ $exit_code != 0 ]]; then diff --git a/src/utils.sh b/src/utils.sh index 59430c4..629768b 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -36,6 +36,7 @@ declare -a EXIT_CODES=(0 # success ) CORRELATION_VECTOR="" +DEVICE_UNIQUE_ID="" ###################################### # set_opt_out_selection @@ -44,6 +45,9 @@ CORRELATION_VECTOR="" # # ARGUMENTS: # does_the_user_NOT_consent_to_sending_telemetry +# correlation vector specific to the run +# scope id +# registration id # # OUTPUTS: # Write output to stdout @@ -52,23 +56,25 @@ CORRELATION_VECTOR="" ###################################### function set_opt_out_selection() { - if [ $1 == true ]; + if [[ "$LOCAL_E2E" == "1" || $1 == true ]]; then OPT_IN=false log_info "The user has opted out of sending usage telemetry." else OPT_IN=true log_info "The user has opted in for sending usage telemetry." - fi - # handle correlation vector - if [ -z $2 ]; - then - CORRELATION_VECTOR=$(generate_uuid) - else - CORRELATION_VECTOR=$2 - fi + # handle correlation vector + if [ -z $2 ]; + then + CORRELATION_VECTOR=$(generate_uuid) + else + CORRELATION_VECTOR=$2 + fi + local ret_value=$(openssl dgst -hmac $INSTRUMENTATION_KEY <<< `echo $3$4`) + DEVICE_UNIQUE_ID=${ret_value##* } + fi } function get_opt_in_selection() { @@ -284,7 +290,7 @@ function prepare_apt() { sources="https://packages.microsoft.com/config/"$platform"/multiarch/prod.list" # sources list - log_info "Adding'%s' to package sources lists." $sources + log_info "Adding '%s' to package sources lists." $sources wget $sources -q -O /etc/apt/sources.list.d/microsoft-prod.list 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT local exit_code=$? if [[ $exit_code != 0 ]]; @@ -292,7 +298,7 @@ function prepare_apt() { log_error "prepare_apt() step 1 failed with error: %d" exit_code exit ${EXIT_CODES[4]} fi - log_info "Added'%s' to package sources lists." $sources + log_info "Added '%s' to package sources lists." $sources log_info "Downloading key" local tmp_file=$(echo `mktemp -u`) @@ -301,7 +307,7 @@ function prepare_apt() { if [[ $exit_code != 0 ]]; then log_error "prepare_apt() step 2 failed with error %d" exit_code - rm -f /etc/apt/sources.list.d/microsoft-prod.list &> /dev/null + rm -f /etc/apt/sources.list.d/microsoft-prod.list 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT exit ${EXIT_CODES[5]} fi @@ -309,17 +315,17 @@ function prepare_apt() { local gpg_file=/etc/apt/trusted.gpg.d/microsoft.gpg if [[ -f $gpg_file ]]; then - rm -f $gpg_file &> /dev/null + rm -f $gpg_file 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT fi gpg --dearmor --output $gpg_file $tmp_file exit_code=$? - rm -f $tmp_file &> /dev/null + rm -f $tmp_file 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT if [[ $exit_code != 0 ]]; then log_error "prepare_apt() step 2 failed with error %d" $exit_code - rm -f /etc/apt/sources.list.d/microsoft-prod.list &> /dev/null + rm -f /etc/apt/sources.list.d/microsoft-prod.list 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT exit ${EXIT_CODES[6]} fi log_info "Downloaded key" @@ -364,13 +370,14 @@ function long_running_command() { local MYPS=$(ps -a | awk '/'$BG_PROCESS_ID'/ {print $1}') if [ "$MYPS" == "" ]; then - BG_PROCESS_ID=-1 BG_PROCESS_ACTIVE=false break fi done done echo -en " \b" + wait $BG_PROCESS_ID + BG_PROCESS_ID=-1 fi } @@ -437,6 +444,19 @@ function handle_exit() { log_info "Removed temporary directory files for iot-edge-installer." fi + if [[ "$LOCAL_E2E" == "1" ]]; + then + if [[ $e_code != 0 ]]; + then + echo errors-file ----------------------------- + cat $STDERR_REDIRECT + echo errors-file ----------------------------- + fi + echo stdout-file ----------------------------- + cat $STDOUT_REDIRECT + echo stdout-file ----------------------------- + fi + announce_my_log_file "All logs were appended to" $OUTPUT_FILE } @@ -487,11 +507,10 @@ function generate_uuid() { } # Constants -InstrumentationKey="d403f627-57b8-4fb0-8001-c51b7466682d" -IngestionEndpoint="https://dc.services.visualstudio.com/v2/track" -EventName="Azure-IoT-Edge-Installer-Summary" -DeviceUniqueID="xinzedPC" -SchemaVersion="1.0" +INSTRUMENTATION_KEY="d403f627-57b8-4fb0-8001-c51b7466682d" +INGESTION_POINT="https://dc.services.visualstudio.com/v2/track" +TELEMETRY_EVENT_NAME="Azure-IoT-Edge-Installer-Summary" +TELEMETRY_SCHEMA_VERSION="1.0" ###################################### # send_appinsight_event_telemetry @@ -520,7 +539,7 @@ function send_appinsight_event_telemetry () log_info "Ready to send telemetry to AppInsights endpoint with wget" local CurrentTime=$(echo `date --utc '+%Y-%m-%dT%H:%M:%S.%N'`) - wget --header='Content-Type: application/json' --header='Accept-Charset: UTF-8' --post-data '{"name":"Microsoft.ApplicationInsights.'$InstrumentationKey'.Event","time": "'$CurrentTime'","iKey": "'$InstrumentationKey'","tags":{"ai.cloud.roleInstance": "'$DeviceUniqueID'"},"data":{"baseType": "EventData","baseData": {"ver": "'$SchemaVersion'","name": "'$EventName'","cv": "'$CORRELATION_VECTOR'","properties":{'$customPropertiesObj'},"measurements":{'$customMeasurementsObj'}}}}' $IngestionEndpoint 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT + wget --header='Content-Type: application/json' --header='Accept-Charset: UTF-8' --post-data '{"name":"Microsoft.ApplicationInsights.'$INSTRUMENTATION_KEY'.Event","time": "'$CurrentTime'","iKey": "'$INSTRUMENTATION_KEY'","tags":{"ai.cloud.roleInstance": "'$DEVICE_UNIQUE_ID'"},"data":{"baseType": "EventData","baseData": {"ver": "'$TELEMETRY_SCHEMA_VERSION'","name": "'$TELEMETRY_EVENT_NAME'","cv": "'$CORRELATION_VECTOR'","properties":{'$customPropertiesObj'},"measurements":{'$customMeasurementsObj'}}}}' $INGESTION_POINT 2>>$STDERR_REDIRECT 1>>$STDOUT_REDIRECT log_info "Finished sending telemetry to AppInsights endpoint with wget" fi diff --git a/vsts_ci/azure-pipelines-e2e.yml b/vsts_ci/azure-pipelines-e2e.yml index 72734c9..f48fab8 100644 --- a/vsts_ci/azure-pipelines-e2e.yml +++ b/vsts_ci/azure-pipelines-e2e.yml @@ -16,8 +16,8 @@ stages: - job: SetupScript steps: - script: | - sudo apt update - sudo apt install jq + sudo apt-get update + sudo apt-get install jq displayName: 'Install jq' - task: AzureCLI@2 inputs: @@ -30,7 +30,7 @@ stages: az --version az account set -s $(AzureSubscriptionId) displayName: 'Set Azure resources' - + - job: LinuxE2ETests pool: vmImage: ubuntu-18.04