Use six.itervalues(x) instead of x.values()

Change-Id: Ie71072940b7b5e599d9012be0bc1874b2a623003
Partial-Bug: #1446254
changes/05/175505/2
Tetiana Lashchova 8 years ago
parent 5854f1d121
commit 4c6810ce1a
  1. 2
      heat/engine/attributes.py
  2. 5
      heat/engine/clients/client_plugin.py
  3. 2
      heat/engine/constraints.py
  4. 2
      heat/engine/function.py
  5. 5
      heat/engine/hot/template.py
  6. 2
      heat/engine/parameters.py
  7. 4
      heat/engine/resources/aws/ec2/internet_gateway.py
  8. 5
      heat/engine/resources/aws/ec2/security_group.py
  9. 2
      heat/engine/resources/openstack/heat/resource_group.py
  10. 2
      heat/engine/resources/openstack/neutron/floatingip.py
  11. 3
      heat/engine/resources/openstack/neutron/port.py
  12. 6
      heat/engine/resources/openstack/neutron/router.py
  13. 2
      heat/engine/resources/openstack/nova/server.py
  14. 5
      heat/engine/resources/wait_condition.py
  15. 4
      heat/engine/scheduler.py
  16. 2
      heat/engine/service.py
  17. 3
      heat/engine/service_stack_watch.py
  18. 21
      heat/engine/stack.py
  19. 2
      heat/engine/template.py
  20. 7
      heat/tests/test_attributes.py
  21. 4
      heat/tests/test_engine_service.py
  22. 3
      heat/tests/test_grouputils.py
  23. 2
      heat/tests/test_hot.py
  24. 6
      heat/tests/test_properties.py
  25. 4
      heat/tests/test_stack.py
  26. 4
      heat/tests/test_stack_collect_attributes.py
  27. 2
      heat/tests/test_template.py

@ -176,7 +176,7 @@ class Attributes(collections.Mapping):
def __repr__(self):
return ("Attributes for %s:\n\t" % self._resource_name +
'\n\t'.join(self._attributes.values()))
'\n\t'.join(six.itervalues(self._attributes)))
def select_from_attribute(attribute_value, path):

@ -147,10 +147,11 @@ class ClientPlugin(object):
if self.exceptions_module:
if isinstance(self.exceptions_module, list):
for m in self.exceptions_module:
if type(ex) in m.__dict__.values():
if type(ex) in six.itervalues(m.__dict__):
return True
else:
return type(ex) in self.exceptions_module.__dict__.values()
return type(ex) in six.itervalues(
self.exceptions_module.__dict__)
return False
def is_not_found(self, ex):

@ -133,7 +133,7 @@ class Schema(collections.Mapping):
if isinstance(self.schema, AnyIndexDict):
self.schema.value.validate(context)
else:
for nested_schema in self.schema.values():
for nested_schema in six.itervalues(self.schema):
nested_schema.validate(context)
def _validate_default(self, context):

@ -132,7 +132,7 @@ def validate(snippet):
if isinstance(snippet, Function):
snippet.validate()
elif isinstance(snippet, collections.Mapping):
for v in snippet.values():
for v in six.itervalues(snippet):
validate(v)
elif (not isinstance(snippet, six.string_types) and
isinstance(snippet, collections.Iterable)):

@ -170,8 +170,9 @@ class HOTemplate20130523(template.Template):
self._RESOURCE_HOT_TO_CFN_ATTRS)
def get_section_name(self, section):
cfn_to_hot_attrs = dict(zip(self._RESOURCE_HOT_TO_CFN_ATTRS.values(),
self._RESOURCE_HOT_TO_CFN_ATTRS.keys()))
cfn_to_hot_attrs = dict(
zip(six.itervalues(self._RESOURCE_HOT_TO_CFN_ATTRS),
self._RESOURCE_HOT_TO_CFN_ATTRS.keys()))
return cfn_to_hot_attrs.get(section, section)
def _translate_outputs(self, outputs):

@ -491,7 +491,7 @@ class Parameters(collections.Mapping):
self._validate_tmpl_parameters()
self._validate_user_parameters()
for param in self.params.values():
for param in six.itervalues(self.params):
param.validate(validate_value, context)
def __contains__(self, key):

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import properties
@ -100,7 +102,7 @@ class VPCGatewayAttachment(resource.Resource):
default_client_name = 'neutron'
def _vpc_route_tables(self):
for res in self.stack.itervalues():
for res in six.itervalues(self.stack):
if (res.has_interface('AWS::EC2::RouteTable') and
res.properties.get(route_table.RouteTable.VPC_ID) ==
self.properties.get(self.VPC_ID)):

@ -43,7 +43,7 @@ class BaseSecurityGroup(object):
ids_to_delete = [id for id, rule in existing.items()
if rule not in updated]
rules_to_create = [rule for rule in updated
if rule not in existing.values()]
if rule not in six.itervalues(existing)]
return ids_to_delete, rules_to_create
@ -320,7 +320,8 @@ class NeutronSecurityGroup(BaseSecurityGroup):
rule['direction'] = 'egress'
for rule in updated[self.sg.SECURITY_GROUP_INGRESS]:
rule['direction'] = 'ingress'
updated_all = updated.values()[0] + updated.values()[1]
updated_rules = list(six.itervalues(updated))
updated_all = updated_rules[0] + updated_rules[1]
return super(NeutronSecurityGroup, self).diff_rules(existing,
updated_all)

@ -294,7 +294,7 @@ class ResourceGroup(stack_resource.StackResource):
if isinstance(val, six.string_types):
return val.replace(repl_var, res_name)
elif isinstance(val, collections.Mapping):
return dict(zip(val, map(recurse, val.values())))
return dict(zip(val, map(recurse, six.itervalues(val))))
elif isinstance(val, collections.Sequence):
return map(recurse, val)
return val

@ -110,7 +110,7 @@ class FloatingIP(neutron.NeutronResource):
def add_dependencies(self, deps):
super(FloatingIP, self).add_dependencies(deps)
for resource in self.stack.itervalues():
for resource in six.itervalues(self.stack):
# depend on any RouterGateway in this template with the same
# network_id as this floating_network_id
if resource.has_interface('OS::Neutron::RouterGateway'):

@ -12,6 +12,7 @@
# under the License.
from oslo_log import log as logging
import six
from heat.common.i18n import _
from heat.common.i18n import _LW
@ -261,7 +262,7 @@ class Port(neutron.NeutronResource):
# It is not known which subnet a port might be assigned
# to so all subnets in a network should be created before
# the ports in that network.
for res in self.stack.itervalues():
for res in six.itervalues(self.stack):
if res.has_interface('OS::Neutron::Subnet'):
dep_network = res.properties.get(
subnet.Subnet.NETWORK) or res.properties.get(

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common import exception
from heat.common.i18n import _
from heat.engine import attributes
@ -171,7 +173,7 @@ class Router(neutron.NeutronResource):
external_gw = self.properties.get(self.EXTERNAL_GATEWAY)
if external_gw:
external_gw_net = external_gw.get(self.EXTERNAL_GATEWAY_NETWORK)
for res in self.stack.itervalues():
for res in six.itervalues(self.stack):
if res.has_interface('OS::Neutron::Subnet'):
subnet_net = res.properties.get(
subnet.Subnet.NETWORK) or res.properties.get(
@ -434,7 +436,7 @@ class RouterGateway(neutron.NeutronResource):
def add_dependencies(self, deps):
super(RouterGateway, self).add_dependencies(deps)
for resource in self.stack.itervalues():
for resource in six.itervalues(self.stack):
# depend on any RouterInterface in this template with the same
# router_id as this router_id
if resource.has_interface('OS::Neutron::RouterInterface'):

@ -902,7 +902,7 @@ class Server(stack_user.StackUser):
nets = self.properties.get(self.NETWORKS)
if not nets:
return
for res in self.stack.itervalues():
for res in six.itervalues(self.stack):
if res.has_interface('OS::Neutron::Subnet'):
subnet_net = (res.properties.get(subnet.Subnet.NETWORK_ID)
or res.properties.get(subnet.Subnet.NETWORK))

@ -12,6 +12,7 @@
# under the License.
from oslo_log import log as logging
import six
from heat.common import exception
from heat.common.i18n import _
@ -78,14 +79,14 @@ class BaseWaitConditionHandle(signal_responder.SignalResponder):
Return a list of the Status values for the handle signals
'''
return [v[self.STATUS]
for v in self.metadata_get(refresh=True).values()]
for v in six.itervalues(self.metadata_get(refresh=True))]
def get_status_reason(self, status):
'''
Return a list of reasons associated with a particular status
'''
return [v[self.REASON]
for v in self.metadata_get(refresh=True).values()
for v in six.itervalues(self.metadata_get(refresh=True))
if v[self.STATUS] == status]

@ -371,7 +371,7 @@ class DependencyTaskGroup(object):
def __call__(self):
"""Return a co-routine which runs the task group."""
raised_exceptions = []
while any(self._runners.itervalues()):
while any(six.itervalues(self._runners)):
try:
for k, r in self._ready():
r.start()
@ -400,7 +400,7 @@ class DependencyTaskGroup(object):
raise exc_type, exc_val, traceback
def cancel_all(self, grace_period=None):
for r in self._runners.itervalues():
for r in six.itervalues(self._runners):
r.cancel(grace_period=grace_period)
def _cancel_recursively(self, key, runner):

@ -206,7 +206,7 @@ class ThreadGroupManager(object):
for th in threads:
th.link(mark_done, th)
while not all(links_done.values()):
while not all(six.itervalues(links_done)):
eventlet.sleep()
def send(self, stack_id, message):

@ -13,6 +13,7 @@
from oslo_log import log as logging
from oslo_utils import timeutils
import six
from heat.common import context
from heat.common.i18n import _LE
@ -94,7 +95,7 @@ class StackWatch(object):
def run_alarm_action(stk, actions, details):
for action in actions:
action(details=details)
for res in stk.itervalues():
for res in six.itervalues(stk):
res.metadata_update()
for wr in wrs:

@ -209,7 +209,7 @@ class Stack(collections.Mapping):
Iterates over all the resources in a stack, including nested stacks up
to `nested_depth` levels below.
'''
for res in self.values():
for res in six.itervalues(self):
yield res
get_nested = getattr(res, 'nested', None)
@ -239,7 +239,7 @@ class Stack(collections.Mapping):
def dependencies(self):
if self._dependencies is None:
self._dependencies = self._get_dependencies(
self.resources.itervalues())
six.itervalues(self.resources))
return self._dependencies
def reset_dependencies(self):
@ -298,7 +298,8 @@ class Stack(collections.Mapping):
return nested_stack.total_resources()
return 0
return len(self) + sum(total_nested(res) for res in self.itervalues())
return len(self) + sum(total_nested(res)
for res in six.itervalues(self))
def _set_param_stackid(self):
'''
@ -557,7 +558,7 @@ class Stack(collections.Mapping):
Return the resource in this stack with the specified
refid, or None if not found
'''
for r in self.values():
for r in six.itervalues(self):
if r.state in (
(r.INIT, r.COMPLETE),
(r.CREATE, r.IN_PROGRESS),
@ -664,7 +665,7 @@ class Stack(collections.Mapping):
during its lifecycle using the configured deferred authentication
method.
'''
return any(res.requires_deferred_auth for res in self.values())
return any(res.requires_deferred_auth for res in six.itervalues(self))
@profiler.trace('Stack.state_set', hide_args=False)
def state_set(self, action, status, reason):
@ -714,7 +715,7 @@ class Stack(collections.Mapping):
Preview the stack with all of the resources.
'''
return [resource.preview()
for resource in self.resources.itervalues()]
for resource in six.itervalues(self.resources)]
def _store_resources(self):
for r in reversed(self.dependencies):
@ -824,7 +825,7 @@ class Stack(collections.Mapping):
return hasattr(res, 'handle_%s' % self.CHECK.lower())
supported = [is_supported(self, res)
for res in self.resources.values()]
for res in six.itervalues(self.resources)]
if not all(supported):
msg = ". '%s' not fully supported (see resources)" % self.CHECK
@ -866,7 +867,7 @@ class Stack(collections.Mapping):
if not self.disable_rollback and self.state == (self.ADOPT,
self.FAILED):
# enter the same flow as abandon and just delete the stack
for res in self.resources.values():
for res in six.itervalues(self.resources):
res.abandon_in_progress = True
self.delete(action=self.ROLLBACK, abandon=True)
@ -1368,7 +1369,7 @@ class Stack(collections.Mapping):
'status': self.status,
'template': self.t.t,
'resources': dict((res.name, res.prepare_abandon())
for res in self.resources.values()),
for res in six.itervalues(self.resources)),
'project_id': self.tenant_id,
'stack_user_project_id': self.stack_user_project_id
}
@ -1393,5 +1394,5 @@ class Stack(collections.Mapping):
return
# a change in some resource may have side-effects in the attributes
# of other resources, so ensure that attributes are re-calculated
for res in self.resources.itervalues():
for res in six.itervalues(self.resources):
res.attributes.reset_resolved_values()

@ -233,7 +233,7 @@ class Template(collections.Mapping):
raise exception.InvalidTemplateSection(section=k)
# check resources
for res in self[self.RESOURCES].values():
for res in six.itervalues(self[self.RESOURCES]):
try:
if not res or not res.get('Type'):
message = _('Each Resource must contain '

@ -12,6 +12,7 @@
# under the License.
import mock
import six
from heat.engine import attributes
from heat.engine import resources
@ -27,9 +28,9 @@ class AttributeSchemaTest(common.HeatTestCase):
def test_all_resource_schemata(self):
for resource_type in resources.global_env().get_types():
for schema in getattr(resource_type,
'attributes_schema',
{}).itervalues():
for schema in six.itervalues(getattr(resource_type,
'attributes_schema',
{})):
attributes.Schema.from_attribute(schema)
def test_from_attribute_new_schema_format(self):

@ -2598,7 +2598,7 @@ class StackServiceTest(common.HeatTestCase):
@stack_context('service_resources_list_test_stack_with_depth')
def test_stack_resources_list_with_depth(self, mock_load):
mock_load.return_value = self.stack
resources = self.stack.values()
resources = six.itervalues(self.stack)
self.stack.iter_resources = mock.Mock(return_value=resources)
resources = self.eng.list_stack_resources(self.ctx,
self.stack.identifier(),
@ -2609,7 +2609,7 @@ class StackServiceTest(common.HeatTestCase):
@stack_context('service_resources_list_test_stack_with_max_depth')
def test_stack_resources_list_with_max_depth(self, mock_load):
mock_load.return_value = self.stack
resources = self.stack.values()
resources = six.itervalues(self.stack)
self.stack.iter_resources = mock.Mock(return_value=resources)
resources = self.eng.list_stack_resources(self.ctx,
self.stack.identifier(),

@ -12,6 +12,7 @@
# under the License.
import mock
import six
from heat.common import grouputils
from heat.common import template_format
@ -61,7 +62,7 @@ class GroupUtilsTest(common.HeatTestCase):
self.assertEqual(2, grouputils.get_size(group))
# member list (sorted)
members = [r for r in stack.itervalues()]
members = [r for r in six.itervalues(stack)]
expected = sorted(members, key=lambda r: (r.created_time, r.name))
actual = grouputils.get_members(group)
self.assertEqual(expected, actual)

@ -881,7 +881,7 @@ class HOTemplateTest(common.HeatTestCase):
empty = template.Template(copy.deepcopy(hot_tpl_empty))
stack = parser.Stack(utils.dummy_context(), 'test_stack', source)
for defn in source.resource_definitions(stack).values():
for defn in six.itervalues(source.resource_definitions(stack)):
empty.add_resource(defn)
self.assertEqual(hot_tpl['resources'], empty.t['resources'])

@ -138,9 +138,9 @@ class PropertySchemaTest(common.HeatTestCase):
def test_all_resource_schemata(self):
for resource_type in resources.global_env().get_types():
for schema in getattr(resource_type,
'properties_schema',
{}).itervalues():
for schema in six.itervalues(getattr(resource_type,
'properties_schema',
{})):
properties.Schema.from_legacy(schema)
def test_from_legacy_idempotency(self):

@ -711,7 +711,7 @@ class StackTest(common.HeatTestCase):
def _mock_check(res):
res.handle_check = mock.Mock()
[_mock_check(res) for res in self.stack.resources.values()]
[_mock_check(res) for res in six.itervalues(self.stack.resources)]
return self.stack
def test_check_supported(self):
@ -721,7 +721,7 @@ class StackTest(common.HeatTestCase):
self.assertEqual(stack1.COMPLETE, stack1.status)
self.assertEqual(stack1.CHECK, stack1.action)
[self.assertTrue(res.handle_check.called)
for res in stack1.resources.values()]
for res in six.itervalues(stack1.resources)]
self.assertNotIn('not fully supported', stack1.status_reason)
def test_check_not_supported(self):

@ -11,6 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from heat.common import template_format
from heat.engine import resource
from heat.engine import stack
@ -173,7 +175,7 @@ class DepAttrsTest(common.HeatTestCase):
parsed_tmpl = template_format.parse(self.tmpl)
self.stack = stack.Stack(self.ctx, 'test_stack',
template.Template(parsed_tmpl))
resources = self.stack.resources.values()
resources = six.itervalues(self.stack.resources)
outputs = self.stack.outputs
for res in resources:

@ -873,7 +873,7 @@ Mappings:
empty = template.Template(copy.deepcopy(empty_template))
stk = stack.Stack(self.ctx, 'test_stack', source)
for defn in source.resource_definitions(stk).values():
for defn in six.itervalues(source.resource_definitions(stk)):
empty.add_resource(defn)
self.assertEqual(cfn_tpl['Resources'], empty.t['Resources'])

Loading…
Cancel
Save