Merge "Control resource extension process defining required extensions"

This commit is contained in:
Jenkins
2013-05-31 08:08:37 +00:00
committed by Gerrit Code Review

View File

@@ -448,23 +448,47 @@ class ExtensionManager(object):
wants to extend this map. wants to extend this map.
""" """
update_exts = [] update_exts = []
for ext in self.extensions.itervalues(): processed_exts = set()
if not hasattr(ext, 'get_extended_resources'): exts_to_process = self.extensions.copy()
continue # Iterate until there are unprocessed extensions or if no progress
if hasattr(ext, 'update_attributes_map'): # is made in a whole iteration
update_exts.append(ext) while exts_to_process:
try: processed_ext_count = len(processed_exts)
extended_attrs = ext.get_extended_resources(version) for ext_name, ext in exts_to_process.items():
for resource, resource_attrs in extended_attrs.iteritems(): if not hasattr(ext, 'get_extended_resources'):
if attr_map.get(resource, None): del exts_to_process[ext_name]
attr_map[resource].update(resource_attrs) continue
else: if hasattr(ext, 'update_attributes_map'):
attr_map[resource] = resource_attrs update_exts.append(ext)
if extended_attrs: if hasattr(ext, 'get_required_extensions'):
attributes.EXT_NSES[ext.get_alias()] = ext.get_namespace() # Process extension only if all required extensions
except AttributeError: # have been processed already
LOG.exception(_("Error fetching extended attributes for " required_exts_set = set(ext.get_required_extensions())
"extension '%s'"), ext.get_name()) if required_exts_set - processed_exts:
continue
try:
extended_attrs = ext.get_extended_resources(version)
for resource, resource_attrs in extended_attrs.iteritems():
if attr_map.get(resource, None):
attr_map[resource].update(resource_attrs)
else:
attr_map[resource] = resource_attrs
if extended_attrs:
attributes.EXT_NSES[ext.get_alias()] = (
ext.get_namespace())
except AttributeError:
LOG.exception(_("Error fetching extended attributes for "
"extension '%s'"), ext.get_name())
processed_exts.add(ext_name)
del exts_to_process[ext_name]
if len(processed_exts) == processed_ext_count:
# Exit loop as no progress was made
break
if exts_to_process:
# NOTE(salv-orlando): Consider wheter this error should be fatal
LOG.error(_("It was impossible to process the following "
"extensions: %s because of missing requirements."),
','.join(exts_to_process.keys()))
"""Extending extensions' attributes map.""" """Extending extensions' attributes map."""
for ext in update_exts: for ext in update_exts: