From f11dbcc538b74236d2b3dac7e37e7cda833579ab Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 8 Jan 2019 09:57:30 -0600 Subject: [PATCH 1/3] Fix improper KeyError raise This is not logging, printf-style expansion is not performed --- salt/loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/loader.py b/salt/loader.py index e0447eaa38..a8312a0d84 100644 --- a/salt/loader.py +++ b/salt/loader.py @@ -1704,7 +1704,7 @@ class LazyLoader(salt.utils.lazy.LazyDict): if not isinstance(key, six.string_types): raise KeyError('The key must be a string.') if '.' not in key: - raise KeyError('The key \'%s\' should contain a \'.\'', key) + raise KeyError('The key \'{0}\' should contain a \'.\''.format(key)) mod_name, _ = key.split('.', 1) with self._lock: # It is possible that the key is in the dictionary after From c0ff7b105b593e5d6d25d80f6e4a887dd6bb0dc4 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 8 Jan 2019 11:24:44 -0600 Subject: [PATCH 2/3] Fix more incorrect exception raises --- salt/log/handlers/sentry_mod.py | 4 +--- salt/modules/snapper.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/salt/log/handlers/sentry_mod.py b/salt/log/handlers/sentry_mod.py index 51decb9315..c4f8e4de74 100644 --- a/salt/log/handlers/sentry_mod.py +++ b/salt/log/handlers/sentry_mod.py @@ -135,9 +135,7 @@ def setup_handlers(): transport_registry = TransportRegistry(default_transports) url = urlparse(dsn) if not transport_registry.supported_scheme(url.scheme): - raise ValueError( - 'Unsupported Sentry DSN scheme: %s', url.scheme - ) + raise ValueError('Unsupported Sentry DSN scheme: {0}'.format(url.scheme)) except ValueError as exc: log.info( 'Raven failed to parse the configuration provided DSN: %s', exc diff --git a/salt/modules/snapper.py b/salt/modules/snapper.py index 74648a8a70..4ae792a1f8 100644 --- a/salt/modules/snapper.py +++ b/salt/modules/snapper.py @@ -412,7 +412,7 @@ def create_snapshot(config='root', snapshot_type='single', pre_number=None, cleanup_algorithm, userdata) else: raise CommandExecutionError( - "Invalid snapshot type '{0}'", format(snapshot_type)) + "Invalid snapshot type '{0}'".format(snapshot_type)) except dbus.DBusException as exc: raise CommandExecutionError( 'Error encountered while listing changed files: {0}' From a3c0b49b64e4d1cb9865b582332256c6a130b441 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 15 Jan 2019 05:56:40 -0600 Subject: [PATCH 3/3] Fix poorly-written test This test was confirming the incorrect prior behavior. --- tests/unit/test_loader.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/unit/test_loader.py b/tests/unit/test_loader.py index 30c8bcaba0..0f22334559 100644 --- a/tests/unit/test_loader.py +++ b/tests/unit/test_loader.py @@ -305,17 +305,13 @@ class LazyLoaderSingleItem(TestCase): ''' Checks that a KeyError is raised when the function key does not contain a '.' ''' + key = 'testing_no_dot' + expected = "The key '{0}' should contain a '.'".format(key) with self.assertRaises(KeyError) as err: inspect.isfunction(self.loader['testing_no_dot']) - if six.PY2: - self.assertEqual(err.exception[0], - 'The key \'%s\' should contain a \'.\'') - else: - self.assertEqual( - six.text_type(err.exception), - six.text_type(("The key '%s' should contain a '.'", 'testing_no_dot')) - ) + result = err.exception.args[0] + assert result == expected, result module_template = '''