replace dict.iteritems() with six.iteritems(dict)

According to https://wiki.openstack.org/wiki/Python3 dict.iteritems()
should be replaced with six.iteritems(dict).

Change-Id: I9e2881a006433c8b44a3caccebc73bae4973a041
changes/76/95476/4
Christian Berendt 8 years ago committed by Ethan Lynn
parent 586395b132
commit 58e141b2ac
  1. 2
      contrib/barbican/barbican/tests/test_order.py
  2. 2
      contrib/barbican/barbican/tests/test_secret.py
  3. 4
      contrib/docker/docker/resources/docker_container.py
  4. 7
      contrib/rackspace/rackspace/resources/cloud_loadbalancer.py
  5. 4
      contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py
  6. 3
      heat/api/cloudwatch/watch.py
  7. 3
      heat/api/openstack/v1/util.py
  8. 2
      heat/common/exception.py
  9. 2
      heat/common/wsgi.py
  10. 4
      heat/db/sqlalchemy/filters.py
  11. 3
      heat/db/sqlalchemy/migrate_repo/versions/037_migrate_hot_template.py
  12. 5
      heat/db/sqlalchemy/migrate_repo/versions/041_migrate_hot_template_resources.py
  13. 3
      heat/db/sqlalchemy/models.py
  14. 2
      heat/engine/cfn/functions.py
  15. 3
      heat/engine/cfn/template.py
  16. 7
      heat/engine/dependencies.py
  17. 5
      heat/engine/environment.py
  18. 11
      heat/engine/hot/template.py
  19. 7
      heat/engine/parameters.py
  20. 4
      heat/engine/plugin_manager.py
  21. 5
      heat/engine/properties.py
  22. 4
      heat/engine/resource.py
  23. 5
      heat/engine/resources/software_config/structured_config.py
  24. 7
      heat/engine/scheduler.py
  25. 2
      heat/engine/service.py
  26. 7
      heat/engine/template.py
  27. 4
      heat/engine/update.py
  28. 2
      heat/tests/test_engine_service.py
  29. 3
      heat/tests/test_nova_floatingip.py
  30. 6
      heat/tests/test_plugin_manager.py
  31. 4
      heat/tests/test_volume.py

@ -62,7 +62,7 @@ class TestOrder(HeatTestCase):
self.patcher_client.stop()
def _register_resources(self):
for res_name, res_class in order.resource_mapping().iteritems():
for res_name, res_class in six.iteritems(order.resource_mapping()):
resource._register_class(res_name, res_class)
def _create_resource(self, name, snippet, stack):

@ -59,7 +59,7 @@ class TestSecret(HeatTestCase):
self.patcher_client.stop()
def _register_resources(self):
for res_name, res_class in secret.resource_mapping().iteritems():
for res_name, res_class in six.iteritems(secret.resource_mapping()):
resource._register_class(res_name, res_class)
def _create_resource(self, name, snippet, stack):

@ -14,6 +14,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.engine import attributes
from heat.engine import properties
from heat.engine import resource
@ -185,7 +187,7 @@ class DockerContainer(resource.Resource):
def _parse_networkinfo_ports(self, networkinfo):
tcp = []
udp = []
for port, info in networkinfo['Ports'].iteritems():
for port, info in six.iteritems(networkinfo['Ports']):
p = port.split('/')
if not info or len(p) != 2 or 'HostPort' not in info[0]:
continue

@ -14,6 +14,8 @@
import copy
import itertools
import six
from heat.common import exception
from heat.engine import attributes
from heat.engine import constraints
@ -411,7 +413,8 @@ class CloudLoadBalancer(resource.Resource):
metadata = None
if self.METADATA in self.properties.data:
metadata = [{'key': k, 'value': v}
for k, v in self.properties[self.METADATA].iteritems()]
for k, v
in six.iteritems(self.properties[self.METADATA])]
return (session_persistence, connection_logging, metadata)
@ -579,7 +582,7 @@ class CloudLoadBalancer(resource.Resource):
These are values that may be initialized to None.
"""
return dict((key, value)
for (key, value) in property_dict.iteritems()
for (key, value) in six.iteritems(property_dict)
if value)
def validate(self):

@ -249,13 +249,13 @@ class LoadBalancerTest(HeatTestCase):
return (rsrc, fake_loadbalancer)
def _set_template(self, templ, **kwargs):
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
templ['Resources'][self._get_first_resource_name(templ)][
'Properties'][k] = v
return templ
def _set_expected(self, expected, **kwargs):
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
expected[k] = v
return expected

@ -15,6 +15,7 @@
endpoint for heat AWS-compatible CloudWatch API
"""
from oslo import messaging
import six
from heat.api.aws import exception
from heat.api.aws import utils as api_utils
@ -220,7 +221,7 @@ class WatchController(object):
con = req.context
parms = dict(req.params)
# FIXME : Don't yet handle filtering by Dimensions
filter_result = dict((k, v) for (k, v) in parms.iteritems() if k in
filter_result = dict((k, v) for (k, v) in six.iteritems(parms) if k in
("MetricName", "Namespace"))
LOG.debug("filter parameters : %s" % filter_result)

@ -13,6 +13,7 @@
from functools import wraps
import six
from webob import exc
from heat.common import identifier
@ -85,7 +86,7 @@ def get_allowed_params(params, whitelist):
'''
allowed_params = {}
for key, get_type in whitelist.iteritems():
for key, get_type in six.iteritems(whitelist):
value = None
if get_type == 'single':
value = params.get(key)

@ -113,7 +113,7 @@ class HeatException(Exception):
#kwargs doesn't match a variable in the message
#log the issue and the kwargs
LOG.exception(_('Exception in string format operation'))
for name, value in kwargs.iteritems():
for name, value in six.iteritems(kwargs):
LOG.error("%s: %s" % (name, value)) # noqa
if _FATAL_EXCEPTION_FORMAT_ERRORS:

@ -407,7 +407,7 @@ class Debug(Middleware):
resp = req.get_response(self.application)
print(("*" * 40) + " RESPONSE HEADERS")
for (key, value) in resp.headers.iteritems():
for (key, value) in six.iteritems(resp.headers):
print(key, "=", value)
print

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
def exact_filter(query, model, filters):
"""Applies exact match filtering to a query.
@ -31,7 +33,7 @@ def exact_filter(query, model, filters):
if filters is None:
filters = {}
for key, value in filters.iteritems():
for key, value in six.iteritems(filters):
if isinstance(value, (list, tuple, set, frozenset)):
column_attr = getattr(model, key)
query = query.filter(column_attr.in_(value))

@ -14,6 +14,7 @@
import copy
from migrate.versioning import util as migrate_util
import six
from sqlalchemy.orm import sessionmaker
from heat.db.sqlalchemy import models
@ -32,7 +33,7 @@ def upgrade(migrate_engine):
and 'parameters' in raw_template.template):
template = copy.deepcopy(raw_template.template)
for parameter, schema in template['parameters'].iteritems():
for parameter, schema in six.iteritems(template['parameters']):
changed = False
def _commit_schema(parameter, schema):

@ -13,6 +13,7 @@
import copy
from migrate.versioning import util as migrate_util
import six
from sqlalchemy.orm import sessionmaker
from heat.db.sqlalchemy import models
@ -38,8 +39,8 @@ def upgrade(migrate_engine):
def _translate(section, translate_map):
changed = False
for name, details in section.iteritems():
for old_key, new_key in translate_map.iteritems():
for name, details in six.iteritems(section):
for old_key, new_key in six.iteritems(translate_map):
if old_key in details:
details[new_key] = details[old_key]
del details[old_key]

@ -17,6 +17,7 @@ SQLAlchemy models for heat data.
import uuid
from oslo.db.sqlalchemy import models
import six
import sqlalchemy
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref
@ -69,7 +70,7 @@ class HeatBase(models.ModelBase, models.TimestampMixin):
if not session:
session = get_session()
session.begin()
for k, v in values.iteritems():
for k, v in six.iteritems(values):
setattr(self, k, v)
session.commit()

@ -425,7 +425,7 @@ class Replace(function.Function):
return string.replace(placeholder, unicode(value))
return reduce(replace, mapping.iteritems(), template)
return reduce(replace, six.iteritems(mapping), template)
class Base64(function.Function):

@ -13,6 +13,7 @@
# under the License.
import collections
import six
from heat.engine import function
from heat.engine import parameters
@ -60,7 +61,7 @@ class CfnTemplate(template.Template):
def param_schemata(self):
params = self.t.get(self.PARAMETERS) or {}
return dict((name, parameters.Schema.from_dict(name, schema))
for name, schema in params.iteritems())
for name, schema in six.iteritems(params))
def parameters(self, stack_identifier, user_params):
return parameters.Parameters(stack_identifier, self,

@ -14,6 +14,7 @@
import collections
import itertools
import six
from six.moves import xrange
from heat.common import exception
@ -120,7 +121,7 @@ class Graph(collections.defaultdict):
for rqd in node:
yield (rqr, rqd)
return itertools.chain.from_iterable(outgoing_edges(*i)
for i in self.iteritems())
for i in six.iteritems(self))
def __delitem__(self, key):
'''Delete the node given by the specified key from the graph.'''
@ -135,7 +136,7 @@ class Graph(collections.defaultdict):
def __str__(self):
'''Convert the graph to a human-readable string.'''
pairs = ('%s: %s' % (str(k), str(v)) for k, v in self.iteritems())
pairs = ('%s: %s' % (str(k), str(v)) for k, v in six.iteritems(self))
return '{%s}' % ', '.join(pairs)
@staticmethod
@ -146,7 +147,7 @@ class Graph(collections.defaultdict):
This is a destructive operation for the graph.
'''
for iteration in xrange(len(graph)):
for key, node in graph.iteritems():
for key, node in six.iteritems(graph):
if not node:
yield key
del graph[key]

@ -16,6 +16,7 @@ import itertools
import os.path
from oslo.config import cfg
import six
from heat.common import environment_format
from heat.common import exception
@ -328,7 +329,7 @@ class ResourceRegistry(object):
cls.get_class().support_status.status ==
support_status.encode())
return [name for name, cls in self._registry.iteritems()
return [name for name, cls in six.iteritems(self._registry)
if is_resource(name) and status_matches(cls)]
@ -360,7 +361,7 @@ class Environment(object):
if 'parameters' in env:
self.params = env['parameters']
else:
self.params = dict((k, v) for (k, v) in env.iteritems()
self.params = dict((k, v) for (k, v) in six.iteritems(env)
if k != RESOURCE_REGISTRY)
self.constraints = {}

@ -11,6 +11,7 @@
# under the License.
import collections
import six
from heat.engine.cfn import template as cfn_template
from heat.engine import function
@ -107,10 +108,10 @@ class HOTemplate(template.Template):
cfn_resources = {}
for resource_name, attrs in resources.iteritems():
for resource_name, attrs in six.iteritems(resources):
cfn_resource = {}
for attr, attr_value in attrs.iteritems():
for attr, attr_value in six.iteritems(attrs):
cfn_attr = self._translate(attr, HOT_TO_CFN_ATTRS,
_('"%s" is not a valid keyword '
'inside a resource definition'))
@ -127,10 +128,10 @@ class HOTemplate(template.Template):
cfn_outputs = {}
for output_name, attrs in outputs.iteritems():
for output_name, attrs in six.iteritems(outputs):
cfn_output = {}
for attr, attr_value in attrs.iteritems():
for attr, attr_value in six.iteritems(attrs):
cfn_attr = self._translate(attr, HOT_TO_CFN_ATTRS,
_('"%s" is not a valid keyword '
'inside an output definition'))
@ -144,7 +145,7 @@ class HOTemplate(template.Template):
parameter_section = self.t.get(self.PARAMETERS)
if parameter_section is None:
parameter_section = {}
params = parameter_section.iteritems()
params = six.iteritems(parameter_section)
return dict((name, parameters.HOTParamSchema.from_dict(name, schema))
for name, schema in params)

@ -419,7 +419,8 @@ class Parameters(collections.Mapping):
self.user_params = user_params
schemata = self.tmpl.param_schemata()
user_parameters = (user_parameter(si) for si in schemata.iteritems())
user_parameters = (user_parameter(si) for si in
six.iteritems(schemata))
pseudo_parameters = self._pseudo_parameters(stack_identifier)
self.params = dict((p.name,
@ -461,7 +462,7 @@ class Parameters(collections.Mapping):
optional filter function) and return the resulting dictionary.
'''
return dict((n, func(p))
for n, p in self.params.iteritems() if filter_func(p))
for n, p in six.iteritems(self.params) if filter_func(p))
def set_stack_id(self, stack_identifier):
'''
@ -487,7 +488,7 @@ class Parameters(collections.Mapping):
break
if param is not None:
template_params = self.tmpl.t[key] or {}
for name, attrs in template_params.iteritems():
for name, attrs in six.iteritems(template_params):
if not isinstance(attrs, dict):
raise exception.InvalidTemplateParameter(key=name)

@ -17,6 +17,7 @@ import itertools
import sys
from oslo.config import cfg
import six
from heat.common import plugin_loader
from heat.openstack.common import log
@ -111,4 +112,5 @@ class PluginMapping(object):
Mappings are returned as a list of (key, value) tuples.
'''
mod_dicts = plugin_manager.map_to_modules(self.load_from_module)
return itertools.chain.from_iterable(d.iteritems() for d in mod_dicts)
return itertools.chain.from_iterable(six.iteritems(d) for d
in mod_dicts)

@ -237,7 +237,8 @@ class Property(object):
if not isinstance(value, collections.Mapping):
raise TypeError(_('"%s" is not a map') % value)
return dict(self._get_children(value.iteritems(), validate=validate))
return dict(self._get_children(six.iteritems(value),
validate=validate))
def _get_list(self, value, validate=False):
if value is None:
@ -451,7 +452,7 @@ class Properties(collections.Mapping):
return {}, {}
param_prop_defs = [param_prop_def_items(n, s)
for n, s in schemata(schema).iteritems()
for n, s in six.iteritems(schemata(schema))
if s.implemented]
param_items, prop_items = zip(*param_prop_defs)
return dict(param_items), dict(prop_items)

@ -314,7 +314,7 @@ class Resource(object):
update_allowed_properties, raises UpdateReplace.
'''
update_allowed_set = set(self.update_allowed_properties)
for (psk, psv) in self.properties.props.iteritems():
for (psk, psv) in six.iteritems(self.properties.props):
if psv.update_allowed():
update_allowed_set.add(psk)
@ -557,7 +557,7 @@ class Resource(object):
# save the resource data
if data and isinstance(data, dict):
for key, value in data.iteritems():
for key, value in six.iteritems(data):
self.data_set(key, value)
# save the resource metadata

@ -15,6 +15,7 @@
import collections
import functools
import six
from heat.engine import properties
from heat.engine.resources.software_config import software_config as sc
@ -110,11 +111,11 @@ class StructuredDeployment(sd.SoftwareDeployment):
if isinstance(snippet, collections.Mapping):
if len(snippet) == 1:
fn_name, args = next(snippet.iteritems())
fn_name, args = next(six.iteritems(snippet))
if fn_name == input_key:
if isinstance(args, basestring):
return inputs.get(args)
return dict((k, parse(v)) for k, v in snippet.iteritems())
return dict((k, parse(v)) for k, v in six.iteritems(snippet))
elif (not isinstance(snippet, basestring) and
isinstance(snippet, collections.Iterable)):
return [parse(v) for v in snippet]

@ -18,6 +18,7 @@ from time import time as wallclock
import types
import eventlet
import six
from heat.openstack.common import excutils
from heat.openstack.common.gettextutils import _
@ -365,7 +366,7 @@ class DependencyTaskGroup(object):
Iterate over all subtasks that are ready to start - i.e. all their
dependencies have been satisfied but they have not yet been started.
"""
for k, n in self._graph.iteritems():
for k, n in six.iteritems(self._graph):
if not n:
runner = self._runners[k]
if not runner.started():
@ -377,7 +378,7 @@ class DependencyTaskGroup(object):
been started but have not yet completed.
"""
running = lambda (k, r): k in self._graph and r.started()
return itertools.ifilter(running, self._runners.iteritems())
return itertools.ifilter(running, six.iteritems(self._runners))
class PollingTaskGroup(object):
@ -409,7 +410,7 @@ class PollingTaskGroup(object):
"""Return a list containing the keyword args for each subtask."""
keygroups = (itertools.izip(itertools.repeat(name),
arglist)
for name, arglist in kwarg_lists.iteritems())
for name, arglist in six.iteritems(kwarg_lists))
return [dict(kwargs) for kwargs in itertools.izip(*keygroups)]
@classmethod

@ -993,7 +993,7 @@ class EngineService(service.Service):
stack = parser.Stack.load(cnxt, stack=s)
return [api.format_stack_resource(resource)
for name, resource in stack.iteritems()
for name, resource in six.iteritems(stack)
if resource_name is None or name == resource_name]
@request_context

@ -15,6 +15,7 @@ import abc
import collections
import copy
import functools
import six
from stevedore import extension
from heat.common import exception
@ -57,7 +58,7 @@ class TemplatePluginManager(object):
def get_version(template_data, available_versions):
version_keys = set(key for key, version in available_versions)
candidate_keys = set(k for k, v in template_data.iteritems() if
candidate_keys = set(k for k, v in six.iteritems(template_data) if
isinstance(v, basestring))
keys_present = version_keys & candidate_keys
@ -244,11 +245,11 @@ def parse(functions, stack, snippet):
if isinstance(snippet, collections.Mapping):
if len(snippet) == 1:
fn_name, args = next(snippet.iteritems())
fn_name, args = next(six.iteritems(snippet))
Func = functions.get(fn_name)
if Func is not None:
return Func(stack, fn_name, recurse(args))
return dict((k, recurse(v)) for k, v in snippet.iteritems())
return dict((k, recurse(v)) for k, v in six.iteritems(snippet))
elif (not isinstance(snippet, basestring) and
isinstance(snippet, collections.Iterable)):
return [recurse(v) for v in snippet]

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.db import api as db_api
from heat.engine import dependencies
from heat.engine import resource
@ -184,7 +186,7 @@ class StackUpdate(object):
for e in existing_deps.graph(reverse=True).edges():
yield e
# Don't cleanup old resources until after they have been replaced
for name, res in self.existing_stack.iteritems():
for name, res in six.iteritems(self.existing_stack):
if name in self.new_stack:
yield (res, self.new_stack[name])

@ -3011,7 +3011,7 @@ class SoftwareConfigServiceTest(HeatTestCase):
values.update(kwargs)
updated = self.engine.update_software_deployment(
self.ctx, deployment_id, **values)
for key, value in kwargs.iteritems():
for key, value in six.iteritems(kwargs):
self.assertEqual(value, updated[key])
check_software_deployment_updated(config_id=config_id)

@ -13,6 +13,7 @@
import copy
import mock
import six
from heat.common import exception as heat_ex
from heat.common import template_format
@ -73,7 +74,7 @@ class NovaFloatingIPTest(HeatTestCase):
def _make_obj(self, **kwargs):
mock = self.m.CreateMockAnything()
for k, v in kwargs.iteritems():
for k, v in six.iteritems(kwargs):
setattr(mock, k, v)
return mock

@ -15,6 +15,8 @@
import sys
import types
import six
from heat.engine import plugin_manager
from heat.tests.common import HeatTestCase
@ -95,7 +97,7 @@ class TestPluginManager(HeatTestCase):
all_items = pm.load_all(mgr)
for item in current_test_mapping().iteritems():
for item in six.iteritems(current_test_mapping()):
self.assertNotIn(item, all_items)
def test_load_all(self):
@ -111,5 +113,5 @@ class TestPluginManager(HeatTestCase):
all_items = pm.load_all(mgr)
for item in current_test_mapping().iteritems():
for item in six.iteritems(current_test_mapping()):
self.assertIn(item, all_items)

@ -1357,7 +1357,7 @@ class FakeVolume(object):
def __init__(self, initial_status, final_status, **attrs):
self.status = initial_status
self.final_status = final_status
for key, value in attrs.iteritems():
for key, value in six.iteritems(attrs):
setattr(self, key, value)
def get(self):
@ -1381,7 +1381,7 @@ class FakeLatencyVolume(object):
raise exception.Error('life_cycle should not be an empty tuple.')
self.life_cycle = iter(life_cycle)
self.status = next(self.life_cycle)
for key, value in attrs.iteritems():
for key, value in six.iteritems(attrs):
setattr(self, key, value)
def get(self):

Loading…
Cancel
Save