diff --git a/heat/engine/attributes.py b/heat/engine/attributes.py index 09630a1a6d..97cbd56208 100644 --- a/heat/engine/attributes.py +++ b/heat/engine/attributes.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): diff --git a/heat/engine/clients/client_plugin.py b/heat/engine/clients/client_plugin.py index b25cbd0b15..397ac307ee 100644 --- a/heat/engine/clients/client_plugin.py +++ b/heat/engine/clients/client_plugin.py @@ -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): diff --git a/heat/engine/constraints.py b/heat/engine/constraints.py index 4c522f4b59..e4dd709315 100644 --- a/heat/engine/constraints.py +++ b/heat/engine/constraints.py @@ -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): diff --git a/heat/engine/function.py b/heat/engine/function.py index 99b1caee00..d721bedf00 100644 --- a/heat/engine/function.py +++ b/heat/engine/function.py @@ -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)): diff --git a/heat/engine/hot/template.py b/heat/engine/hot/template.py index 21c8065fc9..f313979f97 100644 --- a/heat/engine/hot/template.py +++ b/heat/engine/hot/template.py @@ -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): diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index 7c7fc89120..0654713420 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -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): diff --git a/heat/engine/resources/aws/ec2/internet_gateway.py b/heat/engine/resources/aws/ec2/internet_gateway.py index 902107aa82..453e3286c3 100644 --- a/heat/engine/resources/aws/ec2/internet_gateway.py +++ b/heat/engine/resources/aws/ec2/internet_gateway.py @@ -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)): diff --git a/heat/engine/resources/aws/ec2/security_group.py b/heat/engine/resources/aws/ec2/security_group.py index 29a6758b17..fd7cf5f9a6 100644 --- a/heat/engine/resources/aws/ec2/security_group.py +++ b/heat/engine/resources/aws/ec2/security_group.py @@ -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) diff --git a/heat/engine/resources/openstack/heat/resource_group.py b/heat/engine/resources/openstack/heat/resource_group.py index f2d3f82b6c..6648fe4930 100644 --- a/heat/engine/resources/openstack/heat/resource_group.py +++ b/heat/engine/resources/openstack/heat/resource_group.py @@ -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 diff --git a/heat/engine/resources/openstack/neutron/floatingip.py b/heat/engine/resources/openstack/neutron/floatingip.py index 11fdd819cc..b14241e83f 100644 --- a/heat/engine/resources/openstack/neutron/floatingip.py +++ b/heat/engine/resources/openstack/neutron/floatingip.py @@ -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'): diff --git a/heat/engine/resources/openstack/neutron/port.py b/heat/engine/resources/openstack/neutron/port.py index d9dcf228b2..486351d332 100644 --- a/heat/engine/resources/openstack/neutron/port.py +++ b/heat/engine/resources/openstack/neutron/port.py @@ -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( diff --git a/heat/engine/resources/openstack/neutron/router.py b/heat/engine/resources/openstack/neutron/router.py index be15cd1e9a..60a9703374 100644 --- a/heat/engine/resources/openstack/neutron/router.py +++ b/heat/engine/resources/openstack/neutron/router.py @@ -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'): diff --git a/heat/engine/resources/openstack/nova/server.py b/heat/engine/resources/openstack/nova/server.py index 3d6a676819..b93dea84b2 100644 --- a/heat/engine/resources/openstack/nova/server.py +++ b/heat/engine/resources/openstack/nova/server.py @@ -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)) diff --git a/heat/engine/resources/wait_condition.py b/heat/engine/resources/wait_condition.py index 704ea05d6e..f735fe7e43 100644 --- a/heat/engine/resources/wait_condition.py +++ b/heat/engine/resources/wait_condition.py @@ -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] diff --git a/heat/engine/scheduler.py b/heat/engine/scheduler.py index c676d0755b..9479404029 100644 --- a/heat/engine/scheduler.py +++ b/heat/engine/scheduler.py @@ -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): diff --git a/heat/engine/service.py b/heat/engine/service.py index 21b94a2497..7c3eb9a745 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -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): diff --git a/heat/engine/service_stack_watch.py b/heat/engine/service_stack_watch.py index 1ae46ae964..139672cc2f 100644 --- a/heat/engine/service_stack_watch.py +++ b/heat/engine/service_stack_watch.py @@ -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: diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 1655524c3a..59dd2446ec 100755 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -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() diff --git a/heat/engine/template.py b/heat/engine/template.py index 97fb074db1..960e438f0a 100644 --- a/heat/engine/template.py +++ b/heat/engine/template.py @@ -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 ' diff --git a/heat/tests/test_attributes.py b/heat/tests/test_attributes.py index fb99db9f02..18f60e800a 100644 --- a/heat/tests/test_attributes.py +++ b/heat/tests/test_attributes.py @@ -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): diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 7cf06c2949..ecece759e6 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -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(), diff --git a/heat/tests/test_grouputils.py b/heat/tests/test_grouputils.py index 7fbc51e56a..64247b11ad 100644 --- a/heat/tests/test_grouputils.py +++ b/heat/tests/test_grouputils.py @@ -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) diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 7222bb6627..316b39590f 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -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']) diff --git a/heat/tests/test_properties.py b/heat/tests/test_properties.py index 5eb7ec92f2..d6f929b524 100644 --- a/heat/tests/test_properties.py +++ b/heat/tests/test_properties.py @@ -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): diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index 05a8b57506..5cf7f9aae9 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -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): diff --git a/heat/tests/test_stack_collect_attributes.py b/heat/tests/test_stack_collect_attributes.py index 567be6a078..99099d1f73 100644 --- a/heat/tests/test_stack_collect_attributes.py +++ b/heat/tests/test_stack_collect_attributes.py @@ -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: diff --git a/heat/tests/test_template.py b/heat/tests/test_template.py index 78cfcc7f6b..baac83a5a7 100644 --- a/heat/tests/test_template.py +++ b/heat/tests/test_template.py @@ -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'])