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)