From 2c2bb5e6c11a959eb6ce3236b49cdf140cc0b0ba Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 19 Jan 2022 13:45:46 +0900 Subject: [PATCH] Use LOG.warning instead of deprecated LOG.warn The LOG.warn method is deprecated[1] and the LOG.warning method should be used instead. [1] https://docs.python.org/3/library/logging.html#logging.warning Change-Id: I9037d4dfc680586ec5aa14d6f57e12dbdc4a4b91 --- .../metadata/services/baseopenstackservice.py | 3 ++- cloudbaseinit/plugins/common/networkconfig.py | 4 ++-- cloudbaseinit/plugins/common/setuserpassword.py | 4 ++-- cloudbaseinit/plugins/factory.py | 6 +++--- cloudbaseinit/plugins/windows/azureguestagent.py | 4 ++-- cloudbaseinit/plugins/windows/winrmlistener.py | 4 ++-- cloudbaseinit/tests/testutils.py | 2 +- cloudbaseinit/utils/hostname.py | 10 +++++----- cloudbaseinit/utils/log.py | 4 ++-- 9 files changed, 21 insertions(+), 20 deletions(-) diff --git a/cloudbaseinit/metadata/services/baseopenstackservice.py b/cloudbaseinit/metadata/services/baseopenstackservice.py index 6e7d40fd1..9386592db 100644 --- a/cloudbaseinit/metadata/services/baseopenstackservice.py +++ b/cloudbaseinit/metadata/services/baseopenstackservice.py @@ -167,7 +167,8 @@ def _parse_dns_data(services_data): for service_data in services_data: service_type = service_data.get("type") if service_type != NETWORK_SERVICE_TYPE_DNS: - LOG.warn("Skipping unsupported service type: %s", service_type) + LOG.warning("Skipping unsupported service type: %s", + service_type) continue address = service_data.get("address") diff --git a/cloudbaseinit/plugins/common/networkconfig.py b/cloudbaseinit/plugins/common/networkconfig.py index 8704721c8..768212aa2 100644 --- a/cloudbaseinit/plugins/common/networkconfig.py +++ b/cloudbaseinit/plugins/common/networkconfig.py @@ -140,7 +140,7 @@ def _process_network_details(self, network_details): for mac in adapter_macs: nic = macnics.pop(mac, None) if not nic: - LOG.warn("Missing details for adapter %s", mac) + LOG.warning("Missing details for adapter %s", mac) continue name = osutils.get_network_adapter_name_by_mac_address(mac) @@ -168,7 +168,7 @@ def _process_network_details(self, network_details): reboot_required = reboot or reboot_required configured = True for mac in macnics: - LOG.warn("Details not used for adapter %s", mac) + LOG.warning("Details not used for adapter %s", mac) if not configured: LOG.error("No adapters were configured") diff --git a/cloudbaseinit/plugins/common/setuserpassword.py b/cloudbaseinit/plugins/common/setuserpassword.py index a9af93119..7032d9313 100644 --- a/cloudbaseinit/plugins/common/setuserpassword.py +++ b/cloudbaseinit/plugins/common/setuserpassword.py @@ -40,8 +40,8 @@ def _get_password(self, service, shared_data): if password: injected = True - LOG.warn('Using admin_pass metadata user password. Consider ' - 'changing it as soon as possible') + LOG.warning('Using admin_pass metadata user password. Consider ' + 'changing it as soon as possible') else: password = shared_data.get(plugin_constant.SHARED_DATA_PASSWORD) diff --git a/cloudbaseinit/plugins/factory.py b/cloudbaseinit/plugins/factory.py index d7ab88fac..2e41898e2 100644 --- a/cloudbaseinit/plugins/factory.py +++ b/cloudbaseinit/plugins/factory.py @@ -59,9 +59,9 @@ def load_plugins(stage): for class_path in CONF.plugins: if class_path in OLD_PLUGINS: new_class_path = OLD_PLUGINS[class_path] - LOG.warn("Old plugin module %r was found. The new name is %r. " - "The old name will not be supported starting with " - "cloudbaseinit 1.0", class_path, new_class_path) + LOG.warning("Old plugin module %r was found. The new name is %r. " + "The old name will not be supported starting with " + "cloudbaseinit 1.0", class_path, new_class_path) class_path = new_class_path try: diff --git a/cloudbaseinit/plugins/windows/azureguestagent.py b/cloudbaseinit/plugins/windows/azureguestagent.py index 2a33f1fae..a6e056b52 100644 --- a/cloudbaseinit/plugins/windows/azureguestagent.py +++ b/cloudbaseinit/plugins/windows/azureguestagent.py @@ -241,8 +241,8 @@ def execute(self, service, shared_data): self._configure_rd_agent(osutils, ga_target_path) if not osutils.check_dotnet_is_installed("4"): - LOG.warn("The .Net framework 4.5 or greater is required " - "by the Azure guest agent") + LOG.warning("The .Net framework 4.5 or greater is " + "required by the Azure guest agent") else: osutils.set_service_start_mode( SERVICE_NAME_RDAGENT, diff --git a/cloudbaseinit/plugins/windows/winrmlistener.py b/cloudbaseinit/plugins/windows/winrmlistener.py index 01b4dc50c..028d51cbf 100644 --- a/cloudbaseinit/plugins/windows/winrmlistener.py +++ b/cloudbaseinit/plugins/windows/winrmlistener.py @@ -34,8 +34,8 @@ class ConfigWinRMListenerPlugin(base.BasePlugin): def _check_winrm_service(self, osutils): if not osutils.check_service_exists(self._winrm_service_name): - LOG.warn("Cannot configure the WinRM listener as the service " - "is not available") + LOG.warning("Cannot configure the WinRM listener as the service " + "is not available") return False start_mode = osutils.get_service_start_mode(self._winrm_service_name) diff --git a/cloudbaseinit/tests/testutils.py b/cloudbaseinit/tests/testutils.py index 6431c1b55..a80bc83f3 100644 --- a/cloudbaseinit/tests/testutils.py +++ b/cloudbaseinit/tests/testutils.py @@ -84,7 +84,7 @@ class LogSnatcher(object): with LogSnatcher('plugins.windows.createuser') as snatcher: LOG.info("doing stuff") LOG.info("doing stuff %s", 1) - LOG.warn("doing other stuff") + LOG.warning("doing other stuff") ... self.assertEqual(snatcher.output, ['INFO:unknown:doing stuff', diff --git a/cloudbaseinit/utils/hostname.py b/cloudbaseinit/utils/hostname.py index 18acf34ca..fa268b0f4 100644 --- a/cloudbaseinit/utils/hostname.py +++ b/cloudbaseinit/utils/hostname.py @@ -45,11 +45,11 @@ def set_hostname(osutils, hostname): hostname = hostname.split('.', 1)[0] if (len(hostname) > NETBIOS_HOST_NAME_MAX_LEN and CONF.netbios_host_name_compatibility): - LOG.warn('Truncating host name for Netbios compatibility. ' - 'Old name: %(old_hostname)s, new name: ' - '%(new_hostname)s' % - {'old_hostname': hostname, - 'new_hostname': hostname[:NETBIOS_HOST_NAME_MAX_LEN]}) + LOG.warning('Truncating host name for Netbios compatibility. ' + 'Old name: %(old_hostname)s, new name: ' + '%(new_hostname)s' % + {'old_hostname': hostname, + 'new_hostname': hostname[:NETBIOS_HOST_NAME_MAX_LEN]}) hostname = hostname[:NETBIOS_HOST_NAME_MAX_LEN] hostname = re.sub(r'-$', '0', hostname) if platform.node().lower() == hostname.lower(): diff --git a/cloudbaseinit/utils/log.py b/cloudbaseinit/utils/log.py index 20ff1af4b..9bfbf6968 100644 --- a/cloudbaseinit/utils/log.py +++ b/cloudbaseinit/utils/log.py @@ -101,5 +101,5 @@ def setup(product_name): formatters.ContextFormatter(project=product_name, datefmt=datefmt)) except serial.SerialException: - LOG.warn("Serial port: {0} could not be opened".format( - CONF.logging_serial_port_settings)) + LOG.warning("Serial port: {0} could not be opened".format( + CONF.logging_serial_port_settings))