zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0012-Add-dsconf-replication-monitor-test-case-gitHub-issu.patch

27c138
From 8b0ba11c3dfb577d1696f4b71a6f4e9f8d42349f Mon Sep 17 00:00:00 2001
27c138
From: Pierre Rogier <progier@redhat.com>
27c138
Date: Mon, 30 Nov 2020 12:42:17 +0100
27c138
Subject: [PATCH] Add dsconf replication monitor test case (gitHub issue 4449)
27c138
 in  1.4.3 branch
27c138
27c138
---
27c138
 .../tests/suites/clu/repl_monitor_test.py     | 234 ++++++++++++++++++
27c138
 1 file changed, 234 insertions(+)
27c138
 create mode 100644 dirsrvtests/tests/suites/clu/repl_monitor_test.py
27c138
27c138
diff --git a/dirsrvtests/tests/suites/clu/repl_monitor_test.py b/dirsrvtests/tests/suites/clu/repl_monitor_test.py
27c138
new file mode 100644
27c138
index 000000000..b03d170c8
27c138
--- /dev/null
27c138
+++ b/dirsrvtests/tests/suites/clu/repl_monitor_test.py
27c138
@@ -0,0 +1,234 @@
27c138
+# --- BEGIN COPYRIGHT BLOCK ---
27c138
+# Copyright (C) 2020 Red Hat, Inc.
27c138
+# All rights reserved.
27c138
+#
27c138
+# License: GPL (version 3 or any later version).
27c138
+# See LICENSE for details.
27c138
+# --- END COPYRIGHT BLOCK ---
27c138
+#
27c138
+import time
27c138
+import subprocess
27c138
+import pytest
27c138
+
27c138
+from lib389.cli_conf.replication import get_repl_monitor_info
27c138
+from lib389.tasks import *
27c138
+from lib389.utils import *
27c138
+from lib389.topologies import topology_m2
27c138
+from lib389.cli_base import FakeArgs
27c138
+from lib389.cli_base.dsrc import dsrc_arg_concat
27c138
+from lib389.cli_base import connect_instance
27c138
+
27c138
+pytestmark = pytest.mark.tier0
27c138
+
27c138
+LOG_FILE = '/tmp/monitor.log'
27c138
+logging.getLogger(__name__).setLevel(logging.DEBUG)
27c138
+log = logging.getLogger(__name__)
27c138
+
27c138
+
27c138
+@pytest.fixture(scope="function")
27c138
+def set_log_file(request):
27c138
+    fh = logging.FileHandler(LOG_FILE)
27c138
+    fh.setLevel(logging.DEBUG)
27c138
+    log.addHandler(fh)
27c138
+
27c138
+    def fin():
27c138
+        log.info('Delete files')
27c138
+        os.remove(LOG_FILE)
27c138
+
27c138
+        config = os.path.expanduser(DSRC_HOME)
27c138
+        if os.path.exists(config):
27c138
+            os.remove(config)
27c138
+
27c138
+    request.addfinalizer(fin)
27c138
+
27c138
+
27c138
+def check_value_in_log_and_reset(content_list, second_list=None, single_value=None, error_list=None):
27c138
+    with open(LOG_FILE, 'r+') as f:
27c138
+        file_content = f.read()
27c138
+
27c138
+        for item in content_list:
27c138
+            log.info('Check that "{}" is present'.format(item))
27c138
+            assert item in file_content
27c138
+
27c138
+        if second_list is not None:
27c138
+            log.info('Check for "{}"'.format(second_list))
27c138
+            for item in second_list:
27c138
+                assert item in file_content
27c138
+
27c138
+        if single_value is not None:
27c138
+            log.info('Check for "{}"'.format(single_value))
27c138
+            assert single_value in file_content
27c138
+
27c138
+        if error_list is not None:
27c138
+            log.info('Check that "{}" is not present'.format(error_list))
27c138
+            for item in error_list:
27c138
+                assert item not in file_content
27c138
+
27c138
+        log.info('Reset log file')
27c138
+        f.truncate(0)
27c138
+
27c138
+
27c138
+@pytest.mark.ds50545
27c138
+@pytest.mark.bz1739718
27c138
+@pytest.mark.skipif(ds_is_older("1.4.0"), reason="Not implemented")
27c138
+def test_dsconf_replication_monitor(topology_m2, set_log_file):
27c138
+    """Test replication monitor that was ported from legacy tools
27c138
+
27c138
+    :id: ce48020d-7c30-41b7-8f68-144c9cd757f6
27c138
+    :setup: 2 MM topology
27c138
+    :steps:
27c138
+         1. Create DS instance
27c138
+         2. Run replication monitor with connections option
27c138
+         3. Run replication monitor with aliases option
27c138
+         4. Run replication monitor with --json option
27c138
+         5. Run replication monitor with .dsrc file created
27c138
+         6. Run replication monitor with connections option as if using dsconf CLI
27c138
+    :expectedresults:
27c138
+         1. Success
27c138
+         2. Success
27c138
+         3. Success
27c138
+         4. Success
27c138
+         5. Success
27c138
+         6. Success
27c138
+    """
27c138
+
27c138
+    m1 = topology_m2.ms["master1"]
27c138
+    m2 = topology_m2.ms["master2"]
27c138
+
27c138
+    alias_content = ['Supplier: M1 (' + m1.host + ':' + str(m1.port) + ')',
27c138
+                     'Supplier: M2 (' + m2.host + ':' + str(m2.port) + ')']
27c138
+
27c138
+    connection_content = 'Supplier: '+ m1.host + ':' + str(m1.port)
27c138
+    content_list = ['Replica Root: dc=example,dc=com',
27c138
+                    'Replica ID: 1',
27c138
+                    'Replica Status: Available',
27c138
+                    'Max CSN',
27c138
+                    'Status For Agreement: "002" ('+ m2.host + ':' + str(m2.port) + ')',
27c138
+                    'Replica Enabled: on',
27c138
+                    'Update In Progress: FALSE',
27c138
+                    'Last Update Start:',
27c138
+                    'Last Update End:',
27c138
+                    'Number Of Changes Sent:',
27c138
+                    'Number Of Changes Skipped: None',
27c138
+                    'Last Update Status: Error (0) Replica acquired successfully: Incremental update succeeded',
27c138
+                    'Last Init Start:',
27c138
+                    'Last Init End:',
27c138
+                    'Last Init Status:',
27c138
+                    'Reap Active: 0',
27c138
+                    'Replication Status: In Synchronization',
27c138
+                    'Replication Lag Time:',
27c138
+                    'Supplier: ',
27c138
+                     m2.host + ':' + str(m2.port),
27c138
+                    'Replica Root: dc=example,dc=com',
27c138
+                    'Replica ID: 2',
27c138
+                    'Status For Agreement: "001" (' + m1.host + ':' + str(m1.port)+')']
27c138
+
27c138
+    error_list = ['consumer (Unavailable)',
27c138
+                  'Failed to retrieve database RUV entry from consumer']
27c138
+
27c138
+    json_list = ['type',
27c138
+                 'list',
27c138
+                 'items',
27c138
+                 'name',
27c138
+                 m1.host + ':' + str(m1.port),
27c138
+                 'data',
27c138
+                 '"replica_id": "1"',
27c138
+                 '"replica_root": "dc=example,dc=com"',
27c138
+                 '"replica_status": "Available"',
27c138
+                 'maxcsn',
27c138
+                 'agmts_status',
27c138
+                 'agmt-name',
27c138
+                 '002',
27c138
+                 'replica',
27c138
+                 m2.host + ':' + str(m2.port),
27c138
+                 'replica-enabled',
27c138
+                 'update-in-progress',
27c138
+                 'last-update-start',
27c138
+                 'last-update-end',
27c138
+                 'number-changes-sent',
27c138
+                 'number-changes-skipped',
27c138
+                 'last-update-status',
27c138
+                 'Error (0) Replica acquired successfully: Incremental update succeeded',
27c138
+                 'last-init-start',
27c138
+                 'last-init-end',
27c138
+                 'last-init-status',
27c138
+                 'reap-active',
27c138
+                 'replication-status',
27c138
+                 'In Synchronization',
27c138
+                 'replication-lag-time',
27c138
+                 '"replica_id": "2"',
27c138
+                 '001',
27c138
+                 m1.host + ':' + str(m1.port)]
27c138
+
27c138
+    dsrc_content = '[repl-monitor-connections]\n' \
27c138
+                   'connection1 = ' + m1.host + ':' + str(m1.port) + ':' + DN_DM + ':' + PW_DM + '\n' \
27c138
+                   'connection2 = ' + m2.host + ':' + str(m2.port) + ':' + DN_DM + ':' + PW_DM + '\n' \
27c138
+                   '\n' \
27c138
+                   '[repl-monitor-aliases]\n' \
27c138
+                   'M1 = ' + m1.host + ':' + str(m1.port) + '\n' \
27c138
+                   'M2 = ' + m2.host + ':' + str(m2.port)
27c138
+
27c138
+    connections = [m1.host + ':' + str(m1.port) + ':' + DN_DM + ':' + PW_DM,
27c138
+                   m2.host + ':' + str(m2.port) + ':' + DN_DM + ':' + PW_DM]
27c138
+
27c138
+    aliases = ['M1=' + m1.host + ':' + str(m1.port),
27c138
+               'M2=' + m2.host + ':' + str(m2.port)]
27c138
+
27c138
+    args = FakeArgs()
27c138
+    args.connections = connections
27c138
+    args.aliases = None
27c138
+    args.json = False
27c138
+
27c138
+    log.info('Run replication monitor with connections option')
27c138
+    get_repl_monitor_info(m1, DEFAULT_SUFFIX, log, args)
27c138
+    check_value_in_log_and_reset(content_list, connection_content, error_list=error_list)
27c138
+
27c138
+    log.info('Run replication monitor with aliases option')
27c138
+    args.aliases = aliases
27c138
+    get_repl_monitor_info(m1, DEFAULT_SUFFIX, log, args)
27c138
+    check_value_in_log_and_reset(content_list, alias_content)
27c138
+
27c138
+    log.info('Run replication monitor with --json option')
27c138
+    args.aliases = None
27c138
+    args.json = True
27c138
+    get_repl_monitor_info(m1, DEFAULT_SUFFIX, log, args)
27c138
+    check_value_in_log_and_reset(json_list)
27c138
+
27c138
+    with open(os.path.expanduser(DSRC_HOME), 'w+') as f:
27c138
+        f.write(dsrc_content)
27c138
+
27c138
+    args.connections = None
27c138
+    args.aliases = None
27c138
+    args.json = False
27c138
+
27c138
+    log.info('Run replication monitor when .dsrc file is present with content')
27c138
+    get_repl_monitor_info(m1, DEFAULT_SUFFIX, log, args)
27c138
+    check_value_in_log_and_reset(content_list, alias_content)
27c138
+    os.remove(os.path.expanduser(DSRC_HOME))
27c138
+
27c138
+    log.info('Run replication monitor with connections option as if using dsconf CLI')
27c138
+    # Perform same test than steps 2 test but without using directly the topology instance.
27c138
+    # but with an instance similar to those than dsconf cli generates:
27c138
+    # step 2 args
27c138
+    args.connections = connections
27c138
+    args.aliases = None
27c138
+    args.json = False
27c138
+    # args needed to generate an instance with dsrc_arg_concat
27c138
+    args.instance = 'master1'
27c138
+    args.basedn = None
27c138
+    args.binddn = None
27c138
+    args.bindpw = None
27c138
+    args.pwdfile = None
27c138
+    args.prompt = False
27c138
+    args.starttls = False
27c138
+    dsrc_inst = dsrc_arg_concat(args, None)
27c138
+    inst = connect_instance(dsrc_inst, True, args)
27c138
+    get_repl_monitor_info(inst, DEFAULT_SUFFIX, log, args)
27c138
+    check_value_in_log_and_reset(content_list, connection_content, error_list=error_list)
27c138
+
27c138
+
27c138
+if __name__ == '__main__':
27c138
+    # Run isolated
27c138
+    # -s for DEBUG mode
27c138
+    CURRENT_FILE = os.path.realpath(__file__)
27c138
+    pytest.main("-s %s" % CURRENT_FILE)
27c138
-- 
27c138
2.26.2
27c138