Write minion preflight checks

There are some basics we should check before running the install.

Change-Id: I510457333aadcabe0f02c05a39c7c10b221410ae
Blueprint: undercloud-minion
This commit is contained in:
Alex Schultz 2019-07-26 13:41:11 -06:00
parent b1bd2829fe
commit d242ad7cfe
3 changed files with 47 additions and 8 deletions

View File

@ -34,6 +34,7 @@ class TestMinionDeploy(base.TestCase):
# set timezone so we don't have to mock it everywhere
self.conf.set_default('minion_timezone', 'UTC')
@mock.patch('tripleoclient.v1.undercloud_preflight.minion_check')
@mock.patch('tripleoclient.utils.ansible_symlink')
@mock.patch('os.path.isdir', return_value=True)
@mock.patch('tripleoclient.v1.minion_config._process_undercloud_output',
@ -44,7 +45,8 @@ class TestMinionDeploy(base.TestCase):
@mock.patch('tripleoclient.utils.load_config')
def test_basic_deploy(self, mock_load_config, mock_get_user,
mock_write_env, mock_undercloud_output,
mock_images_config, mock_isdir, mock_ans_symlink):
mock_images_config, mock_isdir, mock_ans_symlink,
mock_check):
mock_get_user.return_value = 'foo'
cmd = minion_config.prepare_minion_deploy()
expected_cmd = ['sudo', '--preserve-env',
@ -97,6 +99,7 @@ class TestMinionDeploy(base.TestCase):
env_data, '/home/stack/tripleo-config-generated-env-files/'
'minion_parameters.yaml', {})
@mock.patch('tripleoclient.v1.undercloud_preflight.minion_check')
@mock.patch('tripleoclient.utils.ansible_symlink')
@mock.patch('os.path.exists', return_value=True)
@mock.patch('os.path.isdir', return_value=True)
@ -108,7 +111,7 @@ class TestMinionDeploy(base.TestCase):
def test_configured_deploy(self, mock_load_config,
mock_write_env, mock_undercloud_output,
mock_images_config, mock_isdir, mock_exists,
mock_ans_symlink):
mock_ans_symlink, mock_check):
self.conf.set_default('deployment_user', 'bar')
self.conf.set_default('enable_heat_engine', False)
self.conf.set_default('enable_ironic_conductor', True)

View File

@ -38,6 +38,7 @@ from tripleoclient.config.minion import MinionConfig
from tripleoclient import constants
from tripleoclient import exceptions
from tripleoclient import utils
from tripleoclient.v1 import undercloud_preflight
# Provides mappings for some of the instack_env tags to minion heat
@ -330,8 +331,7 @@ def prepare_minion_deploy(upgrade=False, no_validations=False,
if CONF.get('minion_enable_validations') and not no_validations:
utils.ansible_symlink()
# TODO(aschultz): write this
# minion_preflight.check(verbose_level, upgrade)
undercloud_preflight.minion_check(verbose_level, upgrade)
if CONF.get('custom_env_files'):
for custom_file in CONF['custom_env_files']:

View File

@ -274,12 +274,13 @@ def _validate_inspection_range(subnet_props):
raise FailedValidation(message)
def _validate_interface_exists():
def _validate_interface_exists(config_var='local_interface'):
"""Validate the provided local interface exists"""
if (not CONF.net_config_override
and CONF.local_interface not in netifaces.interfaces()):
message = (_('Invalid local_interface specified. '
'%s is not available.') % CONF.local_interface)
and CONF.get(config_var) not in netifaces.interfaces()):
message = (_('Invalid {0} specified. '
'{1} is not available.').format(config_var,
CONF.get(config_var)))
LOG.error(message)
raise FailedValidation(message)
@ -538,3 +539,38 @@ def check(verbose_level, upgrade=False):
'configuration and try again. Error '
'message: {error}').format(error=e))
sys.exit(1)
def minion_check(verbose_level, upgrade=False):
utils.load_config(CONF, constants.MINION_CONF_PATH)
utils.configure_logging(LOG, verbose_level, CONF['minion_log_file'])
try:
_checking_status('Hostname')
utils.check_hostname()
_checking_status('Sysctl')
_check_sysctl()
_checking_status('Network interfaces')
_validate_interface_exists('minion_local_interface')
_checking_status('Password file')
_validate_passwords_file()
# Heat templates validations
if CONF.get('custom_env_files'):
_checking_status('Custom env file')
_validate_env_files_paths()
except KeyError as e:
LOG.error(_('Key error in configuration: {error}\n'
'Value is missing in configuration.').format(error=e))
sys.exit(1)
except FailedValidation as e:
LOG.error(_('An error occurred during configuration '
'validation, please check your host '
'configuration and try again.\nError '
'message: {error}').format(error=e))
sys.exit(1)
except RuntimeError as e:
LOG.error(_('An error occurred during configuration '
'validation, please check your host '
'configuration and try again. Error '
'message: {error}').format(error=e))
sys.exit(1)