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 misc DeprecationWarnings #6188

Merged
merged 13 commits into from
Apr 30, 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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Changed
Contributed by (@philipphomberger Schwarz IT KG)
* Refactor `tools/launchdev.sh` to use `tmux` instead of `screen`. #6186 (by @nzlosh and @cognifloyd)
* Updated package build container environment to use py3.8 and mongo4.4 #6129
* Fic misc DeprecationWarnings to prepare for python 3.10 support. #6188 (by @nzlosh)

Added
~~~~~
Expand Down
2 changes: 1 addition & 1 deletion st2actions/st2actions/policies/concurrency_by_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def apply_before(self, target):

# Warn users that the coordination service is not configured.
if not coordination.configured():
LOG.warn(
LOG.warning(
"Coordination service is not configured. Policy enforcement is best effort."
)

Expand Down
2 changes: 1 addition & 1 deletion st2actions/st2actions/scheduler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def _handle_execution(self, execution_queue_item_db):
if action_has_policies_require_lock:
# Warn users that the coordination service is not configured.
if not coordination_service.configured():
LOG.warn(
LOG.warning(
"[%s] Coordination backend is not configured. "
"Policy enforcement is best effort.",
action_execution_id,
Expand Down
4 changes: 2 additions & 2 deletions st2api/st2api/controllers/v1/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _create_shadow_trigger(triggertype_db):
# Not aborting as this is convenience.
return
except StackStormDBObjectConflictError as e:
LOG.warn(
LOG.warning(
'Trigger creation of "%s" failed with uniqueness conflict. Exception: %s',
trigger,
six.text_type(e),
Expand All @@ -221,7 +221,7 @@ def _delete_shadow_trigger(triggertype_db):
)
trigger_db = TriggerService.get_trigger_db_by_ref(triggertype_ref.ref)
if not trigger_db:
LOG.warn(
LOG.warning(
"No shadow trigger found for %s. Will skip delete.", triggertype_db
)
return
Expand Down
12 changes: 6 additions & 6 deletions st2client/st2client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_client(self, args, debug=False):
cache_token=cache_token,
)
except requests.exceptions.ConnectionError as e:
self.LOG.warn(
self.LOG.warning(
"Auth API server is not available, skipping authentication."
)
self.LOG.exception(e)
Expand Down Expand Up @@ -280,7 +280,7 @@ def _get_cached_auth_token(self, client, username, password):
"cached token meaning they may be slower."
% (cached_token_path, os.getlogin())
)
self.LOG.warn(message)
self.LOG.warning(message)
return None

if not os.path.isfile(cached_token_path):
Expand All @@ -293,7 +293,7 @@ def _get_cached_auth_token(self, client, username, password):
"access to this file). Subsequent requests won't use a cached token "
"meaning they may be slower." % (cached_token_path, os.getlogin())
)
self.LOG.warn(message)
self.LOG.warning(message)
return None

# Safety check for too permissive permissions
Expand All @@ -307,7 +307,7 @@ def _get_cached_auth_token(self, client, username, password):
"restrict the permissions and make sure only your own user can read "
"from or write to the file." % (file_st_mode, cached_token_path)
)
self.LOG.warn(message)
self.LOG.warning(message)

with open(cached_token_path) as fp:
data = fp.read()
Expand Down Expand Up @@ -359,7 +359,7 @@ def _cache_auth_token(self, token_obj):
"cached token meaning they may be slower."
% (cached_token_path, os.getlogin())
)
self.LOG.warn(message)
self.LOG.warning(message)
return None

if os.path.isfile(cached_token_path) and not os.access(
Expand All @@ -372,7 +372,7 @@ def _cache_auth_token(self, token_obj):
"cached token meaning they may be slower."
% (cached_token_path, os.getlogin())
)
self.LOG.warn(message)
self.LOG.warning(message)
return None

token = token_obj.token
Expand Down
7 changes: 3 additions & 4 deletions st2client/st2client/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def parse(self):
if self.validate_config_permissions:
# Make sure the directory permissions == 0o770
if bool(os.stat(config_dir_path).st_mode & 0o7):
self.LOG.warn(
self.LOG.warning(
"The StackStorm configuration directory permissions are "
"insecure (too permissive): others have access."
)
Expand All @@ -130,15 +130,14 @@ def parse(self):

# Make sure the file permissions == 0o660
if bool(os.stat(self.config_file_path).st_mode & 0o7):
self.LOG.warn(
self.LOG.warning(
"The StackStorm configuration file permissions are "
"insecure: others have access."
)

config = ConfigParser()
with io.open(self.config_file_path, "r", encoding="utf8") as fp:
config.readfp(fp)

config.read_file(fp)
for section, keys in six.iteritems(CONFIG_FILE_OPTIONS):
for key, options in six.iteritems(keys):
key_type = options["type"]
Expand Down
2 changes: 1 addition & 1 deletion st2client/st2client/formatters/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# official StackStorm packages.
# Only time it may not be available is if the user is doing custom install from source or
# similar.
logging.getLogger(__name__).warn(
logging.getLogger(__name__).warning(
"libYAML C bindings are not available. This means YAML "
"parsing and serialization will be significantly slower. You are "
"strongly recommended to install libyaml (libyaml-dev package "
Expand Down
2 changes: 1 addition & 1 deletion st2client/st2client/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def _check_locale_and_print_warning(self):

if preferred_encoding and preferred_encoding.lower() != "utf-8":
msg = NON_UTF8_LOCALE % (default_locale or "unknown", preferred_encoding)
LOGGER.warn(msg)
LOGGER.warning(msg)


def setup_logging(argv):
Expand Down
15 changes: 8 additions & 7 deletions st2client/tests/unit/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_correct_permissions_emit_no_warnings(self):

result = parser.parse() # noqa F841

self.assertEqual(parser.LOG.warn.call_count, 0)
self.assertEqual(parser.LOG.warning.call_count, 0)

# Make sure we left the file alone
self.assertTrue(os.path.exists(self.TEMP_FILE_PATH))
Expand All @@ -173,7 +173,7 @@ def test_weird_but_correct_permissions_emit_no_warnings(self):

result = parser.parse() # noqa F841

self.assertEqual(parser.LOG.warn.call_count, 0)
self.assertEqual(parser.LOG.warning.call_count, 0)

# Make sure we left the file alone
self.assertTrue(os.path.exists(self.TEMP_FILE_PATH))
Expand All @@ -191,7 +191,7 @@ def test_weird_but_correct_permissions_emit_no_warnings(self):

result = parser.parse() # noqa F841

self.assertEqual(parser.LOG.warn.call_count, 0)
self.assertEqual(parser.LOG.warning.call_count, 0)

# Make sure we left the file alone
self.assertTrue(os.path.exists(self.TEMP_FILE_PATH))
Expand All @@ -200,6 +200,7 @@ def test_weird_but_correct_permissions_emit_no_warnings(self):
self.assertTrue(os.path.exists(self.TEMP_CONFIG_DIR))
self.assertEqual(os.stat(self.TEMP_CONFIG_DIR).st_mode & 0o7777, 0o2770)

@unittest.skipIf(os.getuid() == 0, reason="Test must be run as non-root user.")
def test_warn_on_bad_config_permissions(self):
# Setup the config directory
os.chmod(self.TEMP_CONFIG_DIR, 0o0755)
Expand All @@ -225,16 +226,16 @@ def test_warn_on_bad_config_permissions(self):
parser.LOG.info.call_args_list[0][0][0],
)

self.assertEqual(parser.LOG.warn.call_count, 2)
self.assertEqual(parser.LOG.warning.call_count, 2)
self.assertEqual(
"The StackStorm configuration directory permissions are insecure "
"(too permissive): others have access.",
parser.LOG.warn.call_args_list[0][0][0],
parser.LOG.warning.call_args_list[0][0][0],
)

self.assertEqual(
"The StackStorm configuration file permissions are insecure: others have access.",
parser.LOG.warn.call_args_list[1][0][0],
parser.LOG.warning.call_args_list[1][0][0],
)

# Make sure we left the file alone
Expand Down Expand Up @@ -265,7 +266,7 @@ def test_disable_permissions_warnings(self):
result = parser.parse() # noqa F841

self.assertEqual(parser.LOG.info.call_count, 0)
self.assertEqual(parser.LOG.warn.call_count, 0)
self.assertEqual(parser.LOG.warning.call_count, 0)

# Make sure we left the file alone
self.assertTrue(os.path.exists(self.TEMP_FILE_PATH))
Expand Down
32 changes: 17 additions & 15 deletions st2client/tests/unit/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def test_non_unicode_encoding_locale_warning_is_printed(self, mock_logger):
shell = Shell()
shell.run(argv=["trigger", "list"])

call_args = mock_logger.warn.call_args[0][0]
call_args = mock_logger.warning.call_args[0][0]
self.assertIn(
"Locale en_US with encoding iso which is not UTF-8 is used.", call_args
)
Expand All @@ -502,7 +502,7 @@ def test_failed_to_get_locale_encoding_warning_is_printed(self, mock_logger):
shell = Shell()
shell.run(argv=["trigger", "list"])

call_args = mock_logger.warn.call_args[0][0]
call_args = mock_logger.warning.call_args[0][0]
self.assertTrue(
"Locale unknown with encoding unknown which is not UTF-8 is used."
in call_args
Expand Down Expand Up @@ -542,13 +542,13 @@ def test_dont_warn_multiple_times(self):
# Test without token.
shell.run(["--config-file", mock_config_path, "action", "list"])

self.assertEqual(shell.LOG.warn.call_count, 2)
self.assertEqual(shell.LOG.warning.call_count, 2)
self.assertEqual(
shell.LOG.warn.call_args_list[0][0][0][:63],
shell.LOG.warning.call_args_list[0][0][0][:63],
"The StackStorm configuration directory permissions are insecure",
)
self.assertEqual(
shell.LOG.warn.call_args_list[1][0][0][:58],
shell.LOG.warning.call_args_list[1][0][0][:58],
"The StackStorm configuration file permissions are insecure",
)

Expand Down Expand Up @@ -617,6 +617,7 @@ def _write_mock_config(self):
with open(self._mock_config_path, "w") as fp:
fp.write(MOCK_CONFIG)

@unittest.skipIf(os.getuid() == 0, reason="Test must be run as non-root user.")
def test_get_cached_auth_token_invalid_permissions(self):
shell = Shell()
client = Client()
Expand All @@ -637,8 +638,8 @@ def test_get_cached_auth_token_invalid_permissions(self):
)

self.assertEqual(result, None)
self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
self.assertEqual(shell.LOG.warning.call_count, 1)
log_message = shell.LOG.warning.call_args[0][0]

expected_msg = (
"Unable to retrieve cached token from .*? read access to the parent "
Expand All @@ -656,8 +657,8 @@ def test_get_cached_auth_token_invalid_permissions(self):
)
self.assertEqual(result, None)

self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
self.assertEqual(shell.LOG.warning.call_count, 1)
log_message = shell.LOG.warning.call_args[0][0]

expected_msg = (
"Unable to retrieve cached token from .*? read access to this file"
Expand All @@ -674,12 +675,13 @@ def test_get_cached_auth_token_invalid_permissions(self):
)
self.assertEqual(result, "yayvalid")

self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
self.assertEqual(shell.LOG.warning.call_count, 1)
log_message = shell.LOG.warning.call_args[0][0]

expected_msg = "Permissions .*? for cached token file .*? are too permissive.*"
self.assertRegex(log_message, expected_msg)

@unittest.skipIf(os.getuid() == 0, reason="Test must be run as non-root user.")
def test_cache_auth_token_invalid_permissions(self):
shell = Shell()
username = "testu"
Expand All @@ -700,8 +702,8 @@ def test_cache_auth_token_invalid_permissions(self):
shell.LOG = mock.Mock()
shell._cache_auth_token(token_obj=token_db)

self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
self.assertEqual(shell.LOG.warning.call_count, 1)
log_message = shell.LOG.warning.call_args[0][0]

expected_msg = (
"Unable to write token to .*? doesn't have write access to the parent "
Expand All @@ -716,8 +718,8 @@ def test_cache_auth_token_invalid_permissions(self):
shell.LOG = mock.Mock()
shell._cache_auth_token(token_obj=token_db)

self.assertEqual(shell.LOG.warn.call_count, 1)
log_message = shell.LOG.warn.call_args[0][0]
self.assertEqual(shell.LOG.warning.call_count, 1)
log_message = shell.LOG.warning.call_args[0][0]

expected_msg = (
"Unable to write token to .*? doesn't have write access to this file"
Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/constants/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# official StackStorm packages.
# Only time it may not be available is if the user is doing custom install from source or
# similar.
logging.getLogger(__name__).warn(
logging.getLogger(__name__).warning(
"libYAML C bindings are not available. This means YAML "
"parsing and serialization will be significantly slower. You are "
"strongly recommended to install libyaml (libyaml-dev package "
Expand Down
19 changes: 10 additions & 9 deletions st2common/st2common/expressions/functions/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,37 @@


def version_compare(value, pattern):
return semver.compare(value, pattern)
return semver.Version.parse(value).compare(pattern)


def version_more_than(value, pattern):
return semver.compare(value, pattern) == 1
return version_compare(value, pattern) == 1


def version_less_than(value, pattern):
return semver.compare(value, pattern) == -1
return version_compare(value, pattern) == -1


def version_equal(value, pattern):
return semver.compare(value, pattern) == 0
return version_compare(value, pattern) == 0


def version_match(value, pattern):
return semver.match(value, pattern)
return semver.Version.parse(value).match(pattern)


def version_bump_major(value):
return semver.bump_major(value)
return str(semver.Version.parse(value).bump_major())


def version_bump_minor(value):
return semver.bump_minor(value)
return str(semver.Version.parse(value).bump_minor())


def version_bump_patch(value):
return semver.bump_patch(value)
return str(semver.Version.parse(value).bump_patch())


def version_strip_patch(value):
return "{major}.{minor}".format(**semver.parse(value))
sv = semver.Version.parse(value)
return f"{sv.major}.{sv.minor}"
2 changes: 1 addition & 1 deletion st2common/st2common/logging/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def reopen_log_files(handlers):
if "cannot release" in six.text_type(e):
# Release failed which most likely indicates that acquire failed
# and lock was never acquired
LOG.warn("Failed to release lock", exc_info=True)
LOG.warning("Failed to release lock", exc_info=True)
else:
raise e

Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/persistence/db_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _retry_if_connection_error(error):
# start of error msg.
is_connection_error = isinstance(error, mongoengine.connection.ConnectionFailure)
if is_connection_error:
LOG.warn("Retry on ConnectionError - %s", error)
LOG.warning("Retry on ConnectionError - %s", error)
return is_connection_error


Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/services/coordination.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def get_coordinator(start_heart=True, use_cache=True):
global COORDINATOR

if not configured():
LOG.warn(
LOG.warning(
"Coordination backend is not configured. Code paths which use coordination "
"service will use best effort approach and race conditions are possible."
)
Expand Down
Loading
Loading