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
1diff --git a/data/hanoi/test-config-hook.sh b/data/hanoi/test-config-hook.sh
2new file mode 100755
3index 0000000..38807eb
4--- /dev/null
5+++ b/data/hanoi/test-config-hook.sh
6@@ -0,0 +1,253 @@
7+#!/bin/bash -e
8+#
9+# This test validates the snap configure hook settings that are supported by
10+# the edgexfoundry snap.
11+#
12+# TODO:
13+#
14+# - add negative test (i.e. bad key(s)) -- should be ignored
15+# - add support for service restart
16+# - ensure service has restarted!
17+# - when services are restarted, overrides all work!
18+# - add support for redis options
19+
20+# get the directory of this script
21+# snippet from https://stackoverflow.com/a/246128/10102404
22+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
23+
24+declare services
25+services[0]=core-data
26+services[1]=core-metadata
27+services[2]=core-command
28+services[3]=support-notifications
29+services[4]=support-scheduler
30+services[5]=device-virtual
31+services[6]=sys-mgmt-agent
32+
33+# define config to EdgeX environment variable mappings
34+#
35+# TODO: add scoping support (i.e. add a csv prefix to the keys
36+# which scopes the setting to one or more services. No prefix
37+# means "applies to all".
38+#
39+declare -A conf_to_env
40+conf_to_env[service_boot-timeout]="SERVICE_BOOTTIMEOUT/60000"
41+conf_to_env[service_check-interval]="SERVICE_CHECKINTERVAL/'20s'"
42+conf_to_env[service_host]="SERVICE_HOST/127.0.0.1"
43+conf_to_env[service_server-bind-addr]="SERVICE_SERVERBINDADDR/'localhost'"
44+conf_to_env[service_port]="SERVICE_PORT/2112"
45+conf_to_env[service_protocol]="SERVICE_PROTOCOL/'http'"
46+conf_to_env[service_max-result-count]="SERVICE_MAXRESULTCOUNT/25000"
47+conf_to_env[service_read-max-limit]="SERVICE_READMAXLIMIT/200"
48+conf_to_env[service_startup-msg]="SERVICE_STARTUPMSG/'hello,world!'"
49+conf_to_env[service_timeout]="SERVICE_TIMEOUT/10000"
50+
51+# [Clients.Command]
52+conf_to_env[clients_command_port]="CLIENTS_COMMAND_PORT/12"
53+
54+# [Clients.Coredata]
55+conf_to_env[clients_coredata_port]="CLIENTS_COREDATA_PORT/12"
56+
57+# [Clients.Data]
58+#
59+# NOTE - this key is present because device-sdk-go used a different
60+# key for CoreData than the core services, which use the previous key.
61+#
62+conf_to_env[clients_data_port]="CLIENTS_DATA_PORT/12"
63+
64+# [Clients.Metadata]
65+conf_to_env[clients_metadata_port]="CLIENTS_METADATA_PORT/13"
66+
67+# [Clients.Notifications]
68+conf_to_env[clients_notifications_port]="CLIENTS_NOTIFICATIONS_PORT/14"
69+
70+# [Clients.Scheduler] - sys-mgmt-only
71+conf_to_env[clients_scheduler_port]="CLIENTS_SCHEDULER_PORT/14"
72+
73+# [MessageQueue] -- core-data ONLY!
74+conf_to_env[messagequeue_topic]="MESSAGEQUEUE_TOPIC/'fubar'"
75+
76+# [SecretStore] -- !app-service-configurable
77+conf_to_env[secretstore_additional-retry-attempts]="SECRETSTORE_ADDITIONALRETRYATTEMPTS/20"
78+conf_to_env[secretstore_retry-wait-period]="SECRETSTORE_RETRYWAITPERIOD/'10s'"
79+
80+# load the utils
81+# shellcheck source=/dev/null
82+source "$SCRIPT_DIR/utils.sh"
83+
84+DEFAULT_TEST_CHANNEL=${DEFAULT_TEST_CHANNEL:-beta}
85+
86+snap_remove
87+
88+# install the snap to make sure it installs
89+if [ -n "$REVISION_TO_TEST" ]; then
90+ snap_install "$REVISION_TO_TEST" "$REVISION_TO_TEST_CHANNEL" "$REVISION_TO_TEST_CONFINEMENT"
91+else
92+ snap_install edgexfoundry "$DEFAULT_TEST_CHANNEL"
93+fi
94+
95+# wait for services to come online
96+# NOTE: this may have to be significantly increased on arm64 or low RAM platforms
97+# to accomodate time for everything to come online
98+sleep 120
99+
100+test_smtp() {
101+ # [Smtp] support-notifications options
102+ declare -A smtp_to_env
103+ smtp_to_env[smtp_host]="SMTP_HOST/127.0.0.1"
104+ smtp_to_env[smtp_username]="SMTP_USERNAME/'joe'"
105+ smtp_to_env[smtp_password]="SMTP_PASSWORD/'password!'"
106+ smtp_to_env[smtp_port]="SMTP_PORT/2112"
107+ smtp_to_env[smtp_sender]="SMTP_SENDER/'henry'"
108+ smtp_to_env[smtp_enable-self-signed-cert]="SMTP_ENABLE_SELF_SIGNED_CERT/true"
109+
110+ for key in "${!smtp_to_env[@]}"; do
111+ echo "$key" --- ${smtp_to_env[$key]};
112+
113+ option=${key/_/.}
114+ echo "$option"
115+ env=$(echo ${smtp_to_env[$key]} | cut -d / -f 1)
116+ val=$(echo ${smtp_to_env[$key]} | cut -d / -f 2)
117+ service_key="env.support-notifications.$option"
118+ snap set edgexfoundry "$service_key=$val"
119+ done
120+}
121+
122+# test config hook service-specific config options
123+#
124+# Note, this test iterates through all of the possible configuration options.
125+# It currently only validates that the service.env for each service is created.
126+#
127+test_options()
128+{
129+ service="$1"
130+ for key in "${!conf_to_env[@]}"; do
131+ echo "$key" --- ${conf_to_env[$key]};
132+
133+ if [ "$key" == "service_read-max-limit" ] &&
134+ [ "$service" != "app-service-configurable" ]; then
135+ continue
136+ fi
137+
138+ if [ "$key" == "messagequeue_topic" ] &&
139+ [ "$service" != "core-data" ]; then
140+ continue
141+ fi
142+
143+ # handle mismatched client keys due device-sdk-go bug
144+ if [ "$key" == "clients_coredata_port" ] &&
145+ [ "$service" == "device-virtual" ]; then
146+ continue
147+ fi
148+
149+ if [ "$key" == "clients_data_port" ] &&
150+ [ "$service" != "device-virtual" ]; then
151+ continue
152+ fi
153+
154+ option=${key//_/.}
155+ echo "$option"
156+ env=$(echo ${conf_to_env[$key]} | cut -d / -f 1)
157+ val=$(echo ${conf_to_env[$key]} | cut -d / -f 2)
158+ service_key="env.$service.$option"
159+ snap set edgexfoundry "$service_key=$val"
160+ echo "$env=$val"
161+ done
162+
163+ if [ "$service" == "support-notifications" ]; then
164+ test_smtp
165+ fi
166+}
167+
168+validate_service_env()
169+{
170+ service="$1"
171+ snapFile=$(cat "/var/snap/edgexfoundry/current/config/$service/res/$service.env" | sort)
172+ testFile=$(cat "./test-files/$service.env" | sort)
173+
174+ if [ "$snapFile" != "$testFile" ]; then
175+ snap_remove
176+ echo "$service.env file doesn't match test file."
177+ exit 1
178+ fi
179+}
180+
181+test_base_services()
182+{
183+ for key in "${!services[@]}"; do
184+ service=${services[key]}
185+ echo "*****${service}*******"
186+ test_options "$service"
187+ validate_service_env "$service"
188+ done
189+}
190+
191+# test-proxy
192+#
193+# ADD_PROXY_ROUTE is a csv list of URLs to be added to the
194+# API Gateway (aka Kong). For references:
195+#
196+# https://docs.edgexfoundry.org/1.3/microservices/security/Ch-APIGateway/
197+#
198+# NOTE - this setting is not a configuration override, it's a top-level
199+# environment variable used by the security-proxy-setup.
200+#
201+# KONGAUTH_NAME can be "jwt" (default) or "oauth2"
202+test_proxy()
203+{
204+ snap set edgexfoundry "env.security-proxy.add-proxy-route=myservice.http://localhost:2112"
205+ set +e
206+ match=$(grep "export ADD_PROXY_ROUTE=myservice.http://localhost:2112" \
207+ /var/snap/edgexfoundry/current/config/security-proxy-setup/res/security-proxy-setup.env)
208+ set -e
209+
210+ if [ -z "$match" ]; then
211+ snap_remove
212+ echo "security-proxy-setup.env file missing correct ADD_PROXY_ROUTE env export."
213+ exit 1
214+ fi
215+
216+ snap set edgexfoundry "env.security-proxy.kongauth.name=oauth2"
217+ set +e
218+ match=$(grep "export KONGAUTH_NAME=oauth2" \
219+ /var/snap/edgexfoundry/current/config/security-proxy-setup/res/security-proxy-setup.env)
220+ set -e
221+
222+ if [ -z "$match" ]; then
223+ snap_remove
224+ echo "security-proxy-setup.env file missing correct KONGAUTH_NAME env export."
225+ exit 1
226+ fi
227+}
228+
229+# security-secret-store
230+#
231+# ADD_SECRETSTORE_TOKENS is a csv list of service keys to be added to the
232+# list of Vault tokens that security-file-token-provider (launched by
233+# security-secretstore-setup) creates.
234+#
235+# NOTE - this setting is not a configuration override, it's a top-level
236+# environment variable used by the security-secretstore-setup.
237+#
238+test_secret-store()
239+{
240+ snap set edgexfoundry "env.security-secret-store.add-secretstore-tokens=myservice,yourservice"
241+
242+ set +e
243+ match=$(grep "export ADD_SECRETSTORE_TOKENS=myservice,yourservice" \
244+ /var/snap/edgexfoundry/current/config/security-secretstore-setup/res/security-secretstore-setup.env)
245+ set -e
246+
247+ if [ -z "$match" ]; then
248+ snap_remove
249+ echo "security-secretstore-setup.env file missing correct env export."
250+ exit 1
251+ fi
252+}
253+
254+test_base_services
255+test_proxy
256+test_secret-store
257+
258+# remove the snap to run the next test
259+snap_remove
260diff --git a/data/hanoi/test-files/core-command.env b/data/hanoi/test-files/core-command.env
261new file mode 100644
262index 0000000..48e95cc
263--- /dev/null
264+++ b/data/hanoi/test-files/core-command.env
265@@ -0,0 +1,16 @@
266+export CLIENTS_METADATA_PORT=13
267+export CLIENTS_COMMAND_PORT=12
268+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
269+export SERVICE_BOOTTIMEOUT=60000
270+export SERVICE_PORT=2112
271+export SERVICE_SERVERBINDADDR='localhost'
272+export CLIENTS_SCHEDULER_PORT=14
273+export CLIENTS_COREDATA_PORT=12
274+export SERVICE_CHECKINTERVAL='20s'
275+export SERVICE_TIMEOUT=10000
276+export SERVICE_MAXRESULTCOUNT=25000
277+export SERVICE_STARTUPMSG='hello,world!'
278+export CLIENTS_NOTIFICATIONS_PORT=14
279+export SECRETSTORE_RETRYWAITPERIOD='10s'
280+export SERVICE_HOST=127.0.0.1
281+export SERVICE_PROTOCOL='http'
282diff --git a/data/hanoi/test-files/core-data.env b/data/hanoi/test-files/core-data.env
283new file mode 100644
284index 0000000..7f2e3f3
285--- /dev/null
286+++ b/data/hanoi/test-files/core-data.env
287@@ -0,0 +1,17 @@
288+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
289+export SECRETSTORE_RETRYWAITPERIOD='10s'
290+export SERVICE_STARTUPMSG='hello,world!'
291+export SERVICE_CHECKINTERVAL='20s'
292+export CLIENTS_SCHEDULER_PORT=14
293+export SERVICE_BOOTTIMEOUT=60000
294+export SERVICE_MAXRESULTCOUNT=25000
295+export SERVICE_PROTOCOL='http'
296+export CLIENTS_COREDATA_PORT=12
297+export SERVICE_HOST=127.0.0.1
298+export SERVICE_PORT=2112
299+export CLIENTS_COMMAND_PORT=12
300+export CLIENTS_METADATA_PORT=13
301+export MESSAGEQUEUE_TOPIC='fubar'
302+export SERVICE_SERVERBINDADDR='localhost'
303+export SERVICE_TIMEOUT=10000
304+export CLIENTS_NOTIFICATIONS_PORT=14
305diff --git a/data/hanoi/test-files/core-metadata.env b/data/hanoi/test-files/core-metadata.env
306new file mode 100644
307index 0000000..1aa2ef6
308--- /dev/null
309+++ b/data/hanoi/test-files/core-metadata.env
310@@ -0,0 +1,16 @@
311+export CLIENTS_COREDATA_PORT=12
312+export CLIENTS_SCHEDULER_PORT=14
313+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
314+export SERVICE_HOST=127.0.0.1
315+export SERVICE_CHECKINTERVAL='20s'
316+export CLIENTS_METADATA_PORT=13
317+export CLIENTS_NOTIFICATIONS_PORT=14
318+export SERVICE_BOOTTIMEOUT=60000
319+export SERVICE_TIMEOUT=10000
320+export CLIENTS_COMMAND_PORT=12
321+export SECRETSTORE_RETRYWAITPERIOD='10s'
322+export SERVICE_PORT=2112
323+export SERVICE_PROTOCOL='http'
324+export SERVICE_MAXRESULTCOUNT=25000
325+export SERVICE_SERVERBINDADDR='localhost'
326+export SERVICE_STARTUPMSG='hello,world!'
327diff --git a/data/hanoi/test-files/device-virtual.env b/data/hanoi/test-files/device-virtual.env
328new file mode 100644
329index 0000000..e028b84
330--- /dev/null
331+++ b/data/hanoi/test-files/device-virtual.env
332@@ -0,0 +1,16 @@
333+export CLIENTS_SCHEDULER_PORT=14
334+export SERVICE_PROTOCOL='http'
335+export SERVICE_BOOTTIMEOUT=60000
336+export SERVICE_MAXRESULTCOUNT=25000
337+export CLIENTS_METADATA_PORT=13
338+export SERVICE_STARTUPMSG='hello,world!'
339+export SERVICE_TIMEOUT=10000
340+export SERVICE_PORT=2112
341+export CLIENTS_COMMAND_PORT=12
342+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
343+export SECRETSTORE_RETRYWAITPERIOD='10s'
344+export SERVICE_CHECKINTERVAL='20s'
345+export SERVICE_SERVERBINDADDR='localhost'
346+export SERVICE_HOST=127.0.0.1
347+export CLIENTS_DATA_PORT=12
348+export CLIENTS_NOTIFICATIONS_PORT=14
349diff --git a/data/hanoi/test-files/support-notifications.env b/data/hanoi/test-files/support-notifications.env
350new file mode 100644
351index 0000000..77faad9
352--- /dev/null
353+++ b/data/hanoi/test-files/support-notifications.env
354@@ -0,0 +1,22 @@
355+export SERVICE_STARTUPMSG='hello,world!'
356+export SERVICE_TIMEOUT=10000
357+export SERVICE_CHECKINTERVAL='20s'
358+export SERVICE_HOST=127.0.0.1
359+export SMTP_ENABLE_SELF_SIGNED_CERT=true
360+export CLIENTS_COMMAND_PORT=12
361+export CLIENTS_COREDATA_PORT=12
362+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
363+export CLIENTS_METADATA_PORT=13
364+export SMTP_PORT=2112
365+export CLIENTS_SCHEDULER_PORT=14
366+export SERVICE_BOOTTIMEOUT=60000
367+export SERVICE_PROTOCOL='http'
368+export SMTP_PASSWORD='password!'
369+export CLIENTS_NOTIFICATIONS_PORT=14
370+export SERVICE_MAXRESULTCOUNT=25000
371+export SERVICE_SERVERBINDADDR='localhost'
372+export SERVICE_PORT=2112
373+export SMTP_SENDER='henry'
374+export SMTP_USERNAME='joe'
375+export SMTP_HOST=127.0.0.1
376+export SECRETSTORE_RETRYWAITPERIOD='10s'
377diff --git a/data/hanoi/test-files/support-scheduler.env b/data/hanoi/test-files/support-scheduler.env
378new file mode 100644
379index 0000000..de028d9
380--- /dev/null
381+++ b/data/hanoi/test-files/support-scheduler.env
382@@ -0,0 +1,16 @@
383+export SERVICE_BOOTTIMEOUT=60000
384+export SERVICE_CHECKINTERVAL='20s'
385+export SERVICE_STARTUPMSG='hello,world!'
386+export CLIENTS_SCHEDULER_PORT=14
387+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
388+export SERVICE_PROTOCOL='http'
389+export SERVICE_SERVERBINDADDR='localhost'
390+export CLIENTS_METADATA_PORT=13
391+export CLIENTS_NOTIFICATIONS_PORT=14
392+export CLIENTS_COREDATA_PORT=12
393+export SECRETSTORE_RETRYWAITPERIOD='10s'
394+export SERVICE_HOST=127.0.0.1
395+export SERVICE_TIMEOUT=10000
396+export SERVICE_PORT=2112
397+export CLIENTS_COMMAND_PORT=12
398+export SERVICE_MAXRESULTCOUNT=25000
399diff --git a/data/hanoi/test-files/sys-mgmt-agent.env b/data/hanoi/test-files/sys-mgmt-agent.env
400new file mode 100644
401index 0000000..956d8f7
402--- /dev/null
403+++ b/data/hanoi/test-files/sys-mgmt-agent.env
404@@ -0,0 +1,16 @@
405+export SERVICE_PORT=2112
406+export SERVICE_SERVERBINDADDR='localhost'
407+export SERVICE_CHECKINTERVAL='20s'
408+export CLIENTS_COREDATA_PORT=12
409+export CLIENTS_METADATA_PORT=13
410+export SECRETSTORE_ADDITIONALRETRYATTEMPTS=20
411+export SERVICE_PROTOCOL='http'
412+export SERVICE_STARTUPMSG='hello,world!'
413+export SERVICE_MAXRESULTCOUNT=25000
414+export CLIENTS_NOTIFICATIONS_PORT=14
415+export CLIENTS_SCHEDULER_PORT=14
416+export SECRETSTORE_RETRYWAITPERIOD='10s'
417+export SERVICE_HOST=127.0.0.1
418+export CLIENTS_COMMAND_PORT=12
419+export SERVICE_TIMEOUT=10000
420+export SERVICE_BOOTTIMEOUT=60000

Subscribers

People subscribed via source and target branches