basic_test.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2015 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. #
  9. import os
  10. import sys
  11. import time
  12. import ldap
  13. import ldap.sasl
  14. import logging
  15. import pytest
  16. import shutil
  17. from subprocess import check_output
  18. from lib389 import DirSrv, Entry, tools, tasks
  19. from lib389.tools import DirSrvTools
  20. from lib389._constants import *
  21. from lib389.properties import *
  22. from lib389.tasks import *
  23. from lib389.utils import *
  24. log = logging.getLogger(__name__)
  25. installation_prefix = None
  26. # Globals
  27. USER1_DN = 'uid=user1,' + DEFAULT_SUFFIX
  28. USER2_DN = 'uid=user2,' + DEFAULT_SUFFIX
  29. USER3_DN = 'uid=user3,' + DEFAULT_SUFFIX
  30. class TopologyStandalone(object):
  31. def __init__(self, standalone):
  32. standalone.open()
  33. self.standalone = standalone
  34. @pytest.fixture(scope="module")
  35. def topology(request):
  36. """This fixture is used to standalone topology for the 'module'."""
  37. global installation_prefix
  38. if installation_prefix:
  39. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  40. standalone = DirSrv(verbose=False)
  41. # Args for the standalone instance
  42. args_instance[SER_HOST] = HOST_STANDALONE
  43. args_instance[SER_PORT] = PORT_STANDALONE
  44. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  45. args_standalone = args_instance.copy()
  46. standalone.allocate(args_standalone)
  47. # Get the status of the instance and restart it if it exists
  48. instance_standalone = standalone.exists()
  49. # Remove the instance
  50. if instance_standalone:
  51. standalone.delete()
  52. # Create the instance
  53. standalone.create()
  54. # Used to retrieve configuration information (dbdir, confdir...)
  55. standalone.open()
  56. # Delete each instance in the end
  57. def fin():
  58. standalone.delete()
  59. request.addfinalizer(fin)
  60. # clear the tmp directory
  61. standalone.clearTmpDir(__file__)
  62. # Here we have standalone instance up and running
  63. return TopologyStandalone(standalone)
  64. @pytest.fixture(scope="module")
  65. def import_example_ldif(topology):
  66. """Import the Example LDIF for the tests in this suite"""
  67. log.info('Initializing the "basic" test suite')
  68. import_ldif = '%s/Example.ldif' % get_data_dir(topology.standalone.prefix)
  69. try:
  70. topology.standalone.tasks.importLDIF(suffix=DEFAULT_SUFFIX,
  71. input_file=import_ldif,
  72. args={TASK_WAIT: True})
  73. except ValueError:
  74. log.error('Online import failed')
  75. assert False
  76. def test_basic_ops(topology, import_example_ldif):
  77. """Test doing adds, mods, modrdns, and deletes"""
  78. log.info('Running test_basic_ops...')
  79. USER1_NEWDN = 'cn=user1'
  80. USER2_NEWDN = 'cn=user2'
  81. USER3_NEWDN = 'cn=user3'
  82. NEW_SUPERIOR = 'ou=people,' + DEFAULT_SUFFIX
  83. USER1_RDN_DN = 'cn=user1,' + DEFAULT_SUFFIX
  84. USER2_RDN_DN = 'cn=user2,' + DEFAULT_SUFFIX
  85. USER3_RDN_DN = 'cn=user3,' + NEW_SUPERIOR # New superior test
  86. #
  87. # Adds
  88. #
  89. try:
  90. topology.standalone.add_s(Entry((USER1_DN,
  91. {'objectclass': "top extensibleObject".split(),
  92. 'sn': '1',
  93. 'cn': 'user1',
  94. 'uid': 'user1',
  95. 'userpassword': 'password'})))
  96. except ldap.LDAPError as e:
  97. log.error('Failed to add test user' + USER1_DN + ': error ' + e.message['desc'])
  98. assert False
  99. try:
  100. topology.standalone.add_s(Entry((USER2_DN,
  101. {'objectclass': "top extensibleObject".split(),
  102. 'sn': '2',
  103. 'cn': 'user2',
  104. 'uid': 'user2',
  105. 'userpassword': 'password'})))
  106. except ldap.LDAPError as e:
  107. log.error('Failed to add test user' + USER2_DN + ': error ' + e.message['desc'])
  108. assert False
  109. try:
  110. topology.standalone.add_s(Entry((USER3_DN,
  111. {'objectclass': "top extensibleObject".split(),
  112. 'sn': '3',
  113. 'cn': 'user3',
  114. 'uid': 'user3',
  115. 'userpassword': 'password'})))
  116. except ldap.LDAPError as e:
  117. log.error('Failed to add test user' + USER3_DN + ': error ' + e.message['desc'])
  118. assert False
  119. #
  120. # Mods
  121. #
  122. try:
  123. topology.standalone.modify_s(USER1_DN, [(ldap.MOD_ADD, 'description',
  124. 'New description')])
  125. except ldap.LDAPError as e:
  126. log.error('Failed to add description: error ' + e.message['desc'])
  127. assert False
  128. try:
  129. topology.standalone.modify_s(USER1_DN, [(ldap.MOD_REPLACE, 'description',
  130. 'Modified description')])
  131. except ldap.LDAPError as e:
  132. log.error('Failed to modify description: error ' + e.message['desc'])
  133. assert False
  134. try:
  135. topology.standalone.modify_s(USER1_DN, [(ldap.MOD_DELETE, 'description',
  136. None)])
  137. except ldap.LDAPError as e:
  138. log.error('Failed to delete description: error ' + e.message['desc'])
  139. assert False
  140. #
  141. # Modrdns
  142. #
  143. try:
  144. topology.standalone.rename_s(USER1_DN, USER1_NEWDN, delold=1)
  145. except ldap.LDAPError as e:
  146. log.error('Failed to modrdn user1: error ' + e.message['desc'])
  147. assert False
  148. try:
  149. topology.standalone.rename_s(USER2_DN, USER2_NEWDN, delold=0)
  150. except ldap.LDAPError as e:
  151. log.error('Failed to modrdn user2: error ' + e.message['desc'])
  152. assert False
  153. # Modrdn - New superior
  154. try:
  155. topology.standalone.rename_s(USER3_DN, USER3_NEWDN,
  156. newsuperior=NEW_SUPERIOR, delold=1)
  157. except ldap.LDAPError as e:
  158. log.error('Failed to modrdn(new superior) user3: error ' + e.message['desc'])
  159. assert False
  160. #
  161. # Deletes
  162. #
  163. try:
  164. topology.standalone.delete_s(USER1_RDN_DN)
  165. except ldap.LDAPError as e:
  166. log.error('Failed to delete test entry1: ' + e.message['desc'])
  167. assert False
  168. try:
  169. topology.standalone.delete_s(USER2_RDN_DN)
  170. except ldap.LDAPError as e:
  171. log.error('Failed to delete test entry2: ' + e.message['desc'])
  172. assert False
  173. try:
  174. topology.standalone.delete_s(USER3_RDN_DN)
  175. except ldap.LDAPError as e:
  176. log.error('Failed to delete test entry3: ' + e.message['desc'])
  177. assert False
  178. log.info('test_basic_ops: PASSED')
  179. def test_basic_import_export(topology, import_example_ldif):
  180. """Test online and offline LDIF imports & exports"""
  181. log.info('Running test_basic_import_export...')
  182. tmp_dir = topology.standalone.getDir(__file__, TMP_DIR)
  183. #
  184. # Test online/offline LDIF imports
  185. #
  186. # Generate a test ldif (50k entries)
  187. import_ldif = tmp_dir + '/basic_import.ldif'
  188. try:
  189. topology.standalone.buildLDIF(50000, import_ldif)
  190. except OSError as e:
  191. log.fatal('test_basic_import_export: failed to create test ldif,\
  192. error: %s - %s' % (e.errno, e.strerror))
  193. assert False
  194. # Online
  195. try:
  196. topology.standalone.tasks.importLDIF(suffix=DEFAULT_SUFFIX,
  197. input_file=import_ldif,
  198. args={TASK_WAIT: True})
  199. except ValueError:
  200. log.fatal('test_basic_import_export: Online import failed')
  201. assert False
  202. # Offline
  203. if not topology.standalone.ldif2db(DEFAULT_BENAME, None, None, None, import_ldif):
  204. log.fatal('test_basic_import_export: Offline import failed')
  205. assert False
  206. #
  207. # Test online and offline LDIF export
  208. #
  209. # Online export
  210. export_ldif = tmp_dir + 'export.ldif'
  211. exportTask = Tasks(topology.standalone)
  212. try:
  213. args = {TASK_WAIT: True}
  214. exportTask.exportLDIF(DEFAULT_SUFFIX, None, export_ldif, args)
  215. except ValueError:
  216. log.fatal('test_basic_import_export: Online export failed')
  217. assert False
  218. # Offline export
  219. if not topology.standalone.db2ldif(DEFAULT_BENAME, (DEFAULT_SUFFIX,),
  220. None, None, None, export_ldif):
  221. log.fatal('test_basic_import_export: Failed to run offline db2ldif')
  222. assert False
  223. #
  224. # Cleanup - Import the Example LDIF for the other tests in this suite
  225. #
  226. import_ldif = '%s/Example.ldif' % get_data_dir(topology.standalone.prefix)
  227. try:
  228. topology.standalone.tasks.importLDIF(suffix=DEFAULT_SUFFIX,
  229. input_file=import_ldif,
  230. args={TASK_WAIT: True})
  231. except ValueError:
  232. log.fatal('test_basic_import_export: Online import failed')
  233. assert False
  234. log.info('test_basic_import_export: PASSED')
  235. def test_basic_backup(topology, import_example_ldif):
  236. """Test online and offline back and restore"""
  237. log.info('Running test_basic_backup...')
  238. backup_dir = '%sbasic_backup/' % topology.standalone.getDir(__file__, TMP_DIR)
  239. # Test online backup
  240. try:
  241. topology.standalone.tasks.db2bak(backup_dir=backup_dir,
  242. args={TASK_WAIT: True})
  243. except ValueError:
  244. log.fatal('test_basic_backup: Online backup failed')
  245. assert False
  246. # Test online restore
  247. try:
  248. topology.standalone.tasks.bak2db(backup_dir=backup_dir,
  249. args={TASK_WAIT: True})
  250. except ValueError:
  251. log.fatal('test_basic_backup: Online restore failed')
  252. assert False
  253. # Test offline backup
  254. if not topology.standalone.db2bak(backup_dir):
  255. log.fatal('test_basic_backup: Offline backup failed')
  256. assert False
  257. # Test offline restore
  258. if not topology.standalone.bak2db(backup_dir):
  259. log.fatal('test_basic_backup: Offline backup failed')
  260. assert False
  261. log.info('test_basic_backup: PASSED')
  262. def test_basic_acl(topology, import_example_ldif):
  263. """Run some basic access control(ACL) tests"""
  264. log.info('Running test_basic_acl...')
  265. DENY_ACI = ('(targetattr = "*") (version 3.0;acl "deny user";deny (all)' +
  266. '(userdn = "ldap:///' + USER1_DN + '");)')
  267. #
  268. # Add two users
  269. #
  270. try:
  271. topology.standalone.add_s(Entry((USER1_DN,
  272. {'objectclass': "top extensibleObject".split(),
  273. 'sn': '1',
  274. 'cn': 'user 1',
  275. 'uid': 'user1',
  276. 'userpassword': PASSWORD})))
  277. except ldap.LDAPError as e:
  278. log.fatal('test_basic_acl: Failed to add test user ' + USER1_DN
  279. + ': error ' + e.message['desc'])
  280. assert False
  281. try:
  282. topology.standalone.add_s(Entry((USER2_DN,
  283. {'objectclass': "top extensibleObject".split(),
  284. 'sn': '2',
  285. 'cn': 'user 2',
  286. 'uid': 'user2',
  287. 'userpassword': PASSWORD})))
  288. except ldap.LDAPError as e:
  289. log.fatal('test_basic_acl: Failed to add test user ' + USER1_DN
  290. + ': error ' + e.message['desc'])
  291. assert False
  292. #
  293. # Add an aci that denies USER1 from doing anything,
  294. # and also set the default anonymous access
  295. #
  296. try:
  297. topology.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_ADD, 'aci', DENY_ACI)])
  298. except ldap.LDAPError as e:
  299. log.fatal('test_basic_acl: Failed to add DENY ACI: error ' + e.message['desc'])
  300. assert False
  301. #
  302. # Make sure USER1_DN can not search anything, but USER2_dn can...
  303. #
  304. try:
  305. topology.standalone.simple_bind_s(USER1_DN, PASSWORD)
  306. except ldap.LDAPError as e:
  307. log.fatal('test_basic_acl: Failed to bind as user1, error: ' + e.message['desc'])
  308. assert False
  309. try:
  310. entries = topology.standalone.search_s(DEFAULT_SUFFIX,
  311. ldap.SCOPE_SUBTREE,
  312. '(uid=*)')
  313. if entries:
  314. log.fatal('test_basic_acl: User1 was incorrectly able to search the suffix!')
  315. assert False
  316. except ldap.LDAPError as e:
  317. log.fatal('test_basic_acl: Search suffix failed(as user1): ' + e.message['desc'])
  318. assert False
  319. # Now try user2... Also check that userpassword is stripped out
  320. try:
  321. topology.standalone.simple_bind_s(USER2_DN, PASSWORD)
  322. except ldap.LDAPError as e:
  323. log.fatal('test_basic_acl: Failed to bind as user2, error: ' + e.message['desc'])
  324. assert False
  325. try:
  326. entries = topology.standalone.search_s(DEFAULT_SUFFIX,
  327. ldap.SCOPE_SUBTREE,
  328. '(uid=user1)')
  329. if not entries:
  330. log.fatal('test_basic_acl: User1 incorrectly not able to search the suffix')
  331. assert False
  332. if entries[0].hasAttr('userpassword'):
  333. # The default anonymous access aci should have stripped out userpassword
  334. log.fatal('test_basic_acl: User2 was incorrectly able to see userpassword')
  335. assert False
  336. except ldap.LDAPError as e:
  337. log.fatal('test_basic_acl: Search for user1 failed(as user2): ' + e.message['desc'])
  338. assert False
  339. # Make sure Root DN can also search (this also resets the bind dn to the
  340. # Root DN for future operations)
  341. try:
  342. topology.standalone.simple_bind_s(DN_DM, PW_DM)
  343. except ldap.LDAPError as e:
  344. log.fatal('test_basic_acl: Failed to bind as ROotDN, error: ' + e.message['desc'])
  345. assert False
  346. try:
  347. entries = topology.standalone.search_s(DEFAULT_SUFFIX,
  348. ldap.SCOPE_SUBTREE,
  349. '(uid=*)')
  350. if not entries:
  351. log.fatal('test_basic_acl: Root DN incorrectly not able to search the suffix')
  352. assert False
  353. except ldap.LDAPError as e:
  354. log.fatal('test_basic_acl: Search for user1 failed(as user2): ' + e.message['desc'])
  355. assert False
  356. #
  357. # Cleanup
  358. #
  359. try:
  360. topology.standalone.modify_s(DEFAULT_SUFFIX, [(ldap.MOD_DELETE, 'aci', DENY_ACI)])
  361. except ldap.LDAPError as e:
  362. log.fatal('test_basic_acl: Failed to delete DENY ACI: error ' + e.message['desc'])
  363. assert False
  364. try:
  365. topology.standalone.delete_s(USER1_DN)
  366. except ldap.LDAPError as e:
  367. log.fatal('test_basic_acl: Failed to delete test entry1: ' + e.message['desc'])
  368. assert False
  369. try:
  370. topology.standalone.delete_s(USER2_DN)
  371. except ldap.LDAPError as e:
  372. log.fatal('test_basic_acl: Failed to delete test entry2: ' + e.message['desc'])
  373. assert False
  374. log.info('test_basic_acl: PASSED')
  375. def test_basic_searches(topology, import_example_ldif):
  376. """The search results are gathered from testing with Example.ldif"""
  377. log.info('Running test_basic_searches...')
  378. filters = (('(uid=scarter)', 1),
  379. ('(uid=tmorris*)', 1),
  380. ('(uid=*hunt*)', 4),
  381. ('(uid=*cope)', 2),
  382. ('(mail=*)', 150),
  383. ('(roomnumber>=4000)', 35),
  384. ('(roomnumber<=4000)', 115),
  385. ('(&(roomnumber>=4000)(roomnumber<=4500))', 18),
  386. ('(!(l=sunnyvale))', 120),
  387. ('(&(uid=t*)(l=santa clara))', 7),
  388. ('(|(uid=k*)(uid=r*))', 18),
  389. ('(|(uid=t*)(l=sunnyvale))', 50),
  390. ('(&(!(uid=r*))(ou=people))', 139),
  391. ('(&(uid=m*)(l=sunnyvale)(ou=people)(mail=*example*)(roomNumber=*))', 3),
  392. ('(&(|(uid=m*)(l=santa clara))(roomNumber=22*))', 5),
  393. ('(&(|(uid=m*)(l=santa clara))(roomNumber=22*)(!(roomnumber=2254)))', 4))
  394. for (search_filter, search_result) in filters:
  395. try:
  396. entries = topology.standalone.search_s(DEFAULT_SUFFIX,
  397. ldap.SCOPE_SUBTREE,
  398. search_filter)
  399. if len(entries) != search_result:
  400. log.fatal('test_basic_searches: An incorrect number of entries\
  401. was returned from filter (%s): (%d) expected (%d)' %
  402. (search_filter, len(entries), search_result))
  403. assert False
  404. except ldap.LDAPError as e:
  405. log.fatal('Search failed: ' + e.message['desc'])
  406. assert False
  407. log.info('test_basic_searches: PASSED')
  408. def test_basic_referrals(topology, import_example_ldif):
  409. """Set the server to referral mode,
  410. and make sure we recive the referal error(10)
  411. """
  412. log.info('Running test_basic_referrals...')
  413. SUFFIX_CONFIG = 'cn="dc=example,dc=com",cn=mapping tree,cn=config'
  414. #
  415. # Set the referral, adn the backend state
  416. #
  417. try:
  418. topology.standalone.modify_s(SUFFIX_CONFIG,
  419. [(ldap.MOD_REPLACE,
  420. 'nsslapd-referral',
  421. 'ldap://localhost.localdomain:389/o%3dnetscaperoot')])
  422. except ldap.LDAPError as e:
  423. log.fatal('test_basic_referrals: Failed to set referral: error ' + e.message['desc'])
  424. assert False
  425. try:
  426. topology.standalone.modify_s(SUFFIX_CONFIG, [(ldap.MOD_REPLACE,
  427. 'nsslapd-state', 'Referral')])
  428. except ldap.LDAPError as e:
  429. log.fatal('test_basic_referrals: Failed to set backend state: error '
  430. + e.message['desc'])
  431. assert False
  432. #
  433. # Test that a referral error is returned
  434. #
  435. topology.standalone.set_option(ldap.OPT_REFERRALS, 0) # Do not follow referral
  436. try:
  437. topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'objectclass=top')
  438. except ldap.REFERRAL:
  439. pass
  440. except ldap.LDAPError as e:
  441. log.fatal('test_basic_referrals: Search failed: ' + e.message['desc'])
  442. assert False
  443. #
  444. # Make sure server can restart in referral mode
  445. #
  446. topology.standalone.restart(timeout=10)
  447. #
  448. # Cleanup
  449. #
  450. try:
  451. topology.standalone.modify_s(SUFFIX_CONFIG, [(ldap.MOD_REPLACE,
  452. 'nsslapd-state', 'Backend')])
  453. except ldap.LDAPError as e:
  454. log.fatal('test_basic_referrals: Failed to set backend state: error '
  455. + e.message['desc'])
  456. assert False
  457. try:
  458. topology.standalone.modify_s(SUFFIX_CONFIG, [(ldap.MOD_DELETE,
  459. 'nsslapd-referral', None)])
  460. except ldap.LDAPError as e:
  461. log.fatal('test_basic_referrals: Failed to delete referral: error '
  462. + e.message['desc'])
  463. assert False
  464. topology.standalone.set_option(ldap.OPT_REFERRALS, 1)
  465. log.info('test_basic_referrals: PASSED')
  466. def test_basic_systemctl(topology, import_example_ldif):
  467. """Test systemctl can stop and start the server. Also test that start reports an
  468. error when the instance does not start. Only for RPM builds
  469. """
  470. log.info('Running test_basic_systemctl...')
  471. # We can only use systemctl on RPM installations
  472. if topology.standalone.prefix and topology.standalone.prefix != '/':
  473. return
  474. data_dir = topology.standalone.getDir(__file__, DATA_DIR)
  475. tmp_dir = topology.standalone.getDir(__file__, TMP_DIR)
  476. config_dir = topology.standalone.confdir
  477. start_ds = 'sudo systemctl start dirsrv@' + topology.standalone.serverid + '.service'
  478. stop_ds = 'sudo systemctl stop dirsrv@' + topology.standalone.serverid + '.service'
  479. is_running = 'sudo systemctl is-active dirsrv@' + topology.standalone.serverid + '.service'
  480. #
  481. # Stop the server
  482. #
  483. log.info('Stopping the server...')
  484. rc = os.system(stop_ds)
  485. log.info('Check the status...')
  486. if rc != 0 or os.system(is_running) == 0:
  487. log.fatal('test_basic_systemctl: Failed to stop the server')
  488. assert False
  489. log.info('Stopped the server.')
  490. #
  491. # Start the server
  492. #
  493. log.info('Starting the server...')
  494. rc = os.system(start_ds)
  495. log.info('Check the status...')
  496. if rc != 0 or os.system(is_running) != 0:
  497. log.fatal('test_basic_systemctl: Failed to start the server')
  498. assert False
  499. log.info('Started the server.')
  500. #
  501. # Stop the server, break the dse.ldif so a start fails,
  502. # and verify that systemctl detects the failed start
  503. #
  504. log.info('Stopping the server...')
  505. rc = os.system(stop_ds)
  506. log.info('Check the status...')
  507. if rc != 0 or os.system(is_running) == 0:
  508. log.fatal('test_basic_systemctl: Failed to stop the server')
  509. assert False
  510. log.info('Stopped the server before breaking the dse.ldif.')
  511. shutil.copy(config_dir + '/dse.ldif', tmp_dir)
  512. shutil.copy(data_dir + 'basic/dse.ldif.broken', config_dir + '/dse.ldif')
  513. log.info('Attempting to start the server with broken dse.ldif...')
  514. rc = os.system(start_ds)
  515. log.info('Check the status...')
  516. if rc == 0 or os.system(is_running) == 0:
  517. log.fatal('test_basic_systemctl: The server incorrectly started')
  518. assert False
  519. log.info('Server failed to start as expected')
  520. #
  521. # Fix the dse.ldif, and make sure the server starts up,
  522. # and systemctl correctly identifies the successful start
  523. #
  524. shutil.copy(tmp_dir + 'dse.ldif', config_dir)
  525. log.info('Starting the server...')
  526. rc = os.system(start_ds)
  527. time.sleep(10)
  528. log.info('Check the status...')
  529. if rc != 0 or os.system(is_running) != 0:
  530. log.fatal('test_basic_systemctl: Failed to start the server')
  531. assert False
  532. log.info('Server started after fixing dse.ldif.')
  533. time.sleep(1)
  534. log.info('test_basic_systemctl: PASSED')
  535. def test_basic_ldapagent(topology, import_example_ldif):
  536. """Test that the ldap agent starts"""
  537. log.info('Running test_basic_ldapagent...')
  538. tmp_dir = topology.standalone.getDir(__file__, TMP_DIR)
  539. var_dir = topology.standalone.prefix + '/var'
  540. config_file = tmp_dir + '/agent.conf'
  541. cmd = 'sudo %s/ldap-agent %s' % (get_sbin_dir(prefix=topology.standalone.prefix),
  542. config_file)
  543. agent_config_file = open(config_file, 'w')
  544. agent_config_file.write('agentx-master ' + var_dir + '/agentx/master\n')
  545. agent_config_file.write('agent-logdir ' + var_dir + '/log/dirsrv\n')
  546. agent_config_file.write('server slapd-' + topology.standalone.serverid + '\n')
  547. agent_config_file.close()
  548. rc = os.system(cmd)
  549. if rc != 0:
  550. log.fatal('test_basic_ldapagent: Failed to start snmp ldap agent: error %d' % rc)
  551. assert False
  552. log.info('snmp ldap agent started')
  553. #
  554. # Cleanup - kill the agent
  555. #
  556. pid = check_output(['pidof', '-s', 'ldap-agent-bin'])
  557. log.info('Cleanup - killing agent: ' + pid)
  558. rc = os.system('sudo kill -9 ' + pid)
  559. log.info('test_basic_ldapagent: PASSED')
  560. def test_basic_dse(topology, import_example_ldif):
  561. """Test that the dse.ldif is not wipped out
  562. after the process is killed (bug 910581)
  563. """
  564. log.info('Running test_basic_dse...')
  565. dse_file = topology.standalone.confdir + '/dse.ldif'
  566. pid = check_output(['pidof', '-s', 'ns-slapd'])
  567. os.system('sudo kill -9 ' + pid)
  568. if os.path.getsize(dse_file) == 0:
  569. log.fatal('test_basic_dse: dse.ldif\'s content was incorrectly removed!')
  570. assert False
  571. topology.standalone.start(timeout=10)
  572. log.info('dse.ldif was not corrupted, and the server was restarted')
  573. log.info('test_basic_dse: PASSED')
  574. if __name__ == '__main__':
  575. # Run isolated
  576. # -s for DEBUG mode
  577. CURRENT_FILE = os.path.realpath(__file__)
  578. pytest.main("-s %s" % CURRENT_FILE)