Import Upstream version 4.12.4
This commit is contained in:
@@ -3,9 +3,7 @@
|
||||
#
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
|
||||
from abc import ABCMeta, abstractproperty
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from collections import namedtuple
|
||||
import itertools
|
||||
|
||||
@@ -17,11 +15,12 @@ from ipaserver.install.ipa_replica_install import ReplicaInstall
|
||||
Keyval = namedtuple('Keyval', ['option', 'value'])
|
||||
|
||||
|
||||
class InstallerTestBase(six.with_metaclass(ABCMeta, object)):
|
||||
class InstallerTestBase(metaclass=ABCMeta):
|
||||
OPTS_DICT = {}
|
||||
|
||||
# don't allow creating classes with tested_cls unspecified
|
||||
@abstractproperty
|
||||
@property
|
||||
@abstractmethod
|
||||
def tested_cls(self):
|
||||
return None
|
||||
|
||||
@@ -47,7 +46,6 @@ class InstallerTestBase(six.with_metaclass(ABCMeta, object)):
|
||||
"class first.")
|
||||
|
||||
# add all options from the option groups
|
||||
# pylint: disable=no-member
|
||||
for opt_group in cls.tested_cls.option_parser.option_groups:
|
||||
for opt in opt_group.option_list:
|
||||
cls.OPTS_DICT[opt.dest] = opt._short_opts + opt._long_opts
|
||||
|
||||
@@ -55,21 +55,28 @@ def gpgkey(request, tempdir):
|
||||
f.write("allow-preset-passphrase\n")
|
||||
|
||||
# daemonize agent (detach from the console and run in the background)
|
||||
subprocess.Popen(
|
||||
[paths.GPG_AGENT, '--batch', '--daemon'],
|
||||
env=env, stdout=devnull, stderr=devnull
|
||||
subprocess.run(
|
||||
[paths.SYSTEMD_RUN, '--service-type=forking',
|
||||
'--property', 'SELinuxContext=system_u:system_r:initrc_t:s0',
|
||||
'--setenv=GNUPGHOME={}'.format(gnupghome),
|
||||
'--setenv=LC_ALL=C.UTF-8',
|
||||
'--setenv=LANGUAGE=C',
|
||||
'--unit=gpg-agent', '/bin/bash',
|
||||
'-c', ' '.join([paths.GPG_AGENT, '--daemon', '--batch'])],
|
||||
check=True,
|
||||
env=env,
|
||||
)
|
||||
|
||||
def fin():
|
||||
subprocess.run(
|
||||
[paths.SYSTEMCTL, 'stop', 'gpg-agent'],
|
||||
check=True,
|
||||
env=env,
|
||||
)
|
||||
if orig_gnupghome is not None:
|
||||
os.environ['GNUPGHOME'] = orig_gnupghome
|
||||
else:
|
||||
os.environ.pop('GNUPGHOME', None)
|
||||
subprocess.run(
|
||||
[paths.GPG_CONF, '--kill', 'all'],
|
||||
check=True,
|
||||
env=env,
|
||||
)
|
||||
|
||||
request.addfinalizer(fin)
|
||||
|
||||
@@ -205,7 +212,7 @@ RAM_NOT_OK = str(10 * 1000 * 1000)
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi(RAM_NOT_OK, "0"))
|
||||
@patch('os.path.exists')
|
||||
def test_in_container_insufficient_ram(mock_exists, mock_in_container):
|
||||
def test_cgroup_v1_insufficient_ram(mock_exists, mock_in_container):
|
||||
"""In a container with insufficient RAM and zero used"""
|
||||
mock_in_container.return_value = True
|
||||
mock_exists.side_effect = [True, True]
|
||||
@@ -217,7 +224,7 @@ def test_in_container_insufficient_ram(mock_exists, mock_in_container):
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi(RAM_OK, RAM_CA_USED))
|
||||
@patch('os.path.exists')
|
||||
def test_in_container_ram_ok_no_ca(mock_exists, mock_in_container):
|
||||
def test_cgroup_v1_ram_ok_no_ca(mock_exists, mock_in_container):
|
||||
"""In a container with just enough RAM to install w/o a CA"""
|
||||
mock_in_container.return_value = True
|
||||
mock_exists.side_effect = [True, True]
|
||||
@@ -228,7 +235,7 @@ def test_in_container_ram_ok_no_ca(mock_exists, mock_in_container):
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi(RAM_OK, RAM_MOSTLY_USED))
|
||||
@patch('os.path.exists')
|
||||
def test_in_container_insufficient_ram_with_ca(mock_exists, mock_in_container):
|
||||
def test_cgroup_v1_insufficient_ram_with_ca(mock_exists, mock_in_container):
|
||||
"""In a container and just miss the minimum RAM required"""
|
||||
mock_in_container.return_value = True
|
||||
mock_exists.side_effect = [True, True]
|
||||
@@ -238,8 +245,74 @@ def test_in_container_insufficient_ram_with_ca(mock_exists, mock_in_container):
|
||||
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi(RAM_NOT_OK, "0"))
|
||||
@patch('os.path.exists')
|
||||
def test_cgroup_v2_insufficient_ram(mock_exists, mock_in_container):
|
||||
"""In a container with insufficient RAM and zero used"""
|
||||
mock_in_container.return_value = True
|
||||
mock_exists.side_effect = [False, True, True]
|
||||
|
||||
with pytest.raises(ScriptError):
|
||||
installutils.check_available_memory(True)
|
||||
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi(RAM_OK, RAM_CA_USED))
|
||||
@patch('os.path.exists')
|
||||
def test_cgroup_v2_ram_ok_no_ca(mock_exists, mock_in_container):
|
||||
"""In a container with just enough RAM to install w/o a CA"""
|
||||
mock_in_container.return_value = True
|
||||
mock_exists.side_effect = [False, True, True]
|
||||
|
||||
installutils.check_available_memory(False)
|
||||
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi(RAM_OK, RAM_MOSTLY_USED))
|
||||
@patch('os.path.exists')
|
||||
def test_cgroup_v2_insufficient_ram_with_ca(mock_exists, mock_in_container):
|
||||
"""In a container and just miss the minimum RAM required"""
|
||||
mock_in_container.return_value = True
|
||||
mock_exists.side_effect = [False, True, True]
|
||||
|
||||
with pytest.raises(ScriptError):
|
||||
installutils.check_available_memory(True)
|
||||
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi('max', RAM_MOSTLY_USED))
|
||||
@patch('os.path.exists')
|
||||
@patch('psutil.virtual_memory')
|
||||
def test_not_container_insufficient_ram_with_ca(mock_psutil, mock_in_container):
|
||||
def test_cgroup_v2_no_limit_ok(mock_psutil, mock_exists, mock_in_container):
|
||||
"""In a container and just miss the minimum RAM required"""
|
||||
mock_in_container.return_value = True
|
||||
fake_memory = psutil._pslinux.svmem
|
||||
fake_memory.available = int(RAM_OK)
|
||||
mock_psutil.return_value = fake_memory
|
||||
mock_exists.side_effect = [False, True, True]
|
||||
|
||||
installutils.check_available_memory(True)
|
||||
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('builtins.open', mock_open_multi('max', RAM_MOSTLY_USED))
|
||||
@patch('os.path.exists')
|
||||
@patch('psutil.virtual_memory')
|
||||
def test_cgroup_v2_no_limit_not_ok(mock_psutil, mock_exists, mock_in_container):
|
||||
"""In a container and just miss the minimum RAM required"""
|
||||
mock_in_container.return_value = True
|
||||
fake_memory = psutil._pslinux.svmem
|
||||
fake_memory.available = int(RAM_NOT_OK)
|
||||
mock_psutil.return_value = fake_memory
|
||||
mock_exists.side_effect = [False, True, True]
|
||||
|
||||
with pytest.raises(ScriptError):
|
||||
installutils.check_available_memory(True)
|
||||
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('psutil.virtual_memory')
|
||||
def test_bare_insufficient_ram_with_ca(mock_psutil, mock_in_container):
|
||||
"""Not a container and insufficient RAM"""
|
||||
mock_in_container.return_value = False
|
||||
fake_memory = psutil._pslinux.svmem
|
||||
@@ -252,7 +325,7 @@ def test_not_container_insufficient_ram_with_ca(mock_psutil, mock_in_container):
|
||||
|
||||
@patch('ipaserver.install.installutils.in_container')
|
||||
@patch('psutil.virtual_memory')
|
||||
def test_not_container_ram_ok(mock_psutil, mock_in_container):
|
||||
def test_bare_ram_ok(mock_psutil, mock_in_container):
|
||||
"""Not a container and sufficient RAM"""
|
||||
mock_in_container.return_value = False
|
||||
fake_memory = psutil._pslinux.svmem
|
||||
|
||||
Reference in New Issue
Block a user