| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2023 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 ldap |
| 10 |
import logging |
| 11 |
import pytest |
| 12 |
import time |
| 13 |
import subprocess |
| 14 |
import os |
| 15 |
from test389.topologies import topology_st as topo |
| 16 |
from lib389.backend import Backends, DatabaseConfig |
| 17 |
from lib389.dseldif import DSEldif |
| 18 |
from lib389.plugins import Plugins |
| 19 |
|
| 20 |
log = logging.getLogger(__name__) |
| 21 |
|
| 22 |
|
| 23 |
def test_upgradednformat(topo): |
| 24 |
"""Test the upgradednformat does not crash the server |
| 25 |
|
| 26 |
:id: 5f138d97-9384-4c9b-ad66-dc902b61de99 |
| 27 |
:setup: Standalone Instance |
| 28 |
:steps: |
| 29 |
1. Check we are running in BDB else skip the test |
| 30 |
2. Stop Server |
| 31 |
3. launch upgradednformat subcommand |
| 32 |
4. Check messages of completion are logged in error logs |
| 33 |
:expectedresults: |
| 34 |
1. Success |
| 35 |
2. Success |
| 36 |
3. Success |
| 37 |
4. Success |
| 38 |
""" |
| 39 |
|
| 40 |
# Are we using BDB? |
| 41 |
topo.standalone.restart() |
| 42 |
db_config = DatabaseConfig(topo.standalone) |
| 43 |
db_lib = db_config.get_db_lib() |
| 44 |
|
| 45 |
# Check for library specific attributes |
| 46 |
if db_lib == 'bdb': |
| 47 |
pass |
| 48 |
elif db_lib == 'mdb': |
| 49 |
# upgradednformat only applicable with BDB |
| 50 |
return |
| 51 |
else: |
| 52 |
# Unknown - the server would probably fail to start but check it anyway |
| 53 |
log.fatal(f'Unknown backend library: {db_lib}') |
| 54 |
assert False |
| 55 |
|
| 56 |
# Stop the server |
| 57 |
topo.standalone.stop() |
| 58 |
|
| 59 |
# Launch upgradednformat command |
| 60 |
cmd = ["/usr/sbin/ns-slapd", "upgradednformat", "-D", topo.standalone.ds_paths.config_dir, "-n", "userroot", "-a", "%s/userRoot" % topo.standalone.dbdir] |
| 61 |
log.debug(f"DEBUG: Running {cmd}") |
| 62 |
try: |
| 63 |
output = subprocess.check_output(cmd, universal_newlines=True, stderr=subprocess.STDOUT) |
| 64 |
except: |
| 65 |
pass |
| 66 |
|
| 67 |
# likely useless as write to error log is in-sync |
| 68 |
time.sleep(2) |
| 69 |
|
| 70 |
# Check for successful completion |
| 71 |
assert topo.standalone.ds_error_log.match('.*Start upgrade dn format.*') |
| 72 |
assert topo.standalone.ds_error_log.match('.*bdb_upgradednformat - Instance userroot in.*is up-to-date.*') |
| 73 |
|
| 74 |
if __name__ == '__main__': |
| 75 |
# Run isolated |
| 76 |
# -s for DEBUG mode |
| 77 |
CURRENT_FILE = os.path.realpath(__file__) |
| 78 |
pytest.main(["-s", CURRENT_FILE]) |
| 79 |
|