aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhoulinhui <df.some@foxmail.com>2020-08-30 00:34:27 +0800
committerzhoulinhui <df.some@foxmail.com>2020-08-30 22:11:52 +0800
commit33970fcc6b8f4cffe116d66cee8a94e19e743937 (patch)
tree5d8199ac6b0e74541676871dc47e5f081562488f
parent5dcd1dd915189e047e1e3b481c1b0d2dba9ea2fe (diff)
downloadkolla-33970fcc6b8f4cffe116d66cee8a94e19e743937.tar.gz
kolla-33970fcc6b8f4cffe116d66cee8a94e19e743937.zip
Update imp module to importlib
The imp module is deprecated[1] since version 3.4, use importlib to instead 1: https://docs.python.org/3/library/imp.html Change-Id: I79dfd923531dd3e00d23e1682865f56f0cf437d2
-rw-r--r--tests/test_set_config.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/test_set_config.py b/tests/test_set_config.py
index 3888a38cc..1f49edc3c 100644
--- a/tests/test_set_config.py
+++ b/tests/test_set_config.py
@@ -11,7 +11,7 @@
# limitations under the License.
import copy
-import imp
+import importlib.util
import json
import os.path
import sys
@@ -19,13 +19,23 @@ from unittest import mock
from oslotest import base
+
+def load_module(name, path):
+ module_spec = importlib.util.spec_from_file_location(
+ name, path
+ )
+ module = importlib.util.module_from_spec(module_spec)
+ module_spec.loader.exec_module(module)
+ return module
+
+
# nasty: to import set_config (not a part of the kolla package)
this_dir = os.path.dirname(sys.modules[__name__].__file__)
set_configs_file = os.path.abspath(
os.path.join(this_dir, '..',
'docker', 'base', 'set_configs.py'))
-set_configs = imp.load_source('set_configs', set_configs_file)
+set_configs = load_module('set_configs', set_configs_file)
class LoadFromFile(base.BaseTestCase):