tests: Replace imp with importlib.machinery
It's needed for Python3.12 support, because imp has been dropped [1]. Also shlex dropped s=None support [2]. [1]: https://docs.python.org/3/whatsnew/3.12.html [2]: https://github.com/python/cpython/issues/94352 Change-Id: I23f37897ea08ac708f6df485f699122df647e552
This commit is contained in:
parent
2a150d1be9
commit
3c3c517958
@ -78,6 +78,7 @@ class PodmanWorker(ContainerWorker):
|
|||||||
)
|
)
|
||||||
|
|
||||||
command = self.params.pop('command', '')
|
command = self.params.pop('command', '')
|
||||||
|
if command:
|
||||||
self.params['command'] = shlex.split(command)
|
self.params['command'] = shlex.split(command)
|
||||||
|
|
||||||
# we have to transform volumes into mounts because podman-py
|
# we have to transform volumes into mounts because podman-py
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@ -32,8 +32,8 @@ kolla_container_file = os.path.join(ansible_dir,
|
|||||||
'library', 'kolla_container.py')
|
'library', 'kolla_container.py')
|
||||||
docker_worker_file = os.path.join(ansible_dir,
|
docker_worker_file = os.path.join(ansible_dir,
|
||||||
'module_utils', 'kolla_docker_worker.py')
|
'module_utils', 'kolla_docker_worker.py')
|
||||||
kc = imp.load_source('kolla_container', kolla_container_file)
|
kc = SourceFileLoader('kolla_container', kolla_container_file).load_module()
|
||||||
dwm = imp.load_source('kolla_docker_worker', docker_worker_file)
|
dwm = SourceFileLoader('kolla_docker_worker', docker_worker_file).load_module()
|
||||||
|
|
||||||
|
|
||||||
FAKE_DATA = {
|
FAKE_DATA = {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
@ -31,8 +31,8 @@ kolla_container_file = os.path.join(ansible_dir,
|
|||||||
'library', 'kolla_container.py')
|
'library', 'kolla_container.py')
|
||||||
podman_worker_file = os.path.join(ansible_dir,
|
podman_worker_file = os.path.join(ansible_dir,
|
||||||
'module_utils', 'kolla_podman_worker.py')
|
'module_utils', 'kolla_podman_worker.py')
|
||||||
kc = imp.load_source('kolla_container', kolla_container_file)
|
kc = SourceFileLoader('kolla_container', kolla_container_file).load_module()
|
||||||
pwm = imp.load_source('kolla_podman_worker', podman_worker_file)
|
pwm = SourceFileLoader('kolla_podman_worker', podman_worker_file).load_module()
|
||||||
|
|
||||||
FAKE_DATA = {
|
FAKE_DATA = {
|
||||||
'params': {
|
'params': {
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@ -26,7 +26,8 @@ this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
|||||||
ansible_dir = os.path.join(this_dir, '..', '..', 'ansible')
|
ansible_dir = os.path.join(this_dir, '..', '..', 'ansible')
|
||||||
systemd_worker_file = os.path.join(ansible_dir,
|
systemd_worker_file = os.path.join(ansible_dir,
|
||||||
'module_utils', 'kolla_systemd_worker.py')
|
'module_utils', 'kolla_systemd_worker.py')
|
||||||
swm = imp.load_source('kolla_systemd_worker', systemd_worker_file)
|
swm = SourceFileLoader('kolla_systemd_worker',
|
||||||
|
systemd_worker_file).load_module()
|
||||||
|
|
||||||
|
|
||||||
class TestSystemd(base.BaseTestCase):
|
class TestSystemd(base.BaseTestCase):
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ this_dir = os.path.dirname(sys.modules[__name__].__file__)
|
|||||||
file_under_test = os.path.join(this_dir, '..', 'ansible',
|
file_under_test = os.path.join(this_dir, '..', 'ansible',
|
||||||
'roles', 'keystone', 'files',
|
'roles', 'keystone', 'files',
|
||||||
'fernet_rotate_cron_generator.py')
|
'fernet_rotate_cron_generator.py')
|
||||||
generator = imp.load_source('generator', file_under_test)
|
generator = SourceFileLoader('generator', file_under_test).load_module()
|
||||||
|
|
||||||
|
|
||||||
class FernetRotateCronGeneratorTest(base.BaseTestCase):
|
class FernetRotateCronGeneratorTest(base.BaseTestCase):
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
# FIXME(yoctozepto): tests do not imitate how ansible would handle module args
|
# FIXME(yoctozepto): tests do not imitate how ansible would handle module args
|
||||||
|
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
@ -28,8 +28,8 @@ kolla_container_file = os.path.join(ansible_dir,
|
|||||||
'library', 'kolla_container.py')
|
'library', 'kolla_container.py')
|
||||||
docker_worker_file = os.path.join(ansible_dir,
|
docker_worker_file = os.path.join(ansible_dir,
|
||||||
'module_utils', 'kolla_docker_worker.py')
|
'module_utils', 'kolla_docker_worker.py')
|
||||||
kc = imp.load_source('kolla_container', kolla_container_file)
|
kc = SourceFileLoader('kolla_container', kolla_container_file).load_module()
|
||||||
dwm = imp.load_source('kolla_docker_worker', docker_worker_file)
|
dwm = SourceFileLoader('kolla_docker_worker', docker_worker_file).load_module()
|
||||||
|
|
||||||
|
|
||||||
class ModuleArgsTest(base.BaseTestCase):
|
class ModuleArgsTest(base.BaseTestCase):
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
@ -25,7 +25,8 @@ MERGE_CONFIG_FILE = os.path.join(PROJECT_DIR,
|
|||||||
'ansible/action_plugins/merge_configs.py')
|
'ansible/action_plugins/merge_configs.py')
|
||||||
|
|
||||||
|
|
||||||
merge_configs = imp.load_source('merge_configs', MERGE_CONFIG_FILE)
|
merge_configs = SourceFileLoader('merge_configs',
|
||||||
|
MERGE_CONFIG_FILE).load_module()
|
||||||
|
|
||||||
TESTA = '''[DEFAULT]
|
TESTA = '''[DEFAULT]
|
||||||
key1 = b
|
key1 = b
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import imp
|
from importlib.machinery import SourceFileLoader
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ansible.errors import AnsibleModuleError
|
from ansible.errors import AnsibleModuleError
|
||||||
@ -22,7 +22,7 @@ from oslotest import base
|
|||||||
PROJECT_DIR = os.path.abspath(os.path.join(os. path.dirname(__file__), '../'))
|
PROJECT_DIR = os.path.abspath(os.path.join(os. path.dirname(__file__), '../'))
|
||||||
MERGE_YAML_FILE = os.path.join(PROJECT_DIR,
|
MERGE_YAML_FILE = os.path.join(PROJECT_DIR,
|
||||||
'ansible/action_plugins/merge_yaml.py')
|
'ansible/action_plugins/merge_yaml.py')
|
||||||
merge_yaml = imp.load_source('merge_yaml', MERGE_YAML_FILE)
|
merge_yaml = SourceFileLoader('merge_yaml', MERGE_YAML_FILE).load_module()
|
||||||
|
|
||||||
|
|
||||||
class MergeYamlConfigTest(base.BaseTestCase):
|
class MergeYamlConfigTest(base.BaseTestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user