| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2021 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 time |
| 10 |
import subprocess |
| 11 |
import pytest |
| 12 |
from lib389.tasks import * |
| 13 |
from lib389.utils import * |
| 14 |
from test389.topologies import topology_st |
| 15 |
from lib389._mapped_object import DSLdapObjects |
| 16 |
|
| 17 |
pytestmark = pytest.mark.tier2 |
| 18 |
disk_monitoring_ack = pytest.mark.skipif(not os.environ.get('DISK_MONITORING_ACK', False), reason="Disk monitoring tests may damage system configuration.") |
| 19 |
|
| 20 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
|
| 24 |
@pytest.fixture(scope="function") |
| 25 |
def create_dummy_mount(topology_st, request): |
| 26 |
cmds = ['setenforce 0', |
| 27 |
'mkdir /var/log/dirsrv/slapd-{}/tmp'.format(topology_st.standalone.serverid), |
| 28 |
'mount -t tmpfs tmpfs /var/log/dirsrv/slapd-{}/tmp -o size=0'.format(topology_st.standalone.serverid), |
| 29 |
'chown dirsrv: /var/log/dirsrv/slapd-{}/tmp'.format(topology_st.standalone.serverid)] |
| 30 |
|
| 31 |
log.info('Create dummy mount') |
| 32 |
for cmd in cmds: |
| 33 |
log.info('Command used : %s' % cmd) |
| 34 |
subprocess.run(cmd, shell=True) |
| 35 |
|
| 36 |
def fin(): |
| 37 |
cmds = ['umount /var/log/dirsrv/slapd-{}/tmp'.format(topology_st.standalone.serverid), |
| 38 |
'rmdir /var/log/dirsrv/slapd-{}/tmp'.format(topology_st.standalone.serverid), |
| 39 |
'setenforce 1'] |
| 40 |
|
| 41 |
for cmd in cmds: |
| 42 |
log.info('Command used : %s' % cmd) |
| 43 |
subprocess.run(cmd, shell=True) |
| 44 |
|
| 45 |
request.addfinalizer(fin) |
| 46 |
|
| 47 |
|
| 48 |
@pytest.fixture(scope="function") |
| 49 |
def change_config(topology_st): |
| 50 |
topology_st.standalone.config.set('nsslapd-disk-monitoring', 'on') |
| 51 |
topology_st.standalone.config.set('nsslapd-disk-monitoring-readonly-on-threshold', 'on') |
| 52 |
|
| 53 |
|
| 54 |
@pytest.mark.skipif(ds_is_older("1.4.3.16"), reason="Might fail because of bz1890118") |
| 55 |
@disk_monitoring_ack |
| 56 |
def test_produce_division_by_zero(topology_st, create_dummy_mount, change_config): |
| 57 |
"""Test dirsrv will not crash when division by zero occurs |
| 58 |
|
| 59 |
:id: 51b11093-8851-41bd-86cb-217b1a3339c7 |
| 60 |
:customerscenario: True |
| 61 |
:setup: Standalone |
| 62 |
:steps: |
| 63 |
1. Turn on disk monitoring |
| 64 |
2. Go below the threshold |
| 65 |
3. Check DS is up and not entering shutdown mode |
| 66 |
:expectedresults: |
| 67 |
1. Success |
| 68 |
2. Success |
| 69 |
3. Success |
| 70 |
""" |
| 71 |
|
| 72 |
standalone = topology_st.standalone |
| 73 |
|
| 74 |
log.info('Check search works before changing the nsslapd-auditlog attribute') |
| 75 |
try: |
| 76 |
DSLdapObjects(topology_st.standalone, basedn='cn=disk space,cn=monitor').filter("(objectclass=*)", scope=0) |
| 77 |
except ldap.SERVER_DOWN as e: |
| 78 |
log.info('Test failed - dirsrv crashed') |
| 79 |
assert False |
| 80 |
|
| 81 |
log.info('Change location of nsslapd-auditlog') |
| 82 |
standalone.config.set('nsslapd-auditlog', '/var/log/dirsrv/slapd-{}/tmp/audit'.format(standalone.serverid)) |
| 83 |
|
| 84 |
log.info('Check search will not fail') |
| 85 |
try: |
| 86 |
DSLdapObjects(topology_st.standalone, basedn='cn=disk space,cn=monitor').filter("(objectclass=*)", scope=0) |
| 87 |
except ldap.SERVER_DOWN as e: |
| 88 |
log.info('Test failed - dirsrv crashed') |
| 89 |
assert False |
| 90 |
|
| 91 |
log.info('If passed, run search again just in case') |
| 92 |
try: |
| 93 |
DSLdapObjects(topology_st.standalone, basedn='cn=disk space,cn=monitor').filter("(objectclass=*)", scope=0) |
| 94 |
except ldap.SERVER_DOWN as e: |
| 95 |
log.info('Test failed - dirsrv crashed') |
| 96 |
assert False |
| 97 |
|
| 98 |
|
| 99 |
if __name__ == '__main__': |
| 100 |
# Run isolated |
| 101 |
# -s for DEBUG mode |
| 102 |
CURRENT_FILE = os.path.realpath(__file__) |
| 103 |
pytest.main("-s %s" % CURRENT_FILE) |