ticket48665_test.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import pytest
  7. from lib389 import DirSrv, Entry, tools, tasks
  8. from lib389.tools import DirSrvTools
  9. from lib389._constants import *
  10. from lib389.properties import *
  11. from lib389.tasks import *
  12. from lib389.utils import *
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. class TopologyStandalone(object):
  16. def __init__(self, standalone):
  17. standalone.open()
  18. self.standalone = standalone
  19. @pytest.fixture(scope="module")
  20. def topology(request):
  21. # Creating standalone instance ...
  22. standalone = DirSrv(verbose=False)
  23. args_instance[SER_HOST] = HOST_STANDALONE
  24. args_instance[SER_PORT] = PORT_STANDALONE
  25. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  26. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  27. args_standalone = args_instance.copy()
  28. standalone.allocate(args_standalone)
  29. instance_standalone = standalone.exists()
  30. if instance_standalone:
  31. standalone.delete()
  32. standalone.create()
  33. standalone.open()
  34. # Delete each instance in the end
  35. def fin():
  36. # This is useful for analysing the test env.
  37. #standalone.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], excludeSuffixes=[], encrypt=False, \
  38. # repl_data=True, outputfile='%s/ldif/%s.ldif' % (standalone.dbdir,SERVERID_STANDALONE ))
  39. #standalone.clearBackupFS()
  40. #standalone.backupFS()
  41. standalone.delete()
  42. request.addfinalizer(fin)
  43. # Clear out the tmp dir
  44. standalone.clearTmpDir(__file__)
  45. return TopologyStandalone(standalone)
  46. def test_ticket48665(topology):
  47. """
  48. This tests deletion of certain cn=config values.
  49. First, it should be able to delete, and not crash the server.
  50. Second, we might be able to delete then add to replace values.
  51. We should also still be able to mod replace the values and keep the server alive.
  52. """
  53. #topology.standalone.config.enable_log('audit')
  54. #topology.standalone.config.enable_log('auditfail')
  55. # This will trigger a mod delete then add.
  56. try:
  57. modlist = [(ldap.MOD_DELETE, 'nsslapd-cachememsize', None), (ldap.MOD_ADD, 'nsslapd-cachememsize', '1')]
  58. topology.standalone.modify_s("cn=%s,cn=ldbm database,cn=plugins,cn=config" % DEFAULT_BENAME,
  59. modlist)
  60. except:
  61. pass
  62. # Check the server has not commited seppuku.
  63. result = topology.standalone.whoami_s()
  64. assert(DN_DM.lower() in result.lower())
  65. # This has a magic hack to determine if we are in cn=config.
  66. try:
  67. topology.standalone.modify_s(DEFAULT_BENAME, [(ldap.MOD_REPLACE,
  68. 'nsslapd-cachememsize', '1')])
  69. except ldap.LDAPError as e:
  70. log.fatal('Failed to change nsslapd-cachememsize ' + e.message['desc'])
  71. # Check the server has not commited seppuku.
  72. result = topology.standalone.whoami_s()
  73. assert(DN_DM.lower() in result.lower())
  74. # Now try with mod_replace. This should be okay.
  75. modlist = [(ldap.MOD_REPLACE, 'nsslapd-cachememsize', '1')]
  76. topology.standalone.modify_s("cn=%s,cn=ldbm database,cn=plugins,cn=config" % DEFAULT_BENAME,
  77. modlist)
  78. # Check the server has not commited seppuku.
  79. result = topology.standalone.whoami_s()
  80. assert(DN_DM.lower() in result.lower())
  81. log.info('Test complete')
  82. if __name__ == '__main__':
  83. # Run isolated
  84. # -s for DEBUG mode
  85. CURRENT_FILE = os.path.realpath(__file__)
  86. pytest.main("-s %s" % CURRENT_FILE)