Adjusted paste config modification (for nova).

This commit is contained in:
Joshua Harlow
2012-02-02 18:09:13 -08:00
parent 7dc1ac7c89
commit daf700ec69
6 changed files with 55 additions and 24 deletions

View File

@@ -57,6 +57,9 @@ class ComponentBase(object):
return list()
return list(deps)
def pre_fetch_configs(self):
pass
class PkgInstallComponent(ComponentBase):
def __init__(self, component_name, *args, **kargs):

View File

@@ -121,6 +121,9 @@ class GlanceInstaller(comp.PythonInstallComponent):
#then extract known configs that
#will need locations/directories/files made (or touched)...
with io.BytesIO(contents) as stream:
#for paste files we might not be doing this 100% right
#since it seems like the paste config format is not the same as
#the python config parser format....
config = cfg.IgnoreMissingConfigParser()
config.readfp(stream)
if config.getboolean('image_cache_enabled', CFG_SECTION):

View File

@@ -137,6 +137,9 @@ class KeystoneInstaller(comp.PythonInstallComponent):
#then extract known configs that
#will need locations/directories/files made (or touched)...
with io.BytesIO(contents) as stream:
#for paste files we might not be doing this 100% right
#since it seems like the paste config format is not the same as
#the python config parser format....
config = cfg.IgnoreMissingConfigParser()
config.readfp(stream)
log_filename = config.get('log_file', CFG_SECTION)

View File

@@ -125,10 +125,11 @@ ADD_PKGS = {
# Adjustments to nova paste pipeline for keystone
PASTE_PIPELINE_KEYSTONE_ADJUST = {
'ec2cloud': 'ec2faultwrap logrequest totoken authtoken keystonecontext cloudrequest authorizer validator ec2executor',
'ec2admin': "ec2faultwrap logrequest totoken authtoken keystonecontext adminrequest authorizer ec2executor",
'openstack_compute_api_v2': "faultwrap authtoken keystonecontext ratelimit osapi_compute_app_v2",
'openstack_volume_api_v1': "faultwrap authtoken keystonecontext ratelimit osapi_volume_app_v1",
'pipeline:ec2cloud': {'pipeline': 'ec2faultwrap logrequest totoken authtoken keystonecontext cloudrequest authorizer ec2executor'},
'pipeline:ec2admin': {'pipeline': "ec2faultwrap logrequest totoken authtoken keystonecontext adminrequest authorizer ec2executor"},
'pipeline:openstack_compute_api_v2': {'pipeline': "faultwrap authtoken keystonecontext ratelimit osapi_compute_app_v2"},
'pipeline:openstack_volume_api_v1': {'pipeline': "faultwrap authtoken keystonecontext ratelimit osapi_volume_app_v1"},
'pipeline:openstack_api_v2': {'pipeline': 'faultwrap authtoken keystonecontext ratelimit osapi_app_v2'},
}
# What to start
@@ -323,26 +324,10 @@ class NovaInstaller(comp.PythonInstallComponent):
def _config_adjust(self, contents, config_fn):
if config_fn == PASTE_CONF and settings.KEYSTONE in self.instances:
#We change the pipelines in nova to use keystone
newcontents = contents
with io.BytesIO(contents) as stream:
config = cfg.IgnoreMissingConfigParser()
config.readfp(stream)
adjusted_pipelines = 0
for (name, value) in PASTE_PIPELINE_KEYSTONE_ADJUST.items():
section_name = "pipeline:" + name
if config.has_section(section_name):
LOG.debug("Adjusting section named \"%s\" option \"pipeline\" to \"%s\"", section_name, value)
config.set(section_name, "pipeline", value)
adjusted_pipelines += 1
if adjusted_pipelines:
#we changed it, guess we have to write it out
with io.BytesIO() as outputstream:
config.write(outputstream)
outputstream.flush()
#TODO can we write to contents here directly?
newcontents = outputstream.getvalue()
contents = newcontents
#it seems like paste actually uses it own custom config parser
#which looks like the python config parser files format but actually isn't
#great (not)
contents = utils.adjust_paste_config(contents, PASTE_PIPELINE_KEYSTONE_ADJUST)
return contents
def _get_source_config(self, config_fn):

View File

@@ -234,6 +234,11 @@ def _run_components(action_name, component_order, components, distro, root_dir,
_pre_run(action_name, root_dir=root_dir, pkg=pkg_manager, cfg=config)
results = list()
force = program_args.get('force', False)
for component in component_order:
#this instance was just made
instance = all_instances.get(component)
#prefetch configs
instance.pre_fetch_configs()
for component in component_order:
#this instance was just made
instance = all_instances.get(component)

View File

@@ -45,6 +45,38 @@ def load_template(component, fn):
return (full_pth, contents)
def adjust_paste_config(contents, section_rep):
lines = contents.splitlines()
for section in section_rep.keys():
section_str = "[" + section.strip() + "]"
section_replacements = section_rep.get(section)
if not section_replacements:
continue
LOG.debug("Looking for section %s" % (section))
matching = False
for i in range(len(lines)):
line = lines[i]
if matching and line.startswith("["):
#new section
LOG.debug("Finished section named %s ending at line %s" % (section, (i + 1)))
break
elif matching:
for (key, rep) in section_replacements.items():
#does not handle multi-lines values (fix that?)
pieces = line.split("=", 1)
if len(pieces) == 2:
pot_key = pieces[0].strip()
if pot_key == key:
new_line = "%s = %s" % (key, rep)
LOG.debug("Replacing paste line %s with %s for line %s" % (line, new_line, (i + 1)))
lines[i] = new_line
elif not matching and section_str == line.strip():
#found the section
matching = True
LOG.debug("Found section named %s starting at line %s" % (section, (i + 1)))
return joinlinesep(*lines)
def execute_template(*cmds, **kargs):
params_replacements = kargs.pop('params', None)
tracewriter = kargs.pop('tracewriter', None)