keactrl_tests.sh.in 40.4 KB
Newer Older
1
2
#!/bin/sh

3
# Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
4
#
5
6
7
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
9
10
11
12
13
14

# Include common test library.
. @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh

# Set location of the keactrl.
keactrl=@abs_top_builddir@/src/bin/keactrl/keactrl

15
16
# Name of the configuration file without its extension.
CFG_FILE_NAME="test_config"
17
# A name of the configuration file to be used by Kea.
18
CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/${CFG_FILE_NAME}.json
19
20
21
22
23
# A name of the keactrl config file
KEACTRL_CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/keactrl_test.conf
# Path to the Kea log file.
LOG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/test.log
# Binaries' names
24
25
26
27
28
wildcard_name="kea-"
kea4_name="${wildcard_name}dhcp4"
kea6_name="${wildcard_name}dhcp6"
d2_name="${wildcard_name}dhcp-ddns"
agent_name="${wildcard_name}ctrl-agent"
29
30
31
32
# Kea configuration
config="{
    \"Dhcp4\":
    {
33
34
35
        \"interfaces-config\": {
            \"interfaces\": [ ]
        },
36
37
38
39
40
41
42
43
44
45
46
        \"valid-lifetime\": 4000,
        \"renew-timer\": 1000,
        \"rebind-timer\": 2000,
        \"lease-database\":
        {
            \"type\": \"memfile\",
            \"persist\": false
        },
        \"subnet4\": [
        {
            \"subnet\": \"10.0.0.0/24\",
47
            \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
48
49
50
51
        } ]
    },
    \"Dhcp6\":
    {
52
53
54
        \"interfaces-config\": {
            \"interfaces\": [ ]
        },
55
56
57
58
        \"server-id\": {
          \"type\": \"LLT\",
          \"persist\": false
        },
59
60
61
62
63
64
65
66
67
68
69
70
        \"preferred-lifetime\": 3000,
        \"valid-lifetime\": 4000,
        \"renew-timer\": 1000,
        \"rebind-timer\": 2000,
        \"lease-database\":
        {
            \"type\": \"memfile\",
            \"persist\": false
        },
        \"subnet6\": [
        {
            \"subnet\": \"2001:db8:1::/64\",
71
            \"pools\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
72
        } ]
73
74
75
    },
    \"DhcpDdns\":
    {
76
        \"ip-address\": \"127.0.0.1\",
77
        \"port\": 53001,
78
79
80
        \"tsig-keys\": [],
        \"forward-ddns\" : {},
        \"reverse-ddns\" : {}
Tomek Mrugalski's avatar
Tomek Mrugalski committed
81
    },
82
83
84
85
    \"Control-agent\": {
        \"http-host\": \"127.0.0.1\",
        \"http-port\": 18080
    },
Tomek Mrugalski's avatar
Tomek Mrugalski committed
86
87
88
89
    \"Logging\":
    {
        \"loggers\": [
        {
Tomek Mrugalski's avatar
Tomek Mrugalski committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
            \"name\": \"kea-dhcp4\",
            \"output_options\": [
                {
                    \"output\": \"$LOG_FILE\"
                }
            ],
            \"severity\": \"INFO\"
        },
        {
            \"name\": \"kea-dhcp6\",
            \"output_options\": [
                {
                    \"output\": \"$LOG_FILE\"
                }
            ],
            \"severity\": \"INFO\"
        },
        {
            \"name\": \"kea-dhcp-ddns\",
Tomek Mrugalski's avatar
Tomek Mrugalski committed
109
110
111
112
113
114
            \"output_options\": [
                {
                    \"output\": \"$LOG_FILE\"
                }
            ],
            \"severity\": \"INFO\"
115
116
117
118
119
120
121
122
123
        },
        {
            \"name\": \"kea-ctrl-agent\",
            \"output_options\": [
                {
                    \"output\": \"$LOG_FILE\"
                }
            ],
            \"severity\": \"INFO\"
Tomek Mrugalski's avatar
Tomek Mrugalski committed
124
125
        }
        ]
126
127
128
    }
}"

129
# Fixed part of the keactrl configuration file.
130
131
keactrl_fixed_config="dhcp4_srv=${KEACTRL_BUILD_DIR}/src/bin/dhcp4/kea-dhcp4\n\
dhcp6_srv=${KEACTRL_BUILD_DIR}/src/bin/dhcp6/kea-dhcp6\n\
132
133
dhcp_ddns_srv=${KEACTRL_BUILD_DIR}/src/bin/d2/kea-dhcp-ddns\n\
ctrl_agent_srv=${KEACTRL_BUILD_DIR}/src/bin/agent/kea-ctrl-agent\n"
134

135
# This test checks that DHCPv4, DHCPv6 and D2 server can be started and
136
# shut down.
137
start_all_servers_no_verbose_test() {
138
    # Create configuration file for keactrl. This configuration enables
139
    # DHCPv4, DHCPv6, D2 and CA.
140
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
141
dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
142

143
    test_start "keactrl.start_all_servers_no_verbose_test"
144
145
146
147
148
149
150
151
152

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start servers using keactrl script.
153
154
155
156
157
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE} -s all\n"
    # Append the -s option to specify all servers. This is not necessary
    # because all should be a default but let's see if it is accepted
    # by the command line parser.
    ${keactrl} start -c ${KEACTRL_CFG_FILE} -s all
158
    ret=${?}
159
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
160
161
162
163
164
165
166
167
168
169
170
171
172

    # Wait up to 20s for the DHCPv6 server to configure.
    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to start. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 20s for the DHCPv4 server to configure.
    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

173
174
175
176
177
178
179
    # Wait for D2 and CA to configure.
    wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for CPL daemons to start. \
Expected wait_for_message return %d, returned %d."

    wait_for_message 20 "DHCP_DDNS_STARTED" 1
180
181
182
183
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to start. \
Expected wait_for_message return %d, returned %d."

184
185
186
187
188
    wait_for_message 20 "CTRL_AGENT_HTTP_SERVICE_STARTED" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${agent_name} to start. \
Expected wait_for_message return %d, returned %d."

189
190
    # Make sure that debug messages are logged for neither
    # server (non-verbose mode).
191
192
193
194
195
196
197
198
    get_log_messages "DHCP6_START_INFO"
    assert_eq 0 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages return %d, returned %d."

    get_log_messages "DHCP4_START_INFO"
    assert_eq 0 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages return %d, returned %d."

199
    get_log_messages "DCTL_STANDALONE"
200
201
202
    assert_eq 0 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages return %d, returned %d."

Josh Soref's avatar
Josh Soref committed
203
    # Server may shut down immediately after configuration has completed.
204
205
206
    # Give it some time to shutdown.
    sleep 3

207
    # Make sure that all servers are running.
208
    get_pid ${kea4_name}
209
210
211
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

212
    get_pid ${kea6_name}
213
214
215
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

216
    get_pid ${d2_name}
217
218
219
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

220
221
222
223
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

224
    # Use keactrl stop to shutdown the servers.
225
226
    printf "Stopping Kea: ${keactrl} stop  -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -c ${KEACTRL_CFG_FILE}
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv6 server to stop.
    wait_for_message 10 "DHCP6_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 10s for the DHCPv4 server to stop.
    wait_for_message 10 "DHCP4_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

242
243
    # Wait up to 10s for the D2 and CA to stop.
    wait_for_message 10 "DCTL_SHUTDOWN" 2
244
245
246
247
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

248
249
250
251
    # Make sure that all servers are down.
    wait_for_server_down 5 ${wildcard_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
252

253
254
255
256
257
    test_finish 0
}

# This test checks that both DHCPv4 and DHCPv6 server can be started in
# a verbose mode.
258
start_all_servers_verbose_test() {
259
    # Create configuration file for keactrl. This configuration enables
260
261
    # all servers.
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
262
dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
263

264
    test_start "keactrl.start_all_servers_verbose_test"
265
266
267
268
269
270
271
272
273

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start servers using keactrl script.
274
275
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"

    # Wait up to 20s for the DHCPv6 server to configure.
    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to start. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 20s for the DHCPv4 server to configure.
    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

291
292
293
294
295
296
    wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for CPL daemons to start. \
Expected wait_for_message return %d, returned %d."

    wait_for_message 20 "DHCP_DDNS_STARTED" 1
297
298
299
300
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to start. \
Expected wait_for_message return %d, returned %d."

301
302
303
304
305
    wait_for_message 20 "CTRL_AGENT_HTTP_SERVICE_STARTED" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${agent_name} to start. \
Expected wait_for_message return %d, returned %d."

306
307
    # Check if the debug messages are present, which should only be
    # the case if the verbose mode is on.
308
309
310
311
312
313
314
315
    get_log_messages "DHCP6_START_INFO" 1
    assert_eq 1 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages for DHCP6_START_INFO return %d, returned %d."

    get_log_messages "DHCP4_START_INFO" 1
    assert_eq 1 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages for DHCP4_START_INFO return %d, returned %d."

316
317
    get_log_messages "DCTL_STANDALONE" 2
    assert_eq 2 ${_GET_LOG_MESSAGES} \
318
        "Expected get_log_messages for DCT_STANDALONE return %d, returned %d."
319

Josh Soref's avatar
Josh Soref committed
320
    # Server may shut down immediately after configuration has completed.
321
322
323
    # Give it some time to shutdown.
    sleep 3

324
    # Make sure that all servers are running.
325
    get_pid ${kea4_name}
326
327
328
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

329
    get_pid ${kea6_name}
330
331
332
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

333
    get_pid ${d2_name}
334
335
336
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

337
338
339
340
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

341
    # Use keactrl stop to shutdown the servers.
342
343
    printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -c ${KEACTRL_CFG_FILE}
344
345
346
347
348
349
350
351
352
353
354
355
356
357
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv6 server to stop.
    wait_for_message 10 "DHCP6_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 10s for the DHCPv4 server to stop.
    wait_for_message 10 "DHCP4_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to shutdown. \
Expected wait_for_message return %d, returned %d."
358

359
360
    # Wait up to 10s for the D2 and CA to stop.
    wait_for_message 10 "DCTL_SHUTDOWN" 2
361
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
362
        "Timeout waiting for ${d2_name} and ${agent_name} to shutdown. \
363
364
Expected wait_for_message return %d, returned %d."

365
366
367
368
    # Make sure that all servers are down.
    wait_for_server_down 5 ${wildcard_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
369

370
    test_finish 0
371
372
}

373

374
375
# This test checks that only DHCPv4 server can be started and that other
# servers are not started.
376
377
start_v4_server_test() {
    # Create configuration file for keactrl. This configuration enables
378
379
    # DHCPv4 server but disables other servers.
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=no\n\
380
dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
381

382
    test_start "keactrl.start_v4_server_test"
383
384
385
386
387
388
389
390
391

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start DHCPv4 server using keactrl script.
392
393
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
394
    ret=${?}
Josh Soref's avatar
Josh Soref committed
395
    assert_eq 0 ${ret} "Expected keactrl to return 0, returned value was ${ret}"
396
397
398
399
400
401
402

    # Wait up to 20s for the DHCPv4 server to configure.
    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

Josh Soref's avatar
Josh Soref committed
403
    # Server may shut down immediately after configuration has completed.
404
405
406
407
    # Give it some time to shutdown.
    sleep 3

    # Make sure that DHCPv4 server is running.
408
    get_pid ${kea4_name}
409
410
411
412
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

    # Make sure that DHCPv6 server is not running.
413
    get_pid ${kea6_name}
414
415
416
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

417
    # Make sure that D2 server is not running.
418
    get_pid ${d2_name}
419
420
421
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

422
423
424
425
426
    # Make sure that CA is not running.
    get_pid ${agent_name}
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

427
    # Make sure that the status command returns appropriate status.
428
429
430
    printf "Getting status of Kea modules: %s\n" "${keactrl} status \
-c ${KEACTRL_CFG_FILE}"
    output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
431
432
433
434
435
436
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned %d"
    assert_string_contains "DHCPv4 server: active" "${output}" \
        "Expected keactrl status command return %s"
    assert_string_contains "DHCPv6 server: inactive" "${output}" \
        "Expected keactrl status command return %s"
437
    assert_string_contains "DHCP DDNS: inactive" "${output}" \
438
        "Expected keactrl status command return %s"
439
440
    assert_string_contains "Control Agent: inactive" "${output}" \
        "Expected keactrl status command return %s"
441

442
    # Use keactrl stop to shutdown the servers.
443
444
    printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -c ${KEACTRL_CFG_FILE}
445
446
447
448
449
450
451
452
453
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv4 server to stop.
    wait_for_message 10 "DHCP4_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

454
455
456
457
    # Make sure that all servers are down.
    wait_for_server_down 5 ${wildcard_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
458

459
    test_finish 0
460
461
}

462
463
# This test checks that only DHCPv6 server can be started and that other
# servers are not started.
464
465
start_v6_server_test() {
    # Create configuration file for keactrl. This configuration enables
466
467
    # DHCPv6 server but disables other servers..
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=no\ndhcp6=yes\n\
468
dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
469

470
    test_start "keactrl.start_v6_server_test"
471
472
473
474
475
476
477
478
479

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start DHCPv6 server using keactrl script.
480
481
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
482
    ret=${?}
483
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
484
485
486
487
488
489
490

    # Wait up to 20s for the DHCPv6 server to configure.
    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to start. \
Expected wait_for_message return %d, returned %d."

Josh Soref's avatar
Josh Soref committed
491
    # Server may shut down immediately after configuration has completed.
492
493
494
495
    # Give it some time to shutdown.
    sleep 3

    # Make sure that DHCPv6 server is running.
496
    get_pid ${kea6_name}
497
498
499
500
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

    # Make sure that DHCPv4 server is not running.
501
    get_pid ${kea4_name}
502
503
504
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

505
    # Make sure that D2 server is not running.
506
    get_pid ${d2_name}
507
508
509
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

510
511
512
513
514
    # Make sure that CA is not running.
    get_pid ${agent_name}
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

515
    # Make sure that the status command returns appropriate status.
516
517
    printf "Getting status of Kea modules: %s\n" "${keactrl} status -c ${KEACTRL_CFG_FILE}"
    output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
518
519
520
521
522
523
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned %d"
    assert_string_contains "DHCPv4 server: inactive" "${output}" \
        "Expected keactrl status command return %s"
    assert_string_contains "DHCPv6 server: active" "${output}" \
        "Expected keactrl status command return %s"
524
    assert_string_contains "DHCP DDNS: inactive" "${output}" \
525
        "Expected keactrl status command return %s"
526
527
    assert_string_contains "Control Agent: inactive" "${output}" \
        "Expected keactrl status command return %s"
528

529
    # Use keactrl stop to shutdown the servers.
530
531
    printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -c ${KEACTRL_CFG_FILE}
532
533
534
535
536
537
538
539
540
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv6 server to stop.
    wait_for_message 10 "DHCP6_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

541
542
543
544
    # Make sure that all servers are down.
    wait_for_server_down 5 ${wildcard_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
545

546
    test_finish 0
547
548
}

549
550
# This test checks that the DHCPv4 server can be started first, and then the
# other servers can be started while DHCPv4 server is already running.
551
# Also check that both servers can be reconfigured.
552
553
late_start_v4_server_test() {
    # Create configuration file for keactrl. This configuration enables
554
555
    # DHCPv6 server but disables other servers.
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=no\ndhcp6=yes\n\
556
dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
557

558
    test_start "keactrl.late_start_v4_server_test"
559
560
561
562
563
564
565
566
567

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start DHCPv6 server using keactrl script.
568
569
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
570
    ret=${?}
Josh Soref's avatar
Josh Soref committed
571
    assert_eq 0 ${ret} "Expected keactrl to return 0, returned value was ${ret}"
572
573
574
575
576
577
578

    # Wait up to 20s for the DHCPv6 server to configure.
    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to start. \
Expected wait_for_message return %d, returned %d."

Josh Soref's avatar
Josh Soref committed
579
    # Server may shut down immediately after configuration has completed.
580
581
582
583
    # Give it some time to shutdown.
    sleep 3

    # Make sure that DHCPv6 server is running.
584
    get_pid ${kea6_name}
585
586
587
588
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

    # Make sure that DHCPv4 server is not running.
589
    get_pid ${kea4_name}
590
591
592
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

593
594
595
596
597
598
599
600
601
602
    # Make sure that D2 server is not running.
    get_pid ${d2_name}
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

    # Make sure that CA is not running.
    get_pid ${agent_name}
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

603
    # Trigger reconfiguration, make sure that the DHCPv6 server reconfigured.
604
605
    printf "Reconfiguring the DHCPv6 server: ${keactrl} reload -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} reload -c ${KEACTRL_CFG_FILE}
606
607
608
609
610
611
612
613
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"

    # There should be two completed reconfigurations so far.
    wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea6_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

614
615
    # Update keactrl config to enable other servers.
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
616
dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
617
618
    create_keactrl_config "${keactrl_config}"

619
    # Start other servers using keactrl script.
620
621
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
622
    ret=${?}
623
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
624
625
626
627
628
629
630

    # Wait up to 20s for the DHCPv4 server to configure.
    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

631
632
    # Wait up to 20s for the D2 and CA to configure.
    wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
633
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
634
        "Timeout waiting for ${d2_name} to start. \
635
636
Expected wait_for_message return %d, returned %d."

637
    # Make sure that DHCPv6 server is running.
638
    get_pid ${kea6_name}
639
640
641
642
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

    # Make sure that DHCPv4 server is running.
643
    get_pid ${kea4_name}
644
645
646
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

647
    # Make sure that D2 server is running.
648
    get_pid ${d2_name}
649
650
651
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

652
653
654
655
    # Make sure that CA is running.
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"
656

657
    # Trigger reconfiguration, make sure that servers are reconfigured.
658
    printf "Reconfiguring all servers: ${keactrl} reload \
659
660
-c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} reload -c ${KEACTRL_CFG_FILE}
661
662
663
664
665
666
667
668
669
670
671
672
673
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"

    # There should be three completed configurations of DHCPv6 server.
    wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 3
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea6_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

    # There should be two completed configurations of DHCPv4 server.
    wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea4_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

674
675
676
677
678
    # There should be two completed configurations of D2 and two
    # configurations of CA.
    wait_for_message 10 "DCTL_CONFIG_COMPLETE" 4
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${d2_name} or ${ca_name} \
to reconfigure. Expected wait_for_message to return %d, returned %d."
679

680
    # Use keactrl stop to shutdown the servers.
681
682
    printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -c ${KEACTRL_CFG_FILE}
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv6 server to stop.
    wait_for_message 10 "DHCP6_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 10s for the DHCPv4 server to stop.
    wait_for_message 10 "DHCP4_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

698
699
    # Wait up to 10s for the D2 and CA to stop.
    wait_for_message 10 "DCTL_SHUTDOWN" 2
700
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
701
        "Timeout waiting for ${d2_name} and ${ca_name} to shutdown. \
702
703
Expected wait_for_message return %d, returned %d."

704
705
706
707
    # Make sure that all servers are down.
    wait_for_server_down 5 ${wildcard_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
708

709
    test_finish 0
710
711
712
}

# This test checks that the DHCPv4 server can be started first, and then the
713
# other servers can be started while DHCPv4 server is already running.
714
# Also check that both servers can be reconfigured.
715
716
717
late_start_v6_server_test() {
    # Create configuration file for keactrl. This configuration enables
    # DHCPv4 server but disables DHCPv6 server.
718
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=no\n\
719
dhcp_ddns=no\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
720

721
    test_start "keactrl.late_start_v6_server_test"
722
723
724
725
726
727
728
729
730

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start DHCPv4 server using keactrl script.
731
732
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
733
    ret=${?}
Josh Soref's avatar
Josh Soref committed
734
    assert_eq 0 ${ret} "Expected keactrl to return 0, returned value was ${ret}"
735
736
737
738
739
740
741

    # Wait up to 20s for the DHCPv4 server to configure.
    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

Josh Soref's avatar
Josh Soref committed
742
    # Server may shut down immediately after configuration has completed.
743
744
745
746
    # Give it some time to shutdown.
    sleep 3

    # Make sure that DHCPv4 server is running.
747
    get_pid ${kea4_name}
748
749
750
751
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

    # Make sure that DHCPv6 server is not running.
752
    get_pid ${kea6_name}
753
754
755
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

756
    # Make sure that D2 server is not running.
757
    get_pid ${d2_name}
758
759
760
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

761
762
763
764
765
    # Make sure that CA is not running.
    get_pid ${d2_name}
    assert_eq 0 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

766
    # Trigger reconfiguration, make sure that the DHCPv4 server is reconfigured.
767
768
    printf "Reconfiguring the DHCPv4 server: ${keactrl} reload -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} reload -c ${KEACTRL_CFG_FILE}
769
770
771
772
773
774
775
776
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"

    # There should be two completed reconfigurations so far.
    wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea4_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

777
778
    # Update keactrl config to enable other servers.
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
779
dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
780
781
    create_keactrl_config "${keactrl_config}"

782
    # Start other servers using keactrl script.
783
784
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
785
    ret=${?}
Josh Soref's avatar
Josh Soref committed
786
    assert_eq 0 ${ret} "Expected keactrl to return 0, returned value was ${ret}"
787
788
789
790
791
792
793

    # Wait up to 20s for the DHCPv6 server to configure.
    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

794
795
    # Wait up to 20s for the D2 and CA to configure.
    wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
796
797
798
799
800
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to start. \
Expected wait_for_message return %d, returned %d."


801
    # Make sure that DHCPv6 server is running.
802
    get_pid ${kea6_name}
803
804
805
806
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

    # Make sure that DHCPv4 server is running.
807
    get_pid ${kea4_name}
808
809
810
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

811
    # Make sure that D2 server is running.
812
    get_pid ${d2_name}
813
814
815
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

816
817
818
819
820
    # Make sure that CA is running.
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

821
    # Trigger reconfiguration, make sure that servers are reconfigured.
822
823
824
    printf "Reconfiguring DHCPv6 and DHCPv4 servers: ${keactrl} reload \
-c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} reload -c ${KEACTRL_CFG_FILE}
825
826
827
828
829
830
831
832
833
834
835
836
837
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"

    # There should be three completed configurations of DHCPv4 server.
    wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 3
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea4_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

    # There should be two completed configurations of DHCPv6 server.
    wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea6_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

838
839
840
    # There should be two completed configurations of D2 and two
    # configurations of the CA.
    wait_for_message 10 "DCTL_CONFIG_COMPLETE" 4
841
842
843
    assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${d2_name} to reconfigure. \
Expected wait_for_message to return %d, returned %d."

844
    # Use keactrl stop to shutdown the servers.
845
846
    printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -c ${KEACTRL_CFG_FILE}
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv6 server to stop.
    wait_for_message 10 "DHCP6_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 10s for the DHCPv4 server to stop.
    wait_for_message 10 "DHCP4_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

862
863
    # Wait up to 10s for the D2 and CA to stop.
    wait_for_message 10 "DCTL_SHUTDOWN" 2
864
865
866
867
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

868
869
870
871
    # Make sure that all servers are down.
    wait_for_server_down 5 ${wildcard_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
872

873
    test_finish 0
874
875
}

876
877
878
# This test checks that the servers can be shutdown selectively.
stop_selected_server_test() {
    # Create configuration file for keactrl. This configuration enables
879
880
    # all servers.
    keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
881
dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909

    test_start "keactrl.stop_selected_server_test"

    # Create configuration file for Kea and for keactrl.
    create_config "${config}"
    create_keactrl_config "${keactrl_config}"

    # Set logging to a file.
    set_logger

    # Start servers using keactrl script.
    printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} start -c ${KEACTRL_CFG_FILE}
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"

    # Wait up to 20s for the DHCPv6 server to configure.
    wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to start. \
Expected wait_for_message return %d, returned %d."

    # Wait up to 20s for the DHCPv4 server to configure.
    wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to start. \
Expected wait_for_message return %d, returned %d."

910
911
    # Wait up to 20s for the D2 and CA to configure.
    wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
912
913
914
915
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to start. \
Expected wait_for_message return %d, returned %d."

916
917
918
919
920
921
922
923
924
    # Make sure that debug messages are not logged (non-verbose mode).
    get_log_messages "DHCP6_START_INFO"
    assert_eq 0 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages return %d, returned %d."

    get_log_messages "DHCP4_START_INFO"
    assert_eq 0 ${_GET_LOG_MESSAGES} \
        "Expected get_log_messages return %d, returned %d."

925
    get_log_messages "DCTL_STANDALONE"
926
    assert_eq 0 ${_GET_LOG_MESSAGES} \
927
    "Expected get_log_messages return %d, returned %d."
928

Josh Soref's avatar
Josh Soref committed
929
    # Server may shut down immediately after configuration has completed.
930
931
932
    # Give it some time to shutdown.
    sleep 3

933
    # Make sure that all servers are running.
934
    get_pid ${kea4_name}
935
936
937
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea4_name} process running, found %d processes running"

938
    get_pid ${kea6_name}
939
940
941
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

942
    get_pid ${d2_name}
943
944
945
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

946
947
948
949
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

950
951
952
953
954
955
956
957
958
959
960
961
    # Use keactrl stop to shutdown DHCPv4 server.
    printf "Stopping DHCPv4 server: ${keactrl} stop -s dhcp4 -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -s dhcp4 -c ${KEACTRL_CFG_FILE}
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv4 server to stop.
    wait_for_message 10 "DHCP4_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea4_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

962
963
964
965
966
    # Make sure that the DHCPv4 server is down.
    wait_for_server_down 5 ${kea4_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"

967
    # Make sure DHCPv6 server is still running
968
    get_pid ${kea6_name}
969
970
971
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${kea6_name} process running, found %d processes running"

972
    # Make sure D2 server is still running
973
    get_pid ${kea6_name}
974
975
976
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

977
978
979
980
981
    # Make sure CA is still running
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

982
983
984
985
986
987
988
989
990
991
992
993
994
    # Use keactrl stop to shutdown DHCPv6 server.
    printf "Stopping DHCPv6 server: ${keactrl} stop -s dhcp6 -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -s dhcp6 -c ${KEACTRL_CFG_FILE}
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the DHCPv6 server to stop.
    wait_for_message 10 "DHCP6_SHUTDOWN" 1
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${kea6_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Make sure that the DHCPv6 server is down.
995
996
997
    wait_for_server_down 5 ${kea6_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
998

999
    # Make sure D2 server is still running
1000
    get_pid ${d2_name}
1001
1002
1003
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${d2_name} process running, found %d processes running"

1004
1005
1006
1007
1008
    # Make sure CA is still running
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

1009
    # Use keactrl stop to shutdown D2 server.
1010
    printf "Stopping DHCP DDNS server: ${keactrl} stop -s dhcp_ddns -c ${KEACTRL_CFG_FILE}\n"
1011
1012
1013
1014
1015
    ${keactrl} stop -s dhcp_ddns -c ${KEACTRL_CFG_FILE}
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the D2 server to stop.
1016
    wait_for_message 10 "DCTL_SHUTDOWN" 1
1017
1018
1019
1020
1021
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${d2_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Make sure that the D2 server is down.
1022
1023
1024
    wait_for_server_down 5 ${d2_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"
1025

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
    # Make sure CA is still running
    get_pid ${agent_name}
    assert_eq 1 ${_GET_PIDS_NUM} \
        "Expected %d ${agent_name} process running, found %d processes running"

    # Use keactrl stop to shutdown CA.
    printf "Stopping DHCP DDNS server: ${keactrl} stop -s ctrl_agent -c ${KEACTRL_CFG_FILE}\n"
    ${keactrl} stop -s ctrl_agent -c ${KEACTRL_CFG_FILE}
    ret=${?}
    assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."

    # Wait up to 10s for the CA to stop.
    wait_for_message 10 "DCTL_SHUTDOWN" 2
    assert_eq 1 ${_WAIT_FOR_MESSAGE} \
        "Timeout waiting for ${agent_name} to shutdown. \
Expected wait_for_message return %d, returned %d."

    # Make sure that the CA is down.
    wait_for_server_down 5 ${agent_name}
    assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
        "Expected wait_for_server_down return %d, returned %d"

1048
1049
1050
    test_finish 0
}

1051
1052
# This test checks that the "status" command doesn't check the presence of the
# config file.
1053
1054
1055
status_no_config_test() {
    test_start "keactrl.status_no_config_test"

1056
1057
    # Make sure that all config files are removed.
    cleanup
1058

1059
1060
    # Create keactrl configuration file.
    create_keactrl_config "${keactrl_config}"
1061

1062
1063
    # Make sure that the "status" command doesn't check the presence of
    # the config file.
1064
    printf "Getting status without a Kea config file\n"
1065

1066
1067
1068
    output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
    ret=${?}
    assert_eq 1 ${ret} "Expected keactrl to return %d, returned %d"
1069
    assert_string_contains "DHCPv4 server: inactive" "${output}" \
1070
1071
1072
1073
1074
        "Expected keactrl status command return %s"
    assert_string_contains "DHCPv6 server: inactive" "${output}" \
        "Expected keactrl status command return %s"
    assert_string_contains "DHCP DDNS: inactive" "${output}" \
        "Expected keactrl status command return %s"
1075
1076
    assert_string_contains "Control Agent: inactive" "${output}" \
        "Expected keactrl status command return %s"
1077
    assert_string_contains "Configuration file for Kea does not exist" \
Francis Dupont's avatar
Francis Dupont committed
1078
        "${output}" "Expected keactrl status command return %s"
1079
1080
1081

    test_finish 0
}
1082

1083
1084
start_all_servers_no_verbose_test
start_all_servers_verbose_test
1085
1086
1087
1088
start_v4_server_test
start_v6_server_test
late_start_v4_server_test
late_start_v6_server_test
1089
stop_selected_server_test
1090
status_no_config_test