[fuel-bootstrap] Remove external call for activate function
* Switch activate function to use execute calls directly * Activate still uses 'docker shell' and 'puppet apply' Change-Id: Ia725c2ceaa159b8797b420d74dcc7c1caf5fbfcf Related-bug: #1522066
This commit is contained in:
parent
06bd5bc228
commit
470bfc5213
@ -44,3 +44,18 @@ UBUNTU_RELEASE = 'trusty'
|
|||||||
|
|
||||||
ERROR_MSG = "Ubuntu bootstrap image is not available. Please use"\
|
ERROR_MSG = "Ubuntu bootstrap image is not available. Please use"\
|
||||||
" fuel-bootstrap manager for fix it."
|
" fuel-bootstrap manager for fix it."
|
||||||
|
|
||||||
|
# FIXME(azvyagintsev) bug: https://bugs.launchpad.net/fuel/+bug/1525882
|
||||||
|
# Nailgun\astute should support API call to change their bootstrap profile
|
||||||
|
# While its not implemented, we need astute.yaml file to perform
|
||||||
|
# bootstrap_image._activate_dockerized process
|
||||||
|
ASTUTE_CONFIG_FILE = "/etc/fuel/astute.yaml"
|
||||||
|
# FIXME(azvyagintsev) bug: https://bugs.launchpad.net/fuel/+bug/1525857
|
||||||
|
DISTROS = {'ubuntu': {'cobbler_profile': 'ubuntu_bootstrap',
|
||||||
|
'astute_flavor': 'ubuntu'},
|
||||||
|
'centos': {'cobbler_profile': 'bootstrap',
|
||||||
|
'astute_flavor': 'centos'}}
|
||||||
|
COBBLER_DOCKER = 'cobbler'
|
||||||
|
COBBLER_MANIFEST = '/etc/puppet/modules/nailgun/examples/cobbler-only.pp'
|
||||||
|
ASTUTE_DOCKER = 'astute'
|
||||||
|
ASTUTE_MANIFEST = '/etc/puppet/modules/nailgun/examples/astute-only.pp'
|
||||||
|
@ -47,3 +47,7 @@ class IncorrectImage(FuelBootstrapException):
|
|||||||
|
|
||||||
class ConfigFileNotExists(FuelBootstrapException):
|
class ConfigFileNotExists(FuelBootstrapException):
|
||||||
"""Should be raised when default config file is not found"""
|
"""Should be raised when default config file is not found"""
|
||||||
|
|
||||||
|
|
||||||
|
class WrongCobblerProfile(FuelBootstrapException):
|
||||||
|
"""Should be raised when wrong cobbler profile has been chosen"""
|
||||||
|
@ -155,6 +155,68 @@ def make_bootstrap(data=None):
|
|||||||
return bootdata['bootstrap']['uuid'], bootdata['output']
|
return bootdata['bootstrap']['uuid'], bootdata['output']
|
||||||
|
|
||||||
|
|
||||||
|
def _update_astute_yaml(flavor=None):
|
||||||
|
config = consts.ASTUTE_CONFIG_FILE
|
||||||
|
LOG.debug("Switching in %s BOOTSTRAP/flavor to :%s",
|
||||||
|
config, flavor)
|
||||||
|
try:
|
||||||
|
with open(config, 'r') as f:
|
||||||
|
data = yaml.safe_load(f)
|
||||||
|
data.update({'BOOTSTRAP': {'flavor': flavor}})
|
||||||
|
with open(config, 'wt') as f:
|
||||||
|
yaml.safe_dump(data, stream=f, encoding='utf-8',
|
||||||
|
default_flow_style=False,
|
||||||
|
default_style='"')
|
||||||
|
except IOError:
|
||||||
|
LOG.error("Config file %s has not been processed successfully", config)
|
||||||
|
raise
|
||||||
|
except AttributeError:
|
||||||
|
LOG.error("Seems %s config file is empty", config)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
def _run_puppet(container=None, manifest=None):
|
||||||
|
"""Run puppet apply inside docker container
|
||||||
|
|
||||||
|
:param container:
|
||||||
|
:param manifest:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
LOG.debug('Trying apply manifest:%s \ninside container:%s',
|
||||||
|
manifest, container)
|
||||||
|
utils.execute('dockerctl', 'shell', container, 'puppet', 'apply',
|
||||||
|
'--detailed-exitcodes', '-dv', manifest, logged=True,
|
||||||
|
check_exit_code=[0, 2], attempts=2)
|
||||||
|
|
||||||
|
|
||||||
|
def _activate_dockerized(flavor=None):
|
||||||
|
"""Switch between cobbler distro profiles, in case dockerized system
|
||||||
|
|
||||||
|
Unfortunately, we don't support switching between profiles "on fly",
|
||||||
|
so to perform this we need:
|
||||||
|
1) Update asute.yaml - which used by puppet to determine options
|
||||||
|
2) Re-run puppet for cobbler(to perform default system update, regarding
|
||||||
|
new profile)
|
||||||
|
3) Re-run puppet for astute
|
||||||
|
4) Restart astuted service in container
|
||||||
|
|
||||||
|
:param flavor: Switch between ubuntu\centos cobbler profile
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
flavor = flavor.lower()
|
||||||
|
if flavor not in consts.DISTROS:
|
||||||
|
raise errors.WrongCobblerProfile(
|
||||||
|
'Wrong cobbler profile passed:%s \n possible profiles:',
|
||||||
|
flavor, consts.DISTROS.keys())
|
||||||
|
_update_astute_yaml(consts.DISTROS[flavor]['astute_flavor'])
|
||||||
|
_run_puppet(consts.COBBLER_DOCKER, consts.COBBLER_MANIFEST)
|
||||||
|
_run_puppet(consts.ASTUTE_DOCKER, consts.ASTUTE_MANIFEST)
|
||||||
|
# restart astuted to be sure that it catches new profile
|
||||||
|
LOG.debug('Reloading astuted')
|
||||||
|
utils.execute('dockerctl', 'shell', 'astute', 'service', 'astute',
|
||||||
|
'restart')
|
||||||
|
|
||||||
|
|
||||||
def activate(image_uuid=""):
|
def activate(image_uuid=""):
|
||||||
is_centos = image_uuid.lower() == 'centos'
|
is_centos = image_uuid.lower() == 'centos'
|
||||||
symlink = CONF.active_bootstrap_symlink
|
symlink = CONF.active_bootstrap_symlink
|
||||||
@ -172,9 +234,9 @@ def activate(image_uuid=""):
|
|||||||
else:
|
else:
|
||||||
LOG.warning("WARNING: switching to depracated centos-bootstrap")
|
LOG.warning("WARNING: switching to depracated centos-bootstrap")
|
||||||
|
|
||||||
# FIXME: Do normal activation when it become clear how to do it
|
# FIXME: Add pre-activate verify
|
||||||
flavor = 'centos' if is_centos else 'ubuntu'
|
flavor = 'centos' if is_centos else 'ubuntu'
|
||||||
utils.execute('fuel-bootstrap-image-set', flavor)
|
_activate_dockerized(flavor)
|
||||||
|
|
||||||
return image_uuid
|
return image_uuid
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user