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
This commit is contained in:
parent
d687248000
commit
be9dade365
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user