From 7a0b8ae5fcb99d5948e771b04cb730650094cb47 Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Apr 02 2019 13:31:07 +0000 Subject: Issue 50032 - Fix deprecation warnings in tests Bug Description: Deprecation warnings are issued by Python for the following changes: 1. https://docs.python.org/3/whatsnew/3.6.html#deprecated-python-behavior https://bugs.python.org/issue27364 - Deprecate invalid escape sequences in str/bytes 2. https://docs.python.org/3/whatsnew/3.7.html#deprecated-python-behavior https://bugs.python.org/issue25988 - collections.abc.Indexable 3. https://docs.python.org/3/library/logging.html#logging.warning https://bugs.python.org/issue13235 - logging.warn() is not documented Fix Description: 1. Use correct escape sequences or raw strings where needed. 2. Import Callable from collections.abc instead of collections module directly. 3. Use logging.warning() instead of logging.warn(). Fixes https://pagure.io/389-ds-base/issue/50032 Reviewed by: mreynolds, spichugi --- diff --git a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py index be4d8f8..a45dd46 100644 --- a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py +++ b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py @@ -212,7 +212,7 @@ def test_log_plugin_on(topology_st): log.info('parse the access logs') access_log_lines = topology_st.standalone.ds_access_log.readlines() assert len(access_log_lines) > 0 - assert topology_st.standalone.ds_access_log.match('^\[.+\d{9}.+\].+') + assert topology_st.standalone.ds_access_log.match(r'^\[.+\d{9}.+\].+') @pytest.mark.bz1273549 @@ -261,7 +261,7 @@ def test_log_plugin_off(topology_st): log.info('check access log that microseconds are not present') access_log_lines = topology_st.standalone.ds_access_log.readlines() assert len(access_log_lines) > 0 - assert not topology_st.standalone.ds_access_log.match('^\[.+\d{9}.+\].+') + assert not topology_st.standalone.ds_access_log.match(r'^\[.+\d{9}.+\].+') @pytest.mark.bz1358706 diff --git a/dirsrvtests/tests/suites/filter/filter_test.py b/dirsrvtests/tests/suites/filter/filter_test.py index c0715e9..abe9257 100644 --- a/dirsrvtests/tests/suites/filter/filter_test.py +++ b/dirsrvtests/tests/suites/filter/filter_test.py @@ -31,7 +31,7 @@ def test_filter_escaped(topology_st): 1. Add a test user with an '*' in its attribute value i.e. 'cn=test * me' 2. Add another similar test user without '*' in its attribute value - 3. Search test user using search filter "cn=*\**" + 3. Search test user using search filter "cn=*\\**" :expectedresults: 1. This should pass 2. This should pass @@ -64,9 +64,9 @@ def test_filter_escaped(topology_st): assert False try: - entry = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'cn=*\**') + entry = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'cn=*\\**') if not entry or len(entry) > 1: - log.fatal('test_filter_escaped: Entry was not found using "cn=*\**"') + log.fatal('test_filter_escaped: Entry was not found using "cn=*\\**"') assert False except ldap.LDAPError as e: log.fatal('test_filter_escaped: Failed to search for user(%s), error: %s' % diff --git a/dirsrvtests/tests/suites/plugins/pluginpath_validation_test.py b/dirsrvtests/tests/suites/plugins/pluginpath_validation_test.py index 25d5503..5c66636 100644 --- a/dirsrvtests/tests/suites/plugins/pluginpath_validation_test.py +++ b/dirsrvtests/tests/suites/plugins/pluginpath_validation_test.py @@ -43,7 +43,7 @@ def test_pluginpath_validation(topology_st): """ if os.geteuid() != 0: - log.warn('This script must be run as root') + log.warning('This script must be run as root') return os.system('setenforce 0') @@ -62,7 +62,7 @@ def test_pluginpath_validation(topology_st): try: shutil.copy('%s/libwhoami-plugin.la' % plugin_dir, tmp_dir) except IOError as e: - log.warn('Failed to copy ' + plugin_dir + + log.warning('Failed to copy ' + plugin_dir + '/libwhoami-plugin.la to the tmp directory, error: ' + e.strerror) diff --git a/dirsrvtests/tests/suites/plugins/referint_test.py b/dirsrvtests/tests/suites/plugins/referint_test.py index 67a11de..7198e6a 100644 --- a/dirsrvtests/tests/suites/plugins/referint_test.py +++ b/dirsrvtests/tests/suites/plugins/referint_test.py @@ -24,7 +24,7 @@ from lib389.topologies import topology_st as topo log = logging.getLogger(__name__) -ESCAPED_RDN_BASE = "foo\,oo" +ESCAPED_RDN_BASE = "foo\\,oo" def _user_get_dn(no): uid = '%s%d' % (ESCAPED_RDN_BASE, no) dn = 'uid=%s,%s' % (uid, SUFFIX) diff --git a/dirsrvtests/tests/suites/schema/schema_replication_test.py b/dirsrvtests/tests/suites/schema/schema_replication_test.py index 00568c8..1b2117d 100644 --- a/dirsrvtests/tests/suites/schema/schema_replication_test.py +++ b/dirsrvtests/tests/suites/schema/schema_replication_test.py @@ -234,7 +234,7 @@ def test_schema_replication_one(topology_m1c1, schema_replication_init): assert master_schema_csn == consumer_schema_csn # Check the error log of the supplier does not contain an error - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) if res is not None: assert False @@ -294,7 +294,7 @@ def test_schema_replication_two(topology_m1c1, schema_replication_init): # Check the error log of the supplier does not contain an error # This message may happen during the learning phase - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) @@ -341,7 +341,7 @@ def test_schema_replication_three(topology_m1c1, schema_replication_init): assert master_schema_csn == consumer_schema_csn # Check the error log of the supplier does not contain an error - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) if res is not None: assert False @@ -390,7 +390,7 @@ def test_schema_replication_four(topology_m1c1, schema_replication_init): assert master_schema_csn == consumer_schema_csn # Check the error log of the supplier does not contain an error - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) if res is not None: assert False @@ -457,7 +457,7 @@ def test_schema_replication_five(topology_m1c1, schema_replication_init): # Check the error log of the supplier does not contain an error # This message may happen during the learning phase - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) @@ -510,7 +510,7 @@ def test_schema_replication_six(topology_m1c1, schema_replication_init): # Check the error log of the supplier does not contain an error # This message may happen during the learning phase - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) if res is not None: assert False @@ -563,7 +563,7 @@ def test_schema_replication_seven(topology_m1c1, schema_replication_init): assert master_schema_csn == consumer_schema_csn # Check the error log of the supplier does not contain an error - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) if res is not None: assert False @@ -630,7 +630,7 @@ def test_schema_replication_eight(topology_m1c1, schema_replication_init): # Check the error log of the supplier does not contain an error # This message may happen during the learning phase - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) @@ -686,7 +686,7 @@ def test_schema_replication_nine(topology_m1c1, schema_replication_init): assert master_schema_csn == consumer_schema_csn # Check the error log of the supplier does not contain an error - regex = re.compile("must not be overwritten \(set replication log for additional info\)") + regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") res = pattern_errorlog(topology_m1c1.ms["master1"].errorlog_file, regex) if res is not None: assert False diff --git a/dirsrvtests/tests/suites/schema/test_schema.py b/dirsrvtests/tests/suites/schema/test_schema.py index 23dae71..4a6ecad 100644 --- a/dirsrvtests/tests/suites/schema/test_schema.py +++ b/dirsrvtests/tests/suites/schema/test_schema.py @@ -132,7 +132,7 @@ def test_schema_comparewithfiles(topology_st): if fschema is None: raise Exception("Empty schema file %s" % fn) except: - log.warn("Unable to parse %s as a schema file - skipping" % fn) + log.warning("Unable to parse %s as a schema file - skipping" % fn) continue log.info("Parsed %s as a schema file - checking" % fn) for oid in fschema.listall(occlass): diff --git a/dirsrvtests/tests/tickets/ticket47808_test.py b/dirsrvtests/tests/tickets/ticket47808_test.py index 074f5e1..2863176 100644 --- a/dirsrvtests/tests/tickets/ticket47808_test.py +++ b/dirsrvtests/tests/tickets/ticket47808_test.py @@ -70,7 +70,7 @@ def test_ticket47808_run(topology_st): try: topology_st.standalone.add_s(entry_2) except: - topology_st.standalone.log.warn("Adding %s failed" % entry_dn_2) + topology_st.standalone.log.warning("Adding %s failed" % entry_dn_2) pass topology_st.standalone.log.info("\n\n######################### IS SERVER UP? ######################\n") diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py index b9a87a7..0c5852a 100644 --- a/src/lib389/lib389/__init__.py +++ b/src/lib389/lib389/__init__.py @@ -48,7 +48,7 @@ import decimal import glob import tarfile import subprocess -import collections +from collections.abc import Callable import signal import errno import pwd @@ -1769,7 +1769,7 @@ class DirSrv(SimpleLDAPObject, object): wrap entries in an Entry class that provides some useful methods""" for name in dir(self.__class__.__bases__[0]): attr = getattr(self, name) - if isinstance(attr, collections.Callable): + if isinstance(attr, Callable): setattr(self, name, wrapper(attr, name)) def addLDIF(self, input_file, cont=False): @@ -2109,7 +2109,7 @@ class DirSrv(SimpleLDAPObject, object): try: self.add_s(ent) except ldap.ALREADY_EXISTS: - self.log.warn("Entry %s already exists", binddn) + self.log.warning("Entry %s already exists", binddn) try: entry = self._test_entry(binddn, ldap.SCOPE_BASE) @@ -2247,11 +2247,11 @@ class DirSrv(SimpleLDAPObject, object): except ldap.NO_SUCH_OBJECT: entry = None if entry: - self.log.warn("Agreement exists:", dn_agreement) + self.log.warning("Agreement exists:", dn_agreement) self.suffixes.setdefault(nsuffix, {})[str(consumer)] = dn_agreement return dn_agreement if (nsuffix in self.agmt) and (consumer in self.agmt[nsuffix]): - self.log.warn("Agreement exists:", dn_agreement) + self.log.warning("Agreement exists:", dn_agreement) return dn_agreement # In a separate function in this scope? @@ -2445,7 +2445,7 @@ class DirSrv(SimpleLDAPObject, object): }) self.setupBindDN(*attrs) except ldap.ALREADY_EXISTS: - self.log.warn("User already exists: %r ", user) + self.log.warning("User already exists: %r ", user) # setup replica # map old style args to new style replica args diff --git a/src/lib389/lib389/_entry.py b/src/lib389/lib389/_entry.py index 1f039ff..be8d7c5 100644 --- a/src/lib389/lib389/_entry.py +++ b/src/lib389/lib389/_entry.py @@ -370,7 +370,7 @@ class Entry(object): try: self.add_s(ent) except ldap.ALREADY_EXISTS: - log.warn("Entry %s already exists" % entry_dn) + log.warning("Entry %s already exists" % entry_dn) try: entry = self._test_entry(entry_dn, ldap.SCOPE_BASE) diff --git a/src/lib389/lib389/agreement.py b/src/lib389/lib389/agreement.py index 128a607..9690057 100644 --- a/src/lib389/lib389/agreement.py +++ b/src/lib389/lib389/agreement.py @@ -944,7 +944,7 @@ class AgreementLegacy(object): # we can just raise ALREADY_EXISTS try: entry = self.conn.getEntry(dn_agreement, ldap.SCOPE_BASE) - self.log.warn("Agreement already exists: %r", dn_agreement) + self.log.warning("Agreement already exists: %r", dn_agreement) return dn_agreement except ldap.NO_SUCH_OBJECT: entry = None diff --git a/src/lib389/lib389/changelog.py b/src/lib389/lib389/changelog.py index 4cb3063..cb218d4 100644 --- a/src/lib389/lib389/changelog.py +++ b/src/lib389/lib389/changelog.py @@ -128,7 +128,7 @@ class ChangelogLegacy(object): try: self.conn.add_s(entry) except ldap.ALREADY_EXISTS: - self.log.warn("entry %s already exists", dn) + self.log.warning("entry %s already exists", dn) return dn def delete(self): diff --git a/src/lib389/lib389/ds_instance.py b/src/lib389/lib389/ds_instance.py index d4601da..3ac4102 100644 --- a/src/lib389/lib389/ds_instance.py +++ b/src/lib389/lib389/ds_instance.py @@ -9,7 +9,7 @@ import os import re import sys -import collections +from collections.abc import Callable class DSDecorator(object): @@ -81,7 +81,7 @@ class DSModuleProxy(object): # for each function from module create decorated one for attr in dir(module): fun = getattr(module, attr) - if isinstance(fun, collections.Callable): + if isinstance(fun, Callable): decorated = DSDecorator(fun, ds) setattr(proxy, attr, decorated) setattr(obj, item, proxy) diff --git a/src/lib389/lib389/replica.py b/src/lib389/lib389/replica.py index 9117661..8be0b47 100644 --- a/src/lib389/lib389/replica.py +++ b/src/lib389/lib389/replica.py @@ -130,7 +130,7 @@ class ReplicaLegacy(object): 'passwordExpirationTime': '20381010000000Z'} self.conn.setupBindDN(repl_manager_dn, repl_manager_pw, attrs) except ldap.ALREADY_EXISTS: - self.log.warn("User already exists (weird we just checked: %s ", + self.log.warning("User already exists (weird we just checked: %s ", repl_manager_dn) def list(self, suffix=None, replica_dn=None): @@ -384,7 +384,7 @@ class ReplicaLegacy(object): dn_replica = ','.join((RDN_REPLICA, mtent.dn)) try: entry = self.conn.getEntry(dn_replica, ldap.SCOPE_BASE) - self.log.warn("Already setup replica for suffix %r", nsuffix) + self.log.warning("Already setup replica for suffix %r", nsuffix) self.conn.suffixes.setdefault(nsuffix, {}) self.conn.replica.setProperties(replica_dn=dn_replica, properties=properties) @@ -662,7 +662,7 @@ class ReplicaLegacy(object): if ents and (len(ents) > 0): ent = ents[0] elif tryrepl: - self.log.warn("Could not get RUV from %r entry -" + self.log.warning("Could not get RUV from %r entry -" " trying cn=replica", suffix) ensuffix = escapeDNValue(normalizeDN(suffix)) dn = ','.join(("cn=replica", "cn=%s" % ensuffix, DN_MAPPING_TREE)) diff --git a/src/lib389/lib389/repltools.py b/src/lib389/lib389/repltools.py index 180a37d..b2676f3 100644 --- a/src/lib389/lib389/repltools.py +++ b/src/lib389/lib389/repltools.py @@ -168,7 +168,7 @@ class ReplTools(object): for inst in all_replicas: replObj = inst.replicas.get(suffix) if replObj is None: - inst.log.warn('(%s) not setup for replication of (%s)' % + inst.log.warning('(%s) not setup for replication of (%s)' % (inst.serverid, suffix)) continue ctime = _getCSNTime(inst, csnstr) diff --git a/src/lib389/lib389/tests/dsadmin_basic_test.py b/src/lib389/lib389/tests/dsadmin_basic_test.py index 8164c84..a4f509d 100644 --- a/src/lib389/lib389/tests/dsadmin_basic_test.py +++ b/src/lib389/lib389/tests/dsadmin_basic_test.py @@ -46,7 +46,7 @@ def tearDown(): try: conn.delete_s(e) except ldap.NO_SUCH_OBJECT: - log.warn("entry not found %r" % e) + log.warning("entry not found %r" % e) def bind_test():