| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2022 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 logging |
| 10 |
import pytest |
| 11 |
import os |
| 12 |
import ldap |
| 13 |
from lib389._constants import * |
| 14 |
from test389.topologies import topology_st as topo |
| 15 |
|
| 16 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 17 |
if DEBUGGING: |
| 18 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 19 |
else: |
| 20 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 21 |
log = logging.getLogger(__name__) |
| 22 |
|
| 23 |
big_value = "1111111111111111111111111111111111111111111" |
| 24 |
|
| 25 |
pytestmark = pytest.mark.tier1 |
| 26 |
|
| 27 |
@pytest.mark.parametrize("attr, invalid_vals, valid_vals", |
| 28 |
[ |
| 29 |
("logexpirationtime", ["-2", "0"], ["1", "-1"]), |
| 30 |
("maxlogsize", ["-2", "0"], ["100", "-1"]), |
| 31 |
("logmaxdiskspace", ["-2", "0"], ["100", "-1"]), |
| 32 |
("logminfreediskspace", ["-2", "0"], ["100", "-1"]), |
| 33 |
("mode", ["888", "778", "77", "7777"], ["777", "000", "600"]), |
| 34 |
("maxlogsperdir", ["-1", "0"], ["1", "20"]), |
| 35 |
("logrotationsynchour", ["-1", "24"], ["0", "23"]), |
| 36 |
("logrotationsyncmin", ["-1", "60"], ["0", "59"]), |
| 37 |
("logrotationtime", ["-2", "0"], ["100", "-1"]) |
| 38 |
]) |
| 39 |
def test_logging_digit_config(topo, attr, invalid_vals, valid_vals): |
| 40 |
"""Validate logging config settings |
| 41 |
|
| 42 |
:id: a0ef30e5-538b-46fa-9762-01a4435a15e9 |
| 43 |
:parametrized: yes |
| 44 |
:setup: Standalone Instance |
| 45 |
:steps: |
| 46 |
1. Test log expiration time |
| 47 |
2. Test log max size |
| 48 |
3. Test log max disk space |
| 49 |
4. Test log min disk space |
| 50 |
5. Test log mode |
| 51 |
6. Test log max number of logs |
| 52 |
7. Test log rotation hour |
| 53 |
8. Test log rotation minute |
| 54 |
9. Test log rotation time |
| 55 |
:expectedresults: |
| 56 |
1. Success |
| 57 |
2. Success |
| 58 |
3. Success |
| 59 |
4. Success |
| 60 |
5. Success |
| 61 |
6. Success |
| 62 |
7. Success |
| 63 |
8. Success |
| 64 |
9. Success |
| 65 |
""" |
| 66 |
|
| 67 |
accesslog_attr = "nsslapd-accesslog-{}".format(attr) |
| 68 |
auditlog_attr = "nsslapd-auditlog-{}".format(attr) |
| 69 |
auditfaillog_attr = "nsslapd-auditfaillog-{}".format(attr) |
| 70 |
errorlog_attr = "nsslapd-errorlog-{}".format(attr) |
| 71 |
securitylog_attr = "nsslapd-securitylog-{}".format(attr) |
| 72 |
|
| 73 |
# Test each log |
| 74 |
for attr in [accesslog_attr, auditlog_attr, auditfaillog_attr, errorlog_attr, securitylog_attr]: |
| 75 |
# Invalid values |
| 76 |
for invalid_val in invalid_vals: |
| 77 |
with pytest.raises(ldap.LDAPError): |
| 78 |
topo.standalone.config.set(attr, invalid_val) |
| 79 |
|
| 80 |
# Invalid high value |
| 81 |
with pytest.raises(ldap.LDAPError): |
| 82 |
topo.standalone.config.set(attr, big_value) |
| 83 |
|
| 84 |
# Non digits |
| 85 |
with pytest.raises(ldap.LDAPError): |
| 86 |
topo.standalone.config.set(attr, "abc") |
| 87 |
|
| 88 |
# Valid values |
| 89 |
for valid_val in valid_vals: |
| 90 |
topo.standalone.config.set(attr, valid_val) |
| 91 |
|
| 92 |
|
| 93 |
if __name__ == '__main__': |
| 94 |
# Run isolated |
| 95 |
# -s for DEBUG mode |
| 96 |
CURRENT_FILE = os.path.realpath(__file__) |
| 97 |
pytest.main(["-s", CURRENT_FILE]) |