ticket48383_test.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. import string
  14. import random
  15. logging.getLogger(__name__).setLevel(logging.DEBUG)
  16. log = logging.getLogger(__name__)
  17. class TopologyStandalone(object):
  18. def __init__(self, standalone):
  19. standalone.open()
  20. self.standalone = standalone
  21. @pytest.fixture(scope="module")
  22. def topology(request):
  23. # Creating standalone instance ...
  24. standalone = DirSrv(verbose=True)
  25. args_instance[SER_HOST] = HOST_STANDALONE
  26. args_instance[SER_PORT] = PORT_STANDALONE
  27. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  28. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  29. args_standalone = args_instance.copy()
  30. standalone.allocate(args_standalone)
  31. instance_standalone = standalone.exists()
  32. if instance_standalone:
  33. standalone.delete()
  34. standalone.create()
  35. standalone.open()
  36. # Delete each instance in the end
  37. def fin():
  38. # This is useful for analysing the test env.
  39. #standalone.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], excludeSuffixes=[], encrypt=False, \
  40. # repl_data=True, outputfile='%s/ldif/%s.ldif' % (standalone.dbdir,SERVERID_STANDALONE ))
  41. #standalone.clearBackupFS()
  42. #standalone.backupFS()
  43. standalone.delete()
  44. request.addfinalizer(fin)
  45. # Clear out the tmp dir
  46. standalone.clearTmpDir(__file__)
  47. return TopologyStandalone(standalone)
  48. def test_ticket48383(topology):
  49. """
  50. This test case will check that we re-alloc buffer sizes on import.c
  51. We achieve this by setting the servers dbcachesize to a stupid small value
  52. and adding huge objects to ds.
  53. Then when we run db2index, either:
  54. * If we are not using the re-alloc code, it will FAIL (Bad)
  55. * If we re-alloc properly, it all works regardless.
  56. """
  57. topology.standalone.config.set('nsslapd-maxbersize', '200000000')
  58. topology.standalone.restart()
  59. # Create some stupid huge objects / attributes in DS.
  60. # seeAlso is indexed by default. Lets do that!
  61. # This will take a while ...
  62. data = [random.choice(string.letters) for x in xrange(10000000)]
  63. s = "".join(data)
  64. # This was here for an iteration test.
  65. i = 1
  66. USER_DN = 'uid=user%s,ou=people,%s' % (i, DEFAULT_SUFFIX)
  67. padding = ['%s' % n for n in range(400)]
  68. user = Entry((USER_DN, {
  69. 'objectclass': 'top posixAccount person extensibleObject'.split(),
  70. 'uid': 'user%s' % (i),
  71. 'cn': 'user%s' % (i),
  72. 'uidNumber': '%s' % (i),
  73. 'gidNumber': '%s' % (i),
  74. 'homeDirectory': '/home/user%s' % (i),
  75. 'description': 'user description',
  76. 'sn' : s ,
  77. 'padding' : padding ,
  78. }))
  79. try:
  80. topology.standalone.add_s(user)
  81. except ldap.LDAPError as e:
  82. log.fatal('test 48383: Failed to user%s: error %s ' % (i, e.message['desc']))
  83. assert False
  84. # Set the dbsize really low.
  85. topology.standalone.backend.setProperties(bename=DEFAULT_BENAME,
  86. prop='nsslapd-cachememsize', values='1')
  87. ## Does ds try and set a minimum possible value for this?
  88. ## Yes: [16/Feb/2016:16:39:18 +1000] - WARNING: cache too small, increasing to 500K bytes
  89. # Given the formula, by default, this means DS will make the buffsize 400k
  90. # So an object with a 1MB attribute should break indexing
  91. # stop the server
  92. topology.standalone.stop(timeout=30)
  93. # Now export and import the DB. It's easier than db2index ...
  94. topology.standalone.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], excludeSuffixes=[], encrypt=False, \
  95. repl_data=True, outputfile='%s/ldif/%s.ldif' % (topology.standalone.dbdir,SERVERID_STANDALONE ))
  96. result = topology.standalone.ldif2db(DEFAULT_BENAME, None, None, False, '%s/ldif/%s.ldif' % (topology.standalone.dbdir,SERVERID_STANDALONE ))
  97. assert(result)
  98. # see if user1 exists at all ....
  99. result_user = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=user1)')
  100. assert(len(result_user) > 0)
  101. log.info('Test complete')
  102. if __name__ == '__main__':
  103. # Run isolated
  104. # -s for DEBUG mode
  105. CURRENT_FILE = os.path.realpath(__file__)
  106. pytest.main("-s %s" % CURRENT_FILE)