From 5566e6f2c8985757388bb76ae08314e98eef168d Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 31 May 2016 12:45:58 -0400 Subject: [PATCH] Get rid of gratuitous use of six.iterkeys() In Python3, dict.keys() returns a view object rather than a list. This behaves differently in that changes to the dict also modify the view, and in that the view type interacts with various operators in different ways to lists. One universally correct transformation to preserve Python2 behaviour in Python3 would be to replace all instances of d.keys() with list(six.iterkeys(d)), and indeed we did. However, like many automatic transformations the results are usually unsightly, invariably inefficient, and frequently absurd. Not least because list(d.keys()) and indeed list(d) are also equivalent. This patch changes to using the simplest correct method of accessing the data we want in each case. This reverts or rewrites most of commit 4ace95ad47da7099191a06325c5d0b156fd54894. Change-Id: Iba3cf48246d8cbc958d8fb577cd700a218b0bebf --- .../rackspace/resources/cloud_loadbalancer.py | 9 +++-- .../tests/test_cloud_loadbalancer.py | 22 ++++++------- doc/source/ext/resources.py | 4 +-- heat/api/cloudwatch/watch.py | 6 ++-- heat/engine/api.py | 6 ++-- heat/engine/cfn/functions.py | 2 +- heat/engine/cfn/template.py | 3 +- heat/engine/clients/os/nova.py | 3 +- heat/engine/environment.py | 6 ++-- heat/engine/parameters.py | 6 ++-- .../openstack/heat/software_deployment.py | 3 +- .../resources/openstack/mistral/workflow.py | 2 +- .../openstack/neutron/loadbalancer.py | 4 +-- .../resources/openstack/neutron/neutron.py | 14 ++++---- .../resources/openstack/senlin/cluster.py | 12 +++---- heat/engine/stack.py | 3 +- heat/engine/template.py | 7 ++-- .../api/cloudwatch/test_api_cloudwatch.py | 3 +- heat/tests/aws/test_user.py | 3 +- heat/tests/openstack/nova/fakes.py | 33 +++++++++---------- heat/tests/openstack/nova/test_server.py | 2 +- heat/tests/test_engine_api_utils.py | 10 +++--- heat/tests/test_hot.py | 6 ++-- heat/tests/test_signal.py | 2 +- heat/tests/test_template.py | 7 ++-- heat/tests/test_template_format.py | 2 +- 26 files changed, 83 insertions(+), 97 deletions(-) diff --git a/contrib/rackspace/rackspace/resources/cloud_loadbalancer.py b/contrib/rackspace/rackspace/resources/cloud_loadbalancer.py index b356428884..a73474eafd 100644 --- a/contrib/rackspace/rackspace/resources/cloud_loadbalancer.py +++ b/contrib/rackspace/rackspace/resources/cloud_loadbalancer.py @@ -801,7 +801,7 @@ class CloudLoadBalancer(resource.Resource): old_props = {} new_props = {} - for prop in six.iterkeys(prop_diff): + for prop in prop_diff: if prop in self.LB_UPDATE_PROPS: old_props[prop] = getattr(lb, prop) new_props[prop] = prop_diff[prop] @@ -831,8 +831,8 @@ class CloudLoadBalancer(resource.Resource): node[self.NODE_PORT]), node) for node in diff_nodes) - old_set = set(six.iterkeys(old)) - new_set = set(six.iterkeys(new)) + old_set = set(old) + new_set = set(new) deleted = old_set.difference(new_set) added = new_set.difference(old_set) @@ -900,8 +900,7 @@ class CloudLoadBalancer(resource.Resource): for node in updated: node_changed = False - for attribute in six.iterkeys(new[node]): - new_value = new[node][attribute] + for attribute, new_value in new[node].items(): if new_value and new_value != getattr(old[node], attribute): node_changed = True setattr(old[node], attribute, new_value) diff --git a/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py b/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py index ee5cbff4c1..0837535033 100644 --- a/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py +++ b/contrib/rackspace/rackspace/tests/test_cloud_loadbalancer.py @@ -1379,7 +1379,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_health_monitor_delete(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) hm = {'type': "HTTP", 'delay': 10, 'timeout': 10, 'attemptsBeforeDeactivation': 4, 'path': "/", 'statusRegex': "^[234][0-9][0-9]$", 'bodyRegex': ".* testing .*", @@ -1433,7 +1433,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_session_persistence_delete(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties'][ 'sessionPersistence'] = "SOURCE_IP" expected_body = copy.deepcopy(self.expected_body) @@ -1493,7 +1493,7 @@ class LoadBalancerTest(common.HeatTestCase): 'securePort': 443, 'privatekey': private_key, 'certificate': cert, 'intermediateCertificate': '', 'secureTrafficOnly': False} ssl_termination_api = copy.deepcopy(ssl_termination_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties']['sslTermination'] = ( ssl_termination_template) # The SSL termination config is done post-creation, so no need @@ -1563,7 +1563,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_metadata_delete(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties']['metadata'] = { 'a': 1, 'b': 2} expected_body = copy.deepcopy(self.expected_body) @@ -1622,7 +1622,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_errorpage_delete(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) error_page = ( 'Service Unavailable

' 'Service Unavailable

The service is unavailable') @@ -1685,7 +1685,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_connection_logging_delete(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties'][ 'connectionLogging'] = True expected_body = copy.deepcopy(self.expected_body) @@ -1718,7 +1718,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_connection_logging_disable(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties'][ 'connectionLogging'] = True expected_body = copy.deepcopy(self.expected_body) @@ -1773,7 +1773,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_connection_throttle_delete(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties'][ 'connectionThrottle'] = {'maxConnections': 1000} expected_body = copy.deepcopy(self.expected_body) @@ -1833,7 +1833,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_content_caching_deleted(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties'][ 'contentCaching'] = 'ENABLED' # Enabling the content cache is done post-creation, so no need @@ -1864,7 +1864,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_content_caching_disable(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) template['Resources'][lb_name]['Properties'][ 'contentCaching'] = 'ENABLED' # Enabling the content cache is done post-creation, so no need @@ -2168,7 +2168,7 @@ class LoadBalancerTest(common.HeatTestCase): def test_update_nodes_defaults(self): template = copy.deepcopy(self.lb_template) - lb_name = list(six.iterkeys(template['Resources']))[0] + lb_name = next(iter(template['Resources'])) tmpl_node = template['Resources'][lb_name]['Properties']['nodes'][0] tmpl_node['type'] = "PRIMARY" tmpl_node['condition'] = "ENABLED" diff --git a/doc/source/ext/resources.py b/doc/source/ext/resources.py index ca4b0e3605..f4a057d272 100644 --- a/doc/source/ext/resources.py +++ b/doc/source/ext/resources.py @@ -163,7 +163,7 @@ class ResourcePages(compat.Directive): def contribute_hot_syntax(self, parent): section = self._section(parent, _('HOT Syntax'), '%s-hot') props = [] - for prop_key in sorted(six.iterkeys(self.props_schemata)): + for prop_key in sorted(self.props_schemata.keys()): prop = self.props_schemata[prop_key] if (prop.implemented and prop.support_status.status == support.SUPPORTED): @@ -363,7 +363,7 @@ def _filter_resources(prefix=None, path=None, statuses=None): statuses = statuses or [] filtered_resources = {} - for name in sorted(six.iterkeys(all_resources)): + for name in sorted(all_resources.keys()): if prefix_match(name): for cls in all_resources.get(name): if (path_match(cls) and status_match(cls) and diff --git a/heat/api/cloudwatch/watch.py b/heat/api/cloudwatch/watch.py index aa3d073d9c..7ca6488d57 100644 --- a/heat/api/cloudwatch/watch.py +++ b/heat/api/cloudwatch/watch.py @@ -66,8 +66,8 @@ class WatchController(object): """ newdims = [] for count, d in enumerate(dims, 1): - for key in six.iterkeys(d): - newdims.append({'Name': key, 'Value': d[key]}) + for key, value in d.items(): + newdims.append({'Name': key, 'Value': value}) return newdims def delete_alarms(self, req): @@ -302,7 +302,7 @@ class WatchController(object): msg = _('Invalid state %(state)s, ' 'expecting one of %(expect)s') % { 'state': state, - 'expect': list(six.iterkeys(state_map))} + 'expect': list(state_map.keys())} LOG.error(msg) return exception.HeatInvalidParameterValueError(msg) diff --git a/heat/engine/api.py b/heat/engine/api.py index 42f2d913ba..5972bc788f 100644 --- a/heat/engine/api.py +++ b/heat/engine/api.py @@ -290,7 +290,7 @@ def format_resource_attributes(resource, with_attr=None): # including the ones are not represented in response of show API, such as # 'console_urls' for nova server, user can view it by taking with_attr # parameter - if 'show' in six.iterkeys(resolver): + if 'show' in resolver: show_attr = resolve('show', resolver) # check if 'show' resolved to dictionary. so it's not None if isinstance(show_attr, collections.Mapping): @@ -302,7 +302,7 @@ def format_resource_attributes(resource, with_attr=None): # remove 'show' attribute if it's None or not a mapping # then resolve all attributes manually del resolver._attributes['show'] - attributes = set(list(six.iterkeys(resolver)) + with_attr) + attributes = set(resolver) | set(with_attr) return dict((attr, resolve(attr, resolver)) for attr in attributes) @@ -315,7 +315,7 @@ def format_resource_properties(resource): return None return dict((prop, get_property(prop)) - for prop in six.iterkeys(resource.properties_schema)) + for prop in resource.properties_schema.keys()) def format_stack_resource(resource, detail=True, with_props=False, diff --git a/heat/engine/cfn/functions.py b/heat/engine/cfn/functions.py index f1f02299ab..35627f1662 100644 --- a/heat/engine/cfn/functions.py +++ b/heat/engine/cfn/functions.py @@ -221,7 +221,7 @@ class GetAtt(function.Function): attr = function.resolve(self._attribute) from heat.engine import resource if (type(res).get_attribute == resource.Resource.get_attribute and - attr not in six.iterkeys(res.attributes_schema)): + attr not in res.attributes_schema): raise exception.InvalidTemplateAttribute( resource=self._resource_name, key=attr) diff --git a/heat/engine/cfn/template.py b/heat/engine/cfn/template.py index e579532915..5526316b02 100644 --- a/heat/engine/cfn/template.py +++ b/heat/engine/cfn/template.py @@ -155,8 +155,7 @@ class CfnTemplate(template.Template): deletion_policy = function.resolve(data.get(RES_DELETION_POLICY)) if deletion_policy is not None: - if deletion_policy not in six.iterkeys( - self.deletion_policies): + if deletion_policy not in self.deletion_policies: msg = _('Invalid deletion policy "%s"') % deletion_policy raise exception.StackValidationFailed(message=msg) else: diff --git a/heat/engine/clients/os/nova.py b/heat/engine/clients/os/nova.py index 4d63335a40..d3b7c4170a 100644 --- a/heat/engine/clients/os/nova.py +++ b/heat/engine/clients/os/nova.py @@ -535,8 +535,7 @@ echo -e '%s\tALL=(ALL)\tNOPASSWD: ALL' >> /etc/sudoers """Delete/Add the metadata in nova as needed.""" metadata = self.meta_serialize(metadata) current_md = server.metadata - to_del = sorted([key for key in six.iterkeys(current_md) - if key not in metadata]) + to_del = sorted(set(current_md) - set(metadata)) client = self.client() if len(to_del) > 0: client.servers.delete_meta(server, to_del) diff --git a/heat/engine/environment.py b/heat/engine/environment.py index b406848b5f..7a29290d8b 100644 --- a/heat/engine/environment.py +++ b/heat/engine/environment.py @@ -306,8 +306,8 @@ class ResourceRegistry(object): if info is None: if name.endswith('*'): # delete all matching entries. - for res_name in list(six.iterkeys(registry)): - if (isinstance(registry[res_name], ResourceInfo) and + for res_name, reg_info in list(registry.items()): + if (isinstance(reg_info, ResourceInfo) and res_name.startswith(name[:-1])): LOG.warning(_LW('Removing %(item)s from %(path)s'), { 'item': res_name, @@ -469,7 +469,7 @@ class ResourceRegistry(object): # handle: "OS::*" -> "Dreamhost::*" def is_a_glob(resource_type): return resource_type.endswith('*') - globs = six.moves.filter(is_a_glob, six.iterkeys(self._registry)) + globs = six.moves.filter(is_a_glob, iter(self._registry)) for pattern in globs: if self._registry[pattern].matches(resource_type): yield self._registry[pattern] diff --git a/heat/engine/parameters.py b/heat/engine/parameters.py index 11fde01cba..33bcc2f1e0 100644 --- a/heat/engine/parameters.py +++ b/heat/engine/parameters.py @@ -501,9 +501,9 @@ class Parameters(collections.Mapping): self.non_pseudo_param_keys = [p for p in self.params if p not in self.PSEUDO_PARAMETERS] - for pd in six.iterkeys(param_defaults): - if pd in self.params: - self.params[pd].set_default(param_defaults[pd]) + for pd_name, param_default in param_defaults.items(): + if pd_name in self.params: + self.params[pd_name].set_default(param_default) def validate(self, validate_value=True, context=None): """Validates all parameters. diff --git a/heat/engine/resources/openstack/heat/software_deployment.py b/heat/engine/resources/openstack/heat/software_deployment.py index 2984471d6c..695563b14a 100644 --- a/heat/engine/resources/openstack/heat/software_deployment.py +++ b/heat/engine/resources/openstack/heat/software_deployment.py @@ -12,7 +12,6 @@ # under the License. import copy -import six import uuid from oslo_config import cfg @@ -636,7 +635,7 @@ class SoftwareDeploymentGroup(resource_group.ResourceGroup): return len(self.properties.get(self.SERVERS, {})) def _resource_names(self): - return six.iterkeys(self.properties.get(self.SERVERS, {})) + return iter(self.properties.get(self.SERVERS, {})) def get_resource_def(self, include_all=False): return dict(self.properties) diff --git a/heat/engine/resources/openstack/mistral/workflow.py b/heat/engine/resources/openstack/mistral/workflow.py index 8c22699c43..1c43be333b 100644 --- a/heat/engine/resources/openstack/mistral/workflow.py +++ b/heat/engine/resources/openstack/mistral/workflow.py @@ -380,7 +380,7 @@ class Workflow(signal_responder.SignalResponder, raise exception.StackValidationFailed( error=_('Signal data error'), message=message) - for key in six.iterkeys(inputs): + for key in inputs: if (self.properties.get(self.INPUT) is None or key not in self.properties.get(self.INPUT)): message = _('Unknown input %s') % key diff --git a/heat/engine/resources/openstack/neutron/loadbalancer.py b/heat/engine/resources/openstack/neutron/loadbalancer.py index 72cfb00bee..46b8e299fe 100644 --- a/heat/engine/resources/openstack/neutron/loadbalancer.py +++ b/heat/engine/resources/openstack/neutron/loadbalancer.py @@ -11,8 +11,6 @@ # 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 @@ -780,7 +778,7 @@ class LoadBalancer(resource.Resource): new_props[self.MEMBERS] is not None)): members = set(new_props[self.MEMBERS] or []) rd_members = self.data() - old_members = set(six.iterkeys(rd_members)) + old_members = set(rd_members) for member in old_members - members: member_id = rd_members[member] with self.client_plugin().ignore_not_found: diff --git a/heat/engine/resources/openstack/neutron/neutron.py b/heat/engine/resources/openstack/neutron/neutron.py index 740cafaad3..0ff8d7cc98 100644 --- a/heat/engine/resources/openstack/neutron/neutron.py +++ b/heat/engine/resources/openstack/neutron/neutron.py @@ -10,7 +10,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import six from heat.common import exception from heat.common.i18n import _ @@ -38,12 +37,11 @@ class NeutronResource(resource.Resource): Also ensures that shared and tenant_id is not specified in value_specs. """ - if 'value_specs' in six.iterkeys(properties): - vs = properties.get('value_specs') - banned_keys = set(['shared', 'tenant_id']).union( - six.iterkeys(properties)) - for k in banned_keys.intersection(six.iterkeys(vs)): - return '%s not allowed in value_specs' % k + if 'value_specs' in properties: + banned_keys = set(['shared', 'tenant_id']).union(set(properties)) + found = banned_keys.intersection(set(properties['value_specs'])) + if found: + return '%s not allowed in value_specs' % ', '.join(found) @staticmethod def prepare_properties(properties, name): @@ -58,7 +56,7 @@ class NeutronResource(resource.Resource): props = dict((k, v) for k, v in properties.items() if v is not None) - if 'name' in six.iterkeys(properties): + if 'name' in properties: props.setdefault('name', name) if 'value_specs' in props: diff --git a/heat/engine/resources/openstack/senlin/cluster.py b/heat/engine/resources/openstack/senlin/cluster.py index 2c00aa58cf..224dcae37a 100644 --- a/heat/engine/resources/openstack/senlin/cluster.py +++ b/heat/engine/resources/openstack/senlin/cluster.py @@ -233,13 +233,13 @@ class Cluster(resource.Resource): if not updaters: return True - for k in six.iterkeys(updaters): - if not updaters[k]['start']: - action_id = start_action(k, updaters[k]['params']) - updaters[k]['action'] = action_id - updaters[k]['start'] = True + for k, updater in list(updaters.items()): + if not updater['start']: + action_id = start_action(k, updater['params']) + updater['action'] = action_id + updater['start'] = True else: - action = self.client().get_action(updaters[k]['action']) + action = self.client().get_action(updater['action']) if action.status == self.ACTION_SUCCEEDED: del updaters[k] elif action.status == self.ACTION_FAILED: diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 956bf2979f..28f146e46e 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -748,8 +748,7 @@ class Stack(collections.Mapping): self.t.validate_resource_definitions(self) # Check duplicate names between parameters and resources - dup_names = (set(six.iterkeys(self.parameters)) & - set(six.iterkeys(self))) + dup_names = set(self.parameters) & set(self.keys()) if dup_names: LOG.debug("Duplicate names %s" % dup_names) diff --git a/heat/engine/template.py b/heat/engine/template.py index 39bd2b660b..fb941ce13f 100644 --- a/heat/engine/template.py +++ b/heat/engine/template.py @@ -66,7 +66,7 @@ class TemplatePluginNotRegistered(exception.HeatException): def get_template_class(template_data): - available_versions = list(six.iterkeys(_template_classes)) + available_versions = _template_classes.keys() version = get_version(template_data, available_versions) version_type = version[0] try: @@ -114,8 +114,7 @@ class Template(collections.Mapping): self.maps = self[self.MAPPINGS] self.env = env or environment.Environment({}) - self.version = get_version(self.t, - list(six.iterkeys(_template_classes))) + self.version = get_version(self.t, _template_classes.keys()) self.t_digest = None def __deepcopy__(self, memo): @@ -257,7 +256,7 @@ class Template(collections.Mapping): return # check top-level sections - for k in six.iterkeys(self.t): + for k in self.t.keys(): if k not in self.SECTIONS: raise exception.InvalidTemplateSection(section=k) diff --git a/heat/tests/api/cloudwatch/test_api_cloudwatch.py b/heat/tests/api/cloudwatch/test_api_cloudwatch.py index 568d270453..edebd1bf7d 100644 --- a/heat/tests/api/cloudwatch/test_api_cloudwatch.py +++ b/heat/tests/api/cloudwatch/test_api_cloudwatch.py @@ -12,7 +12,6 @@ # under the License. import os -import six from oslo_config import fixture as config_fixture @@ -500,7 +499,7 @@ class WatchControllerTest(common.HeatTestCase): 'ALARM': rpc_api.WATCH_STATE_ALARM, 'INSUFFICIENT_DATA': rpc_api.WATCH_STATE_NODATA} - for state in six.iterkeys(state_map): + for state in state_map: params = {u'StateValue': state, u'StateReason': u'', u'AlarmName': u'HttpFailureAlarm', diff --git a/heat/tests/aws/test_user.py b/heat/tests/aws/test_user.py index 78d75ffe19..6e126c28bd 100644 --- a/heat/tests/aws/test_user.py +++ b/heat/tests/aws/test_user.py @@ -13,7 +13,6 @@ import mock from oslo_config import cfg -import six from heat.common import exception from heat.common import short_id @@ -346,7 +345,7 @@ class AccessKeyTest(common.HeatTestCase): rs_data = resource_data_object.ResourceData.get_all(rsrc) self.assertEqual(self.fc.secret, rs_data.get('secret_key')) self.assertEqual(self.fc.credential_id, rs_data.get('credential_id')) - self.assertEqual(2, len(list(six.iterkeys(rs_data)))) + self.assertEqual(2, len(rs_data.keys())) self.assertEqual(utils.PhysName(stack.name, 'CfnUser'), rsrc.FnGetAtt('UserName')) diff --git a/heat/tests/openstack/nova/fakes.py b/heat/tests/openstack/nova/fakes.py index 8192654634..1a871c24a1 100644 --- a/heat/tests/openstack/nova/fakes.py +++ b/heat/tests/openstack/nova/fakes.py @@ -18,7 +18,6 @@ import mock from novaclient import client as base_client from novaclient import exceptions as nova_exceptions import requests -import six from six.moves.urllib import parse as urlparse from heat.tests import fakes @@ -245,19 +244,19 @@ class FakeHTTPClient(base_client.HTTPClient): def post_servers_1234_action(self, body, **kw): _body = None resp = 202 - assert len(list(six.iterkeys(body))) == 1 - action = list(six.iterkeys(body))[0] + assert len(body.keys()) == 1 + action = next(iter(body)) if action == 'reboot': - assert list(six.iterkeys(body[action])) == ['type'] + assert list(body[action].keys()) == ['type'] assert body[action]['type'] in ['HARD', 'SOFT'] elif action == 'rebuild': - keys = list(six.iterkeys(body[action])) + keys = list(body[action].keys()) if 'adminPass' in keys: keys.remove('adminPass') assert keys == ['imageRef'] _body = self.get_servers_1234()[1] elif action == 'resize': - assert list(six.iterkeys(body[action])) == ['flavorRef'] + assert list(body[action].keys()) == ['flavorRef'] elif action == 'confirmResize': assert body[action] is None # This one method returns a different response code @@ -270,27 +269,27 @@ class FakeHTTPClient(base_client.HTTPClient): ]: assert body[action] is None elif action == 'addFixedIp': - assert list(six.iterkeys(body[action])) == ['networkId'] + assert list(body[action].keys()) == ['networkId'] elif action in ['removeFixedIp', 'addFloatingIp', 'removeFloatingIp', ]: - assert list(six.iterkeys(body[action])) == ['address'] + assert list(body[action].keys()) == ['address'] elif action == 'createImage': - assert set(six.iterkeys(body[action])) == set(['name', 'metadata']) + assert set(body[action].keys()) == set(['name', 'metadata']) resp = {"status": 202, "location": "http://blah/images/456"} elif action == 'changePassword': - assert list(six.iterkeys(body[action])) == ['adminPass'] + assert list(body[action].keys()) == ['adminPass'] elif action == 'os-getConsoleOutput': - assert list(six.iterkeys(body[action])) == ['length'] + assert list(body[action].keys()) == ['length'] return (202, {'output': 'foo'}) elif action == 'os-getVNCConsole': - assert list(six.iterkeys(body[action])) == ['type'] + assert list(body[action].keys()) == ['type'] elif action == 'os-migrateLive': - assert set(six.iterkeys(body[action])) == set(['host', - 'block_migration', - 'disk_over_commit']) + assert set(body[action].keys()) == set(['host', + 'block_migration', + 'disk_over_commit']) else: raise AssertionError("Unexpected server action: %s" % action) return (resp, _body) @@ -298,8 +297,8 @@ class FakeHTTPClient(base_client.HTTPClient): def post_servers_5678_action(self, body, **kw): _body = None resp = 202 - assert len(list(six.iterkeys(body))) == 1 - action = list(six.iterkeys(body))[0] + assert len(body.keys()) == 1 + action = next(iter(body)) if action in ['addFloatingIp', 'removeFloatingIp', ]: diff --git a/heat/tests/openstack/nova/test_server.py b/heat/tests/openstack/nova/test_server.py index 02c4b6128f..d085382179 100644 --- a/heat/tests/openstack/nova/test_server.py +++ b/heat/tests/openstack/nova/test_server.py @@ -2863,7 +2863,7 @@ class ServersTest(common.HeatTestCase): supported_consoles = ('novnc', 'xvpvnc', 'spice-html5', 'rdp-html5', 'serial') self.assertEqual(set(supported_consoles), - set(six.iterkeys(console_urls))) + set(console_urls)) def test_resolve_attribute_networks(self): return_server = self.fc.servers.list()[1] diff --git a/heat/tests/test_engine_api_utils.py b/heat/tests/test_engine_api_utils.py index 22ac06aaa2..fbad8b78de 100644 --- a/heat/tests/test_engine_api_utils.py +++ b/heat/tests/test_engine_api_utils.py @@ -88,10 +88,10 @@ class FormatTest(common.HeatTestCase): ))) formatted = api.format_stack_resource(res, True) - self.assertEqual(resource_details_keys, set(six.iterkeys(formatted))) + self.assertEqual(resource_details_keys, set(formatted.keys())) formatted = api.format_stack_resource(res, False) - self.assertEqual(resource_keys, set(six.iterkeys(formatted))) + self.assertEqual(resource_keys, set(formatted.keys())) self.assertEqual(self.stack.created_time.isoformat(), formatted[rpc_api.RES_CREATION_TIME]) self.assertEqual(self.stack.updated_time.isoformat(), @@ -232,7 +232,7 @@ class FormatTest(common.HeatTestCase): rpc_api.RES_REQUIRED_BY)) formatted = api.format_stack_resource(res, False) - self.assertEqual(resource_keys, set(six.iterkeys(formatted))) + self.assertEqual(resource_keys, set(formatted.keys())) def test_format_stack_resource_with_nested_stack_not_found(self): res = self.stack['generic4'] @@ -255,7 +255,7 @@ class FormatTest(common.HeatTestCase): formatted = api.format_stack_resource(res, False) # 'nested_stack_id' is not in formatted - self.assertEqual(resource_keys, set(six.iterkeys(formatted))) + self.assertEqual(resource_keys, set(formatted.keys())) def test_format_stack_resource_with_nested_stack_empty(self): res = self.stack['generic4'] @@ -300,7 +300,7 @@ class FormatTest(common.HeatTestCase): rpc_api.EVENT_RES_PROPERTIES)) formatted = api.format_event(event) - self.assertEqual(event_keys, set(six.iterkeys(formatted))) + self.assertEqual(event_keys, set(formatted.keys())) event_id_formatted = formatted[rpc_api.EVENT_ID] event_identifier = identifier.EventIdentifier( diff --git a/heat/tests/test_hot.py b/heat/tests/test_hot.py index 351087c7cb..9079d40826 100644 --- a/heat/tests/test_hot.py +++ b/heat/tests/test_hot.py @@ -1158,7 +1158,7 @@ class HOTemplateTest(common.HeatTestCase): {'foo': {'Type': 'String', 'Required': True}}}) self.assertEqual(expected_description, tmpl['description']) - self.assertNotIn('parameters', six.iterkeys(tmpl)) + self.assertNotIn('parameters', tmpl.keys()) def test_invalid_hot_version(self): """Test HOT version check. @@ -1241,7 +1241,7 @@ class HOTemplateTest(common.HeatTestCase): self.resolve, snippet, stack.t, stack) - self.assertIn(list(six.iterkeys(snippet))[0], six.text_type(error)) + self.assertIn(next(iter(snippet)), six.text_type(error)) def test_resource_facade_missing_deletion_policy(self): snippet = {'resource_facade': 'deletion_policy'} @@ -1266,7 +1266,7 @@ class HOTemplateTest(common.HeatTestCase): error = self.assertRaises(exception.InvalidTemplateVersion, function.validate, stack.t.parse(stack, snippet)) - self.assertIn(next(six.iterkeys(snippet)), six.text_type(error)) + self.assertIn(next(iter(snippet)), six.text_type(error)) def test_add_resource(self): hot_tpl = template_format.parse(''' diff --git a/heat/tests/test_signal.py b/heat/tests/test_signal.py index 0ce01a515f..de49db5798 100644 --- a/heat/tests/test_signal.py +++ b/heat/tests/test_signal.py @@ -121,7 +121,7 @@ class SignalTest(common.HeatTestCase): self.assertEqual('verysecret', rs_data.get('secret_key')) self.assertEqual('1234', rs_data.get('user_id')) self.assertEqual(rsrc.resource_id, rs_data.get('user_id')) - self.assertEqual(4, len(list(six.iterkeys(rs_data)))) + self.assertEqual(4, len(rs_data)) def test_get_user_id(self): # Setup diff --git a/heat/tests/test_template.py b/heat/tests/test_template.py index 09f2bf06e3..a47ed41e1f 100644 --- a/heat/tests/test_template.py +++ b/heat/tests/test_template.py @@ -897,7 +897,7 @@ class TemplateTest(common.HeatTestCase): template.Template(empty_template)) error = self.assertRaises(ValueError, self.resolve, snippet, stk.t, stk) - self.assertIn(list(six.iterkeys(snippet))[0], six.text_type(error)) + self.assertIn(next(iter(snippet)), six.text_type(error)) def test_resource_facade_missing_deletion_policy(self): snippet = {'Fn::ResourceFacade': 'DeletionPolicy'} @@ -937,7 +937,7 @@ class TemplateTest(common.HeatTestCase): } }) self.assertEqual(expected_description, tmpl['Description']) - self.assertNotIn('Parameters', six.iterkeys(tmpl)) + self.assertNotIn('Parameters', tmpl.keys()) def test_add_resource(self): cfn_tpl = template_format.parse(''' @@ -1158,8 +1158,7 @@ class TemplateFnErrorTest(common.HeatTestCase): error = self.assertRaises(self.expect, resolve, self.snippet) - self.assertIn(list(six.iterkeys(self.snippet))[0], - six.text_type(error)) + self.assertIn(next(iter(self.snippet)), six.text_type(error)) class ResolveDataTest(common.HeatTestCase): diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index 2838dbb6f0..d3b8afe037 100644 --- a/heat/tests/test_template_format.py +++ b/heat/tests/test_template_format.py @@ -202,7 +202,7 @@ class JsonYamlResolvedCompareTest(common.HeatTestCase): del(t2nr['Resources']) self.assertEqual(t1nr, t2nr) - self.assertEqual(set(six.iterkeys(stack1)), set(six.iterkeys(stack2))) + self.assertEqual(set(stack1), set(stack2)) for key in stack1: self.assertEqual(stack1[key].t, stack2[key].t)