Apply feature_groups settings in Nailgun

Apply feature_groups settings in Nailgun only during post-deployment
phase (when Fuel master is installed) and only if they were changed.

Change-Id: Ia849153e15f4bd9ab568221374a7f8ef2fb6c52d
Closes-Bug: #1578979
Signed-off-by: Maksim Malchuk <mmalchuk@mirantis.com>
This commit is contained in:
Maksim Malchuk 2016-05-09 21:38:37 +03:00
parent f4b30c916a
commit 5b7a49575f
4 changed files with 56 additions and 1 deletions

View File

@ -68,3 +68,23 @@ def puppetApply(classes):
log.error("Exit code: %d. Error: %s Stdout: %s",
code, err, out)
return False
def puppetApplyManifest(manifest):
log = logging
log.info("Start puppet apply with manifest {0}".format(manifest))
cmd = ["puppet", "apply", "--debug", "--verbose", "--logdest",
consts.PUPPET_LOGFILE, manifest]
log.debug(' '.join(cmd))
err_code, _, errout = utils.execute(cmd)
if err_code != 0:
msg = "Puppet apply failed. Check logs for more details."
log.error(msg)
return False, msg
msg = "Puppet apply successfully executed."
log.info(msg)
return True, msg

View File

@ -17,6 +17,7 @@
LOGFILE = "/var/log/fuelmenu.log"
PUPPET_LOGFILE = "/var/log/puppet/fuelmenu-puppet.log"
PUPPET_NAILGUN = "/etc/puppet/modules/fuel/examples/nailgun.pp"
SETTINGS_FILE = "/etc/fuel/astute.yaml"
RELEASE_FILE = "/etc/fuel_release"

View File

@ -90,6 +90,8 @@ class FuelSetup(object):
self.dns_might_have_changed = False
# Set to true to move all settings to end
self.globalsave = True
# Tasks to be executed on Apply
self.apply_tasks = set()
self.version = utils.get_fuel_version()
# settings load
@ -310,6 +312,12 @@ class FuelSetup(object):
% (modulename, e))
self.settings.write(outfn=consts.SETTINGS_FILE)
# Runs tasks for every module, stop on error
for apply_task in self.apply_tasks:
if not apply_task():
return False, None
return True, None
def reload_modules(self):

View File

@ -19,6 +19,9 @@ import urwid
from fuelmenu.common.modulehelper import ModuleHelper
from fuelmenu.common.modulehelper import WidgetType
from fuelmenu.common import puppet
from fuelmenu.common import utils
from fuelmenu import consts
log = logging.getLogger(__name__)
@ -75,7 +78,29 @@ class feature_groups(urwid.WidgetWrap):
log.error("Check failed. Not applying")
log.error("%s", responses)
return False
self.save(responses)
oldsettings = self.parent.settings.get('FEATURE_GROUPS')
newsettings = self.save(responses).get('FEATURE_GROUPS')
if utils.is_post_deployment() and oldsettings != newsettings:
self.parent.apply_tasks.add(self.apply_to_nailgun)
return True
def apply_to_nailgun(self):
"""Apply changes to the Nailgun"""
msg = "Apply settings to Nailgun."
log.info(msg)
self.parent.footer.set_text(msg)
self.parent.refreshScreen()
result, msg = puppet.puppetApplyManifest(consts.PUPPET_NAILGUN)
if not result:
self.parent.footer.set_text(msg)
return False
self.parent.footer.set_text(msg)
return True
def load(self):
@ -98,6 +123,7 @@ class feature_groups(urwid.WidgetWrap):
if responses[setting]:
newsettings[part1].append(part2)
self.parent.settings.merge(newsettings)
return newsettings
def cancel(self, button):
ModuleHelper.cancel(self, button)