Skip sysctl configuration in containers

Some testing use cases make use of containers to host nova-compute;
sysctl options can't be tweaked in this use case so detect and
skip if executing in a container.

Change-Id: I9ff894e728e46b229068e91a290b84cde73eb09c
This commit is contained in:
James Page 2019-03-05 12:19:54 +00:00
parent e6c592ebfe
commit 954a86a895
2 changed files with 15 additions and 1 deletions

View File

@ -49,6 +49,7 @@ from charmhelpers.core.host import (
service_stop,
write_file,
umount,
is_container,
)
from charmhelpers.fetch import (
apt_install,
@ -181,7 +182,7 @@ def config_changed():
send_remote_restart = True
sysctl_settings = config('sysctl')
if sysctl_settings:
if sysctl_settings and not is_container():
create_sysctl(sysctl_settings, '/etc/sysctl.d/50-nova-compute.conf')
remove_libvirt_network('default')

View File

@ -54,6 +54,7 @@ TO_PATCH = [
'filter_installed_packages',
'restart_on_change',
'service_restart',
'is_container',
# charmhelpers.contrib.openstack.utils
'configure_installation_source',
'openstack_upgrade_available',
@ -110,6 +111,7 @@ class NovaComputeRelationsTests(CharmTestCase):
MagicMock(side_effect=lambda pkgs: pkgs)
self.gethostname.return_value = 'testserver'
self.get_relation_ip.return_value = '10.0.0.50'
self.is_container.return_value = False
def test_install_hook(self):
repo = 'cloud:precise-grizzly'
@ -222,6 +224,17 @@ class NovaComputeRelationsTests(CharmTestCase):
'{foo : bar}',
'/etc/sysctl.d/50-nova-compute.conf')
@patch.object(hooks, 'compute_joined')
def test_config_changed_with_sysctl_in_container(self, compute_joined):
self.migration_enabled.return_value = False
self.is_container.return_value = True
self.test_config.set(
'sysctl',
'{foo : bar}'
)
hooks.config_changed()
self.create_sysctl.assert_not_called()
@patch.object(hooks, 'compute_joined')
def test_config_changed_no_nrpe(self, compute_joined):
self.openstack_upgrade_available.return_value = False