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

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