Merge ~sylvain-pineau/checkbox-provider-edgex:hanoi-add-config-test into ~checkbox-dev/checkbox-provider-edgex:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 370a803f4b5d357b0451800d109b8dadf58d3b74
Merged at revision: 525824a987b9be469123fe520cfacad18298aef0
Proposed branch: ~sylvain-pineau/checkbox-provider-edgex:hanoi-add-config-test
Merge into: ~checkbox-dev/checkbox-provider-edgex:master
Diff against target: 420 lines (+372/-0)
8 files modified
data/hanoi/test-config-hook.sh (+253/-0)
data/hanoi/test-files/core-command.env (+16/-0)
data/hanoi/test-files/core-data.env (+17/-0)
data/hanoi/test-files/core-metadata.env (+16/-0)
data/hanoi/test-files/device-virtual.env (+16/-0)
data/hanoi/test-files/support-notifications.env (+22/-0)
data/hanoi/test-files/support-scheduler.env (+16/-0)
data/hanoi/test-files/sys-mgmt-agent.env (+16/-0)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+402348@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Based on Siggi's review

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/data/hanoi/test-config-hook.sh b/data/hanoi/test-config-hook.sh
0new file mode 1007550new file mode 100755
index 0000000..38807eb
--- /dev/null
+++ b/data/hanoi/test-config-hook.sh
@@ -0,0 +1,253 @@
1#!/bin/bash -e
2#
3# This test validates the snap configure hook settings that are supported by
4# the edgexfoundry snap.
5#
6# TODO:
7#
8# - add negative test (i.e. bad key(s)) -- should be ignored
9# - add support for service restart
10# - ensure service has restarted!
11# - when services are restarted, overrides all work!
12# - add support for redis options
13
14# get the directory of this script
15# snippet from https://stackoverflow.com/a/246128/10102404
16SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
17
18declare services
19services[0]=core-data
20services[1]=core-metadata
21services[2]=core-command
22services[3]=support-notifications
23services[4]=support-scheduler
24services[5]=device-virtual
25services[6]=sys-mgmt-agent
26
27# define config to EdgeX environment variable mappings
28#
29# TODO: add scoping support (i.e. add a csv prefix to the keys
30# which scopes the setting to one or more services. No prefix
31# means "applies to all".
32#
33declare -A conf_to_env
34conf_to_env[service_boot-timeout]="SERVICE_BOOTTIMEOUT/60000"
35conf_to_env[service_check-interval]="SERVICE_CHECKINTERVAL/'20s'"
36conf_to_env[service_host]="SERVICE_HOST/127.0.0.1"
37conf_to_env[service_server-bind-addr]="SERVICE_SERVERBINDADDR/'localhost'"
38conf_to_env[service_port]="SERVICE_PORT/2112"
39conf_to_env[service_protocol]="SERVICE_PROTOCOL/'http'"
40conf_to_env[service_max-result-count]="SERVICE_MAXRESULTCOUNT/25000"
41conf_to_env[service_read-max-limit]="SERVICE_READMAXLIMIT/200"
42conf_to_env[service_startup-msg]="SERVICE_STARTUPMSG/'hello,world!'"
43conf_to_env[service_timeout]="SERVICE_TIMEOUT/10000"
44
45# [Clients.Command]
46conf_to_env[clients_command_port]="CLIENTS_COMMAND_PORT/12"
47
48# [Clients.Coredata]
49conf_to_env[clients_coredata_port]="CLIENTS_COREDATA_PORT/12"
50
51# [Clients.Data]
52#
53# NOTE - this key is present because device-sdk-go used a different
54# key for CoreData than the core services, which use the previous key.
55#
56conf_to_env[clients_data_port]="CLIENTS_DATA_PORT/12"
57
58# [Clients.Metadata]
59conf_to_env[clients_metadata_port]="CLIENTS_METADATA_PORT/13"
60
61# [Clients.Notifications]
62conf_to_env[clients_notifications_port]="CLIENTS_NOTIFICATIONS_PORT/14"
63
64# [Clients.Scheduler] - sys-mgmt-only
65conf_to_env[clients_scheduler_port]="CLIENTS_SCHEDULER_PORT/14"
66
67# [MessageQueue] -- core-data ONLY!
68conf_to_env[messagequeue_topic]="MESSAGEQUEUE_TOPIC/'fubar'"
69
70# [SecretStore] -- !app-service-configurable
71conf_to_env[secretstore_additional-retry-attempts]="SECRETSTORE_ADDITIONALRETRYATTEMPTS/20"
72conf_to_env[secretstore_retry-wait-period]="SECRETSTORE_RETRYWAITPERIOD/'10s'"
73
74# load the utils
75# shellcheck source=/dev/null
76source "$SCRIPT_DIR/utils.sh"
77
78DEFAULT_TEST_CHANNEL=${DEFAULT_TEST_CHANNEL:-beta}
79
80snap_remove
81
82# install the snap to make sure it installs
83if [ -n "$REVISION_TO_TEST" ]; then
84 snap_install "$REVISION_TO_TEST" "$REVISION_TO_TEST_CHANNEL" "$REVISION_TO_TEST_CONFINEMENT"
85else
86 snap_install edgexfoundry "$DEFAULT_TEST_CHANNEL"
87fi
88
89# wait for services to come online
90# NOTE: this may have to be significantly increased on arm64 or low RAM platforms
91# to accomodate time for everything to come online
92sleep 120
93
94test_smtp() {
95 # [Smtp] support-notifications options
96 declare -A smtp_to_env
97 smtp_to_env[smtp_host]="SMTP_HOST/127.0.0.1"
98 smtp_to_env[smtp_username]="SMTP_USERNAME/'joe'"
99 smtp_to_env[smtp_password]="SMTP_PASSWORD/'password!'"
100 smtp_to_env[smtp_port]="SMTP_PORT/2112"
101 smtp_to_env[smtp_sender]="SMTP_SENDER/'henry'"
102 smtp_to_env[smtp_enable-self-signed-cert]="SMTP_ENABLE_SELF_SIGNED_CERT/true"
103
104 for key in "${!smtp_to_env[@]}"; do
105 echo "$key" --- ${smtp_to_env[$key]};
106
107 option=${key/_/.}
108 echo "$option"
109 env=$(echo ${smtp_to_env[$key]} | cut -d / -f 1)
110 val=$(echo ${smtp_to_env[$key]} | cut -d / -f 2)
111 service_key="env.support-notifications.$option"
112 snap set edgexfoundry "$service_key=$val"
113 done
114}
115
116# test config hook service-specific config options
117#
118# Note, this test iterates through all of the possible configuration options.
119# It currently only validates that the service.env for each service is created.
120#
121test_options()
122{
123 service="$1"
124 for key in "${!conf_to_env[@]}"; do
125 echo "$key" --- ${conf_to_env[$key]};
126
127 if [ "$key" == "service_read-max-limit" ] &&
128 [ "$service" != "app-service-configurable" ]; then
129 continue
130 fi
131
132 if [ "$key" == "messagequeue_topic" ] &&
133 [ "$service" != "core-data" ]; then
134 continue
135 fi
136
137 # handle mismatched client keys due device-sdk-go bug
138 if [ "$key" == "clients_coredata_port" ] &&
139 [ "$service" == "device-virtual" ]; then
140 continue
141 fi
142
143 if [ "$key" == "clients_data_port" ] &&
144 [ "$service" != "device-virtual" ]; then
145 continue
146 fi
147
148 option=${key//_/.}
149 echo "$option"
150 env=$(echo ${conf_to_env[$key]} | cut -d / -f 1)
151 val=$(echo ${conf_to_env[$key]} | cut -d / -f 2)
152 service_key="env.$service.$option"
153 snap set edgexfoundry "$service_key=$val"
154 echo "$env=$val"
155 done
156
157 if [ "$service" == "support-notifications" ]; then
158 test_smtp
159 fi
160}
161
162validate_service_env()
163{
164 service="$1"
165 snapFile=$(cat "/var/snap/edgexfoundry/current/config/$service/res/$service.env" | sort)
166 testFile=$(cat "./test-files/$service.env" | sort)
167
168 if [ "$snapFile" != "$testFile" ]; then
169 snap_remove
170 echo "$service.env file doesn't match test file."
171 exit 1
172 fi
173}
174
175test_base_services()
176{
177 for key in "${!services[@]}"; do
178 service=${services[key]}
179 echo "*****${service}*******"
180 test_options "$service"
181 validate_service_env "$service"
182 done
183}
184
185# test-proxy
186#
187# ADD_PROXY_ROUTE is a csv list of URLs to be added to the
188# API Gateway (aka Kong). For references:
189#
190# https://docs.edgexfoundry.org/1.3/microservices/security/Ch-APIGateway/
191#
192# NOTE - this setting is not a configuration override, it's a top-level
193# environment variable used by the security-proxy-setup.
194#
195# KONGAUTH_NAME can be "jwt" (default) or "oauth2"
196test_proxy()
197{
198 snap set edgexfoundry "env.security-proxy.add-proxy-route=myservice.http://localhost:2112"
199 set +e
200 match=$(grep "export ADD_PROXY_ROUTE=myservice.http://localhost:2112" \
201 /var/snap/edgexfoundry/current/config/security-proxy-setup/res/security-proxy-setup.env)
202 set -e
203
204 if [ -z "$match" ]; then
205 snap_remove
206 echo "security-proxy-setup.env file missing correct ADD_PROXY_ROUTE env export."
207 exit 1
208 fi
209
210 snap set edgexfoundry "env.security-proxy.kongauth.name=oauth2"
211 set +e
212 match=$(grep "export KONGAUTH_NAME=oauth2" \
213 /var/snap/edgexfoundry/current/config/security-proxy-setup/res/security-proxy-setup.env)
214 set -e
215
216 if [ -z "$match" ]; then
217 snap_remove
218 echo "security-proxy-setup.env file missing correct KONGAUTH_NAME env export."
219 exit 1
220 fi
221}
222
223# security-secret-store
224#
225# ADD_SECRETSTORE_TOKENS is a csv list of service keys to be added to the
226# list of Vault tokens that security-file-token-provider (launched by
227# security-secretstore-setup) creates.
228#
229# NOTE - this setting is not a configuration override, it's a top-level
230# environment variable used by the security-secretstore-setup.
231#
232test_secret-store()
233{
234 snap set edgexfoundry "env.security-secret-store.add-secretstore-tokens=myservice,yourservice"
235
236 set +e
237 match=$(grep "export ADD_SECRETSTORE_TOKENS=myservice,yourservice" \
238 /var/snap/edgexfoundry/current/config/security-secretstore-setup/res/security-secretstore-setup.env)
239 set -e
240
241 if [ -z "$match" ]; then
242 snap_remove
243 echo "security-secretstore-setup.env file missing correct env export."
244 exit 1
245 fi
246}
247
248test_base_services
249test_proxy
250test_secret-store
251
252# remove the snap to run the next test
253snap_remove
diff --git a/data/hanoi/test-files/core-command.env b/data/hanoi/test-files/core-command.env
0new file mode 100644254new file mode 100644
index 0000000..48e95cc
--- /dev/null
+++ b/data/hanoi/test-files/core-command.env
@@ -0,0 +1,16 @@
1export CLIENTS_METADATA_PORT=13
2export CLIENTS_COMMAND_PORT=12
3export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
4export SERVICE_BOOTTIMEOUT=60000
5export SERVICE_PORT=2112
6export SERVICE_SERVERBINDADDR='localhost'
7export CLIENTS_SCHEDULER_PORT=14
8export CLIENTS_COREDATA_PORT=12
9export SERVICE_CHECKINTERVAL='20s'
10export SERVICE_TIMEOUT=10000
11export SERVICE_MAXRESULTCOUNT=25000
12export SERVICE_STARTUPMSG='hello,world!'
13export CLIENTS_NOTIFICATIONS_PORT=14
14export SECRETSTORE_RETRYWAITPERIOD='10s'
15export SERVICE_HOST=127.0.0.1
16export SERVICE_PROTOCOL='http'
diff --git a/data/hanoi/test-files/core-data.env b/data/hanoi/test-files/core-data.env
0new file mode 10064417new file mode 100644
index 0000000..7f2e3f3
--- /dev/null
+++ b/data/hanoi/test-files/core-data.env
@@ -0,0 +1,17 @@
1export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
2export SECRETSTORE_RETRYWAITPERIOD='10s'
3export SERVICE_STARTUPMSG='hello,world!'
4export SERVICE_CHECKINTERVAL='20s'
5export CLIENTS_SCHEDULER_PORT=14
6export SERVICE_BOOTTIMEOUT=60000
7export SERVICE_MAXRESULTCOUNT=25000
8export SERVICE_PROTOCOL='http'
9export CLIENTS_COREDATA_PORT=12
10export SERVICE_HOST=127.0.0.1
11export SERVICE_PORT=2112
12export CLIENTS_COMMAND_PORT=12
13export CLIENTS_METADATA_PORT=13
14export MESSAGEQUEUE_TOPIC='fubar'
15export SERVICE_SERVERBINDADDR='localhost'
16export SERVICE_TIMEOUT=10000
17export CLIENTS_NOTIFICATIONS_PORT=14
diff --git a/data/hanoi/test-files/core-metadata.env b/data/hanoi/test-files/core-metadata.env
0new file mode 10064418new file mode 100644
index 0000000..1aa2ef6
--- /dev/null
+++ b/data/hanoi/test-files/core-metadata.env
@@ -0,0 +1,16 @@
1export CLIENTS_COREDATA_PORT=12
2export CLIENTS_SCHEDULER_PORT=14
3export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
4export SERVICE_HOST=127.0.0.1
5export SERVICE_CHECKINTERVAL='20s'
6export CLIENTS_METADATA_PORT=13
7export CLIENTS_NOTIFICATIONS_PORT=14
8export SERVICE_BOOTTIMEOUT=60000
9export SERVICE_TIMEOUT=10000
10export CLIENTS_COMMAND_PORT=12
11export SECRETSTORE_RETRYWAITPERIOD='10s'
12export SERVICE_PORT=2112
13export SERVICE_PROTOCOL='http'
14export SERVICE_MAXRESULTCOUNT=25000
15export SERVICE_SERVERBINDADDR='localhost'
16export SERVICE_STARTUPMSG='hello,world!'
diff --git a/data/hanoi/test-files/device-virtual.env b/data/hanoi/test-files/device-virtual.env
0new file mode 10064417new file mode 100644
index 0000000..e028b84
--- /dev/null
+++ b/data/hanoi/test-files/device-virtual.env
@@ -0,0 +1,16 @@
1export CLIENTS_SCHEDULER_PORT=14
2export SERVICE_PROTOCOL='http'
3export SERVICE_BOOTTIMEOUT=60000
4export SERVICE_MAXRESULTCOUNT=25000
5export CLIENTS_METADATA_PORT=13
6export SERVICE_STARTUPMSG='hello,world!'
7export SERVICE_TIMEOUT=10000
8export SERVICE_PORT=2112
9export CLIENTS_COMMAND_PORT=12
10export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
11export SECRETSTORE_RETRYWAITPERIOD='10s'
12export SERVICE_CHECKINTERVAL='20s'
13export SERVICE_SERVERBINDADDR='localhost'
14export SERVICE_HOST=127.0.0.1
15export CLIENTS_DATA_PORT=12
16export CLIENTS_NOTIFICATIONS_PORT=14
diff --git a/data/hanoi/test-files/support-notifications.env b/data/hanoi/test-files/support-notifications.env
0new file mode 10064417new file mode 100644
index 0000000..77faad9
--- /dev/null
+++ b/data/hanoi/test-files/support-notifications.env
@@ -0,0 +1,22 @@
1export SERVICE_STARTUPMSG='hello,world!'
2export SERVICE_TIMEOUT=10000
3export SERVICE_CHECKINTERVAL='20s'
4export SERVICE_HOST=127.0.0.1
5export SMTP_ENABLE_SELF_SIGNED_CERT=true
6export CLIENTS_COMMAND_PORT=12
7export CLIENTS_COREDATA_PORT=12
8export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
9export CLIENTS_METADATA_PORT=13
10export SMTP_PORT=2112
11export CLIENTS_SCHEDULER_PORT=14
12export SERVICE_BOOTTIMEOUT=60000
13export SERVICE_PROTOCOL='http'
14export SMTP_PASSWORD='password!'
15export CLIENTS_NOTIFICATIONS_PORT=14
16export SERVICE_MAXRESULTCOUNT=25000
17export SERVICE_SERVERBINDADDR='localhost'
18export SERVICE_PORT=2112
19export SMTP_SENDER='henry'
20export SMTP_USERNAME='joe'
21export SMTP_HOST=127.0.0.1
22export SECRETSTORE_RETRYWAITPERIOD='10s'
diff --git a/data/hanoi/test-files/support-scheduler.env b/data/hanoi/test-files/support-scheduler.env
0new file mode 10064423new file mode 100644
index 0000000..de028d9
--- /dev/null
+++ b/data/hanoi/test-files/support-scheduler.env
@@ -0,0 +1,16 @@
1export SERVICE_BOOTTIMEOUT=60000
2export SERVICE_CHECKINTERVAL='20s'
3export SERVICE_STARTUPMSG='hello,world!'
4export CLIENTS_SCHEDULER_PORT=14
5export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
6export SERVICE_PROTOCOL='http'
7export SERVICE_SERVERBINDADDR='localhost'
8export CLIENTS_METADATA_PORT=13
9export CLIENTS_NOTIFICATIONS_PORT=14
10export CLIENTS_COREDATA_PORT=12
11export SECRETSTORE_RETRYWAITPERIOD='10s'
12export SERVICE_HOST=127.0.0.1
13export SERVICE_TIMEOUT=10000
14export SERVICE_PORT=2112
15export CLIENTS_COMMAND_PORT=12
16export SERVICE_MAXRESULTCOUNT=25000
diff --git a/data/hanoi/test-files/sys-mgmt-agent.env b/data/hanoi/test-files/sys-mgmt-agent.env
0new file mode 10064417new file mode 100644
index 0000000..956d8f7
--- /dev/null
+++ b/data/hanoi/test-files/sys-mgmt-agent.env
@@ -0,0 +1,16 @@
1export SERVICE_PORT=2112
2export SERVICE_SERVERBINDADDR='localhost'
3export SERVICE_CHECKINTERVAL='20s'
4export CLIENTS_COREDATA_PORT=12
5export CLIENTS_METADATA_PORT=13
6export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
7export SERVICE_PROTOCOL='http'
8export SERVICE_STARTUPMSG='hello,world!'
9export SERVICE_MAXRESULTCOUNT=25000
10export CLIENTS_NOTIFICATIONS_PORT=14
11export CLIENTS_SCHEDULER_PORT=14
12export SECRETSTORE_RETRYWAITPERIOD='10s'
13export SERVICE_HOST=127.0.0.1
14export CLIENTS_COMMAND_PORT=12
15export SERVICE_TIMEOUT=10000
16export SERVICE_BOOTTIMEOUT=60000

Subscribers

People subscribed via source and target branches