-
Notifications
You must be signed in to change notification settings - Fork 455
/
NestTestHelper.sh
144 lines (115 loc) · 4.09 KB
/
NestTestHelper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
function clean_up() {
print_highlighted_message 'Clean up'
stop_iotedge_service || true
echo 'Remove IoT Edge and config file'
apt-get purge libiothsm-std --yes || true
rm -rf /var/lib/iotedge/
rm -rf /var/run/iotedge/
rm -rf /etc/iotedge/config.yaml
rm -rf /etc/systemd/system/aziot-*.service.d/
if [ "$CLEAN_ALL" = '1' ]; then
echo 'Prune docker system'
docker system prune -af --volumes || true
echo 'Restart docker'
systemctl restart docker # needed due to https://github.com/moby/moby/issues/23302
else
echo 'Remove docker containers'
docker rm -f $(docker ps -aq) || true
fi
}
function create_iotedge_service_config {
print_highlighted_message 'Create IoT Edge service config'
mkdir /etc/systemd/system/iotedge.service.d/ || true
bash -c "echo '[Service]
Environment=IOTEDGE_LOG=edgelet=debug' > /etc/systemd/system/iotedge.service.d/override.conf"
}
function get_connectivity_deployment_artifact_file() {
local testDir=$1
local path
path="$testDir/artifacts/core-linux/e2e_deployment_files/connectivity_deployment.template.json"
echo "$path"
}
function get_image_architecture_label() {
local arch
arch="$(uname -m)"
case "$arch" in
'x86_64' ) image_architecture_label='amd64';;
'armv7l' ) image_architecture_label='arm32v7';;
'aarch64' ) image_architecture_label='arm64v8';;
*) print_error "Unsupported OS architecture: $arch"; exit 1;;
esac
}
function get_iotedged_artifact_folder() {
local testDir=$1
local path
if [ "$image_architecture_label" = 'amd64' ]; then
path="$testDir/artifacts/iotedged-ubuntu18.04-amd64"
elif [ "$image_architecture_label" = 'arm64v8' ]; then
path="$testDir/artifacts/iotedged-ubuntu18.04-aarch64"
else
path="$testDir/artifacts/iotedged-debian9-arm32v7"
fi
echo "$path"
}
function get_iotedge_quickstart_artifact_file() {
local testDir=$1
local path
if [ "$image_architecture_label" = 'amd64' ]; then
path="$testDir/artifacts/core-linux/IotEdgeQuickstart.linux-x64.tar.gz"
elif [ "$image_architecture_label" = 'arm64v8' ]; then
path="$testDir/artifacts/core-linux/IotEdgeQuickstart.linux-arm64.tar.gz"
else
path="$testDir/artifacts/core-linux/IotEdgeQuickstart.linux-arm.tar.gz"
fi
echo "$path"
}
function get_leafdevice_artifact_file() {
local testDir=$1
local path
if [ "$image_architecture_label" = 'amd64' ]; then
path="$testDir/artifacts/core-linux/LeafDevice.linux-x64.tar.gz"
elif [ "$image_architecture_label" = 'arm64v8' ]; then
path="$testDir/artifacts/core-linux/LeafDevice.linux-arm64.tar.gz"
else
path="$testDir/artifacts/core-linux/LeafDevice.linux-arm.tar.gz"
fi
echo "$path"
}
function get_hash() {
local length=$1
local hash=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c $length)
echo "$hash"
}
function is_cancel_build_requested() {
local accessToken=$1
local buildId=$2
if [[ ( -z "$accessToken" ) || ( -z "$buildId" ) ]]; then
echo 0
fi
local output1=$(curl -s -u :$accessToken --request GET "https://dev.azure.com/msazure/one/_apis/build/builds/$buildId?api-version=5.1" | grep -oe '"status":"cancel')
local output2=$(curl -s -u :$accessToken --request GET "https://dev.azure.com/msazure/one/_apis/build/builds/$buildId/Timeline?api-version=5.1" | grep -oe '"result":"canceled"')
if [[ -z "$output1" && -z "$output2" ]]; then
echo 0
else
echo 1
fi
}
function print_error() {
local message=$1
local red='\033[0;31m'
local color_reset='\033[0m'
echo -e "${red}$message${color_reset}"
}
function print_highlighted_message() {
local message=$1
local cyan='\033[0;36m'
local color_reset='\033[0m'
echo -e "${cyan}$message${color_reset}"
}
function stop_iotedge_service() {
echo 'Stop IoT Edge services'
systemctl stop iotedge.socket iotedge.mgmt.socket || true
systemctl kill iotedge || true
systemctl stop iotedge || true
}