diff --git a/heat/common/plugin_loader.py b/heat/common/plugin_loader.py index 59f75df153..90233742f3 100644 --- a/heat/common/plugin_loader.py +++ b/heat/common/plugin_loader.py @@ -66,11 +66,11 @@ def _import_module(importer, module_name, package): if module_name in sys.modules: return sys.modules[module_name] - loader = importer.find_module(module_name) - if loader is None: + module_spec = importer.find_spec(module_name) + if module_spec is None: return None - module = loader.load_module(module_name) + module = module_spec.loader.load_module(module_name) # Make this accessible through the parent package for static imports local_name = module_name.partition(package.__name__ + '.')[2] diff --git a/heat/tests/test_plugin_loader.py b/heat/tests/test_plugin_loader.py index 681e7b2e93..9a6be30e5e 100644 --- a/heat/tests/test_plugin_loader.py +++ b/heat/tests/test_plugin_loader.py @@ -12,7 +12,7 @@ # under the License. -import pkgutil +import importlib.machinery import sys from unittest import mock @@ -53,14 +53,14 @@ class PluginLoaderTest(common.HeatTestCase): def test_import_module_existing(self): import heat.engine.service existing = heat.engine.service - importer = pkgutil.ImpImporter(heat.engine.__path__[0]) + importer = importlib.machinery.FileFinder(heat.engine.__path__[0]) loaded = plugin_loader._import_module(importer, 'heat.engine.service', heat.engine) self.assertIs(existing, loaded) def test_import_module_garbage(self): - importer = pkgutil.ImpImporter(heat.engine.__path__[0]) + importer = importlib.machinery.FileFinder(heat.engine.__path__[0]) self.assertIsNone(plugin_loader._import_module(importer, 'wibble', heat.engine)) @@ -68,7 +68,7 @@ class PluginLoaderTest(common.HeatTestCase): @mock.patch.object(plugin_loader, "_import_module", mock.MagicMock()) @mock.patch('pkgutil.walk_packages') def test_load_modules_skip_test(self, mp): - importer = pkgutil.ImpImporter(heat.engine.__path__[0]) + importer = importlib.machinery.FileFinder(heat.engine.__path__[0]) mp.return_value = ((importer, "hola.foo", None), (importer, "hola.tests.test_foo", None)) @@ -79,7 +79,7 @@ class PluginLoaderTest(common.HeatTestCase): @mock.patch.object(plugin_loader, "_import_module", mock.MagicMock()) @mock.patch('pkgutil.walk_packages') def test_load_modules_skip_setup(self, mp): - importer = pkgutil.ImpImporter(heat.engine.__path__[0]) + importer = importlib.machinery.FileFinder(heat.engine.__path__[0]) mp.return_value = ((importer, "hola.foo", None), (importer, "hola.setup", None))