| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2020 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 |
|
| 13 |
from lib389.tasks import * |
| 14 |
from lib389.utils import * |
| 15 |
from test389.topologies import topology_st |
| 16 |
from lib389.cli_base import FakeArgs |
| 17 |
from lib389.plugins import POSIXWinsyncPlugin |
| 18 |
from lib389.cli_conf.plugins.posix_winsync import do_fixup |
| 19 |
|
| 20 |
pytestmark = pytest.mark.tier0 |
| 21 |
|
| 22 |
LOG_FILE = '/tmp/fixup.log' |
| 23 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 24 |
log = logging.getLogger(__name__) |
| 25 |
|
| 26 |
|
| 27 |
@pytest.fixture(scope="function") |
| 28 |
def set_log_file_and_ldif(topology_st, request): |
| 29 |
MYLDIF = 'example1k_posix.ldif' |
| 30 |
global ldif_file |
| 31 |
|
| 32 |
fh = logging.FileHandler(LOG_FILE) |
| 33 |
fh.setLevel(logging.DEBUG) |
| 34 |
log.addHandler(fh) |
| 35 |
|
| 36 |
data_dir_path = topology_st.standalone.getDir(__file__, DATA_DIR) |
| 37 |
ldif_file = f"{data_dir_path}ticket48212/{MYLDIF}" |
| 38 |
ldif_dir = topology_st.standalone.get_ldif_dir() |
| 39 |
shutil.copy(ldif_file, ldif_dir) |
| 40 |
ldif_file = ldif_dir + '/' + MYLDIF |
| 41 |
|
| 42 |
def fin(): |
| 43 |
log.info('Delete files') |
| 44 |
os.remove(LOG_FILE) |
| 45 |
os.remove(ldif_file) |
| 46 |
|
| 47 |
request.addfinalizer(fin) |
| 48 |
|
| 49 |
|
| 50 |
@pytest.mark.skipif(ds_is_older("1.4.1"), reason="Not implemented") |
| 51 |
def test_posix_winsync_fixup(topology_st, set_log_file_and_ldif): |
| 52 |
"""Test posix-winsync fixup that was ported from legacy tools |
| 53 |
|
| 54 |
:id: ce691017-cbd2-49ed-ac2d-8c3ea78050f6 |
| 55 |
:setup: Standalone instance |
| 56 |
:steps: |
| 57 |
1. Create DS instance |
| 58 |
2. Enable PosixWinsync plugin |
| 59 |
3. Run fixup task |
| 60 |
4. Check log for output |
| 61 |
:expectedresults: |
| 62 |
1. Success |
| 63 |
2. Success |
| 64 |
3. Success |
| 65 |
4. Success |
| 66 |
""" |
| 67 |
|
| 68 |
standalone = topology_st.standalone |
| 69 |
output_list = ['Attempting to add task entry', 'Successfully added task entry'] |
| 70 |
|
| 71 |
log.info('Enable POSIXWinsyncPlugin') |
| 72 |
posix = POSIXWinsyncPlugin(standalone) |
| 73 |
posix.enable() |
| 74 |
|
| 75 |
log.info('Stopping the server and importing posix accounts') |
| 76 |
standalone.stop() |
| 77 |
assert standalone.ldif2db(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], encrypt=None, excludeSuffixes=None, |
| 78 |
import_file=ldif_file) |
| 79 |
standalone.start() |
| 80 |
|
| 81 |
args = FakeArgs() |
| 82 |
args.DN = DEFAULT_SUFFIX |
| 83 |
args.filter = None |
| 84 |
args.timeout = 0 |
| 85 |
|
| 86 |
log.info('Run Fixup task') |
| 87 |
do_fixup(standalone, DEFAULT_SUFFIX, log, args) |
| 88 |
|
| 89 |
log.info('Check log if fixup task was successful') |
| 90 |
with open(LOG_FILE, 'r') as f: |
| 91 |
file_content = f.read() |
| 92 |
for item in output_list: |
| 93 |
assert item in file_content |
| 94 |
|
| 95 |
|
| 96 |
if __name__ == '__main__': |
| 97 |
# Run isolated |
| 98 |
# -s for DEBUG mode |
| 99 |
CURRENT_FILE = os.path.realpath(__file__) |
| 100 |
pytest.main("-s %s" % CURRENT_FILE) |