Merge "Add sysctl preflight install check"

This commit is contained in:
Jenkins 2016-09-20 17:06:44 +00:00 committed by Gerrit Code Review
commit 208f7ae1a7
2 changed files with 39 additions and 1 deletions

View File

@ -77,13 +77,16 @@ class TestUndercloud(BaseTestCase):
@mock.patch('instack_undercloud.undercloud._check_hostname')
@mock.patch('instack_undercloud.undercloud._check_memory')
@mock.patch('instack_undercloud.undercloud._check_sysctl')
@mock.patch('instack_undercloud.undercloud._validate_network')
def test_validate_configuration(self, mock_validate_network,
mock_check_memory, mock_check_hostname):
mock_check_memory, mock_check_hostname,
mock_check_sysctl):
undercloud._validate_configuration()
self.assertTrue(mock_validate_network.called)
self.assertTrue(mock_check_memory.called)
self.assertTrue(mock_check_hostname.called)
self.assertTrue(mock_check_sysctl.called)
class TestCheckHostname(BaseTestCase):
@ -182,6 +185,18 @@ class TestCheckMemory(BaseTestCase):
self.assertRaises(RuntimeError, undercloud._check_memory)
class TestCheckSysctl(BaseTestCase):
@mock.patch('os.path.isfile')
def test_missing_options(self, mock_isfile):
mock_isfile.return_value = False
self.assertRaises(RuntimeError, undercloud._check_sysctl)
@mock.patch('os.path.isfile')
def test_available_option(self, mock_isfile):
mock_isfile.return_value = True
undercloud._check_sysctl()
class TestGenerateEnvironment(BaseTestCase):
def setUp(self):
super(TestGenerateEnvironment, self).setUp()

View File

@ -582,6 +582,28 @@ def _check_memory():
raise RuntimeError('Insufficient memory available')
def _check_sysctl():
"""Check sysctl option availability
The undercloud will not install properly if some of the expected sysctl
values are not available to be set.
"""
options = ['net.ipv4.ip_forward', 'net.ipv4.ip_nonlocal_bind',
'net.ipv6.ip_nonlocal_bind']
not_available = []
for option in options:
path = '/proc/sys/{opt}'.format(opt=option.replace('.', '/'))
if not os.path.isfile(path):
not_available.append(option)
if not_available:
LOG.error('Required sysctl options are not available. Check '
'that your kernel is up to date. Missing: '
'{options}'.format(options=", ".join(not_available)))
raise RuntimeError('Missing sysctl options')
def _validate_network():
def error_handler(message):
LOG.error('Undercloud configuration validation failed: %s', message)
@ -615,6 +637,7 @@ def _validate_configuration():
try:
_check_hostname()
_check_memory()
_check_sysctl()
_validate_network()
except RuntimeError as e:
LOG.error('ERROR: An error occured during configuration validation, '