From be9dade365dfcb01c5eb74065c8cb6a1d75cad24 Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Wed, 13 May 2015 14:42:42 +0300 Subject: [PATCH] Add a mapping between old plugin names and new plugin names Some plugins were moved to plugins.common, in order to better reflect the fact that they are not platform specific. Unfortunately, there are a lot of users out there with old config files which are using the old plugin names. So in order not to crash cloudbaseinit for their cases, we provide an explicit mapping between old plugin names, found in plugin.windows to new plugin names, found in plugins.common. This will be removed when we'll reach 1.0 though. Change-Id: I1102260849bbc940f2a26325c652e2cf02892eab --- cloudbaseinit/plugins/common/factory.py | 38 +++++++++++++++++++++ cloudbaseinit/tests/plugins/test_factory.py | 21 ++++++++++++ 2 files changed, 59 insertions(+) diff --git a/cloudbaseinit/plugins/common/factory.py b/cloudbaseinit/plugins/common/factory.py index b74f4139..b222223f 100644 --- a/cloudbaseinit/plugins/common/factory.py +++ b/cloudbaseinit/plugins/common/factory.py @@ -47,11 +47,49 @@ CONF = cfg.CONF CONF.register_opts(opts) LOG = logging.getLogger(__name__) +# Some plugins were moved to plugins.common, in order to +# better reflect the fact that they are not platform specific. +# Unfortunately, there are a lot of users out there with old +# config files which are using the old plugin names. +# So in order not to crash cloudbaseinit for their cases, +# we provide this explicit mapping. This will be removed +# when we'll reach 1.0 though. + +OLD_PLUGINS = { + 'cloudbaseinit.plugins.windows.mtu.MTUPlugin': + 'cloudbaseinit.plugins.common.mtu.MTUPlugin', + + 'cloudbaseinit.plugins.windows.sethostname.SetHostNamePlugin': + 'cloudbaseinit.plugins.common.sethostname.SetHostNamePlugin', + + 'cloudbaseinit.plugins.windows.networkconfig.NetworkConfigPlugin': + 'cloudbaseinit.plugins.common.networkconfig.NetworkConfigPlugin', + + 'cloudbaseinit.plugins.windows.sshpublickeys.SetUserSSHPublicKeysPlugin': + 'cloudbaseinit.plugins.common.sshpublickeys.SetUserSSHPublicKeysPlugin', + + 'cloudbaseinit.plugins.windows.userdata.UserDataPlugin': + 'cloudbaseinit.plugins.common.userdata.UserDataPlugin', + + 'cloudbaseinit.plugins.windows.setuserpassword.SetUserPasswordPlugin': + 'cloudbaseinit.plugins.common.setuserpassword.SetUserPasswordPlugin', + + 'cloudbaseinit.plugins.windows.localscripts.LocalScriptsPlugin': + 'cloudbaseinit.plugins.common.localscripts.LocalScriptsPlugin', +} + def load_plugins(): plugins = [] cl = classloader.ClassLoader() 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) + class_path = new_class_path + try: plugin_cls = cl.load_class(class_path) except ImportError: diff --git a/cloudbaseinit/tests/plugins/test_factory.py b/cloudbaseinit/tests/plugins/test_factory.py index ff05240e..3b911d05 100644 --- a/cloudbaseinit/tests/plugins/test_factory.py +++ b/cloudbaseinit/tests/plugins/test_factory.py @@ -46,3 +46,24 @@ class PluginFactoryTests(unittest.TestCase): self.assertEqual([], plugins) self.assertEqual(["Could not import plugin module 'missing.plugin'"], snatcher.output) + + @testutils.ConfPatcher('plugins', ["cloudbaseinit.plugins.windows." + "localscripts.LocalScriptsPlugin"]) + @mock.patch('cloudbaseinit.utils.classloader.ClassLoader.load_class') + def test_old_plugin_mapping(self, mock_load_class): + with testutils.LogSnatcher('cloudbaseinit.plugins.common.' + 'factory') as snatcher: + factory.load_plugins() + + expected = [ + "Old plugin module 'cloudbaseinit.plugins.windows." + "localscripts.LocalScriptsPlugin' was found. " + "The new name is 'cloudbaseinit.plugins.common." + "localscripts.LocalScriptsPlugin'. The old name will not " + "be supported starting with cloudbaseinit 1.0", + ] + expected_call = mock.call('cloudbaseinit.plugins.common.' + 'localscripts.LocalScriptsPlugin') + self.assertEqual(expected, snatcher.output) + called = mock_load_class.mock_calls[0] + self.assertEqual(expected_call, called)