Skip to content

Commit 7c335b3

Browse files
authored
Fix misc DeprecationWarnings (#6188)
2 parents d4cd09f + 8054c6b commit 7c335b3

File tree

21 files changed

+71
-63
lines changed

21 files changed

+71
-63
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Changed
2020
Contributed by (@philipphomberger Schwarz IT KG)
2121
* Refactor `tools/launchdev.sh` to use `tmux` instead of `screen`. #6186 (by @nzlosh and @cognifloyd)
2222
* Updated package build container environment to use py3.8 and mongo4.4 #6129
23+
* Fic misc DeprecationWarnings to prepare for python 3.10 support. #6188 (by @nzlosh)
2324

2425
Added
2526
~~~~~

st2actions/st2actions/policies/concurrency_by_attr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def apply_before(self, target):
120120

121121
# Warn users that the coordination service is not configured.
122122
if not coordination.configured():
123-
LOG.warn(
123+
LOG.warning(
124124
"Coordination service is not configured. Policy enforcement is best effort."
125125
)
126126

st2actions/st2actions/scheduler/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def _handle_execution(self, execution_queue_item_db):
290290
if action_has_policies_require_lock:
291291
# Warn users that the coordination service is not configured.
292292
if not coordination_service.configured():
293-
LOG.warn(
293+
LOG.warning(
294294
"[%s] Coordination backend is not configured. "
295295
"Policy enforcement is best effort.",
296296
action_execution_id,

st2api/st2api/controllers/v1/triggers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _create_shadow_trigger(triggertype_db):
205205
# Not aborting as this is convenience.
206206
return
207207
except StackStormDBObjectConflictError as e:
208-
LOG.warn(
208+
LOG.warning(
209209
'Trigger creation of "%s" failed with uniqueness conflict. Exception: %s',
210210
trigger,
211211
six.text_type(e),
@@ -221,7 +221,7 @@ def _delete_shadow_trigger(triggertype_db):
221221
)
222222
trigger_db = TriggerService.get_trigger_db_by_ref(triggertype_ref.ref)
223223
if not trigger_db:
224-
LOG.warn(
224+
LOG.warning(
225225
"No shadow trigger found for %s. Will skip delete.", triggertype_db
226226
)
227227
return

st2client/st2client/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def get_client(self, args, debug=False):
169169
cache_token=cache_token,
170170
)
171171
except requests.exceptions.ConnectionError as e:
172-
self.LOG.warn(
172+
self.LOG.warning(
173173
"Auth API server is not available, skipping authentication."
174174
)
175175
self.LOG.exception(e)
@@ -280,7 +280,7 @@ def _get_cached_auth_token(self, client, username, password):
280280
"cached token meaning they may be slower."
281281
% (cached_token_path, os.getlogin())
282282
)
283-
self.LOG.warn(message)
283+
self.LOG.warning(message)
284284
return None
285285

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

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

312312
with open(cached_token_path) as fp:
313313
data = fp.read()
@@ -359,7 +359,7 @@ def _cache_auth_token(self, token_obj):
359359
"cached token meaning they may be slower."
360360
% (cached_token_path, os.getlogin())
361361
)
362-
self.LOG.warn(message)
362+
self.LOG.warning(message)
363363
return None
364364

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

378378
token = token_obj.token

st2client/st2client/config_parser.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def parse(self):
116116
if self.validate_config_permissions:
117117
# Make sure the directory permissions == 0o770
118118
if bool(os.stat(config_dir_path).st_mode & 0o7):
119-
self.LOG.warn(
119+
self.LOG.warning(
120120
"The StackStorm configuration directory permissions are "
121121
"insecure (too permissive): others have access."
122122
)
@@ -130,15 +130,14 @@ def parse(self):
130130

131131
# Make sure the file permissions == 0o660
132132
if bool(os.stat(self.config_file_path).st_mode & 0o7):
133-
self.LOG.warn(
133+
self.LOG.warning(
134134
"The StackStorm configuration file permissions are "
135135
"insecure: others have access."
136136
)
137137

138138
config = ConfigParser()
139139
with io.open(self.config_file_path, "r", encoding="utf8") as fp:
140-
config.readfp(fp)
141-
140+
config.read_file(fp)
142141
for section, keys in six.iteritems(CONFIG_FILE_OPTIONS):
143142
for key, options in six.iteritems(keys):
144143
key_type = options["type"]

st2client/st2client/formatters/execution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# official StackStorm packages.
2929
# Only time it may not be available is if the user is doing custom install from source or
3030
# similar.
31-
logging.getLogger(__name__).warn(
31+
logging.getLogger(__name__).warning(
3232
"libYAML C bindings are not available. This means YAML "
3333
"parsing and serialization will be significantly slower. You are "
3434
"strongly recommended to install libyaml (libyaml-dev package "

st2client/st2client/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def _check_locale_and_print_warning(self):
518518

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

523523

524524
def setup_logging(argv):

st2client/tests/unit/test_config_parser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_correct_permissions_emit_no_warnings(self):
147147

148148
result = parser.parse() # noqa F841
149149

150-
self.assertEqual(parser.LOG.warn.call_count, 0)
150+
self.assertEqual(parser.LOG.warning.call_count, 0)
151151

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

174174
result = parser.parse() # noqa F841
175175

176-
self.assertEqual(parser.LOG.warn.call_count, 0)
176+
self.assertEqual(parser.LOG.warning.call_count, 0)
177177

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

192192
result = parser.parse() # noqa F841
193193

194-
self.assertEqual(parser.LOG.warn.call_count, 0)
194+
self.assertEqual(parser.LOG.warning.call_count, 0)
195195

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

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

228-
self.assertEqual(parser.LOG.warn.call_count, 2)
229+
self.assertEqual(parser.LOG.warning.call_count, 2)
229230
self.assertEqual(
230231
"The StackStorm configuration directory permissions are insecure "
231232
"(too permissive): others have access.",
232-
parser.LOG.warn.call_args_list[0][0][0],
233+
parser.LOG.warning.call_args_list[0][0][0],
233234
)
234235

235236
self.assertEqual(
236237
"The StackStorm configuration file permissions are insecure: others have access.",
237-
parser.LOG.warn.call_args_list[1][0][0],
238+
parser.LOG.warning.call_args_list[1][0][0],
238239
)
239240

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

267268
self.assertEqual(parser.LOG.info.call_count, 0)
268-
self.assertEqual(parser.LOG.warn.call_count, 0)
269+
self.assertEqual(parser.LOG.warning.call_count, 0)
269270

270271
# Make sure we left the file alone
271272
self.assertTrue(os.path.exists(self.TEMP_FILE_PATH))

st2client/tests/unit/test_shell.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def test_non_unicode_encoding_locale_warning_is_printed(self, mock_logger):
483483
shell = Shell()
484484
shell.run(argv=["trigger", "list"])
485485

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

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

545-
self.assertEqual(shell.LOG.warn.call_count, 2)
545+
self.assertEqual(shell.LOG.warning.call_count, 2)
546546
self.assertEqual(
547-
shell.LOG.warn.call_args_list[0][0][0][:63],
547+
shell.LOG.warning.call_args_list[0][0][0][:63],
548548
"The StackStorm configuration directory permissions are insecure",
549549
)
550550
self.assertEqual(
551-
shell.LOG.warn.call_args_list[1][0][0][:58],
551+
shell.LOG.warning.call_args_list[1][0][0][:58],
552552
"The StackStorm configuration file permissions are insecure",
553553
)
554554

@@ -617,6 +617,7 @@ def _write_mock_config(self):
617617
with open(self._mock_config_path, "w") as fp:
618618
fp.write(MOCK_CONFIG)
619619

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

639640
self.assertEqual(result, None)
640-
self.assertEqual(shell.LOG.warn.call_count, 1)
641-
log_message = shell.LOG.warn.call_args[0][0]
641+
self.assertEqual(shell.LOG.warning.call_count, 1)
642+
log_message = shell.LOG.warning.call_args[0][0]
642643

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

659-
self.assertEqual(shell.LOG.warn.call_count, 1)
660-
log_message = shell.LOG.warn.call_args[0][0]
660+
self.assertEqual(shell.LOG.warning.call_count, 1)
661+
log_message = shell.LOG.warning.call_args[0][0]
661662

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

677-
self.assertEqual(shell.LOG.warn.call_count, 1)
678-
log_message = shell.LOG.warn.call_args[0][0]
678+
self.assertEqual(shell.LOG.warning.call_count, 1)
679+
log_message = shell.LOG.warning.call_args[0][0]
679680

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

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

703-
self.assertEqual(shell.LOG.warn.call_count, 1)
704-
log_message = shell.LOG.warn.call_args[0][0]
705+
self.assertEqual(shell.LOG.warning.call_count, 1)
706+
log_message = shell.LOG.warning.call_args[0][0]
705707

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

719-
self.assertEqual(shell.LOG.warn.call_count, 1)
720-
log_message = shell.LOG.warn.call_args[0][0]
721+
self.assertEqual(shell.LOG.warning.call_count, 1)
722+
log_message = shell.LOG.warning.call_args[0][0]
721723

722724
expected_msg = (
723725
"Unable to write token to .*? doesn't have write access to this file"

0 commit comments

Comments
 (0)