Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Replace all warn() with warning() #413

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,14 +979,23 @@ def testLineContinuationInConfig(self):

self.assertEqual(config["server"], 'http://1.2.3.4\nvalue')

@patch('logging.Logger.warn')
def testCommentedOutLineContinuationInConfig(self, logger_warn):
@patch('logging.Logger.warning')
def testCommentedOutLineContinuationInConfig(self, logger_warning):
"""Test that when a config line that starts with space or tab which is followed by a '#',
if we are running python2: it is treated as a continuation of the previous line,
but a warning is logged for the user.
If we are running python3: it is ignored as a comment, and no warning is logged.
:return:
"""
# Alter the main conf file constant temporarily:
virtwho.config.VW_GENERAL_CONF_PATH = os.path.join(self.general_config_file_dir, "virt-who.conf")
# We need to have [global] section with at least some value. Otherwise,
# init_config() returns warning, and we test that no warning is returned.
with open(virtwho.config.VW_GENERAL_CONF_PATH, "w") as f:
f.write("""
[global]
debug=True
""")

with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
f.write("""
[test1]
Expand All @@ -1003,8 +1012,8 @@ def testCommentedOutLineContinuationInConfig(self, logger_warn):
config = manager.configs[0][1]
self.assertEqual(config.name, "test1")
self.assertEqual(config["server"], "http://1.2.3.4")
self.assertFalse(logger_warn.called)
self.assertEqual(logger_warn.call_count, 0)
self.assertFalse(logger_warning.called)
self.assertEqual(logger_warning.call_count, 0)


class TestParseList(TestBase):
Expand Down
16 changes: 8 additions & 8 deletions virtwho/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def parse_file(filename):
except InvalidOption as e:
# When a configuration section has an Invalid Option, continue
# See https://bugzilla.redhat.com/show_bug.cgi?id=1457101 for more info
logger.warn("Invalid configuration detected: %s", str(e))
logger.warning("Invalid configuration detected: %s", str(e))
except DuplicateOptionError as e:
logger.warning(str(e))
except Exception as e:
Expand Down Expand Up @@ -1342,15 +1342,15 @@ def all_drop_dir_config_sections(config_dir=VW_CONF_DIR):
conf_files = set(s for s in all_dir_content if s.endswith('.conf'))
non_conf_files = all_dir_content - conf_files
except OSError:
logger.warn("Configuration directory '%s' doesn't exist or is not accessible",
config_dir)
logger.warning("Configuration directory '%s' doesn't exist or is not accessible",
config_dir)
return {}

if not all_dir_content:
logger.warn("Configuration directory '%s' appears empty", config_dir)
logger.warning("Configuration directory '%s' appears empty", config_dir)
elif not conf_files:
logger.warn("Configuration directory '%s' does not have any '*.conf' files but "
"is not empty", config_dir)
logger.warning("Configuration directory '%s' does not have any '*.conf' files but "
"is not empty", config_dir)
elif non_conf_files:
logger.debug("There are files in '%s' not ending in '*.conf' is this "
"intentional?", config_dir)
Expand All @@ -1372,8 +1372,8 @@ def has_config_files_in_drop_dir(config_dir=VW_CONF_DIR):
all_dir_content = set(os.listdir(config_dir))
conf_files = set(s for s in all_dir_content if s.endswith('.conf'))
except OSError:
logger.warn("Configuration directory '%s' doesn't exist or is not accessible",
config_dir)
logger.warning("Configuration directory '%s' doesn't exist or is not accessible",
config_dir)
return False

if not conf_files:
Expand Down
2 changes: 1 addition & 1 deletion virtwho/manager/satellite/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def hypervisorCheckIn(self, report, options=None):
self.server_xmlrpc.registration.virt_notify(hypervisor_systemid["system_id"], plan)
except xmlrpc.client.Fault as e:
if e.faultCode == -9:
self.logger.warn("System was deleted from Satellite 5, reregistering")
self.logger.warning("System was deleted from Satellite 5, re-registering")
hypervisor_systemid = self._load_hypervisor(hypervisor.hypervisorId,
hypervisor_type=report.config['type'], force=True)
self.server_xmlrpc.registration.virt_notify(hypervisor_systemid["system_id"], plan)
Expand Down
2 changes: 1 addition & 1 deletion virtwho/virt/libvirtd/libvirtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __validate_password(self, pass_key):
server = self._values['server']
if 'ssh://' in server or '://' not in server:
result = [(
'warn',
'warning',
"Password authentication doesn't work with ssh transport on libvirt backend, "
"copy your public ssh key to the remote machine"
)]
Expand Down
Loading