| 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.cli_ctl.dbtasks import dbtasks_verify |
| 14 |
from lib389.tasks import * |
| 15 |
from lib389.utils import * |
| 16 |
from test389.topologies import topology_st |
| 17 |
from lib389.cli_base import FakeArgs |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier0 |
| 20 |
|
| 21 |
LOG_FILE = '/tmp/dbverify.log' |
| 22 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 23 |
log = logging.getLogger(__name__) |
| 24 |
|
| 25 |
|
| 26 |
@pytest.fixture(scope="function") |
| 27 |
def set_log_file(request): |
| 28 |
fh = logging.FileHandler(LOG_FILE) |
| 29 |
fh.setLevel(logging.DEBUG) |
| 30 |
log.addHandler(fh) |
| 31 |
|
| 32 |
def fin(): |
| 33 |
log.info('Delete log file') |
| 34 |
log.removeHandler(fh) |
| 35 |
os.remove(LOG_FILE) |
| 36 |
|
| 37 |
request.addfinalizer(fin) |
| 38 |
|
| 39 |
|
| 40 |
@pytest.mark.skipif(ds_is_older("1.4.2"), reason="Not implemented") |
| 41 |
def test_dsctl_dbverify(topology_st, set_log_file): |
| 42 |
"""Test dbverify tool, that was ported from legacy tools to dsctl |
| 43 |
|
| 44 |
:id: 1b22b363-a6e5-4922-ad42-ae80446d69fe |
| 45 |
:setup: Standalone instance |
| 46 |
:steps: |
| 47 |
1. Create DS instance |
| 48 |
2. Run dbverify |
| 49 |
3. Check if dbverify was successful |
| 50 |
:expectedresults: |
| 51 |
1. Success |
| 52 |
2. Success |
| 53 |
3. Success |
| 54 |
""" |
| 55 |
|
| 56 |
standalone = topology_st.standalone |
| 57 |
message = 'dbverify successful' |
| 58 |
|
| 59 |
args = FakeArgs() |
| 60 |
args.backend = DEFAULT_BENAME |
| 61 |
|
| 62 |
log.info('Run dbverify') |
| 63 |
standalone.stop() |
| 64 |
dbtasks_verify(standalone, log, args) |
| 65 |
|
| 66 |
log.info('Check dbverify was successful') |
| 67 |
with open(LOG_FILE, 'r+') as f: |
| 68 |
file_content = f.read() |
| 69 |
assert message in file_content |
| 70 |
|
| 71 |
|
| 72 |
def run_dbverify(inst, bename, rc=0): |
| 73 |
# Run dsctl inst dbverify bename and check it returns rc |
| 74 |
cmd = [ 'dsctl', inst.serverid, 'dbverify', bename ] |
| 75 |
log.info(f'Run: {cmd}') |
| 76 |
result = subprocess.run(cmd, encoding='utf-8', capture_output=True, text=True) |
| 77 |
log.info(f'Returned: {result.returncode} stdout: {result.stdout} stderr: {result.stderr}') |
| 78 |
assert result.returncode == rc |
| 79 |
return result |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
def test_dbverify_bad_bename(topology_st, set_log_file): |
| 84 |
"""Test dbverify tool when backend does not exists |
| 85 |
|
| 86 |
:id: da79a4cc-956c-11f0-8220-c85309d5c3e3 |
| 87 |
:setup: Standalone instance |
| 88 |
:steps: |
| 89 |
1. Create DS instance |
| 90 |
2. Run dbverify |
| 91 |
3. Check if dbverify provides the expected messages |
| 92 |
:expectedresults: |
| 93 |
1. Success |
| 94 |
2. Success |
| 95 |
3. Success |
| 96 |
""" |
| 97 |
|
| 98 |
standalone = topology_st.standalone |
| 99 |
if get_default_db_lib() == 'bdb': |
| 100 |
message = "dbverify failed" |
| 101 |
logmessage = "Backend 'userFoot' does not exist." |
| 102 |
rc = 1 |
| 103 |
else: |
| 104 |
message = "dbverify successful" |
| 105 |
logmessage = "db_verify feature is meaningless" |
| 106 |
rc = 0 |
| 107 |
|
| 108 |
standalone.stop() |
| 109 |
result = run_dbverify(standalone, 'userFoot', rc) |
| 110 |
assert message in result.stdout |
| 111 |
assert logmessage in result.stderr |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
if __name__ == '__main__': |
| 116 |
# Run isolated |
| 117 |
# -s for DEBUG mode |
| 118 |
CURRENT_FILE = os.path.realpath(__file__) |
| 119 |
pytest.main("-s %s" % CURRENT_FILE) |