disk_monitoring_test.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2018 Red Hat, Inc.
  3. # All rights reserved.
  4. #
  5. # License: GPL (version 3 or any later version).
  6. # See LICENSE for details.
  7. # --- END COPYRIGHT BLOCK ---
  8. import os
  9. import subprocess
  10. import re
  11. import time
  12. import pytest
  13. from lib389.tasks import *
  14. from lib389._constants import *
  15. from lib389.utils import ensure_bytes
  16. from lib389.backend import Backends
  17. from lib389.topologies import topology_st as topo
  18. from lib389.paths import *
  19. from lib389.idm.user import UserAccounts
  20. pytestmark = pytest.mark.tier2
  21. disk_monitoring_ack = pytest.mark.skipif(not os.environ.get('DISK_MONITORING_ACK', False), reason="Disk monitoring tests may damage system configuration.")
  22. THRESHOLD = '30'
  23. THRESHOLD_BYTES = '30000000'
  24. def _withouterrorlog(topo, condition, maxtimesleep):
  25. timecount = 0
  26. while eval(condition):
  27. time.sleep(1)
  28. timecount += 1
  29. if timecount >= maxtimesleep: break
  30. assert not eval(condition)
  31. def _witherrorlog(topo, condition, maxtimesleep):
  32. timecount = 0
  33. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  34. while condition not in study:
  35. time.sleep(1)
  36. timecount += 1
  37. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  38. if timecount >= maxtimesleep: break
  39. assert condition in study
  40. def presetup(topo):
  41. """
  42. This is function is part of fixture function setup , will setup the environment for this test.
  43. """
  44. topo.standalone.stop()
  45. if os.path.exists(topo.standalone.ds_paths.log_dir):
  46. subprocess.call(['mount', '-t', 'tmpfs', '-o', 'size=35M', 'tmpfs', topo.standalone.ds_paths.log_dir])
  47. else:
  48. os.mkdir(topo.standalone.ds_paths.log_dir)
  49. subprocess.call(['mount', '-t', 'tmpfs', '-o', 'size=35M', 'tmpfs', topo.standalone.ds_paths.log_dir])
  50. subprocess.call('chown {}: -R {}'.format(DEFAULT_USER, topo.standalone.ds_paths.log_dir), shell=True)
  51. subprocess.call('chown {}: -R {}/*'.format(DEFAULT_USER, topo.standalone.ds_paths.log_dir), shell=True)
  52. subprocess.call('restorecon -FvvR {}'.format(topo.standalone.ds_paths.log_dir), shell=True)
  53. topo.standalone.start()
  54. def setupthesystem(topo):
  55. """
  56. This function is part of fixture function setup , will setup the environment for this test.
  57. """
  58. global TOTAL_SIZE, USED_SIZE, AVAIL_SIZE, HALF_THR_FILL_SIZE, FULL_THR_FILL_SIZE
  59. topo.standalone.start()
  60. topo.standalone.config.set('nsslapd-disk-monitoring-grace-period', '1')
  61. topo.standalone.config.set('nsslapd-accesslog-logbuffering', 'off')
  62. topo.standalone.config.set('nsslapd-disk-monitoring-threshold', ensure_bytes(THRESHOLD_BYTES))
  63. TOTAL_SIZE = int(re.findall(r'\d+', str(os.statvfs(topo.standalone.ds_paths.log_dir)))[2])*4096/1024/1024
  64. AVAIL_SIZE = round(int(re.findall(r'\d+', str(os.statvfs(topo.standalone.ds_paths.log_dir)))[3]) * 4096 / 1024 / 1024)
  65. USED_SIZE = TOTAL_SIZE - AVAIL_SIZE
  66. HALF_THR_FILL_SIZE = TOTAL_SIZE - float(THRESHOLD) + 5 - USED_SIZE
  67. FULL_THR_FILL_SIZE = TOTAL_SIZE - 0.5 * float(THRESHOLD) + 5 - USED_SIZE
  68. HALF_THR_FILL_SIZE = round(HALF_THR_FILL_SIZE)
  69. FULL_THR_FILL_SIZE = round(FULL_THR_FILL_SIZE)
  70. topo.standalone.restart()
  71. @pytest.fixture(scope="module")
  72. def setup(request, topo):
  73. """
  74. This is the fixture function , will run before running every test case.
  75. """
  76. presetup(topo)
  77. setupthesystem(topo)
  78. def fin():
  79. topo.standalone.stop()
  80. subprocess.call(['umount', '-fl', topo.standalone.ds_paths.log_dir])
  81. topo.standalone.start()
  82. request.addfinalizer(fin)
  83. @pytest.fixture(scope="function")
  84. def reset_logs(topo):
  85. """
  86. Reset the errors log file before the test
  87. """
  88. open('{}/errors'.format(topo.standalone.ds_paths.log_dir), 'w').close()
  89. @disk_monitoring_ack
  90. def test_verify_operation_when_disk_monitoring_is_off(topo, setup, reset_logs):
  91. """Verify operation when Disk monitoring is off
  92. :id: 73a97536-fe9e-11e8-ba9f-8c16451d917b
  93. :setup: Standalone
  94. :steps:
  95. 1. Turn off disk monitoring
  96. 2. Go below the threshold
  97. 3. Check DS is up and not entering shutdown mode
  98. :expectedresults:
  99. 1. Should Success
  100. 2. Should Success
  101. 3. Should Success
  102. """
  103. try:
  104. # Turn off disk monitoring
  105. topo.standalone.config.set('nsslapd-disk-monitoring', 'off')
  106. topo.standalone.restart()
  107. # go below the threshold
  108. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  109. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo1'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  110. # Wait for disk monitoring plugin thread to wake up
  111. _withouterrorlog(topo, 'topo.standalone.status() != True', 10)
  112. # Check DS is up and not entering shutdown mode
  113. assert topo.standalone.status() == True
  114. finally:
  115. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  116. os.remove('{}/foo1'.format(topo.standalone.ds_paths.log_dir))
  117. @disk_monitoring_ack
  118. def test_free_up_the_disk_space_and_change_ds_config(topo, setup, reset_logs):
  119. """Free up the disk space and change DS config
  120. :id: 7be4d560-fe9e-11e8-a307-8c16451d917b
  121. :setup: Standalone
  122. :steps:
  123. 1. Enabling Disk Monitoring plugin and setting disk monitoring logging to critical
  124. 2. Verify no message about loglevel is present in the error log
  125. 3. Verify no message about disabling logging is present in the error log
  126. 4. Verify no message about removing rotated logs is present in the error log
  127. :expectedresults:
  128. 1. Should Success
  129. 2. Should Success
  130. 3. Should Success
  131. 4. Should Success
  132. """
  133. # Enabling Disk Monitoring plugin and setting disk monitoring logging to critical
  134. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  135. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')
  136. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  137. topo.standalone.restart()
  138. # Verify no message about loglevel is present in the error log
  139. # Verify no message about disabling logging is present in the error log
  140. # Verify no message about removing rotated logs is present in the error log
  141. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  142. assert 'temporarily setting error loglevel to zero' not in study
  143. assert 'disabling access and audit logging' not in study
  144. assert 'deleting rotated logs' not in study
  145. @disk_monitoring_ack
  146. def test_verify_operation_with_nsslapd_disk_monitoring_logging_critical_off(topo, setup, reset_logs):
  147. """Verify operation with "nsslapd-disk-monitoring-logging-critical: off
  148. :id: 82363bca-fe9e-11e8-9ae7-8c16451d917b
  149. :setup: Standalone
  150. :steps:
  151. 1. Verify that verbose logging was set to default level
  152. 2. Verify that logging is disabled
  153. 3. Verify that rotated logs were not removed
  154. :expectedresults:
  155. 1. Should Success
  156. 2. Should Success
  157. 3. Should Success
  158. """
  159. try:
  160. # Verify that verbose logging was set to default level
  161. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  162. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')
  163. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  164. topo.standalone.restart()
  165. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(HALF_THR_FILL_SIZE)])
  166. _witherrorlog(topo, 'temporarily setting error loglevel to the default level', 11)
  167. assert LOG_DEFAULT == int(re.findall(r'nsslapd-errorlog-level: \d+', str(
  168. topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)', ['nsslapd-errorlog-level'])))[
  169. 0].split(' ')[1])
  170. # Verify that logging is disabled
  171. _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'off'", 10)
  172. assert topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') == 'off'
  173. # Verify that rotated logs were not removed
  174. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  175. assert 'disabling access and audit logging' in study
  176. _witherrorlog(topo, 'deleting rotated logs', 11)
  177. study = open(topo.standalone.errlog).read()
  178. assert "Unable to remove file: {}".format(topo.standalone.ds_paths.log_dir) not in study
  179. assert 'is too far below the threshold' not in study
  180. finally:
  181. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  182. @disk_monitoring_ack
  183. def test_operation_with_nsslapd_disk_monitoring_logging_critical_on_below_half_of_the_threshold(topo, setup, reset_logs):
  184. """Verify operation with \"nsslapd-disk-monitoring-logging-critical: on\" below 1/2 of the threshold
  185. Verify recovery
  186. :id: 8940c502-fe9e-11e8-bcc0-8c16451d917b
  187. :setup: Standalone
  188. :steps:
  189. 1. Verify that DS goes into shutdown mode
  190. 2. Verify that DS exited shutdown mode
  191. :expectedresults:
  192. 1. Should Success
  193. 2. Should Success
  194. """
  195. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  196. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')
  197. topo.standalone.restart()
  198. # Verify that DS goes into shutdown mode
  199. if float(THRESHOLD) > FULL_THR_FILL_SIZE:
  200. FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE) + 1
  201. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE_new)])
  202. else:
  203. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  204. _witherrorlog(topo, 'is too far below the threshold', 20)
  205. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  206. # Verify that DS exited shutdown mode
  207. _witherrorlog(topo, 'Available disk space is now acceptable', 25)
  208. @disk_monitoring_ack
  209. def test_setting_nsslapd_disk_monitoring_logging_critical_to_off(topo, setup, reset_logs):
  210. """Setting nsslapd-disk-monitoring-logging-critical to "off"
  211. :id: 93265ec4-fe9e-11e8-af93-8c16451d917b
  212. :setup: Standalone
  213. :steps:
  214. 1. Setting nsslapd-disk-monitoring-logging-critical to "off"
  215. :expectedresults:
  216. 1. Should Success
  217. """
  218. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  219. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')
  220. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  221. topo.standalone.restart()
  222. assert topo.standalone.status() == True
  223. @disk_monitoring_ack
  224. def test_operation_with_nsslapd_disk_monitoring_logging_critical_off(topo, setup, reset_logs):
  225. """Verify operation with nsslapd-disk-monitoring-logging-critical: off
  226. :id: 97985a52-fe9e-11e8-9914-8c16451d917b
  227. :setup: Standalone
  228. :steps:
  229. 1. Verify that logging is disabled
  230. 2. Verify that rotated logs were removed
  231. 3. Verify that verbose logging was set to default level
  232. 4. Verify that logging is disabled
  233. 5. Verify that rotated logs were removed
  234. :expectedresults:
  235. 1. Should Success
  236. 2. Should Success
  237. 3. Should Success
  238. 4. Should Success
  239. 5. Should Success
  240. """
  241. # Verify that logging is disabled
  242. try:
  243. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  244. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')
  245. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  246. assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '1')
  247. assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'minute')
  248. assert topo.standalone.config.set('nsslapd-accesslog-level', '772')
  249. topo.standalone.restart()
  250. # Verify that rotated logs were removed
  251. users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
  252. for i in range(10):
  253. user_properties = {
  254. 'uid': 'cn=anuj{}'.format(i),
  255. 'cn': 'cn=anuj{}'.format(i),
  256. 'sn': 'cn=anuj{}'.format(i),
  257. 'userPassword': "Itsme123",
  258. 'uidNumber': '1{}'.format(i),
  259. 'gidNumber': '2{}'.format(i),
  260. 'homeDirectory': '/home/{}'.format(i)
  261. }
  262. users.create(properties=user_properties)
  263. for j in range(100):
  264. for i in [i for i in users.list()]: i.bind('Itsme123')
  265. assert re.findall(r'access.\d+-\d+',str(os.listdir(topo.standalone.ds_paths.log_dir)))
  266. topo.standalone.bind_s(DN_DM, PW_DM)
  267. assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '100')
  268. assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'day')
  269. assert topo.standalone.config.set('nsslapd-accesslog-level', '256')
  270. topo.standalone.restart()
  271. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo2'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(HALF_THR_FILL_SIZE)])
  272. # Verify that verbose logging was set to default level
  273. _witherrorlog(topo, 'temporarily setting error loglevel to the default level', 10)
  274. assert LOG_DEFAULT == int(re.findall(r'nsslapd-errorlog-level: \d+', str(
  275. topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)', ['nsslapd-errorlog-level'])))[0].split(' ')[1])
  276. # Verify that logging is disabled
  277. _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'off'", 20)
  278. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  279. assert 'disabling access and audit logging' in study
  280. # Verify that rotated logs were removed
  281. _witherrorlog(topo, 'deleting rotated logs', 10)
  282. with open(topo.standalone.errlog, 'r') as study:study = study.read()
  283. assert 'Unable to remove file:' not in study
  284. assert 'is too far below the threshold' not in study
  285. for i in [i for i in users.list()]: i.delete()
  286. finally:
  287. os.remove('{}/foo2'.format(topo.standalone.ds_paths.log_dir))
  288. @disk_monitoring_ack
  289. def test_operation_with_nsslapd_disk_monitoring_logging_critical_off_below_half_of_the_threshold(topo, setup, reset_logs):
  290. """Verify operation with nsslapd-disk-monitoring-logging-critical: off below 1/2 of the threshold
  291. Verify shutdown
  292. Recovery and setup
  293. :id: 9d4c7d48-fe9e-11e8-b5d6-8c16451d917b
  294. :setup: Standalone
  295. :steps:
  296. 1. Verify that DS goes into shutdown mode
  297. 2. Verifying that DS has been shut down after the grace period
  298. 3. Verify logging enabled
  299. 4. Create rotated logfile
  300. 5. Enable verbose logging
  301. :expectedresults:
  302. 1. Should Success
  303. 2. Should Success
  304. 3. Should Success
  305. 4. Should Success
  306. 5. Should Success
  307. """
  308. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  309. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')
  310. topo.standalone.restart()
  311. # Verify that DS goes into shutdown mode
  312. if float(THRESHOLD) > FULL_THR_FILL_SIZE:
  313. FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE)
  314. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE_new)])
  315. else:
  316. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  317. # Increased sleep to avoid failure
  318. _witherrorlog(topo, 'is too far below the threshold', 100)
  319. _witherrorlog(topo, 'Signaling slapd for shutdown', 90)
  320. # Verifying that DS has been shut down after the grace period
  321. time.sleep(2)
  322. assert topo.standalone.status() == False
  323. # free_space
  324. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  325. open('{}/errors'.format(topo.standalone.ds_paths.log_dir), 'w').close()
  326. # StartSlapd
  327. topo.standalone.start()
  328. # verify logging enabled
  329. assert topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') == 'on'
  330. assert topo.standalone.config.get_attr_val_utf8('nsslapd-errorlog-logging-enabled') == 'on'
  331. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  332. assert 'disabling access and audit logging' not in study
  333. assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '1')
  334. assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'minute')
  335. assert topo.standalone.config.set('nsslapd-accesslog-level', '772')
  336. topo.standalone.restart()
  337. # create rotated logfile
  338. users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
  339. for i in range(10):
  340. user_properties = {
  341. 'uid': 'cn=anuj{}'.format(i),
  342. 'cn': 'cn=anuj{}'.format(i),
  343. 'sn': 'cn=anuj{}'.format(i),
  344. 'userPassword': "Itsme123",
  345. 'uidNumber': '1{}'.format(i),
  346. 'gidNumber': '2{}'.format(i),
  347. 'homeDirectory': '/home/{}'.format(i)
  348. }
  349. users.create(properties=user_properties)
  350. for j in range(100):
  351. for i in [i for i in users.list()]: i.bind('Itsme123')
  352. assert re.findall(r'access.\d+-\d+',str(os.listdir(topo.standalone.ds_paths.log_dir)))
  353. topo.standalone.bind_s(DN_DM, PW_DM)
  354. # enable verbose logging
  355. assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '100')
  356. assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'day')
  357. assert topo.standalone.config.set('nsslapd-accesslog-level', '256')
  358. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  359. topo.standalone.restart()
  360. for i in [i for i in users.list()]: i.delete()
  361. @disk_monitoring_ack
  362. def test_go_straight_below_half_of_the_threshold(topo, setup, reset_logs):
  363. """Go straight below 1/2 of the threshold
  364. Recovery and setup
  365. :id: a2a0664c-fe9e-11e8-b220-8c16451d917b
  366. :setup: Standalone
  367. :steps:
  368. 1. Go straight below 1/2 of the threshold
  369. 2. Verify that verbose logging was set to default level
  370. 3. Verify that logging is disabled
  371. 4. Verify DS is in shutdown mode
  372. 5. Verify DS has recovered from shutdown
  373. :expectedresults:
  374. 1. Should Success
  375. 2. Should Success
  376. 3. Should Success
  377. 4. Should Success
  378. 5. Should Success
  379. """
  380. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  381. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')
  382. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  383. topo.standalone.restart()
  384. if float(THRESHOLD) > FULL_THR_FILL_SIZE:
  385. FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE) + 1
  386. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE_new)])
  387. else:
  388. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  389. _witherrorlog(topo, 'temporarily setting error loglevel to the default level', 11)
  390. # Verify that verbose logging was set to default level
  391. assert LOG_DEFAULT == int(re.findall(r'nsslapd-errorlog-level: \d+',
  392. str(topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE,
  393. '(objectclass=*)',
  394. ['nsslapd-errorlog-level']))
  395. )[0].split(' ')[1])
  396. # Verify that logging is disabled
  397. _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'off'", 11)
  398. # Verify that rotated logs were removed
  399. _witherrorlog(topo, 'disabling access and audit logging', 2)
  400. _witherrorlog(topo, 'deleting rotated logs', 11)
  401. with open(topo.standalone.errlog, 'r') as study:study = study.read()
  402. assert 'Unable to remove file:' not in study
  403. # Verify DS is in shutdown mode
  404. _withouterrorlog(topo, 'topo.standalone.status() != False', 90)
  405. _witherrorlog(topo, 'is too far below the threshold', 2)
  406. # Verify DS has recovered from shutdown
  407. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  408. open('{}/errors'.format(topo.standalone.ds_paths.log_dir), 'w').close()
  409. topo.standalone.start()
  410. _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'on'", 20)
  411. with open(topo.standalone.errlog, 'r') as study: study = study.read()
  412. assert 'disabling access and audit logging' not in study
  413. @disk_monitoring_ack
  414. def test_readonly_on_threshold(topo, setup, reset_logs):
  415. """Verify that nsslapd-disk-monitoring-readonly-on-threshold switches the server to read-only mode
  416. :id: 06814c19-ef3c-4800-93c9-c7c6e76fcbb9
  417. :setup: Standalone
  418. :steps:
  419. 1. Verify that the backend is in read-only mode
  420. 2. Go back above the threshold
  421. 3. Verify that the backend is in read-write mode
  422. :expectedresults:
  423. 1. Should Success
  424. 2. Should Success
  425. 3. Should Success
  426. """
  427. file_path = '{}/foo'.format(topo.standalone.ds_paths.log_dir)
  428. backends = Backends(topo.standalone)
  429. backend_name = backends.list()[0].rdn
  430. # Verify that verbose logging was set to default level
  431. topo.standalone.deleteErrorLogs()
  432. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  433. assert topo.standalone.config.set('nsslapd-disk-monitoring-readonly-on-threshold', 'on')
  434. topo.standalone.restart()
  435. try:
  436. subprocess.call(['dd', 'if=/dev/zero', f'of={file_path}', 'bs=1M', f'count={HALF_THR_FILL_SIZE}'])
  437. _witherrorlog(topo, f"Putting the backend '{backend_name}' to read-only mode", 11)
  438. users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
  439. try:
  440. user = users.create_test_user()
  441. user.delete()
  442. except ldap.UNWILLING_TO_PERFORM as e:
  443. if 'database is read-only' not in str(e):
  444. raise
  445. os.remove(file_path)
  446. _witherrorlog(topo, f"Putting the backend '{backend_name}' back to read-write mode", 11)
  447. user = users.create_test_user()
  448. assert user.exists()
  449. user.delete()
  450. finally:
  451. if os.path.exists(file_path):
  452. os.remove(file_path)
  453. @disk_monitoring_ack
  454. def test_readonly_on_threshold_below_half_of_the_threshold(topo, setup, reset_logs):
  455. """Go below 1/2 of the threshold when readonly on threshold is enabled
  456. :id: 10262663-b41f-420e-a2d0-9532dd54fa7c
  457. :setup: Standalone
  458. :steps:
  459. :expectedresults:
  460. 1. Go straight below 1/2 of the threshold
  461. 2. Verify that the backend is in read-only mode
  462. 3. Go back above the threshold
  463. 4. Verify that the backend is in read-write mode
  464. :expectedresults:
  465. 1. Should Success
  466. 2. Should Success
  467. 3. Should Success
  468. 4. Should Success
  469. """
  470. file_path = '{}/foo'.format(topo.standalone.ds_paths.log_dir)
  471. backends = Backends(topo.standalone)
  472. backend_name = backends.list()[0].rdn
  473. topo.standalone.deleteErrorLogs()
  474. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  475. assert topo.standalone.config.set('nsslapd-disk-monitoring-readonly-on-threshold', 'on')
  476. topo.standalone.restart()
  477. try:
  478. if float(THRESHOLD) > FULL_THR_FILL_SIZE:
  479. FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE) + 1
  480. subprocess.call(['dd', 'if=/dev/zero', f'of={file_path}', 'bs=1M', f'count={FULL_THR_FILL_SIZE_new}'])
  481. else:
  482. subprocess.call(['dd', 'if=/dev/zero', f'of={file_path}', 'bs=1M', f'count={FULL_THR_FILL_SIZE}'])
  483. _witherrorlog(topo, f"Putting the backend '{backend_name}' to read-only mode", 11)
  484. users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)
  485. try:
  486. user = users.create_test_user()
  487. user.delete()
  488. except ldap.UNWILLING_TO_PERFORM as e:
  489. if 'database is read-only' not in str(e):
  490. raise
  491. _witherrorlog(topo, 'is too far below the threshold', 51)
  492. # Verify DS has recovered from shutdown
  493. os.remove(file_path)
  494. _witherrorlog(topo, f"Putting the backend '{backend_name}' back to read-write mode", 51)
  495. user = users.create_test_user()
  496. assert user.exists()
  497. user.delete()
  498. finally:
  499. if os.path.exists(file_path):
  500. os.remove(file_path)
  501. @disk_monitoring_ack
  502. def test_below_half_of_the_threshold_not_starting_after_shutdown(topo, setup, reset_logs):
  503. """Test that the instance won't start if we are below 1/2 of the threshold
  504. :id: cceeaefd-9fa4-45c5-9ac6-9887a0671ef8
  505. :setup: Standalone
  506. :steps:
  507. 1. Go straight below 1/2 of the threshold
  508. 2. Try to start the instance
  509. 3. Go back above the threshold
  510. 4. Try to start the instance
  511. :expectedresults:
  512. 1. Should Success
  513. 2. Should Fail
  514. 3. Should Success
  515. 4. Should Success
  516. """
  517. file_path = '{}/foo'.format(topo.standalone.ds_paths.log_dir)
  518. topo.standalone.deleteErrorLogs()
  519. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  520. topo.standalone.restart()
  521. try:
  522. if float(THRESHOLD) > FULL_THR_FILL_SIZE:
  523. FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE) + 1
  524. subprocess.call(['dd', 'if=/dev/zero', f'of={file_path}', 'bs=1M', f'count={FULL_THR_FILL_SIZE_new}'])
  525. else:
  526. subprocess.call(['dd', 'if=/dev/zero', f'of={file_path}', 'bs=1M', f'count={FULL_THR_FILL_SIZE}'])
  527. _withouterrorlog(topo, 'topo.standalone.status() == True', 120)
  528. try:
  529. topo.standalone.start()
  530. except (ValueError, subprocess.CalledProcessError):
  531. topo.standalone.log.info("Instance start up has failed as expected")
  532. _witherrorlog(topo, f'is too far below the threshold({THRESHOLD_BYTES} bytes). Exiting now', 2)
  533. # Verify DS has recovered from shutdown
  534. os.remove(file_path)
  535. topo.standalone.start()
  536. finally:
  537. if os.path.exists(file_path):
  538. os.remove(file_path)
  539. @disk_monitoring_ack
  540. def test_go_straight_below_4kb(topo, setup, reset_logs):
  541. """Go straight below 4KB
  542. :id: a855115a-fe9e-11e8-8e91-8c16451d917b
  543. :setup: Standalone
  544. :steps:
  545. 1. Go straight below 4KB
  546. 2. Clean space
  547. :expectedresults:
  548. 1. Should Success
  549. 2. Should Success
  550. """
  551. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  552. topo.standalone.restart()
  553. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  554. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo1'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])
  555. _withouterrorlog(topo, 'topo.standalone.status() != False', 11)
  556. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  557. os.remove('{}/foo1'.format(topo.standalone.ds_paths.log_dir))
  558. topo.standalone.start()
  559. assert topo.standalone.status() == True
  560. @disk_monitoring_ack
  561. @pytest.mark.bz982325
  562. def test_threshold_to_overflow_value(topo, setup, reset_logs):
  563. """Overflow in nsslapd-disk-monitoring-threshold
  564. :id: ad60ab3c-fe9e-11e8-88dc-8c16451d917b
  565. :setup: Standalone
  566. :steps:
  567. 1. Setting nsslapd-disk-monitoring-threshold to overflow_value
  568. :expectedresults:
  569. 1. Should Success
  570. """
  571. overflow_value = '3000000000'
  572. # Setting nsslapd-disk-monitoring-threshold to overflow_value
  573. assert topo.standalone.config.set('nsslapd-disk-monitoring-threshold', ensure_bytes(overflow_value))
  574. assert overflow_value == re.findall(r'nsslapd-disk-monitoring-threshold: \d+', str(
  575. topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)',
  576. ['nsslapd-disk-monitoring-threshold'])))[0].split(' ')[1]
  577. @disk_monitoring_ack
  578. @pytest.mark.bz970995
  579. def test_threshold_is_reached_to_half(topo, setup, reset_logs):
  580. """RHDS not shutting down when disk monitoring threshold is reached to half.
  581. :id: b2d3665e-fe9e-11e8-b9c0-8c16451d917b
  582. :setup: Standalone
  583. :steps: Standalone
  584. 1. Verify that there is not endless loop of error messages
  585. :expectedresults:
  586. 1. Should Success
  587. """
  588. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  589. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')
  590. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  591. assert topo.standalone.config.set('nsslapd-disk-monitoring-threshold', ensure_bytes(THRESHOLD_BYTES))
  592. topo.standalone.restart()
  593. subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(HALF_THR_FILL_SIZE)])
  594. # Verify that there is not endless loop of error messages
  595. _witherrorlog(topo, "temporarily setting error loglevel to the default level", 10)
  596. with open(topo.standalone.errlog, 'r') as study:study = study.read()
  597. assert len(re.findall("temporarily setting error loglevel to the default level", study)) == 1
  598. os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))
  599. @disk_monitoring_ack
  600. @pytest.mark.parametrize("test_input,expected", [
  601. ("nsslapd-disk-monitoring-threshold", '-2'),
  602. ("nsslapd-disk-monitoring-threshold", '9223372036854775808'),
  603. ("nsslapd-disk-monitoring-threshold", '2047'),
  604. ("nsslapd-disk-monitoring-threshold", '0'),
  605. ("nsslapd-disk-monitoring-threshold", '-1294967296'),
  606. ("nsslapd-disk-monitoring-threshold", 'invalid'),
  607. ("nsslapd-disk-monitoring", 'invalid'),
  608. ("nsslapd-disk-monitoring", '1'),
  609. ("nsslapd-disk-monitoring-grace-period", '0'),
  610. ("nsslapd-disk-monitoring-grace-period", '525 948'),
  611. ("nsslapd-disk-monitoring-grace-period", '-1'),
  612. ("nsslapd-disk-monitoring-logging-critical", 'oninvalid'),
  613. ("nsslapd-disk-monitoring-grace-period", '-1'),
  614. ("nsslapd-disk-monitoring-grace-period", '0'),
  615. ])
  616. def test_negagtive_parameterize(topo, setup, reset_logs, test_input, expected):
  617. """Verify that invalid operations are not permitted
  618. :id: b88efbf8-fe9e-11e8-8499-8c16451d917b
  619. :parametrized: yes
  620. :setup: Standalone
  621. :steps:
  622. 1. Verify that invalid operations are not permitted.
  623. :expectedresults:
  624. 1. Should not success.
  625. """
  626. with pytest.raises(Exception):
  627. topo.standalone.config.set(test_input, ensure_bytes(expected))
  628. @disk_monitoring_ack
  629. def test_valid_operations_are_permitted(topo, setup, reset_logs):
  630. """Verify that valid operations are permitted
  631. :id: bd4f83f6-fe9e-11e8-88f4-8c16451d917b
  632. :setup: Standalone
  633. :steps:
  634. 1. Verify that valid operations are permitted
  635. :expectedresults:
  636. 1. Should Success.
  637. """
  638. assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')
  639. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')
  640. assert topo.standalone.config.set('nsslapd-errorlog-level', '8')
  641. topo.standalone.restart()
  642. # Trying to delete nsslapd-disk-monitoring-threshold
  643. assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring-threshold', '')])
  644. # Trying to add another value to nsslapd-disk-monitoring-threshold (check that it is not multivalued)
  645. topo.standalone.config.add('nsslapd-disk-monitoring-threshold', '2000001')
  646. # Trying to delete nsslapd-disk-monitoring
  647. assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring', ensure_bytes(str(
  648. topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)', ['nsslapd-disk-monitoring'])[
  649. 0]).split(' ')[2].split('\n\n')[0]))])
  650. # Trying to add another value to nsslapd-disk-monitoring
  651. topo.standalone.config.add('nsslapd-disk-monitoring', 'off')
  652. # Trying to delete nsslapd-disk-monitoring-grace-period
  653. assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring-grace-period', '')])
  654. # Trying to add another value to nsslapd-disk-monitoring-grace-period
  655. topo.standalone.config.add('nsslapd-disk-monitoring-grace-period', '61')
  656. # Trying to delete nsslapd-disk-monitoring-logging-critical
  657. assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring-logging-critical',
  658. ensure_bytes(str(
  659. topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE,
  660. '(objectclass=*)', [
  661. 'nsslapd-disk-monitoring-logging-critical'])[
  662. 0]).split(' ')[2].split('\n\n')[0]))])
  663. # Trying to add another value to nsslapd-disk-monitoring-logging-critical
  664. assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')
  665. if __name__ == '__main__':
  666. CURRENT_FILE = os.path.realpath(__file__)
  667. pytest.main("-s -v %s" % CURRENT_FILE)