Merge "common: Replace deprecated importlib API (2/2)"

This commit is contained in:
Zuul 2024-01-29 07:32:45 +00:00 committed by Gerrit Code Review
commit b674962603
3 changed files with 7 additions and 7 deletions

View File

@ -33,8 +33,9 @@ from oslo_config import cfg
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.abspath(os.path.join(BASE_DIR, "..", "..")) ROOT = os.path.abspath(os.path.join(BASE_DIR, "..", ".."))
CONTRIB_DIR = os.path.join(ROOT, 'contrib') # TODO(tkajinam): Fix this
PLUGIN_DIRS = glob.glob(os.path.join(CONTRIB_DIR, '*')) # CONTRIB_DIR = os.path.join(ROOT, 'contrib')
# PLUGIN_DIRS = glob.glob(os.path.join(CONTRIB_DIR, '*'))
ENV_DIR = os.path.join(ROOT, "etc", "heat", "environment.d") ENV_DIR = os.path.join(ROOT, "etc", "heat", "environment.d")
TEMP_ENV_DIR = tempfile.mkdtemp() TEMP_ENV_DIR = tempfile.mkdtemp()
@ -48,7 +49,7 @@ sys.path.insert(0, ROOT)
sys.path.insert(0, BASE_DIR) sys.path.insert(0, BASE_DIR)
cfg.CONF.import_opt('plugin_dirs', 'heat.common.config') cfg.CONF.import_opt('plugin_dirs', 'heat.common.config')
cfg.CONF.set_override(name='plugin_dirs', override=PLUGIN_DIRS) # cfg.CONF.set_override(name='plugin_dirs', override=PLUGIN_DIRS)
cfg.CONF.import_opt('environment_dir', 'heat.common.config') cfg.CONF.import_opt('environment_dir', 'heat.common.config')
cfg.CONF.set_override(name='environment_dir', override=TEMP_ENV_DIR) cfg.CONF.set_override(name='environment_dir', override=TEMP_ENV_DIR)

View File

@ -20,6 +20,7 @@ for them before loading them.
""" """
import functools import functools
import importlib.util
import pkgutil import pkgutil
import sys import sys
import types import types
@ -70,7 +71,8 @@ def _import_module(importer, module_name, package):
if module_spec is None: if module_spec is None:
return None return None
module = module_spec.loader.load_module(module_name) module = importlib.util.module_from_spec(module_spec)
module_spec.loader.exec_module(module)
# Make this accessible through the parent package for static imports # Make this accessible through the parent package for static imports
local_name = module_name.partition(package.__name__ + '.')[2] local_name = module_name.partition(package.__name__ + '.')[2]

View File

@ -12,7 +12,6 @@
# under the License. # under the License.
import os.path import os.path
import sys
from unittest import mock from unittest import mock
import fixtures import fixtures
@ -183,7 +182,6 @@ def constraint_mapping():
plugin_file = os.path.join(plugin_dir.path, 'test.py') plugin_file = os.path.join(plugin_dir.path, 'test.py')
with open(plugin_file, 'w+') as ef: with open(plugin_file, 'w+') as ef:
ef.write(constraint_content) ef.write(constraint_content)
self.addCleanup(sys.modules.pop, "heat.engine.plugins.test")
cfg.CONF.set_override('plugin_dirs', plugin_dir.path) cfg.CONF.set_override('plugin_dirs', plugin_dir.path)
env = environment.Environment({}) env = environment.Environment({})
@ -202,7 +200,6 @@ def constraint_mapping():
plugin_file = os.path.join(plugin_dir.path, 'test.py') plugin_file = os.path.join(plugin_dir.path, 'test.py')
with open(plugin_file, 'w+') as ef: with open(plugin_file, 'w+') as ef:
ef.write(constraint_content) ef.write(constraint_content)
self.addCleanup(sys.modules.pop, "heat.engine.plugins.test")
cfg.CONF.set_override('plugin_dirs', plugin_dir.path) cfg.CONF.set_override('plugin_dirs', plugin_dir.path)
env = environment.Environment({}) env = environment.Environment({})