From 8923567307009b4bc6ebea92c20b74e7f0fb48a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= Date: Fri, 13 Oct 2023 10:31:46 +0200 Subject: [PATCH] Use warning() method instead of warn() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Method warn() has been deprecated in logger and is replaced by warning(). Fixes #24. Signed-off-by: Tomáš Golembiovský --- mom/Collectors/Collector.py | 2 +- mom/Collectors/GuestMemory.py | 2 +- mom/Collectors/GuestNetworkDaemon.py | 8 ++++---- mom/Collectors/GuestQemuAgent.py | 6 +++--- mom/Controllers/KSM.py | 2 +- mom/HypervisorInterfaces/libvirtInterface.py | 18 +++++++++--------- .../vdsmjsonrpcclientInterface.py | 2 +- mom/Monitor.py | 2 +- mom/Plotter.py | 2 +- mom/Policy/Policy.py | 2 +- mom/PolicyEngine.py | 6 +++--- mom/__init__.py | 6 +++--- 12 files changed, 29 insertions(+), 29 deletions(-) diff --git a/mom/Collectors/Collector.py b/mom/Collectors/Collector.py index ae8fbcc..dfd3bed 100644 --- a/mom/Collectors/Collector.py +++ b/mom/Collectors/Collector.py @@ -92,7 +92,7 @@ def get_collectors(config_str, properties, global_config): module = __import__('mom.Collectors.' + name, None, None, name) collectors.append(getattr(module, name)(properties)) except ImportError: - logger.warn("Unable to import collector: %s", name) + logger.warning("Unable to import collector: %s", name) return None except FatalError as e: logger.error("Fatal Collector error: %s", e.msg) diff --git a/mom/Collectors/GuestMemory.py b/mom/Collectors/GuestMemory.py index 3eda53c..0e06075 100644 --- a/mom/Collectors/GuestMemory.py +++ b/mom/Collectors/GuestMemory.py @@ -42,7 +42,7 @@ def stats_error(self, msg): problem. Otherwise the log will be overrun with noise. """ if self.memstats_available: - self.logger.warn(msg) + self.logger.warning(msg) self.memstats_available = False def collect(self): diff --git a/mom/Collectors/GuestNetworkDaemon.py b/mom/Collectors/GuestNetworkDaemon.py index 89a82ae..685fb87 100755 --- a/mom/Collectors/GuestNetworkDaemon.py +++ b/mom/Collectors/GuestNetworkDaemon.py @@ -95,13 +95,13 @@ def get_guest_ip(self, properties): try: output = Popen([prog, name], stdout=PIPE).communicate()[0].decode("utf-8") except OSError as e: - self.logger.warn("Cannot call name-to-ip-helper: %s", e.strerror) + self.logger.warning("Cannot call name-to-ip-helper: %s", e.strerror) return None matches = re.findall(r"^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", output, re.M) if len(matches) != 1: - self.logger.warn("Output from name-to-ip-helper %s is not an IP " \ - "address. (output = '%s')", name, output) + self.logger.warning("Output from name-to-ip-helper %s is not an IP " \ + "address. (output = '%s')", name, output) return None else: ip = matches[0] @@ -217,7 +217,7 @@ def session(self, conn, addr): else: break except socket.error as msg: - self.logger.warn("Exception: %s" % msg) + self.logger.warning("Exception: %s" % msg) break sock_close(conn) self.logger.debug("Connection closed") diff --git a/mom/Collectors/GuestQemuAgent.py b/mom/Collectors/GuestQemuAgent.py index bd548b8..2c39275 100644 --- a/mom/Collectors/GuestQemuAgent.py +++ b/mom/Collectors/GuestQemuAgent.py @@ -49,9 +49,9 @@ def __init__(self, properties): socket_name = socket_name_template % {'name' : self.name} except KeyError as e: socket_name = self.name + '.agent' - self.logger.warn("Error substituting socket name " \ - "template. Invalid key: %s" % e) - self.logger.warn("Using socket name %s." % socket_name) + self.logger.warning("Error substituting socket name " \ + "template. Invalid key: %s" % e) + self.logger.warning("Using socket name %s." % socket_name) self.sockets = [ None, "%s/%s" % (socket_path, socket_name) ] self.agent = None diff --git a/mom/Controllers/KSM.py b/mom/Controllers/KSM.py index 59cbf10..4be56b7 100644 --- a/mom/Controllers/KSM.py +++ b/mom/Controllers/KSM.py @@ -38,7 +38,7 @@ def write_value(self, fname, value): with open(fname, 'w') as f: f.write(str(value)) except IOError as e: - self.logger.warn("KSM: Failed to write %s: %s", fname, e.strerror) + self.logger.warning("KSM: Failed to write %s: %s", fname, e.strerror) def process(self, host, guests): outputs = {} diff --git a/mom/HypervisorInterfaces/libvirtInterface.py b/mom/HypervisorInterfaces/libvirtInterface.py index 64610b3..a856303 100644 --- a/mom/HypervisorInterfaces/libvirtInterface.py +++ b/mom/HypervisorInterfaces/libvirtInterface.py @@ -127,12 +127,12 @@ def _domainGetPid(self, uuid): p1 = Popen(["ps", "axww"], stdout=PIPE).communicate()[0].decode("utf-8") matches = re.findall(r"^\s*(\d+)\s+.*" + uuid, p1, re.M) if len(matches) < 1: - self.logger.warn("No matching process for domain with uuid %s", \ - uuid) + self.logger.warning("No matching process for domain with uuid %s", \ + uuid) return None elif len(matches) > 1: - self.logger.warn("Too many process matches for domain with uuid %s",\ - uuid) + self.logger.warning("Too many process matches for domain with uuid %s",\ + uuid) return None return int(matches[0]) @@ -158,13 +158,13 @@ def _handleException(self, e): do_nothing_errors = (libvirt.VIR_ERR_NO_DOMAIN,) error = e.get_error_code() if error in reconnect_errors: - self.logger.warn('libvirtInterface: connection lost, reconnecting.') + self.logger.warning('libvirtInterface: connection lost, reconnecting.') self._reconnect() elif error in do_nothing_errors: pass else: - self.logger.warn('libvirtInterface: Unhandled libvirt exception '\ - '(%i).', error) + self.logger.warning('libvirtInterface: Unhandled libvirt exception '\ + '(%i).', error) def _domainSetBalloonTarget(self, domain, target): try: @@ -292,7 +292,7 @@ def setVmBalloonTarget(self, uuid, target): if dom is not None: if self._domainSetBalloonTarget(dom, target): name = self._domainGetName(dom) - self.logger.warn("Error while ballooning guest:%i", name) + self.logger.warning("Error while ballooning guest:%i", name) def setVmCpuTune(self, uuid, quota, period): dom = self._getDomainFromUUID(uuid) @@ -308,7 +308,7 @@ def write_value(fname, value): with open(fname, 'w') as f: f.write(str(value)) except IOError as e: - self.logger.warn("KSM: Failed to write %s: %s", fname, e.strerror) + self.logger.warning("KSM: Failed to write %s: %s", fname, e.strerror) for (key, val) in tuningParams.items(): write_value('/sys/kernel/mm/ksm/%s' % key, val) diff --git a/mom/HypervisorInterfaces/vdsmjsonrpcclientInterface.py b/mom/HypervisorInterfaces/vdsmjsonrpcclientInterface.py index d6b9e66..b47c0e1 100644 --- a/mom/HypervisorInterfaces/vdsmjsonrpcclientInterface.py +++ b/mom/HypervisorInterfaces/vdsmjsonrpcclientInterface.py @@ -35,7 +35,7 @@ def __init__(self): try: use_tls = vdsmconfig.getboolean('vars', 'ssl') except Exception as e: - self._logger.warn("Failed to read VDSM config file, using SSL connection. %s", e) + self._logger.warning("Failed to read VDSM config file, using SSL connection. %s", e) use_tls = True try: diff --git a/mom/Monitor.py b/mom/Monitor.py index 978bc3d..aaa1053 100644 --- a/mom/Monitor.py +++ b/mom/Monitor.py @@ -178,7 +178,7 @@ def _disp_collection_error(self, message=None): if self.ready is False: self.logger.debug('%s: %s', self.name, message) else: # True or None - self.logger.warn('%s: %s', self.name, message) + self.logger.warning('%s: %s', self.name, message) def _set_not_ready(self, message=None): self.ready = False diff --git a/mom/Plotter.py b/mom/Plotter.py index c0228e3..9589e32 100644 --- a/mom/Plotter.py +++ b/mom/Plotter.py @@ -27,7 +27,7 @@ def __init__(self, plot_dir, name): self.file = open(filename, 'a') except IOError as e: logger = logging.getLogger('mom.Plotter') - logger.warn("Cannot open plot file %s: %s" , filename, e.strerror) + logger.warning("Cannot open plot file %s: %s" , filename, e.strerror) def __del__(self): if self.file is not None: diff --git a/mom/Policy/Policy.py b/mom/Policy/Policy.py index c1bd71d..63d353f 100644 --- a/mom/Policy/Policy.py +++ b/mom/Policy/Policy.py @@ -63,7 +63,7 @@ def set_policy(self, name, policyStr): try: self.code = get_code(Evaluator(), self._cat_policies()) except PolicyError as e: - self.logger.warn("Unable to load policy: %s" % e) + self.logger.warning("Unable to load policy: %s" % e) if oldStr is None: del self.policy_strings[name] else: diff --git a/mom/PolicyEngine.py b/mom/PolicyEngine.py index a608195..fbd4146 100644 --- a/mom/PolicyEngine.py +++ b/mom/PolicyEngine.py @@ -48,7 +48,7 @@ def read_policy(file_name, policy_name): with open(file_name, 'r') as f: policyStr = f.read() except IOError as e: - self.logger.warn("Unable to read policy file: %s" % e) + self.logger.warning("Unable to read policy file: %s" % e) return False return self.policy.set_policy(policy_name, policyStr) @@ -61,7 +61,7 @@ def read_policy(file_name, policy_name): try: names = sorted(os.listdir(policy_dir)) except OSError as e: - self.logger.warn("Unable to read directory '%s': %s" % ( + self.logger.warning("Unable to read directory '%s': %s" % ( policy_dir, e.strerror)) return False for name in names: @@ -110,7 +110,7 @@ def get_controllers(self): module = __import__('mom.Controllers.' + name, None, None, name) self.logger.debug("Loaded %s controller", name) except ImportError: - self.logger.warn("Unable to import controller: %s", name) + self.logger.warning("Unable to import controller: %s", name) continue self.controllers.append(getattr(module, name)(self.properties)) diff --git a/mom/__init__.py b/mom/__init__.py index e6dc27b..3e4b576 100644 --- a/mom/__init__.py +++ b/mom/__init__.py @@ -186,7 +186,7 @@ def _get_plot_subdir(self, basedir): try: names = os.listdir(basedir) except OSError as e: - self.logger.warn("Cannot read plot-basedir %s: %s", basedir, e.strerror) + self.logger.warning("Cannot read plot-basedir %s: %s", basedir, e.strerror) return '' seq_num = -1 for name in names: @@ -198,13 +198,13 @@ def _get_plot_subdir(self, basedir): seq_num = seq_num + 1 dir = "%s/momplot-%03d" % (basedir, seq_num) if seq_num > 999: - self.logger.warn("Cannot create plot-dir because the sequence number "\ + self.logger.warning("Cannot create plot-dir because the sequence number "\ "is out of range. Clear the directory or choose a different one") return '' try: os.mkdir(dir) except OSError as e: - self.logger.warn("Cannot create plot-dir %s: %s", dir, e.strerror) + self.logger.warning("Cannot create plot-dir %s: %s", dir, e.strerror) return '' return dir