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

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