#50098 Issue: 48064 - CI test - disk_monitoring
Closed 3 years ago by spichugi. Opened 5 years ago by aborah.
aborah/389-ds-base diskmonitoring  into  master

@@ -0,0 +1,569 @@ 

+ # --- BEGIN COPYRIGHT BLOCK ---

+ # Copyright (C) 2018 Red Hat, Inc.

+ # All rights reserved.

+ #

+ # License: GPL (version 3 or any later version).

+ # See LICENSE for details.

+ # --- END COPYRIGHT BLOCK ---

+ 

+ 

+ import os

+ import subprocess

+ import re

+ import time

+ import pytest

+ from lib389.tasks import *

+ from lib389._constants import *

+ from lib389.utils import ensure_bytes

+ from lib389.topologies import topology_st as topo

+ from lib389.paths import *

+ from lib389.idm.user import UserAccounts

+ 

+ 

+ THRESHOLD = '30'

+ THRESHOLD_BYTES = '30000000'

+ 

+ 

+ def _withouterrorlog(topo, condition, maxtimesleep):

+     timecount = 0

+     while eval(condition):

+         time.sleep(1)

+         timecount += 1

+         if timecount >= maxtimesleep: break

+     assert not eval(condition)

+ 

+ 

+ def _witherrorlog(topo, condition, maxtimesleep):

+     timecount = 0

+     with open(topo.standalone.errlog, 'r') as study: study = study.read()

+     while condition not in study:

+         time.sleep(1)

+         with open(topo.standalone.errlog, 'r') as study: study = study.read()

+         if timecount >= maxtimesleep: break

+     assert condition in study

+ 

+ 

+ def presetup(topo):

+     """

+     This is function is part of fixture function setup , will setup the environment for this test.

+     """

+     topo.standalone.stop()

+     if os.path.exists(topo.standalone.ds_paths.log_dir):

+         subprocess.call(['mount', '-t', 'tmpfs', '-o', 'size=35M', 'tmpfs', topo.standalone.ds_paths.log_dir])

+     else:

+         os.mkdir(topo.standalone.ds_paths.log_dir)

+         subprocess.call(['mount', '-t', 'tmpfs', '-o', 'size=35M', 'tmpfs', topo.standalone.ds_paths.log_dir])

+     subprocess.call('chown {}: -R {}'.format(DEFAULT_USER, topo.standalone.ds_paths.log_dir), shell=True)

+     subprocess.call('chown {}: -R {}/*'.format(DEFAULT_USER, topo.standalone.ds_paths.log_dir), shell=True)

+     subprocess.call('restorecon -FvvR {}'.format(topo.standalone.ds_paths.log_dir), shell=True)

+     topo.standalone.start()

+ 

+ 

+ def setupthesystem(topo):

+     """

+     This function is part of fixture function setup , will setup the environment for this test.

+     """

+     global TOTAL_SIZE, USED_SIZE, AVAIL_SIZE, HALF_THR_FILL_SIZE, FULL_THR_FILL_SIZE

+     topo.standalone.start()

+     topo.standalone.config.set('nsslapd-disk-monitoring-grace-period', '1')

+     topo.standalone.config.set('nsslapd-accesslog-logbuffering', 'off')

+     topo.standalone.config.set('nsslapd-disk-monitoring-threshold', ensure_bytes(THRESHOLD_BYTES))

+     TOTAL_SIZE = int(re.findall('\d+', str(os.statvfs(topo.standalone.ds_paths.log_dir)))[2])*4096/1024/1024

+     AVAIL_SIZE = round(int(re.findall('\d+', str(os.statvfs(topo.standalone.ds_paths.log_dir)))[3]) * 4096 / 1024 / 1024)

+     USED_SIZE = TOTAL_SIZE - AVAIL_SIZE

+     HALF_THR_FILL_SIZE = TOTAL_SIZE - float(THRESHOLD) + 5 - USED_SIZE

+     FULL_THR_FILL_SIZE = TOTAL_SIZE - 0.5 * float(THRESHOLD) + 5 - USED_SIZE

+     HALF_THR_FILL_SIZE = round(HALF_THR_FILL_SIZE)

+     FULL_THR_FILL_SIZE = round(FULL_THR_FILL_SIZE)

+     topo.standalone.restart()

+ 

+ 

+ @pytest.fixture(scope="function")

+ def setup(topo):

+     """

+     This is the fixture function , will run before running every test case.

+     """

+     presetup(topo)

+     setupthesystem(topo)

+     # Resetting the error log file before we go for the test.

+     open('{}/errors'.format(topo.standalone.ds_paths.log_dir), 'w').close()

+ 

+ 

+ def test_verify_operation_when_disk_monitoring_is_off(topo, setup):

+     """

+     Verify operation when Disk monitoring is off

+     :id: 73a97536-fe9e-11e8-ba9f-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Turn off disk monitoring

+         2. Go below the threshold

+         3. Check DS is up and not entering shutdown mode

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+         3. Should Success

+     """

+     try:

+         # Turn off disk monitoring

+         topo.standalone.config.set('nsslapd-disk-monitoring', 'off')

+         topo.standalone.restart()

+         # go below the threshold

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo1'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+         # Wait for disk monitoring plugin thread to wake up

+         _withouterrorlog(topo, 'topo.standalone.status() != True', 10)

+         # Check DS is up and not entering shutdown mode

+         assert topo.standalone.status() == True

+     finally:

+         os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+         os.remove('{}/foo1'.format(topo.standalone.ds_paths.log_dir))

+ 

+ 

+ def test_free_up_the_disk_space_and_change_ds_config(topo, setup):

+     """

+     Free up the disk space and change DS config

+     :id: 7be4d560-fe9e-11e8-a307-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Enabling Disk Monitoring plugin and setting disk monitoring logging to critical

+         2. Verify no message about loglevel is present in the error log

+         3. Verify no message about disabling logging is present in the error log

+         4. Verify no message about removing rotated logs is present in the error log

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+         3. Should Success

+         4. Should Success

+     """

+     # Enabling Disk Monitoring plugin and setting disk monitoring logging to critical

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')

+     assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+     topo.standalone.restart()

+     # Verify no message about loglevel is present in the error log

+     # Verify no message about disabling logging is present in the error log

+     # Verify no message about removing rotated logs is present in the error log

+     with open(topo.standalone.errlog, 'r') as study: study = study.read()

+     assert 'temporarily setting error loglevel to zero' not in study

+     assert 'disabling access and audit logging' not in study

+     assert 'deleting rotated logs' not in study

+ 

+ 

+ def test_verify_operation_with_nsslapd_disk_monitoring_logging_critical_off(topo, setup):

+     """

+     Verify operation with "nsslapd-disk-monitoring-logging-critical: off

+     :id: 82363bca-fe9e-11e8-9ae7-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Verify that verbose logging was set to default level

+         2. Verify that logging is disabled

+         3. Verify that rotated logs were not removed

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+         3. Should Success

+     """

+     try:

+         # Verify that verbose logging was set to default level

+         assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+         assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')

+         assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+         topo.standalone.restart()

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(HALF_THR_FILL_SIZE)])

+         _witherrorlog(topo, 'temporarily setting error loglevel to the default level', 11)

+         assert LOG_DEFAULT == int(re.findall('nsslapd-errorlog-level: \d+', str(

+             topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)', ['nsslapd-errorlog-level'])))[

+                                       0].split(' ')[1])

+         # Verify that logging is disabled

+         _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'off'", 10)

+         assert topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') == 'off'

+         # Verify that rotated logs were not removed

+         with open(topo.standalone.errlog, 'r') as study: study = study.read()

+         assert 'disabling access and audit logging' in study

+         _witherrorlog(topo, 'deleting rotated logs', 11)

+         study = open(topo.standalone.errlog).read()

+         assert "Unable to remove file: {}".format(topo.standalone.ds_paths.log_dir) not in study

+         assert 'is too far below the threshold' not in study

+     finally:

+         os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+ 

+ 

+ def test_operation_with_nsslapd_disk_monitoring_logging_critical_on_below_half_of_the_threshold(topo, setup):

+     """

+     Verify operation with \"nsslapd-disk-monitoring-logging-critical: on\" below 1/2 of the threshold

+     Verify recovery

+     :id: 8940c502-fe9e-11e8-bcc0-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Verify that DS goes into shutdown mode

+         2. Verify that DS exited shutdown mode

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+     """

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')

+     topo.standalone.restart()

+     # Verify that DS goes into shutdown mode

+     if float(THRESHOLD) > FULL_THR_FILL_SIZE:

+         FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE) + 1

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE_new)])

+     else:

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+     _witherrorlog(topo, 'is too far below the threshold', 20)

+     os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+     # Verify that DS exited shutdown mode

+     _witherrorlog(topo, 'Available disk space is now acceptable', 25)

+ 

+ 

+ def test_setting_nsslapd_disk_monitoring_logging_critical_to_off(topo, setup):

+     """

+     Setting nsslapd-disk-monitoring-logging-critical to \"off\

+     :id: 93265ec4-fe9e-11e8-af93-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Setting nsslapd-disk-monitoring-logging-critical to \"off\

+     :expectedresults:

+         1. Should Success

+     """

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')

+     assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+     topo.standalone.restart()

+     assert topo.standalone.status() == True

+ 

+ 

+ def test_operation_with_nsslapd_disk_monitoring_logging_critical_off(topo, setup):

+     """

+     Verify operation with \"nsslapd-disk-monitoring-logging-critical: off

+     :id: 97985a52-fe9e-11e8-9914-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Verify that logging is disabled

+         2. Verify that rotated logs were removed

+         3. Verify that verbose logging was set to default level

+         4. Verify that logging is disabled

+         5. Verify that rotated logs were removed

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+         3. Should Success

+         4. Should Success

+         5. Should Success

+     """

+     # Verify that logging is disabled

+     try:

+         assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+         assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')

+         assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+         assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '1')

+         assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'minute')

+         assert topo.standalone.config.set('nsslapd-accesslog-level', '772')

+         topo.standalone.restart()

+         # Verify that rotated logs were removed

+         users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)

+         for i in range(10):

+             user_properties = {

+                 'uid': 'cn=anuj{}'.format(i),

+                 'cn': 'cn=anuj{}'.format(i),

+                 'sn': 'cn=anuj{}'.format(i),

+                 'userPassword': "Itsme123",

+                 'uidNumber': '1{}'.format(i),

+                 'gidNumber': '2{}'.format(i),

+                 'homeDirectory': '/home/{}'.format(i)

+             }

+             users.create(properties=user_properties)

+         for j in range(100):

+             for i in [i for i in users.list()]: i.bind('Itsme123')

+         assert re.findall('access.\d+-\d+',str(os.listdir(topo.standalone.ds_paths.log_dir)))

+         topo.standalone.bind_s(DN_DM, PW_DM)

+         assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '100')

+         assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'day')

+         assert topo.standalone.config.set('nsslapd-accesslog-level', '256')

+         topo.standalone.restart()

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo2'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(HALF_THR_FILL_SIZE)])

+         # Verify that verbose logging was set to default level

+         _witherrorlog(topo, 'temporarily setting error loglevel to the default level', 10)

+         assert LOG_DEFAULT == int(re.findall('nsslapd-errorlog-level: \d+', str(

+             topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)', ['nsslapd-errorlog-level'])))[0].split(' ')[1])

+         # Verify that logging is disabled

+         _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'off'", 20)

+         with open(topo.standalone.errlog, 'r') as study: study = study.read()

+         assert 'disabling access and audit logging' in study

+         # Verify that rotated logs were removed

+         _witherrorlog(topo, 'deleting rotated logs', 10)

+         with open(topo.standalone.errlog, 'r') as study:study = study.read()

+         assert 'Unable to remove file:' not in study

+         assert 'is too far below the threshold' not in study

+         for i in [i for i in users.list()]: i.delete()

+     finally:

+         os.remove('{}/foo2'.format(topo.standalone.ds_paths.log_dir))

+ 

+ 

+ def test_operation_with_nsslapd_disk_monitoring_logging_critical_off_below_half_of_the_threshold(topo, setup):

+     """

+     Verify operation with \"nsslapd-disk-monitoring-logging-critical: off\" below 1/2 of the threshold

+     Verify shutdown

+     Recovery and setup

+     :id: 9d4c7d48-fe9e-11e8-b5d6-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Verify that DS goes into shutdown mode

+         2. Verifying that DS has been shut down after the grace period

+         3. Verify logging enabled

+         4. Create rotated logfile

+         5. Enable verbose logging

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+         3. Should Success

+         4. Should Success

+         5. Should Success

+     """

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')

+     topo.standalone.restart()

+     # Verify that DS goes into shutdown mode

+     if float(THRESHOLD) > FULL_THR_FILL_SIZE:

+         FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE)

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE_new)])

+     else:

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+     # Increased sleep to avoid failure

+     _witherrorlog(topo, 'is too far below the threshold', 100)

+     _witherrorlog(topo, 'Signaling slapd for shutdown', 2)

+     # Verifying that DS has been shut down after the grace period

+     assert topo.standalone.status() == False

+     # free_space

+     os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+     open('{}/errors'.format(topo.standalone.ds_paths.log_dir), 'w').close()

+     # StartSlapd

+     topo.standalone.start()

+     # verify logging enabled

+     assert topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') == 'on'

+     assert topo.standalone.config.get_attr_val_utf8('nsslapd-errorlog-logging-enabled') == 'on'

+     with open(topo.standalone.errlog, 'r') as study: study = study.read()

+     assert 'disabling access and audit logging' not in study

+     assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '1')

+     assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'minute')

+     assert topo.standalone.config.set('nsslapd-accesslog-level', '772')

+     topo.standalone.restart()

+     # create rotated logfile

+     users = UserAccounts(topo.standalone, DEFAULT_SUFFIX)

+     for i in range(10):

+         user_properties = {

+             'uid': 'cn=anuj{}'.format(i),

+             'cn': 'cn=anuj{}'.format(i),

+             'sn': 'cn=anuj{}'.format(i),

+             'userPassword': "Itsme123",

+             'uidNumber': '1{}'.format(i),

+             'gidNumber': '2{}'.format(i),

+             'homeDirectory': '/home/{}'.format(i)

+         }

+         users.create(properties=user_properties)

+     for j in range(100):

+         for i in [i for i in users.list()]: i.bind('Itsme123')

+     assert re.findall('access.\d+-\d+',str(os.listdir(topo.standalone.ds_paths.log_dir)))

+     topo.standalone.bind_s(DN_DM, PW_DM)

+     # enable verbose logging

+     assert topo.standalone.config.set('nsslapd-accesslog-maxlogsize', '100')

+     assert topo.standalone.config.set('nsslapd-accesslog-logrotationtimeunit', 'day')

+     assert topo.standalone.config.set('nsslapd-accesslog-level', '256')

+     assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+     topo.standalone.restart()

+     for i in [i for i in users.list()]: i.delete()

+ 

+ 

+ def test_go_straight_below_half_of_the_threshold(topo, setup):

+     """

+     Go straight below 1/2 of the threshold

+     Recovery and setup

+     :id: a2a0664c-fe9e-11e8-b220-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Go straight below 1/2 of the threshold

+         2. Verify that verbose logging was set to default level

+         3. Verify that logging is disabled

+         4. Verify DS is in shutdown mode

+         5. Verify DS has recovered from shutdown

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+         3. Should Success

+         4. Should Success

+         5. Should Success

+     """

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'off')

+     assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+     topo.standalone.restart()

+     if float(THRESHOLD) > FULL_THR_FILL_SIZE:

+         FULL_THR_FILL_SIZE_new = FULL_THR_FILL_SIZE + round(float(THRESHOLD) - FULL_THR_FILL_SIZE) + 1

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE_new)])

+     else:

+         subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+     _witherrorlog(topo, 'temporarily setting error loglevel to the default level', 11)

+     # Verify that verbose logging was set to default level

+     assert LOG_DEFAULT == int(re.findall('nsslapd-errorlog-level: \d+',

+                                                 str(topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE,

+                                                                              '(objectclass=*)',

+                                                                              ['nsslapd-errorlog-level']))

+                                                 )[0].split(' ')[1])

+     # Verify that logging is disabled

+     _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'off'", 11)

+     # Verify that rotated logs were removed

+     _witherrorlog(topo, 'disabling access and audit logging', 2)

+     _witherrorlog(topo, 'deleting rotated logs', 11)

+     with open(topo.standalone.errlog, 'r') as study:study = study.read()

+     assert 'Unable to remove file:' not in study

+     # Verify DS is in shutdown mode

+     _withouterrorlog(topo, 'topo.standalone.status() != False', 90)

+     _witherrorlog(topo, 'is too far below the threshold', 2)

+     # Verify DS has recovered from shutdown

+     os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+     open('{}/errors'.format(topo.standalone.ds_paths.log_dir), 'w').close()

+     topo.standalone.start()

+     _withouterrorlog(topo, "topo.standalone.config.get_attr_val_utf8('nsslapd-accesslog-logging-enabled') != 'on'", 20)

+     with open(topo.standalone.errlog, 'r') as study: study = study.read()

+     assert 'disabling access and audit logging' not in study

+ 

+ 

+ def test_go_straight_below_4kb(topo, setup):

+     """

+     Go straight below 4KB

+     :id: a855115a-fe9e-11e8-8e91-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Go straight below 4KB

+         2. Clean space

+     :expectedresults:

+         1. Should Success

+         2. Should Success

+     """

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     topo.standalone.restart()

+     subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+     subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo1'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(FULL_THR_FILL_SIZE)])

+     _withouterrorlog(topo, 'topo.standalone.status() != False', 11)

+     os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+     os.remove('{}/foo1'.format(topo.standalone.ds_paths.log_dir))

+     topo.standalone.start()

+     assert topo.standalone.status() == True

+ 

+ 

+ @pytest.mark.bz982325

+ def test_threshold_to_overflow_value(topo, setup):

+     """

+     Overflow in nsslapd-disk-monitoring-threshold

+     :id: ad60ab3c-fe9e-11e8-88dc-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Setting nsslapd-disk-monitoring-threshold to overflow_value

+     :expectedresults:

+         1. Should Success

+     """

+     overflow_value = '3000000000'

+     # Setting nsslapd-disk-monitoring-threshold to overflow_value

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-threshold', ensure_bytes(overflow_value))

+     assert overflow_value == re.findall('nsslapd-disk-monitoring-threshold: \d+', str(

+         topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)',

+                                  ['nsslapd-disk-monitoring-threshold'])))[0].split(' ')[1]

+ 

+ 

+ @pytest.mark.bz970995

+ def test_threshold_is_reached_to_half(topo, setup):

+     """

+     RHDS not shutting down when disk monitoring threshold is reached to half.

+     :id: b2d3665e-fe9e-11e8-b9c0-8c16451d917b

+     :setup: Standalone

+     :steps: Standalone

+         1. Verify that there is not endless loop of error messages

+     :expectedresults:

+         1. Should Success

+     """

+ 

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')

+     assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-threshold', ensure_bytes(THRESHOLD_BYTES))

+     topo.standalone.restart()

+     subprocess.call(['dd', 'if=/dev/zero', 'of={}/foo'.format(topo.standalone.ds_paths.log_dir), 'bs=1M', 'count={}'.format(HALF_THR_FILL_SIZE)])

+     # Verify that there is not endless loop of error messages

+     _witherrorlog(topo, "temporarily setting error loglevel to the default level", 10)

+     with open(topo.standalone.errlog, 'r') as study:study = study.read()

+     assert len(re.findall("temporarily setting error loglevel to the default level", study)) == 1

+     os.remove('{}/foo'.format(topo.standalone.ds_paths.log_dir))

+ 

+ 

+ @pytest.mark.parametrize("test_input,expected", [

+     ("nsslapd-disk-monitoring-threshold", '-2'),

+     ("nsslapd-disk-monitoring-threshold", '9223372036854775808'),

+     ("nsslapd-disk-monitoring-threshold", '2047'),

+     ("nsslapd-disk-monitoring-threshold", '0'),

+     ("nsslapd-disk-monitoring-threshold", '-1294967296'),

+     ("nsslapd-disk-monitoring-threshold", 'invalid'),

+     ("nsslapd-disk-monitoring", 'invalid'),

+     ("nsslapd-disk-monitoring", '1'),

+     ("nsslapd-disk-monitoring-grace-period", '0'),

+     ("nsslapd-disk-monitoring-grace-period", '525 948'),

+     ("nsslapd-disk-monitoring-grace-period", '-1'),

+     ("nsslapd-disk-monitoring-logging-critical", 'oninvalid'),

+     ("nsslapd-disk-monitoring-grace-period", '-1'),

+     ("nsslapd-disk-monitoring-grace-period", '0'),

+ ])

+ def test_negagtive_parameterize(topo, setup, test_input, expected):

+     """

+     Verify that invalid operations are not permitted

+     :id: b88efbf8-fe9e-11e8-8499-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Verify that invalid operations are not permitted.

+     :expectedresults:

+         1. Should not success.

+     """

+     with pytest.raises(Exception):

+         topo.standalone.config.set(test_input, ensure_bytes(expected))

+ 

+ 

+ def test_valid_operations_are_permitted(topo, setup):

+     """

+     Verify that valid operations are  permitted

+     :id: bd4f83f6-fe9e-11e8-88f4-8c16451d917b

+     :setup: Standalone

+     :steps:

+         1. Verify that valid operations are  permitted

+     :expectedresults:

+         1. Should Success.

+     """

+     assert topo.standalone.config.set('nsslapd-disk-monitoring', 'on')

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')

+     assert topo.standalone.config.set('nsslapd-errorlog-level', '8')

+     topo.standalone.restart()

+     # Trying to delete nsslapd-disk-monitoring-threshold

+     assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring-threshold', '')])

+     # Trying to add another value to nsslapd-disk-monitoring-threshold (check that it is not multivalued)

+     topo.standalone.config.add('nsslapd-disk-monitoring-threshold', '2000001')

+     # Trying to delete nsslapd-disk-monitoring

+     assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring', ensure_bytes(str(

+         topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE, '(objectclass=*)', ['nsslapd-disk-monitoring'])[

+             0]).split(' ')[2].split('\n\n')[0]))])

+     # Trying to add another value to nsslapd-disk-monitoring

+     topo.standalone.config.add('nsslapd-disk-monitoring', 'off')

+     # Trying to delete nsslapd-disk-monitoring-grace-period

+     assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring-grace-period', '')])

+     # Trying to add another value to nsslapd-disk-monitoring-grace-period

+     topo.standalone.config.add('nsslapd-disk-monitoring-grace-period', '61')

+     # Trying to delete nsslapd-disk-monitoring-logging-critical

+     assert topo.standalone.modify_s('cn=config', [(ldap.MOD_DELETE, 'nsslapd-disk-monitoring-logging-critical',

+                                                        ensure_bytes(str(

+                                                            topo.standalone.search_s('cn=config', ldap.SCOPE_SUBTREE,

+                                                                                     '(objectclass=*)', [

+                                                                                         'nsslapd-disk-monitoring-logging-critical'])[

+                                                                0]).split(' ')[2].split('\n\n')[0]))])

+     # Trying to add another value to nsslapd-disk-monitoring-logging-critical

+     assert topo.standalone.config.set('nsslapd-disk-monitoring-logging-critical', 'on')

+ 

+ 

+ if __name__ == '__main__':

+     CURRENT_FILE = os.path.realpath(__file__)

+     pytest.main("-s -v %s" % CURRENT_FILE)

Bug Description: CI test - disk_monitoring

Fix Description: Scripts are ported

https://pagure.io/389-ds-base/issue/48064

Reviewed by: ???

rebased onto d3c7567c3909c9a9277e8da8f777358faa7701e9

5 years ago

Why do you use classes here? I think the functions will be less confusing here.

it is okay to pass UTF-8 here, not bytes. lib389 does all the magic for you

topo.standalone.config.set('nsslapd-disk-monitoring-grace-period', '1')

The common practice is to use noun for the fixtures:
smtp_connection, setup, test_user

rebased onto 0cbf6c6baf600685021d1629c95fd0de52db053c

5 years ago

@spichugi all changes are done as suggested by you

rebased onto 1831991e4ac546aaaa4a703b60dd9bddc451c7ba

5 years ago

rebased onto 8ae9b0170f1d0605928659894f15ceb78e0703a1

5 years ago

Please, don't use 'shell=True'. Use a list of arguments like ['dd', 'if=/dev/zero', etc]
Checkout the Warning (red)
https://docs.python.org/2/library/subprocess.html#frequently-used-arguments

One more class here. The same as previous, you don't need it, it can be a function.

these two lines should be put to 'finally' block of 'try-finally'.
We should make sure that the files are deleted even if the test case failed

Always use the open() function in the https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files

with open() as f:
     # do something

It will close the file anyway in the end.

you can get utf8 with get_attr_val_utf8 and compare with a normal string. It is more humany

I think we dont need the sleep here.
It will make the test execution longer for no reason.
You can either verify using a timeout in loop with time.sleep(1) inside (and break from it when the check is successful) or some other way.

topo.standalone.config.set('nsslapd-disk-monitoring', 'on') - this should woek fine (without 'b')

You can add a test user with 'UserAccounts' here instead of legacy Entry object

Please, remove all of the big sleeps (bigger then time.sleep(1)). And use another approach I describe before (or any other way)

we have a topo.standalone.config.remove_all() for that in DSLdapObject

rebased onto ccb4b31d18750ad345aa6b55bc3c7eb0b4384e8d

5 years ago

rebased onto 6fa369b788fa62595cb6fffb8d1f1ad83e4bd4cf

5 years ago

@spichugi all changes done . Please merge if all ok .

rebased onto 89ac37f4efc0a758513cf15e07ddc28a269a8b25

5 years ago

rebased onto 1dc6eab1face48825e78cbb838a39bfeb39e9375

5 years ago

Typo :) And this is copied and pasted throughout the script

rebased onto 1489038

5 years ago

@mreynolds , typo corrected, :) . Please merge if all ok .

Pull-Request has been merged by mreynolds

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/3157

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago