Merge "Replace six.iteritems() with .items()"

This commit is contained in:
Jenkins 2017-07-15 02:27:25 +00:00 committed by Gerrit Code Review
commit 107f89834c
12 changed files with 40 additions and 53 deletions

View File

@ -19,7 +19,6 @@ import netaddr
from oslo_log import log as logging
from oslo_utils import uuidutils
import six
from six import iteritems
from tacker.common import exceptions as n_exc
@ -392,7 +391,7 @@ def _validate_dict_item(key, key_validator, data):
# TODO(salv-orlando): Structure of dict attributes should be improved
# to avoid iterating over items
val_func = val_params = None
for (k, v) in iteritems(key_validator):
for (k, v) in (key_validator).items():
if k.startswith('type:'):
# ask forgiveness, not permission
try:
@ -416,7 +415,7 @@ def _validate_dict(data, key_specs=None):
return
# Check whether all required keys are present
required_keys = [key for key, spec in iteritems(key_specs)
required_keys = [key for key, spec in (key_specs).items()
if spec.get('required')]
if required_keys:
@ -427,7 +426,7 @@ def _validate_dict(data, key_specs=None):
# Perform validation and conversion of all values
# according to the specifications.
for key, key_validator in [(k, v) for k, v in iteritems(key_specs)
for key, key_validator in [(k, v) for k, v in (key_specs).items()
if k in data]:
msg = _validate_dict_item(key, key_validator, data)
if msg:
@ -518,7 +517,7 @@ def convert_kvp_list_to_dict(kvp_list):
key, value = convert_kvp_str_to_list(kvp_str)
kvp_map.setdefault(key, set())
kvp_map[key].add(value)
return dict((x, list(y)) for x, y in iteritems(kvp_map))
return dict((x, list(y)) for x, y in (kvp_map).items())
def convert_none_to_empty_list(value):

View File

@ -14,7 +14,6 @@
# under the License.
import netaddr
from six import iteritems
import webob.exc
from oslo_log import log as logging
@ -92,7 +91,7 @@ class Controller(object):
self._resource)
def _get_primary_key(self, default_primary_key='id'):
for key, value in iteritems(self._attr_info):
for key, value in (self._attr_info).items():
if value.get('primary_key', False):
return key
return default_primary_key
@ -152,7 +151,7 @@ class Controller(object):
def _filter_attributes(self, context, data, fields_to_strip=None):
if not fields_to_strip:
return data
return dict(item for item in iteritems(data)
return dict(item for item in (data).items()
if (item[0] not in fields_to_strip))
def _do_field_list(self, original_fields):
@ -443,7 +442,7 @@ class Controller(object):
# Load object to check authz
# but pass only attributes in the original body and required
# by the policy engine to the policy 'brain'
field_list = [name for (name, value) in iteritems(self._attr_info)
field_list = [name for (name, value) in (self._attr_info).items()
if (value.get('required_by_policy') or
value.get('primary_key') or
'default' not in value)]
@ -535,7 +534,7 @@ class Controller(object):
Controller._verify_attributes(res_dict, attr_info)
if is_create: # POST
for attr, attr_vals in iteritems(attr_info):
for attr, attr_vals in (attr_info).items():
if attr_vals['allow_post']:
if ('default' not in attr_vals and
attr not in res_dict):
@ -549,12 +548,12 @@ class Controller(object):
msg = _("Attribute '%s' not allowed in POST") % attr
raise webob.exc.HTTPBadRequest(msg)
else: # PUT
for attr, attr_vals in iteritems(attr_info):
for attr, attr_vals in (attr_info).items():
if attr in res_dict and not attr_vals['allow_put']:
msg = _("Cannot update read-only attribute %s") % attr
raise webob.exc.HTTPBadRequest(msg)
for attr, attr_vals in iteritems(attr_info):
for attr, attr_vals in (attr_info).items():
if (attr not in res_dict or
res_dict[attr] is attributes.ATTR_NOT_SPECIFIED):
continue

View File

@ -14,7 +14,6 @@
# limitations under the License.
import routes as routes_mapper
from six import iteritems
import six.moves.urllib.parse as urlparse
import webob
import webob.dec
@ -34,7 +33,7 @@ class Index(wsgi.Application):
metadata = {}
layout = []
for name, collection in iteritems(self.resources):
for name, collection in (self.resources).items():
href = urlparse.urljoin(req.path_url, collection)
resource = {'name': name,
'collection': collection,

View File

@ -33,7 +33,6 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_utils import importutils
from six import iteritems
from stevedore import driver
from tacker._i18n import _
@ -163,7 +162,7 @@ def change_memory_unit(mem, to):
"""
mem = str(mem) + " MB" if str(mem).isdigit() else mem.upper()
for unit, value in iteritems(MEM_UNITS):
for unit, value in (MEM_UNITS).items():
mem_arr = mem.split(unit)
if len(mem_arr) < 2:
continue

View File

@ -17,7 +17,6 @@ import uuid
from oslo_db.exception import DBDuplicateEntry
from oslo_log import log as logging
from oslo_utils import timeutils
from six import iteritems
import sqlalchemy as sa
from sqlalchemy import orm
@ -284,7 +283,7 @@ class NSPluginDb(network_service.NSPluginBase, db_base.CommonDbMixin):
mgmt_urls = dict()
vnf_ids = dict()
if len(output) > 0:
for vnfd_name, vnfd_val in iteritems(vnfd_dict):
for vnfd_name, vnfd_val in (vnfd_dict).items():
for instance in vnfd_val['instances']:
if 'mgmt_url_' + instance in output:
mgmt_urls[instance] = ast.literal_eval(

View File

@ -18,7 +18,6 @@ import sqlalchemy as sa
import uuid
from oslo_log import log as logging
from six import iteritems
from sqlalchemy import orm
from sqlalchemy.orm import exc as orm_exc
from tacker._i18n import _
@ -289,7 +288,7 @@ class VnffgPluginDbMixin(vnffg.VNFFGPluginBase, db_base.CommonDbMixin):
if 'get_input' not in str(original):
return
if isinstance(original, dict):
for key_, value in iteritems(original):
for key_, value in (original).items():
if isinstance(value, dict) and 'get_input' in value:
if value['get_input'] in paramvalues:
original[key_] = paramvalues[value['get_input']]

View File

@ -11,7 +11,6 @@
# under the License.
import ast
from six import iteritems
import uuid
from tacker.mistral import workflow_generator
@ -27,7 +26,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
def _add_create_vnf_tasks(self, ns):
vnfds = ns['vnfd_details']
task_dict = dict()
for vnfd_name, vnfd_info in iteritems(vnfds):
for vnfd_name, vnfd_info in (vnfds).items():
nodes = vnfd_info['instances']
for node in nodes:
task = self.wf_name + '_' + node
@ -52,7 +51,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
def _add_wait_vnf_tasks(self, ns):
vnfds = ns['vnfd_details']
task_dict = dict()
for vnfd_name, vnfd_info in iteritems(vnfds):
for vnfd_name, vnfd_info in (vnfds).items():
nodes = vnfd_info['instances']
for node in nodes:
task = 'wait_vnf_active_%s' % node
@ -85,7 +84,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
def _add_delete_vnf_tasks(self, ns):
vnfds = ns['vnfd_details']
task_dict = dict()
for vnfd_name, vnfd_info in iteritems(vnfds):
for vnfd_name, vnfd_info in (vnfds).items():
nodes = vnfd_info['instances']
for node in nodes:
task = 'delete_vnf_%s' % node
@ -98,7 +97,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
def _build_output_dict(self, ns):
vnfds = ns['vnfd_details']
task_dict = dict()
for vnfd_name, vnfd_info in iteritems(vnfds):
for vnfd_name, vnfd_info in (vnfds).items():
nodes = vnfd_info['instances']
for node in nodes:
for op_name in OUTPUT[self.wf_name]:
@ -113,7 +112,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
vnfds = ns['vnfd_details']
id = str(uuid.uuid4())
self.input_dict = {'vnf': {}}
for vnfd_name, vnfd_info in iteritems(vnfds):
for vnfd_name, vnfd_info in (vnfds).items():
nodes = vnfd_info['instances']
for node in nodes:
self.input_dict['vnf'][node] = dict()
@ -121,8 +120,7 @@ class WorkflowGenerator(workflow_generator.WorkflowGeneratorBase):
'attributes': {},
'vim_id': ns['ns'].get('vim_id', ''),
'vnfd_id': vnfd_info['id'],
'name': 'create_vnf_%s_%s' % (vnfd_info['id'],
id)
'name': 'create_vnf_%s_%s' % (vnfd_info['id'], id)
}
if params.get(vnfd_name):
self.input_dict['vnf'][node]['vnf']['attributes'] = {

View File

@ -26,7 +26,6 @@ from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from oslo_utils import strutils
from six import iteritems
from tempfile import mkstemp
from toscaparser.tosca_template import ToscaTemplate
@ -599,7 +598,7 @@ class NfvoPlugin(nfvo_db_plugin.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
# vnfd_dict is used while generating workflow
vnfd_dict = dict()
for node_name, node_val in \
iteritems(nsd_dict['topology_template']['node_templates']):
(nsd_dict['topology_template']['node_templates']).items():
if node_val.get('type') not in vnfds.keys():
continue
vnfd_name = vnfds[node_val.get('type')]
@ -700,7 +699,7 @@ class NfvoPlugin(nfvo_db_plugin.NfvoPluginDb, vnffg_db.VnffgPluginDbMixin,
@log.log
def _update_params(self, original, paramvalues):
for key, value in iteritems(original):
for key, value in (original).items():
if not isinstance(value, dict) or 'get_input' not in str(value):
pass
elif isinstance(value, dict):

View File

@ -28,7 +28,6 @@ import fixtures
import mock
from oslo_config import cfg
from oslo_messaging import conffixture as messaging_conffixture
from six import iteritems
import testtools
from tacker.common import config
@ -195,7 +194,7 @@ class BaseTestCase(testtools.TestCase):
test by the fixtures cleanup process.
"""
group = kw.pop('group', None)
for k, v in iteritems(kw):
for k, v in (kw).items():
CONF.set_override(k, v, group)
@contextlib.contextmanager

View File

@ -17,7 +17,6 @@
Unit tests for extension extended attribute
"""
from six import iteritems
import webob.exc as webexc
import tacker
@ -60,7 +59,7 @@ class ExtensionExtendedAttributeTestCase(base.BaseTestCase):
self._tenant_id = "8c70909f-b081-452d-872b-df48e6c355d1"
# Save the global RESOURCE_ATTRIBUTE_MAP
self.saved_attr_map = {}
for resource, attrs in iteritems(attributes.RESOURCE_ATTRIBUTE_MAP):
for resource, attrs in (attributes.RESOURCE_ATTRIBUTE_MAP).items():
self.saved_attr_map[resource] = attrs.copy()
# Add the resources to the global attribute map
# This is done here as the setup process won't

View File

@ -18,7 +18,6 @@ import sys
import yaml
from oslo_log import log as logging
from six import iteritems
from toscaparser import properties
from toscaparser.utils import yamlparser
@ -117,7 +116,7 @@ def check_for_substitution_mappings(template, params):
elif (not sm_dict or not requirements) and not req_dict_tpl:
return
del params['substitution_mappings']
for req_name, req_val in iteritems(req_dict_tpl):
for req_name, req_val in (req_dict_tpl).items():
if req_name not in requirements:
raise vnfm.SMRequirementMissing(requirement=req_name)
if not isinstance(req_val, list):
@ -190,15 +189,15 @@ def get_mgmt_ports(tosca):
@log.log
def add_resources_tpl(heat_dict, hot_res_tpl):
for res, res_dict in iteritems(hot_res_tpl):
for vdu, vdu_dict in iteritems(res_dict):
for res, res_dict in (hot_res_tpl).items():
for vdu, vdu_dict in (res_dict).items():
res_name = vdu + "_" + res
heat_dict["resources"][res_name] = {
"type": HEAT_RESOURCE_MAP[res],
"properties": {}
}
for prop, val in iteritems(vdu_dict):
for prop, val in (vdu_dict).items():
heat_dict["resources"][res_name]["properties"][prop] = val
heat_dict["resources"][vdu]["properties"][res] = {
"get_resource": res_name
@ -209,7 +208,7 @@ def add_resources_tpl(heat_dict, hot_res_tpl):
def convert_unsupported_res_prop(heat_dict, unsupported_res_prop):
res_dict = heat_dict['resources']
for res, attr in iteritems(res_dict):
for res, attr in (res_dict).items():
res_type = attr['type']
if res_type in unsupported_res_prop:
prop_dict = attr['properties']
@ -261,7 +260,7 @@ def post_process_heat_template(heat_tpl, mgmt_ports, metadata,
#
def fix_user_data(user_data_string):
user_data_string = re.sub('user_data: #', 'user_data: |\n #',
user_data_string, re.MULTILINE)
user_data_string, re.MULTILINE)
return re.sub('\n\n', '\n', user_data_string, re.MULTILINE)
heat_tpl = fix_user_data(heat_tpl)
@ -294,8 +293,8 @@ def post_process_heat_template(heat_tpl, mgmt_ports, metadata,
convert_unsupported_res_prop(heat_dict, unsupported_res_prop)
yaml.SafeDumper.add_representer(OrderedDict,
lambda dumper, value: represent_odict(dumper,
u'tag:yaml.org,2002:map', value))
lambda dumper, value: represent_odict(dumper,
u'tag:yaml.org,2002:map', value))
return yaml.safe_dump(heat_dict)
@ -370,9 +369,9 @@ def get_flavor_dict(template, flavor_extra_input=None):
flavor_dict[nt.name] = {}
properties = nt.get_capabilities()["nfv_compute"].get_properties()
for prop, (hot_prop, default, unit) in \
iteritems(FLAVOR_PROPS):
(FLAVOR_PROPS).items():
hot_prop_val = (properties[prop].value
if properties.get(prop, None) else None)
if properties.get(prop, None) else None)
if unit and hot_prop_val:
hot_prop_val = \
utils.change_memory_unit(hot_prop_val, unit)
@ -442,9 +441,9 @@ def get_image_dict(template):
if not vdu.entity_tpl.get("artifacts"):
continue
artifacts = vdu.entity_tpl["artifacts"]
for name, artifact in iteritems(artifacts):
for name, artifact in (artifacts).items():
if ('type' in artifact.keys() and
artifact["type"] == IMAGE):
artifact["type"] == IMAGE):
if 'file' not in artifact.keys():
raise vnfm.FilePathMissing()
image_dict[vdu.name] = {
@ -458,7 +457,7 @@ def get_image_dict(template):
def get_resources_dict(template, flavor_extra_input=None):
res_dict = dict()
for res, method in iteritems(OS_RESOURCES):
for res, method in (OS_RESOURCES).items():
res_method = getattr(sys.modules[__name__], method)
if res is 'flavor':
res_dict[res] = res_method(template, flavor_extra_input)

View File

@ -15,7 +15,6 @@ import copy
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from six import iteritems
from toscaparser import tosca_template
from toscaparser.utils import yamlparser
from translator.hot import tosca_translator
@ -156,7 +155,7 @@ class TOSCAToHOT(object):
@log.log
def _update_params(self, original, paramvalues, match=False):
for key, value in iteritems(original):
for key, value in (original).items():
if not isinstance(value, dict) or 'get_input' not in str(value):
pass
elif isinstance(value, dict):
@ -272,9 +271,9 @@ class TOSCAToHOT(object):
def _get_unsupported_resource_props(self, heat_client):
unsupported_resource_props = {}
for res, prop_dict in iteritems(HEAT_VERSION_INCOMPATIBILITY_MAP):
for res, prop_dict in (HEAT_VERSION_INCOMPATIBILITY_MAP).items():
unsupported_props = {}
for prop, val in iteritems(prop_dict):
for prop, val in (prop_dict).items():
if not heat_client.resource_attr_support(res, prop):
unsupported_props.update(prop_dict)
if unsupported_props: