1
0

finalizer.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. '''
  2. Created on Nov 5, 2013
  3. @author: tbordaz
  4. '''
  5. import os
  6. import sys
  7. import time
  8. import ldap
  9. import logging
  10. import socket
  11. import time
  12. import logging
  13. import pytest
  14. from lib389 import DirSrv, Entry, tools
  15. from lib389.tools import DirSrvTools
  16. from lib389._constants import DN_DM
  17. from constants import *
  18. log = logging.getLogger(__name__)
  19. global installation_prefix
  20. def _remove_instance(args):
  21. # check the instance parameters
  22. args_instance['newhost'] = args.get('host', None)
  23. if not args_instance['newhost']:
  24. raise ValueError("host not defined")
  25. args_instance['newport'] = args.get('port', None)
  26. if not args_instance['newport']:
  27. raise ValueError("port not defined")
  28. args_instance['newinstance'] = args.get('serverid', None)
  29. if not args_instance['newinstance']:
  30. raise ValueError("serverid not defined")
  31. args_instance['prefix'] = args.get('prefix', None)
  32. # Get the status of the instance and remove it if it exists
  33. instance = DirSrvTools.existsInstance(args_instance)
  34. if instance:
  35. log.debug("_remove_instance %s %s:%d" % (instance.serverId, instance.host, instance.port))
  36. DirSrvTools.removeInstance(instance)
  37. def test_finalizer():
  38. global installation_prefix
  39. # for each defined instance, remove it
  40. for instance in ALL_INSTANCES:
  41. if installation_prefix:
  42. # overwrite the environment setting
  43. instance['prefix'] = installation_prefix
  44. _remove_instance(instance)
  45. def run_isolated():
  46. '''
  47. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  48. To run isolated without py.test, you need to
  49. - set the installation prefix
  50. - run this program
  51. '''
  52. global installation_prefix
  53. installation_prefix = None
  54. test_finalizer()
  55. if __name__ == '__main__':
  56. run_isolated()