keactrl_tests.sh.in 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. #!/bin/sh
  2. # Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. # Include common test library.
  8. . @abs_top_builddir@/src/lib/testutils/dhcp_test_lib.sh
  9. # Set location of the keactrl.
  10. keactrl=@abs_top_builddir@/src/bin/keactrl/keactrl
  11. # Name of the configuration file without its extension.
  12. CFG_FILE_NAME="test_config"
  13. # A name of the configuration file to be used by Kea.
  14. CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/${CFG_FILE_NAME}.json
  15. # A name of the keactrl config file
  16. KEACTRL_CFG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/keactrl_test.conf
  17. # Path to the Kea log file.
  18. LOG_FILE=@abs_top_builddir@/src/bin/keactrl/tests/test.log
  19. # Binaries' names
  20. wildcard_name="kea-"
  21. kea4_name="${wildcard_name}dhcp4"
  22. kea6_name="${wildcard_name}dhcp6"
  23. d2_name="${wildcard_name}dhcp-ddns"
  24. agent_name="${wildcard_name}ctrl-agent"
  25. # Kea configuration
  26. config="{
  27. \"Dhcp4\":
  28. {
  29. \"interfaces-config\": {
  30. \"interfaces\": [ ]
  31. },
  32. \"valid-lifetime\": 4000,
  33. \"renew-timer\": 1000,
  34. \"rebind-timer\": 2000,
  35. \"lease-database\":
  36. {
  37. \"type\": \"memfile\",
  38. \"persist\": false
  39. },
  40. \"subnet4\": [
  41. {
  42. \"subnet\": \"10.0.0.0/24\",
  43. \"pools\": [ { \"pool\": \"10.0.0.10-10.0.0.100\" } ]
  44. } ]
  45. },
  46. \"Dhcp6\":
  47. {
  48. \"interfaces-config\": {
  49. \"interfaces\": [ ]
  50. },
  51. \"server-id\": {
  52. \"type\": \"LLT\",
  53. \"persist\": false
  54. },
  55. \"preferred-lifetime\": 3000,
  56. \"valid-lifetime\": 4000,
  57. \"renew-timer\": 1000,
  58. \"rebind-timer\": 2000,
  59. \"lease-database\":
  60. {
  61. \"type\": \"memfile\",
  62. \"persist\": false
  63. },
  64. \"subnet6\": [
  65. {
  66. \"subnet\": \"2001:db8:1::/64\",
  67. \"pools\": [ { \"pool\": \"2001:db8:1::10-2001:db8:1::100\" } ]
  68. } ]
  69. },
  70. \"DhcpDdns\":
  71. {
  72. \"ip-address\": \"127.0.0.1\",
  73. \"port\": 53001,
  74. \"tsig-keys\": [],
  75. \"forward-ddns\" : {},
  76. \"reverse-ddns\" : {}
  77. },
  78. \"Control-agent\": {
  79. \"http-host\": \"127.0.0.1\",
  80. \"http-port\": 18080
  81. },
  82. \"Logging\":
  83. {
  84. \"loggers\": [
  85. {
  86. \"name\": \"kea-dhcp4\",
  87. \"output_options\": [
  88. {
  89. \"output\": \"$LOG_FILE\"
  90. }
  91. ],
  92. \"severity\": \"INFO\"
  93. },
  94. {
  95. \"name\": \"kea-dhcp6\",
  96. \"output_options\": [
  97. {
  98. \"output\": \"$LOG_FILE\"
  99. }
  100. ],
  101. \"severity\": \"INFO\"
  102. },
  103. {
  104. \"name\": \"kea-dhcp-ddns\",
  105. \"output_options\": [
  106. {
  107. \"output\": \"$LOG_FILE\"
  108. }
  109. ],
  110. \"severity\": \"INFO\"
  111. },
  112. {
  113. \"name\": \"kea-ctrl-agent\",
  114. \"output_options\": [
  115. {
  116. \"output\": \"$LOG_FILE\"
  117. }
  118. ],
  119. \"severity\": \"INFO\"
  120. }
  121. ]
  122. }
  123. }"
  124. # Fixed part of the keactrl configuration file.
  125. keactrl_fixed_config="dhcp4_srv=${KEACTRL_BUILD_DIR}/src/bin/dhcp4/kea-dhcp4\n\
  126. dhcp6_srv=${KEACTRL_BUILD_DIR}/src/bin/dhcp6/kea-dhcp6\n\
  127. dhcp_ddns_srv=${KEACTRL_BUILD_DIR}/src/bin/d2/kea-dhcp-ddns\n\
  128. ctrl_agent_srv=${KEACTRL_BUILD_DIR}/src/bin/agent/kea-ctrl-agent\n"
  129. # This test checks that DHCPv4, DHCPv6 and D2 server can be started and
  130. # shut down.
  131. start_all_servers_no_verbose_test() {
  132. # Create configuration file for keactrl. This configuration enables
  133. # DHCPv4, DHCPv6, D2 and CA.
  134. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
  135. dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
  136. test_start "keactrl.start_all_servers_no_verbose_test"
  137. # Create configuration file for Kea and for keactrl.
  138. create_config "${config}"
  139. create_keactrl_config "${keactrl_config}"
  140. # Set logging to a file.
  141. set_logger
  142. # Start servers using keactrl script.
  143. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE} -s all\n"
  144. # Append the -s option to specify all servers. This is not necessary
  145. # because all should be a default but let's see if it is accepted
  146. # by the command line parser.
  147. ${keactrl} start -c ${KEACTRL_CFG_FILE} -s all
  148. ret=${?}
  149. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  150. # Wait up to 20s for the DHCPv6 server to configure.
  151. wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
  152. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  153. "Timeout waiting for ${kea6_name} to start. \
  154. Expected wait_for_message return %d, returned %d."
  155. # Wait up to 20s for the DHCPv4 server to configure.
  156. wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
  157. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  158. "Timeout waiting for ${kea4_name} to start. \
  159. Expected wait_for_message return %d, returned %d."
  160. # Wait for D2 and CA to configure.
  161. wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
  162. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  163. "Timeout waiting for CPL daemons to start. \
  164. Expected wait_for_message return %d, returned %d."
  165. wait_for_message 20 "DHCP_DDNS_STARTED" 1
  166. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  167. "Timeout waiting for ${d2_name} to start. \
  168. Expected wait_for_message return %d, returned %d."
  169. wait_for_message 20 "CTRL_AGENT_HTTP_SERVICE_STARTED" 1
  170. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  171. "Timeout waiting for ${agent_name} to start. \
  172. Expected wait_for_message return %d, returned %d."
  173. # Make sure that debug messages are logged for neither
  174. # server (non-verbose mode).
  175. get_log_messages "DHCP6_START_INFO"
  176. assert_eq 0 ${_GET_LOG_MESSAGES} \
  177. "Expected get_log_messages return %d, returned %d."
  178. get_log_messages "DHCP4_START_INFO"
  179. assert_eq 0 ${_GET_LOG_MESSAGES} \
  180. "Expected get_log_messages return %d, returned %d."
  181. get_log_messages "DCTL_STANDALONE"
  182. assert_eq 0 ${_GET_LOG_MESSAGES} \
  183. "Expected get_log_messages return %d, returned %d."
  184. # Server may shut down imediatelly after configuration has competed.
  185. # Give it some time to shutdown.
  186. sleep 3
  187. # Make sure that all servers are running.
  188. get_pid ${kea4_name}
  189. assert_eq 1 ${_GET_PIDS_NUM} \
  190. "Expected %d ${kea4_name} process running, found %d processes running"
  191. get_pid ${kea6_name}
  192. assert_eq 1 ${_GET_PIDS_NUM} \
  193. "Expected %d ${kea6_name} process running, found %d processes running"
  194. get_pid ${d2_name}
  195. assert_eq 1 ${_GET_PIDS_NUM} \
  196. "Expected %d ${d2_name} process running, found %d processes running"
  197. get_pid ${agent_name}
  198. assert_eq 1 ${_GET_PIDS_NUM} \
  199. "Expected %d ${agent_name} process running, found %d processes running"
  200. # Use keactrl stop to shutdown the servers.
  201. printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
  202. ${keactrl} stop -c ${KEACTRL_CFG_FILE}
  203. ret=${?}
  204. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  205. # Wait up to 10s for the DHCPv6 server to stop.
  206. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  207. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  208. "Timeout waiting for ${kea6_name} to shutdown. \
  209. Expected wait_for_message return %d, returned %d."
  210. # Wait up to 10s for the DHCPv4 server to stop.
  211. wait_for_message 10 "DHCP4_SHUTDOWN" 1
  212. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  213. "Timeout waiting for ${kea4_name} to shutdown. \
  214. Expected wait_for_message return %d, returned %d."
  215. # Wait up to 10s for the D2 and CA to stop.
  216. wait_for_message 10 "DCTL_SHUTDOWN" 2
  217. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  218. "Timeout waiting for ${d2_name} to shutdown. \
  219. Expected wait_for_message return %d, returned %d."
  220. # Make sure that all servers are down.
  221. wait_for_server_down 5 ${wildcard_name}
  222. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  223. "Expected wait_for_server_down return %d, returned %d"
  224. test_finish 0
  225. }
  226. # This test checks that both DHCPv4 and DHCPv6 server can be started in
  227. # a verbose mode.
  228. start_all_servers_verbose_test() {
  229. # Create configuration file for keactrl. This configuration enables
  230. # all servers.
  231. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
  232. dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
  233. test_start "keactrl.start_all_servers_verbose_test"
  234. # Create configuration file for Kea and for keactrl.
  235. create_config "${config}"
  236. create_keactrl_config "${keactrl_config}"
  237. # Set logging to a file.
  238. set_logger
  239. # Start servers using keactrl script.
  240. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  241. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  242. ret=${?}
  243. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  244. # Wait up to 20s for the DHCPv6 server to configure.
  245. wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
  246. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  247. "Timeout waiting for ${kea6_name} to start. \
  248. Expected wait_for_message return %d, returned %d."
  249. # Wait up to 20s for the DHCPv4 server to configure.
  250. wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
  251. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  252. "Timeout waiting for ${kea4_name} to start. \
  253. Expected wait_for_message return %d, returned %d."
  254. wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
  255. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  256. "Timeout waiting for CPL daemons to start. \
  257. Expected wait_for_message return %d, returned %d."
  258. wait_for_message 20 "DHCP_DDNS_STARTED" 1
  259. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  260. "Timeout waiting for ${d2_name} to start. \
  261. Expected wait_for_message return %d, returned %d."
  262. wait_for_message 20 "CTRL_AGENT_HTTP_SERVICE_STARTED" 1
  263. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  264. "Timeout waiting for ${agent_name} to start. \
  265. Expected wait_for_message return %d, returned %d."
  266. # Check if the debug messages are present, which should only be
  267. # the case if the verbose mode is on.
  268. get_log_messages "DHCP6_START_INFO" 1
  269. assert_eq 1 ${_GET_LOG_MESSAGES} \
  270. "Expected get_log_messages for DHCP6_START_INFO return %d, returned %d."
  271. get_log_messages "DHCP4_START_INFO" 1
  272. assert_eq 1 ${_GET_LOG_MESSAGES} \
  273. "Expected get_log_messages for DHCP4_START_INFO return %d, returned %d."
  274. get_log_messages "DCTL_STANDALONE" 2
  275. assert_eq 2 ${_GET_LOG_MESSAGES} \
  276. "Expected get_log_messages for DCT_STANDALONE return %d, returned %d."
  277. # Server may shut down imediatelly after configuration has competed.
  278. # Give it some time to shutdown.
  279. sleep 3
  280. # Make sure that all servers are running.
  281. get_pid ${kea4_name}
  282. assert_eq 1 ${_GET_PIDS_NUM} \
  283. "Expected %d ${kea4_name} process running, found %d processes running"
  284. get_pid ${kea6_name}
  285. assert_eq 1 ${_GET_PIDS_NUM} \
  286. "Expected %d ${kea6_name} process running, found %d processes running"
  287. get_pid ${d2_name}
  288. assert_eq 1 ${_GET_PIDS_NUM} \
  289. "Expected %d ${d2_name} process running, found %d processes running"
  290. get_pid ${agent_name}
  291. assert_eq 1 ${_GET_PIDS_NUM} \
  292. "Expected %d ${agent_name} process running, found %d processes running"
  293. # Use keactrl stop to shutdown the servers.
  294. printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
  295. ${keactrl} stop -c ${KEACTRL_CFG_FILE}
  296. ret=${?}
  297. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  298. # Wait up to 10s for the DHCPv6 server to stop.
  299. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  300. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  301. "Timeout waiting for ${kea6_name} to shutdown. \
  302. Expected wait_for_message return %d, returned %d."
  303. # Wait up to 10s for the DHCPv4 server to stop.
  304. wait_for_message 10 "DHCP4_SHUTDOWN" 1
  305. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  306. "Timeout waiting for ${kea4_name} to shutdown. \
  307. Expected wait_for_message return %d, returned %d."
  308. # Wait up to 10s for the D2 and CA to stop.
  309. wait_for_message 10 "DCTL_SHUTDOWN" 2
  310. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  311. "Timeout waiting for ${d2_name} and ${agent_name} to shutdown. \
  312. Expected wait_for_message return %d, returned %d."
  313. # Make sure that all servers are down.
  314. wait_for_server_down 5 ${wildcard_name}
  315. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  316. "Expected wait_for_server_down return %d, returned %d"
  317. test_finish 0
  318. }
  319. # This test checks that only DHCPv4 server can be started and that other
  320. # servers are not started.
  321. start_v4_server_test() {
  322. # Create configuration file for keactrl. This configuration enables
  323. # DHCPv4 server but disables other servers.
  324. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=no\n\
  325. dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
  326. test_start "keactrl.start_v4_server_test"
  327. # Create configuration file for Kea and for keactrl.
  328. create_config "${config}"
  329. create_keactrl_config "${keactrl_config}"
  330. # Set logging to a file.
  331. set_logger
  332. # Start DHCPv4 server using keactrl script.
  333. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  334. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  335. ret=${?}
  336. assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
  337. # Wait up to 20s for the DHCPv4 server to configure.
  338. wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
  339. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  340. "Timeout waiting for ${kea4_name} to start. \
  341. Expected wait_for_message return %d, returned %d."
  342. # Server may shut down imediatelly after configuration has competed.
  343. # Give it some time to shutdown.
  344. sleep 3
  345. # Make sure that DHCPv4 server is running.
  346. get_pid ${kea4_name}
  347. assert_eq 1 ${_GET_PIDS_NUM} \
  348. "Expected %d ${kea4_name} process running, found %d processes running"
  349. # Make sure that DHCPv6 server is not running.
  350. get_pid ${kea6_name}
  351. assert_eq 0 ${_GET_PIDS_NUM} \
  352. "Expected %d ${kea6_name} process running, found %d processes running"
  353. # Make sure that D2 server is not running.
  354. get_pid ${d2_name}
  355. assert_eq 0 ${_GET_PIDS_NUM} \
  356. "Expected %d ${d2_name} process running, found %d processes running"
  357. # Make sure that CA is not running.
  358. get_pid ${agent_name}
  359. assert_eq 0 ${_GET_PIDS_NUM} \
  360. "Expected %d ${agent_name} process running, found %d processes running"
  361. # Make sure that the status command returns appropriate status.
  362. printf "Getting status of Kea modules: %s\n" "${keactrl} status \
  363. -c ${KEACTRL_CFG_FILE}"
  364. output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
  365. ret=${?}
  366. assert_eq 0 ${ret} "Expected keactrl to return %d, returned %d"
  367. assert_string_contains "DHCPv4 server: active" "${output}" \
  368. "Expected keactrl status command return %s"
  369. assert_string_contains "DHCPv6 server: inactive" "${output}" \
  370. "Expected keactrl status command return %s"
  371. assert_string_contains "DHCP DDNS: inactive" "${output}" \
  372. "Expected keactrl status command return %s"
  373. assert_string_contains "Control Agent: inactive" "${output}" \
  374. "Expected keactrl status command return %s"
  375. # Use keactrl stop to shutdown the servers.
  376. printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
  377. ${keactrl} stop -c ${KEACTRL_CFG_FILE}
  378. ret=${?}
  379. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  380. # Wait up to 10s for the DHCPv4 server to stop.
  381. wait_for_message 10 "DHCP4_SHUTDOWN" 1
  382. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  383. "Timeout waiting for ${kea4_name} to shutdown. \
  384. Expected wait_for_message return %d, returned %d."
  385. # Make sure that all servers are down.
  386. wait_for_server_down 5 ${wildcard_name}
  387. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  388. "Expected wait_for_server_down return %d, returned %d"
  389. test_finish 0
  390. }
  391. # This test checks that only DHCPv6 server can be started and that other
  392. # servers are not started.
  393. start_v6_server_test() {
  394. # Create configuration file for keactrl. This configuration enables
  395. # DHCPv6 server but disables other servers..
  396. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=no\ndhcp6=yes\n\
  397. dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
  398. test_start "keactrl.start_v6_server_test"
  399. # Create configuration file for Kea and for keactrl.
  400. create_config "${config}"
  401. create_keactrl_config "${keactrl_config}"
  402. # Set logging to a file.
  403. set_logger
  404. # Start DHCPv6 server using keactrl script.
  405. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  406. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  407. ret=${?}
  408. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  409. # Wait up to 20s for the DHCPv6 server to configure.
  410. wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
  411. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  412. "Timeout waiting for ${kea6_name} to start. \
  413. Expected wait_for_message return %d, returned %d."
  414. # Server may shut down imediatelly after configuration has competed.
  415. # Give it some time to shutdown.
  416. sleep 3
  417. # Make sure that DHCPv6 server is running.
  418. get_pid ${kea6_name}
  419. assert_eq 1 ${_GET_PIDS_NUM} \
  420. "Expected %d ${kea6_name} process running, found %d processes running"
  421. # Make sure that DHCPv4 server is not running.
  422. get_pid ${kea4_name}
  423. assert_eq 0 ${_GET_PIDS_NUM} \
  424. "Expected %d ${kea4_name} process running, found %d processes running"
  425. # Make sure that D2 server is not running.
  426. get_pid ${d2_name}
  427. assert_eq 0 ${_GET_PIDS_NUM} \
  428. "Expected %d ${d2_name} process running, found %d processes running"
  429. # Make sure that CA is not running.
  430. get_pid ${agent_name}
  431. assert_eq 0 ${_GET_PIDS_NUM} \
  432. "Expected %d ${agent_name} process running, found %d processes running"
  433. # Make sure that the status command returns appropriate status.
  434. printf "Getting status of Kea modules: %s\n" "${keactrl} status -c ${KEACTRL_CFG_FILE}"
  435. output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
  436. ret=${?}
  437. assert_eq 0 ${ret} "Expected keactrl to return %d, returned %d"
  438. assert_string_contains "DHCPv4 server: inactive" "${output}" \
  439. "Expected keactrl status command return %s"
  440. assert_string_contains "DHCPv6 server: active" "${output}" \
  441. "Expected keactrl status command return %s"
  442. assert_string_contains "DHCP DDNS: inactive" "${output}" \
  443. "Expected keactrl status command return %s"
  444. assert_string_contains "Control Agent: inactive" "${output}" \
  445. "Expected keactrl status command return %s"
  446. # Use keactrl stop to shutdown the servers.
  447. printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
  448. ${keactrl} stop -c ${KEACTRL_CFG_FILE}
  449. ret=${?}
  450. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  451. # Wait up to 10s for the DHCPv6 server to stop.
  452. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  453. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  454. "Timeout waiting for ${kea6_name} to shutdown. \
  455. Expected wait_for_message return %d, returned %d."
  456. # Make sure that all servers are down.
  457. wait_for_server_down 5 ${wildcard_name}
  458. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  459. "Expected wait_for_server_down return %d, returned %d"
  460. test_finish 0
  461. }
  462. # This test checks that the DHCPv4 server can be started first, and then the
  463. # other servers can be started while DHCPv4 server is already running.
  464. # Also check that both servers can be reconfigured.
  465. late_start_v4_server_test() {
  466. # Create configuration file for keactrl. This configuration enables
  467. # DHCPv6 server but disables other servers.
  468. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=no\ndhcp6=yes\n\
  469. dhcp_ddns=no\nctrl_agent=no\nkea_verbose=no\n${keactrl_fixed_config}"
  470. test_start "keactrl.late_start_v4_server_test"
  471. # Create configuration file for Kea and for keactrl.
  472. create_config "${config}"
  473. create_keactrl_config "${keactrl_config}"
  474. # Set logging to a file.
  475. set_logger
  476. # Start DHCPv6 server using keactrl script.
  477. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  478. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  479. ret=${?}
  480. assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
  481. # Wait up to 20s for the DHCPv6 server to configure.
  482. wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
  483. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  484. "Timeout waiting for ${kea6_name} to start. \
  485. Expected wait_for_message return %d, returned %d."
  486. # Server may shut down imediatelly after configuration has competed.
  487. # Give it some time to shutdown.
  488. sleep 3
  489. # Make sure that DHCPv6 server is running.
  490. get_pid ${kea6_name}
  491. assert_eq 1 ${_GET_PIDS_NUM} \
  492. "Expected %d ${kea6_name} process running, found %d processes running"
  493. # Make sure that DHCPv4 server is not running.
  494. get_pid ${kea4_name}
  495. assert_eq 0 ${_GET_PIDS_NUM} \
  496. "Expected %d ${kea4_name} process running, found %d processes running"
  497. # Make sure that D2 server is not running.
  498. get_pid ${d2_name}
  499. assert_eq 0 ${_GET_PIDS_NUM} \
  500. "Expected %d ${d2_name} process running, found %d processes running"
  501. # Make sure that CA is not running.
  502. get_pid ${agent_name}
  503. assert_eq 0 ${_GET_PIDS_NUM} \
  504. "Expected %d ${agent_name} process running, found %d processes running"
  505. # Trigger reconfiguration, make sure that the DHCPv6 server reconfigured.
  506. printf "Reconfiguring the DHCPv6 server: ${keactrl} reload -c ${KEACTRL_CFG_FILE}\n"
  507. ${keactrl} reload -c ${KEACTRL_CFG_FILE}
  508. ret=${?}
  509. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  510. # There should be two completed reconfigurations so far.
  511. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  512. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea6_name} to reconfigure. \
  513. Expected wait_for_message to return %d, returned %d."
  514. # Update keactrl config to enable other servers.
  515. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
  516. dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
  517. create_keactrl_config "${keactrl_config}"
  518. # Start other servers using keactrl script.
  519. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  520. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  521. ret=${?}
  522. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  523. # Wait up to 20s for the DHCPv4 server to configure.
  524. wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
  525. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  526. "Timeout waiting for ${kea4_name} to start. \
  527. Expected wait_for_message return %d, returned %d."
  528. # Wait up to 20s for the D2 and CA to configure.
  529. wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
  530. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  531. "Timeout waiting for ${d2_name} to start. \
  532. Expected wait_for_message return %d, returned %d."
  533. # Make sure that DHCPv6 server is running.
  534. get_pid ${kea6_name}
  535. assert_eq 1 ${_GET_PIDS_NUM} \
  536. "Expected %d ${kea6_name} process running, found %d processes running"
  537. # Make sure that DHCPv4 server is running.
  538. get_pid ${kea4_name}
  539. assert_eq 1 ${_GET_PIDS_NUM} \
  540. "Expected %d ${kea4_name} process running, found %d processes running"
  541. # Make sure that D2 server is running.
  542. get_pid ${d2_name}
  543. assert_eq 1 ${_GET_PIDS_NUM} \
  544. "Expected %d ${d2_name} process running, found %d processes running"
  545. # Make sure that CA is running.
  546. get_pid ${agent_name}
  547. assert_eq 1 ${_GET_PIDS_NUM} \
  548. "Expected %d ${agent_name} process running, found %d processes running"
  549. # Trigger reconfiguration, make sure that servers are reconfigured.
  550. printf "Reconfiguring all servers: ${keactrl} reload \
  551. -c ${KEACTRL_CFG_FILE}\n"
  552. ${keactrl} reload -c ${KEACTRL_CFG_FILE}
  553. ret=${?}
  554. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  555. # There should be three completed configurations of DHCPv6 server.
  556. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 3
  557. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea6_name} to reconfigure. \
  558. Expected wait_for_message to return %d, returned %d."
  559. # There should be two completed configurations of DHCPv4 server.
  560. wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 2
  561. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea4_name} to reconfigure. \
  562. Expected wait_for_message to return %d, returned %d."
  563. # There should be two completed configurations of D2 and two
  564. # configurations of CA.
  565. wait_for_message 10 "DCTL_CONFIG_COMPLETE" 4
  566. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${d2_name} or ${ca_name} \
  567. to reconfigure. Expected wait_for_message to return %d, returned %d."
  568. # Use keactrl stop to shutdown the servers.
  569. printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
  570. ${keactrl} stop -c ${KEACTRL_CFG_FILE}
  571. ret=${?}
  572. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  573. # Wait up to 10s for the DHCPv6 server to stop.
  574. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  575. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  576. "Timeout waiting for ${kea6_name} to shutdown. \
  577. Expected wait_for_message return %d, returned %d."
  578. # Wait up to 10s for the DHCPv4 server to stop.
  579. wait_for_message 10 "DHCP4_SHUTDOWN" 1
  580. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  581. "Timeout waiting for ${kea4_name} to shutdown. \
  582. Expected wait_for_message return %d, returned %d."
  583. # Wait up to 10s for the D2 and CA to stop.
  584. wait_for_message 10 "DCTL_SHUTDOWN" 2
  585. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  586. "Timeout waiting for ${d2_name} and ${ca_name} to shutdown. \
  587. Expected wait_for_message return %d, returned %d."
  588. # Make sure that all servers are down.
  589. wait_for_server_down 5 ${wildcard_name}
  590. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  591. "Expected wait_for_server_down return %d, returned %d"
  592. test_finish 0
  593. }
  594. # This test checks that the DHCPv4 server can be started first, and then the
  595. # other servers can be started while DHCPv4 server is already running.
  596. # Also check that both servers can be reconfigured.
  597. late_start_v6_server_test() {
  598. # Create configuration file for keactrl. This configuration enables
  599. # DHCPv4 server but disables DHCPv6 server.
  600. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=no\n\
  601. dhcp_ddns=no\nctrl_agent=yes\nkea_verbose=yes\n${keactrl_fixed_config}"
  602. test_start "keactrl.late_start_v6_server_test"
  603. # Create configuration file for Kea and for keactrl.
  604. create_config "${config}"
  605. create_keactrl_config "${keactrl_config}"
  606. # Set logging to a file.
  607. set_logger
  608. # Start DHCPv4 server using keactrl script.
  609. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  610. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  611. ret=${?}
  612. assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
  613. # Wait up to 20s for the DHCPv4 server to configure.
  614. wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
  615. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  616. "Timeout waiting for ${kea4_name} to start. \
  617. Expected wait_for_message return %d, returned %d."
  618. # Server may shut down imediatelly after configuration has competed.
  619. # Give it some time to shutdown.
  620. sleep 3
  621. # Make sure that DHCPv4 server is running.
  622. get_pid ${kea4_name}
  623. assert_eq 1 ${_GET_PIDS_NUM} \
  624. "Expected %d ${kea4_name} process running, found %d processes running"
  625. # Make sure that DHCPv6 server is not running.
  626. get_pid ${kea6_name}
  627. assert_eq 0 ${_GET_PIDS_NUM} \
  628. "Expected %d ${kea6_name} process running, found %d processes running"
  629. # Make sure that D2 server is not running.
  630. get_pid ${d2_name}
  631. assert_eq 0 ${_GET_PIDS_NUM} \
  632. "Expected %d ${d2_name} process running, found %d processes running"
  633. # Make sure that CA is not running.
  634. get_pid ${d2_name}
  635. assert_eq 0 ${_GET_PIDS_NUM} \
  636. "Expected %d ${agent_name} process running, found %d processes running"
  637. # Trigger reconfiguration, make sure that the DHCPv4 server is reconfigured.
  638. printf "Reconfiguring the DHCPv4 server: ${keactrl} reload -c ${KEACTRL_CFG_FILE}\n"
  639. ${keactrl} reload -c ${KEACTRL_CFG_FILE}
  640. ret=${?}
  641. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  642. # There should be two completed reconfigurations so far.
  643. wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 2
  644. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea4_name} to reconfigure. \
  645. Expected wait_for_message to return %d, returned %d."
  646. # Update keactrl config to enable other servers.
  647. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
  648. dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
  649. create_keactrl_config "${keactrl_config}"
  650. # Start other servers using keactrl script.
  651. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  652. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  653. ret=${?}
  654. assert_eq 0 ${ret} "Expected keactrl to retrun 0, returned value was ${ret}"
  655. # Wait up to 20s for the DHCPv6 server to configure.
  656. wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
  657. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  658. "Timeout waiting for ${kea4_name} to start. \
  659. Expected wait_for_message return %d, returned %d."
  660. # Wait up to 20s for the D2 and CA to configure.
  661. wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
  662. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  663. "Timeout waiting for ${d2_name} to start. \
  664. Expected wait_for_message return %d, returned %d."
  665. # Make sure that DHCPv6 server is running.
  666. get_pid ${kea6_name}
  667. assert_eq 1 ${_GET_PIDS_NUM} \
  668. "Expected %d ${kea6_name} process running, found %d processes running"
  669. # Make sure that DHCPv4 server is running.
  670. get_pid ${kea4_name}
  671. assert_eq 1 ${_GET_PIDS_NUM} \
  672. "Expected %d ${kea4_name} process running, found %d processes running"
  673. # Make sure that D2 server is running.
  674. get_pid ${d2_name}
  675. assert_eq 1 ${_GET_PIDS_NUM} \
  676. "Expected %d ${d2_name} process running, found %d processes running"
  677. # Make sure that CA is running.
  678. get_pid ${agent_name}
  679. assert_eq 1 ${_GET_PIDS_NUM} \
  680. "Expected %d ${agent_name} process running, found %d processes running"
  681. # Trigger reconfiguration, make sure that servers are reconfigured.
  682. printf "Reconfiguring DHCPv6 and DHCPv4 servers: ${keactrl} reload \
  683. -c ${KEACTRL_CFG_FILE}\n"
  684. ${keactrl} reload -c ${KEACTRL_CFG_FILE}
  685. ret=${?}
  686. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  687. # There should be three completed configurations of DHCPv4 server.
  688. wait_for_message 10 "DHCP4_CONFIG_COMPLETE" 3
  689. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea4_name} to reconfigure. \
  690. Expected wait_for_message to return %d, returned %d."
  691. # There should be two completed configurations of DHCPv6 server.
  692. wait_for_message 10 "DHCP6_CONFIG_COMPLETE" 2
  693. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${kea6_name} to reconfigure. \
  694. Expected wait_for_message to return %d, returned %d."
  695. # There should be two completed configurations of D2 and two
  696. # configurations of the CA.
  697. wait_for_message 10 "DCTL_CONFIG_COMPLETE" 4
  698. assert_eq 1 ${_WAIT_FOR_MESSAGE} "Timeout waiting for ${d2_name} to reconfigure. \
  699. Expected wait_for_message to return %d, returned %d."
  700. # Use keactrl stop to shutdown the servers.
  701. printf "Stopping Kea: ${keactrl} stop -c ${KEACTRL_CFG_FILE}\n"
  702. ${keactrl} stop -c ${KEACTRL_CFG_FILE}
  703. ret=${?}
  704. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  705. # Wait up to 10s for the DHCPv6 server to stop.
  706. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  707. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  708. "Timeout waiting for ${kea6_name} to shutdown. \
  709. Expected wait_for_message return %d, returned %d."
  710. # Wait up to 10s for the DHCPv4 server to stop.
  711. wait_for_message 10 "DHCP4_SHUTDOWN" 1
  712. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  713. "Timeout waiting for ${kea4_name} to shutdown. \
  714. Expected wait_for_message return %d, returned %d."
  715. # Wait up to 10s for the D2 and CA to stop.
  716. wait_for_message 10 "DCTL_SHUTDOWN" 2
  717. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  718. "Timeout waiting for ${d2_name} to shutdown. \
  719. Expected wait_for_message return %d, returned %d."
  720. # Make sure that all servers are down.
  721. wait_for_server_down 5 ${wildcard_name}
  722. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  723. "Expected wait_for_server_down return %d, returned %d"
  724. test_finish 0
  725. }
  726. # This test checks that the servers can be shutdown selectively.
  727. stop_selected_server_test() {
  728. # Create configuration file for keactrl. This configuration enables
  729. # all servers.
  730. keactrl_config="kea_config_file=${CFG_FILE}\ndhcp4=yes\ndhcp6=yes\n\
  731. dhcp_ddns=yes\nctrl_agent=yes\nkea_verbose=no\n${keactrl_fixed_config}"
  732. test_start "keactrl.stop_selected_server_test"
  733. # Create configuration file for Kea and for keactrl.
  734. create_config "${config}"
  735. create_keactrl_config "${keactrl_config}"
  736. # Set logging to a file.
  737. set_logger
  738. # Start servers using keactrl script.
  739. printf "Starting Kea: ${keactrl} start -c ${KEACTRL_CFG_FILE}\n"
  740. ${keactrl} start -c ${KEACTRL_CFG_FILE}
  741. ret=${?}
  742. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d"
  743. # Wait up to 20s for the DHCPv6 server to configure.
  744. wait_for_message 20 "DHCP6_CONFIG_COMPLETE" 1
  745. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  746. "Timeout waiting for ${kea6_name} to start. \
  747. Expected wait_for_message return %d, returned %d."
  748. # Wait up to 20s for the DHCPv4 server to configure.
  749. wait_for_message 20 "DHCP4_CONFIG_COMPLETE" 1
  750. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  751. "Timeout waiting for ${kea4_name} to start. \
  752. Expected wait_for_message return %d, returned %d."
  753. # Wait up to 20s for the D2 and CA to configure.
  754. wait_for_message 20 "DCTL_CONFIG_COMPLETE" 2
  755. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  756. "Timeout waiting for ${d2_name} to start. \
  757. Expected wait_for_message return %d, returned %d."
  758. # Make sure that debug messages are not logged (non-verbose mode).
  759. get_log_messages "DHCP6_START_INFO"
  760. assert_eq 0 ${_GET_LOG_MESSAGES} \
  761. "Expected get_log_messages return %d, returned %d."
  762. get_log_messages "DHCP4_START_INFO"
  763. assert_eq 0 ${_GET_LOG_MESSAGES} \
  764. "Expected get_log_messages return %d, returned %d."
  765. get_log_messages "DCTL_STANDALONE"
  766. assert_eq 0 ${_GET_LOG_MESSAGES} \
  767. "Expected get_log_messages return %d, returned %d."
  768. # Server may shut down imediatelly after configuration has competed.
  769. # Give it some time to shutdown.
  770. sleep 3
  771. # Make sure that all servers are running.
  772. get_pid ${kea4_name}
  773. assert_eq 1 ${_GET_PIDS_NUM} \
  774. "Expected %d ${kea4_name} process running, found %d processes running"
  775. get_pid ${kea6_name}
  776. assert_eq 1 ${_GET_PIDS_NUM} \
  777. "Expected %d ${kea6_name} process running, found %d processes running"
  778. get_pid ${d2_name}
  779. assert_eq 1 ${_GET_PIDS_NUM} \
  780. "Expected %d ${d2_name} process running, found %d processes running"
  781. get_pid ${agent_name}
  782. assert_eq 1 ${_GET_PIDS_NUM} \
  783. "Expected %d ${agent_name} process running, found %d processes running"
  784. # Use keactrl stop to shutdown DHCPv4 server.
  785. printf "Stopping DHCPv4 server: ${keactrl} stop -s dhcp4 -c ${KEACTRL_CFG_FILE}\n"
  786. ${keactrl} stop -s dhcp4 -c ${KEACTRL_CFG_FILE}
  787. ret=${?}
  788. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  789. # Wait up to 10s for the DHCPv4 server to stop.
  790. wait_for_message 10 "DHCP4_SHUTDOWN" 1
  791. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  792. "Timeout waiting for ${kea4_name} to shutdown. \
  793. Expected wait_for_message return %d, returned %d."
  794. # Make sure that the DHCPv4 server is down.
  795. wait_for_server_down 5 ${kea4_name}
  796. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  797. "Expected wait_for_server_down return %d, returned %d"
  798. # Make sure DHCPv6 server is still running
  799. get_pid ${kea6_name}
  800. assert_eq 1 ${_GET_PIDS_NUM} \
  801. "Expected %d ${kea6_name} process running, found %d processes running"
  802. # Make sure D2 server is still running
  803. get_pid ${kea6_name}
  804. assert_eq 1 ${_GET_PIDS_NUM} \
  805. "Expected %d ${d2_name} process running, found %d processes running"
  806. # Make sure CA is still running
  807. get_pid ${agent_name}
  808. assert_eq 1 ${_GET_PIDS_NUM} \
  809. "Expected %d ${agent_name} process running, found %d processes running"
  810. # Use keactrl stop to shutdown DHCPv6 server.
  811. printf "Stopping DHCPv6 server: ${keactrl} stop -s dhcp6 -c ${KEACTRL_CFG_FILE}\n"
  812. ${keactrl} stop -s dhcp6 -c ${KEACTRL_CFG_FILE}
  813. ret=${?}
  814. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  815. # Wait up to 10s for the DHCPv6 server to stop.
  816. wait_for_message 10 "DHCP6_SHUTDOWN" 1
  817. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  818. "Timeout waiting for ${kea6_name} to shutdown. \
  819. Expected wait_for_message return %d, returned %d."
  820. # Make sure that the DHCPv6 server is down.
  821. wait_for_server_down 5 ${kea6_name}
  822. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  823. "Expected wait_for_server_down return %d, returned %d"
  824. # Make sure D2 server is still running
  825. get_pid ${d2_name}
  826. assert_eq 1 ${_GET_PIDS_NUM} \
  827. "Expected %d ${d2_name} process running, found %d processes running"
  828. # Make sure CA is still running
  829. get_pid ${agent_name}
  830. assert_eq 1 ${_GET_PIDS_NUM} \
  831. "Expected %d ${agent_name} process running, found %d processes running"
  832. # Use keactrl stop to shutdown D2 server.
  833. printf "Stopping DHCP DDNS server: ${keactrl} stop -s dhcp_ddns -c ${KEACTRL_CFG_FILE}\n"
  834. ${keactrl} stop -s dhcp_ddns -c ${KEACTRL_CFG_FILE}
  835. ret=${?}
  836. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  837. # Wait up to 10s for the D2 server to stop.
  838. wait_for_message 10 "DCTL_SHUTDOWN" 1
  839. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  840. "Timeout waiting for ${d2_name} to shutdown. \
  841. Expected wait_for_message return %d, returned %d."
  842. # Make sure that the D2 server is down.
  843. wait_for_server_down 5 ${d2_name}
  844. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  845. "Expected wait_for_server_down return %d, returned %d"
  846. # Make sure CA is still running
  847. get_pid ${agent_name}
  848. assert_eq 1 ${_GET_PIDS_NUM} \
  849. "Expected %d ${agent_name} process running, found %d processes running"
  850. # Use keactrl stop to shutdown CA.
  851. printf "Stopping DHCP DDNS server: ${keactrl} stop -s ctrl_agent -c ${KEACTRL_CFG_FILE}\n"
  852. ${keactrl} stop -s ctrl_agent -c ${KEACTRL_CFG_FILE}
  853. ret=${?}
  854. assert_eq 0 ${ret} "Expected keactrl to return %d, returned value was %d."
  855. # Wait up to 10s for the CA to stop.
  856. wait_for_message 10 "DCTL_SHUTDOWN" 2
  857. assert_eq 1 ${_WAIT_FOR_MESSAGE} \
  858. "Timeout waiting for ${agent_name} to shutdown. \
  859. Expected wait_for_message return %d, returned %d."
  860. # Make sure that the CA is down.
  861. wait_for_server_down 5 ${agent_name}
  862. assert_eq 1 ${_WAIT_FOR_SERVER_DOWN} \
  863. "Expected wait_for_server_down return %d, returned %d"
  864. test_finish 0
  865. }
  866. # This test checks that the "status" command doesn't check the presence of the
  867. # config file.
  868. status_no_config_test() {
  869. test_start "keactrl.status_no_config_test"
  870. # Make sure that all config files are removed.
  871. cleanup
  872. # Create keactrl configuration file.
  873. create_keactrl_config "${keactrl_config}"
  874. # Make sure that the "status" command doesn't check the presence of
  875. # the config file.
  876. printf "Getting status without a Kea config file\n"
  877. output=$( ${keactrl} status -c ${KEACTRL_CFG_FILE} )
  878. ret=${?}
  879. assert_eq 1 ${ret} "Expected keactrl to return %d, returned %d"
  880. assert_string_contains "DHCPv4 server: inactive" "${output}" \
  881. "Expected keactrl status command return %s"
  882. assert_string_contains "DHCPv6 server: inactive" "${output}" \
  883. "Expected keactrl status command return %s"
  884. assert_string_contains "DHCP DDNS: inactive" "${output}" \
  885. "Expected keactrl status command return %s"
  886. assert_string_contains "Control Agent: inactive" "${output}" \
  887. "Expected keactrl status command return %s"
  888. assert_string_contains "Configuration file for Kea does not exist" \
  889. "${output}" "Expected keactrl status command return %s"
  890. test_finish 0
  891. }
  892. start_all_servers_no_verbose_test
  893. start_all_servers_verbose_test
  894. start_v4_server_test
  895. start_v6_server_test
  896. late_start_v4_server_test
  897. late_start_v6_server_test
  898. stop_selected_server_test
  899. status_no_config_test