Merge "python3: Refactor dict for python2/python3 compat"

This commit is contained in:
Jenkins 2013-10-13 05:53:35 +00:00 committed by Gerrit Code Review
commit 0c2839414f
14 changed files with 43 additions and 44 deletions

View File

@ -270,7 +270,7 @@ class Resource(object):
return self.__dict__[k]
def __repr__(self):
reprkeys = sorted(k for k in list(self.__dict__.keys()) if k[0] != '_'
reprkeys = sorted(k for k in self.__dict__ if k[0] != '_'
and k != 'manager')
info = ", ".join("%s=%s" % (k, getattr(self, k)) for k in reprkeys)
return "<%s %s>" % (self.__class__.__name__, info)

View File

@ -402,7 +402,7 @@ def get_client_class(version):
client_path = version_map[str(version)]
except (KeyError, ValueError):
msg = "Invalid client version '%s'. must be one of: %s" % (
(version, ', '.join(list(version_map.keys()))))
(version, ', '.join(version_map)))
raise exceptions.UnsupportedVersion(msg)
return utils.import_class(client_path)

View File

@ -166,7 +166,7 @@ def from_response(response, body):
message = "n/a"
details = "n/a"
if hasattr(body, 'keys'):
error = body[list(body.keys())[0]]
error = body[list(body)[0]]
message = error.get('message', None)
details = error.get('details', None)
return cls(code=response.status_code, message=message, details=details,

View File

@ -476,7 +476,7 @@ class OpenStackCinderShell(object):
options = set()
for sc_str, sc in list(self.subcommands.items()):
commands.add(sc_str)
for option in list(sc._optionals._option_string_actions.keys()):
for option in sc._optionals._option_string_actions:
options.add(option)
commands.remove('bash-completion')

View File

@ -23,12 +23,11 @@ from __future__ import print_function
def assert_has_keys(dict, required=[], optional=[]):
keys = list(dict.keys())
for k in required:
try:
assert k in keys
assert k in dict
except AssertionError:
extra_keys = set(keys).difference(set(required + optional))
extra_keys = set(dict).difference(set(required + optional))
raise AssertionError("found unexpected keys: %s" %
list(extra_keys))

View File

@ -268,8 +268,8 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_snapshots_1234_action(self, body, **kw):
_body = None
resp = 202
assert len(body.keys()) == 1
action = body.keys()[0]
assert len(list(body)) == 1
action = list(body)[0]
if action == 'os-reset_status':
assert 'status' in body['os-reset_status']
elif action == 'os-update_snapshot_status':
@ -313,10 +313,10 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_volumes_1234_action(self, body, **kw):
_body = None
resp = 202
assert len(list(body.keys())) == 1
action = list(body.keys())[0]
assert len(list(body)) == 1
action = list(body)[0]
if action == 'os-attach':
assert list(body[action].keys()) == ['instance_uuid', 'mountpoint']
assert list(body[action]) == ['instance_uuid', 'mountpoint']
elif action == 'os-detach':
assert body[action] is None
elif action == 'os-reserve':
@ -324,10 +324,10 @@ class FakeHTTPClient(base_client.HTTPClient):
elif action == 'os-unreserve':
assert body[action] is None
elif action == 'os-initialize_connection':
assert list(body[action].keys()) == ['connector']
assert list(body[action]) == ['connector']
return (202, {}, {'connection_info': 'foos'})
elif action == 'os-terminate_connection':
assert list(body[action].keys()) == ['connector']
assert list(body[action]) == ['connector']
elif action == 'os-begin_detaching':
assert body[action] is None
elif action == 'os-roll_detaching':
@ -335,7 +335,7 @@ class FakeHTTPClient(base_client.HTTPClient):
elif action == 'os-reset_status':
assert 'status' in body[action]
elif action == 'os-extend':
assert body[action].keys() == ['new_size']
assert list(body[action]) == ['new_size']
elif action == 'os-migrate_volume':
assert 'host' in body[action]
assert 'force_host_copy' in body[action]
@ -370,7 +370,7 @@ class FakeHTTPClient(base_client.HTTPClient):
'gigabytes': 1}})
def put_os_quota_sets_test(self, body, **kw):
assert list(body.keys()) == ['quota_set']
assert list(body) == ['quota_set']
fakes.assert_has_keys(body['quota_set'],
required=['tenant_id'])
return (200, {}, {'quota_set': {
@ -393,7 +393,7 @@ class FakeHTTPClient(base_client.HTTPClient):
'gigabytes': 1}})
def put_os_quota_class_sets_test(self, body, **kw):
assert list(body.keys()) == ['quota_class_set']
assert list(body) == ['quota_class_set']
fakes.assert_has_keys(body['quota_class_set'],
required=['class_name'])
return (200, {}, {'quota_class_set': {
@ -431,7 +431,7 @@ class FakeHTTPClient(base_client.HTTPClient):
'extra_specs': {}}})
def post_types_1_extra_specs(self, body, **kw):
assert list(body.keys()) == ['extra_specs']
assert list(body) == ['extra_specs']
return (200, {}, {'extra_specs': {'k': 'v'}})
def delete_types_1_extra_specs_k(self, **kw):

View File

@ -275,8 +275,8 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_snapshots_1234_action(self, body, **kw):
_body = None
resp = 202
assert len(body.keys()) == 1
action = body.keys()[0]
assert len(list(body)) == 1
action = list(body)[0]
if action == 'os-reset_status':
assert 'status' in body['os-reset_status']
elif action == 'os-update_snapshot_status':
@ -320,10 +320,10 @@ class FakeHTTPClient(base_client.HTTPClient):
def post_volumes_1234_action(self, body, **kw):
_body = None
resp = 202
assert len(list(body.keys())) == 1
action = list(body.keys())[0]
assert len(list(body)) == 1
action = list(body)[0]
if action == 'os-attach':
assert list(body[action].keys()) == ['instance_uuid', 'mountpoint']
assert list(body[action]) == ['instance_uuid', 'mountpoint']
elif action == 'os-detach':
assert body[action] is None
elif action == 'os-reserve':
@ -331,10 +331,10 @@ class FakeHTTPClient(base_client.HTTPClient):
elif action == 'os-unreserve':
assert body[action] is None
elif action == 'os-initialize_connection':
assert list(body[action].keys()) == ['connector']
assert list(body[action]) == ['connector']
return (202, {}, {'connection_info': 'foos'})
elif action == 'os-terminate_connection':
assert list(body[action].keys()) == ['connector']
assert list(body[action]) == ['connector']
elif action == 'os-begin_detaching':
assert body[action] is None
elif action == 'os-roll_detaching':
@ -342,7 +342,7 @@ class FakeHTTPClient(base_client.HTTPClient):
elif action == 'os-reset_status':
assert 'status' in body[action]
elif action == 'os-extend':
assert body[action].keys() == ['new_size']
assert list(body[action]) == ['new_size']
elif action == 'os-migrate_volume':
assert 'host' in body[action]
assert 'force_host_copy' in body[action]
@ -377,7 +377,7 @@ class FakeHTTPClient(base_client.HTTPClient):
'gigabytes': 1}})
def put_os_quota_sets_test(self, body, **kw):
assert list(body.keys()) == ['quota_set']
assert list(body) == ['quota_set']
fakes.assert_has_keys(body['quota_set'],
required=['tenant_id'])
return (200, {}, {'quota_set': {
@ -400,7 +400,7 @@ class FakeHTTPClient(base_client.HTTPClient):
'gigabytes': 1}})
def put_os_quota_class_sets_test(self, body, **kw):
assert list(body.keys()) == ['quota_class_set']
assert list(body) == ['quota_class_set']
fakes.assert_has_keys(body['quota_class_set'],
required=['class_name'])
return (200, {}, {'quota_class_set': {
@ -438,7 +438,7 @@ class FakeHTTPClient(base_client.HTTPClient):
'extra_specs': {}}})
def post_types_1_extra_specs(self, body, **kw):
assert list(body.keys()) == ['extra_specs']
assert list(body) == ['extra_specs']
return (200, {}, {'extra_specs': {'k': 'v'}})
def delete_types_1_extra_specs_k(self, **kw):

View File

@ -39,7 +39,7 @@ class QuotaClassSetManager(base.Manager):
def update(self, class_name, **updates):
body = {'quota_class_set': {'class_name': class_name}}
for update in updates.keys():
for update in updates:
body['quota_class_set'][update] = updates[update]
self._update('/os-quota-class-sets/%s' % (class_name), body)

View File

@ -40,7 +40,7 @@ class QuotaSetManager(base.Manager):
def update(self, tenant_id, **updates):
body = {'quota_set': {'tenant_id': tenant_id}}
for update in updates.keys():
for update in updates:
body['quota_set'][update] = updates[update]
self._update('/os-quota-sets/%s' % (tenant_id), body)

View File

@ -95,7 +95,7 @@ def _print_volume_image(image):
def _translate_keys(collection, convert):
for item in collection:
keys = list(item.__dict__.keys())
keys = item.__dict__
for from_key, to_key in convert:
if from_key in keys and to_key not in keys:
setattr(item, to_key, item._info[from_key])
@ -352,7 +352,7 @@ def do_metadata(cs, args):
if args.action == 'set':
cs.volumes.set_metadata(volume, metadata)
elif args.action == 'unset':
cs.volumes.delete_metadata(volume, list(metadata.keys()))
cs.volumes.delete_metadata(volume, list(metadata))
@utils.arg(
@ -560,7 +560,7 @@ def do_type_key(cs, args):
if args.action == 'set':
vtype.set_keys(keypair)
elif args.action == 'unset':
vtype.unset_keys(list(keypair.keys()))
vtype.unset_keys(list(keypair))
def do_endpoints(cs, args):
@ -582,7 +582,7 @@ _quota_resources = ['volumes', 'snapshots', 'gigabytes']
def _quota_show(quotas):
quota_dict = {}
for resource in quotas._info.keys():
for resource in quotas._info:
good_name = False
for name in _quota_resources:
if resource.startswith(name):
@ -1198,7 +1198,7 @@ def do_qos_key(cs, args):
if args.action == 'set':
cs.qos_specs.set_keys(args.qos_specs, keypair)
elif args.action == 'unset':
cs.qos_specs.unset_keys(args.qos_specs, list(keypair.keys()))
cs.qos_specs.unset_keys(args.qos_specs, list(keypair))
@utils.arg('qos_specs', metavar='<qos_specs>',

View File

@ -37,7 +37,7 @@ class QuotaClassSetManager(base.Manager):
def update(self, class_name, **updates):
body = {'quota_class_set': {'class_name': class_name}}
for update in updates.keys():
for update in updates:
body['quota_class_set'][update] = updates[update]
self._update('/os-quota-class-sets/%s' % (class_name), body)

View File

@ -38,7 +38,7 @@ class QuotaSetManager(base.Manager):
def update(self, tenant_id, **updates):
body = {'quota_set': {'tenant_id': tenant_id}}
for update in updates.keys():
for update in updates:
body['quota_set'][update] = updates[update]
self._update('/os-quota-sets/%s' % (tenant_id), body)

View File

@ -89,7 +89,7 @@ def _print_volume_image(image):
def _translate_keys(collection, convert):
for item in collection:
keys = list(item.__dict__.keys())
keys = item.__dict__
for from_key, to_key in convert:
if from_key in keys and to_key not in keys:
setattr(item, to_key, item._info[from_key])
@ -390,7 +390,7 @@ def do_metadata(cs, args):
if args.action == 'set':
cs.volumes.set_metadata(volume, metadata)
elif args.action == 'unset':
cs.volumes.delete_metadata(volume, list(metadata.keys()))
cs.volumes.delete_metadata(volume, list(metadata))
@utils.arg('--all-tenants',
@ -616,7 +616,7 @@ def do_type_key(cs, args):
if args.action == 'set':
vtype.set_keys(keypair)
elif args.action == 'unset':
vtype.unset_keys(list(keypair.keys()))
vtype.unset_keys(list(keypair))
def do_endpoints(cs, args):
@ -638,7 +638,7 @@ _quota_resources = ['volumes', 'snapshots', 'gigabytes']
def _quota_show(quotas):
quota_dict = {}
for resource in quotas._info.keys():
for resource in quotas._info:
good_name = False
for name in _quota_resources:
if resource.startswith(name):
@ -1273,7 +1273,7 @@ def do_qos_key(cs, args):
if args.action == 'set':
cs.qos_specs.set_keys(args.qos_specs, keypair)
elif args.action == 'unset':
cs.qos_specs.unset_keys(args.qos_specs, list(keypair.keys()))
cs.qos_specs.unset_keys(args.qos_specs, list(keypair))
@utils.arg('qos_specs', metavar='<qos_specs>',

View File

@ -267,7 +267,7 @@ class NovaTestResult(testtools.TestResult):
if not self.last_written or (self._now() - time).total_seconds() > 2.0:
diff = 3.0
while diff > 2.0:
classes =list(self.results.keys())
classes =list(self.results)
oldest = min(classes, key=lambda x: self.last_time[x])
diff = (self._now() - self.last_time[oldest]).total_seconds()
self.writeTestCase(oldest)