setup_ds_test.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import pytest
  2. from lib389.utils import *
  3. from lib389._constants import (DEFAULT_SUFFIX, SER_HOST, SER_PORT,
  4. SER_SERVERID_PROP, SER_CREATION_SUFFIX, SER_INST_SCRIPTS_ENABLED,
  5. args_instance, ReplicaRole)
  6. from lib389 import DirSrv
  7. pytestmark = pytest.mark.tier0
  8. DEBUGGING = os.getenv("DEBUGGING", default=False)
  9. if DEBUGGING:
  10. logging.getLogger(__name__).setLevel(logging.DEBUG)
  11. else:
  12. logging.getLogger(__name__).setLevel(logging.INFO)
  13. log = logging.getLogger(__name__)
  14. def create_instance(config_attr):
  15. log.info('create_instance - Installs the instance and Sets the value of InstScriptsEnabled to true OR false.')
  16. log.info("Set up the instance and set the config_attr")
  17. instance_data = generate_ds_params(1, ReplicaRole.STANDALONE)
  18. # Create instance
  19. standalone = DirSrv(verbose=False)
  20. # Args for the instance
  21. args_instance[SER_HOST] = instance_data[SER_HOST]
  22. args_instance[SER_PORT] = instance_data[SER_PORT]
  23. args_instance[SER_SERVERID_PROP] = instance_data[SER_SERVERID_PROP]
  24. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  25. args_instance[SER_INST_SCRIPTS_ENABLED] = config_attr
  26. args_standalone = args_instance.copy()
  27. standalone.allocate(args_standalone)
  28. if standalone.exists():
  29. standalone.delete()
  30. standalone.create()
  31. standalone.open()
  32. return standalone
  33. @pytest.mark.parametrize("config_attr", ('true', 'false'))
  34. def test_slapd_InstScriptsEnabled(config_attr):
  35. """Tests InstScriptsEnabled attribute with "True" and "False" options
  36. :id: 02faac7f-c44d-4a3e-bf2d-1021e51da1ed
  37. :parametrized: yes
  38. :setup: Standalone instance with slapd.InstScriptsEnabled option as "True" and "False"
  39. :steps:
  40. 1. Execute setup-ds.pl with slapd.InstScriptsEnabled option as "True".
  41. 2. Check if /usr/lib64/dirsrv/slapd-instance instance script directory is created or not.
  42. 3. Execute setup-ds.pl with slapd.InstScriptsEnabled option as "False".
  43. 4. Check if /usr/lib64/dirsrv/slapd-instance instance script directory is created or not.
  44. :expectedresults:
  45. 1. Instance should be created.
  46. 2. /usr/lib64/dirsrv/slapd-instance instance script directory should be created.
  47. 3. Instance should be created.
  48. 4. /usr/lib64/dirsrv/slapd-instance instance script directory should not be created.
  49. """
  50. log.info('set SER_INST_SCRIPTS_ENABLED to {}'.format(config_attr))
  51. standalone = create_instance(config_attr)
  52. # Checking the presence of instance script directory when SER_INST_SCRIPTS_ENABLED is set to true and false
  53. if config_attr == 'true':
  54. log.info('checking the presence of instance script directory when SER_INST_SCRIPTS_ENABLED is set to true')
  55. assert os.listdir('/usr/lib64/dirsrv/slapd-standalone1')
  56. elif config_attr == 'false':
  57. log.info('checking instance script directory does not present when SER_INST_SCRIPTS_ENABLED is set to false')
  58. assert not os.path.exists("/usr/lib64/dirsrv/slapd-standalone1")
  59. # Remove instance
  60. standalone.delete()
  61. if __name__ == '__main__':
  62. # Run isolated
  63. # -s for DEBUG mode
  64. CURRENT_FILE = os.path.realpath(__file__)
  65. pytest.main("-s %s" % CURRENT_FILE)