Merge "Replace six.iteritems/itervalues with dict.items()/values()"

This commit is contained in:
Jenkins 2017-02-08 12:51:57 +00:00 committed by Gerrit Code Review
commit 6c4c47d76d
12 changed files with 29 additions and 40 deletions

View File

@ -86,7 +86,7 @@ def keys_and_vals_to_strs(dictionary):
return str(k_or_v) return str(k_or_v)
else: else:
return k_or_v return k_or_v
return dict((to_str(k), to_str(v)) for k, v in six.iteritems(dictionary)) return dict((to_str(k), to_str(v)) for k, v in dictionary.items())
def _format_field_name(attr): def _format_field_name(attr):
@ -135,7 +135,7 @@ def print_dict(dct, dict_property="Property", wrap=0):
""" """
pt = prettytable.PrettyTable([dict_property, 'Value']) pt = prettytable.PrettyTable([dict_property, 'Value'])
pt.align = 'l' pt.align = 'l'
for k, v in six.iteritems(dct): for k, v in dct.items():
# convert dict to str to check length # convert dict to str to check length
if isinstance(v, dict): if isinstance(v, dict):
v = six.text_type(keys_and_vals_to_strs(v)) v = six.text_type(keys_and_vals_to_strs(v))

View File

@ -24,7 +24,6 @@ from ryu.lib.packet import in_proto
from ryu.lib.packet import ipv4 from ryu.lib.packet import ipv4
from ryu.lib.packet import packet from ryu.lib.packet import packet
from ryu.ofproto import ether from ryu.ofproto import ether
import six
from dragonflow._i18n import _LW from dragonflow._i18n import _LW
from dragonflow import conf as cfg from dragonflow import conf as cfg
@ -144,7 +143,7 @@ class DNATApp(df_base_app.DFlowApp):
or mac == '00:00:00:00:00:00'): or mac == '00:00:00:00:00:00'):
return return
for key, floatingip in six.iteritems(self.local_floatingips): for key, floatingip in self.local_floatingips.items():
self._install_dnat_egress_rules(floatingip, mac) self._install_dnat_egress_rules(floatingip, mac)
self.update_floatingip_status( self.update_floatingip_status(
floatingip, n_const.FLOATINGIP_STATUS_ACTIVE) floatingip, n_const.FLOATINGIP_STATUS_ACTIVE)
@ -173,7 +172,7 @@ class DNATApp(df_base_app.DFlowApp):
def _is_first_external_network(self, network_id): def _is_first_external_network(self, network_id):
if self._get_external_network_count(network_id) == 0: if self._get_external_network_count(network_id) == 0:
# check whether there are other networks # check whether there are other networks
for key, val in six.iteritems(self.external_networks): for key, val in self.external_networks.items():
if key != network_id and val > 0: if key != network_id and val > 0:
return False return False
return True return True
@ -182,7 +181,7 @@ class DNATApp(df_base_app.DFlowApp):
def _is_last_external_network(self, network_id): def _is_last_external_network(self, network_id):
if self._get_external_network_count(network_id) == 1: if self._get_external_network_count(network_id) == 1:
# check whether there are other networks # check whether there are other networks
for key, val in six.iteritems(self.external_networks): for key, val in self.external_networks.items():
if key != network_id and val > 0: if key != network_id and val > 0:
return False return False
return True return True
@ -439,7 +438,7 @@ class DNATApp(df_base_app.DFlowApp):
def remove_local_port(self, lport): def remove_local_port(self, lport):
port_id = lport.get_id() port_id = lport.get_id()
ips_to_disassociate = [ ips_to_disassociate = [
fip for fip in six.itervalues(self.local_floatingips) fip for fip in self.local_floatingips.values()
if fip.get_lport_id() == port_id] if fip.get_lport_id() == port_id]
for floatingip in ips_to_disassociate: for floatingip in ips_to_disassociate:
self.disassociate_floatingip(floatingip) self.disassociate_floatingip(floatingip)

View File

@ -22,7 +22,6 @@ from oslo_log import log
from ryu.lib.mac import haddr_to_bin from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import in_proto from ryu.lib.packet import in_proto
from ryu.ofproto import ether from ryu.ofproto import ether
import six
from dragonflow._i18n import _, _LI, _LE from dragonflow._i18n import _, _LI, _LE
from dragonflow import conf as cfg from dragonflow import conf as cfg
@ -75,7 +74,7 @@ class L2App(df_base_app.DFlowApp):
:param bridge_mappings: map physical network names to bridge names. :param bridge_mappings: map physical network names to bridge names.
''' '''
for physical_network, bridge in six.iteritems(bridge_mappings): for physical_network, bridge in bridge_mappings.items():
LOG.info(_LI("Mapping physical network %(physical_network)s to " LOG.info(_LI("Mapping physical network %(physical_network)s to "
"bridge %(bridge)s"), "bridge %(bridge)s"),
{'physical_network': physical_network, {'physical_network': physical_network,

View File

@ -17,7 +17,6 @@ import netaddr
from neutron_lib import constants as n_const from neutron_lib import constants as n_const
from oslo_log import log from oslo_log import log
from ryu.ofproto import ether from ryu.ofproto import ether
import six
from dragonflow._i18n import _LI, _LW, _LE from dragonflow._i18n import _LI, _LW, _LE
from dragonflow.controller.common import constants as const from dragonflow.controller.common import constants as const
@ -792,7 +791,7 @@ class SGApp(df_base_app.DFlowApp):
# of remote group. # of remote group.
secrules = self.remote_secgroup_ref.get(secgroup_id) secrules = self.remote_secgroup_ref.get(secgroup_id)
if secrules: if secrules:
for rule_info in six.itervalues(secrules): for rule_info in secrules.values():
self._update_security_group_rule_flows_by_addresses( self._update_security_group_rule_flows_by_addresses(
rule_info.get_security_group_id(), rule_info.get_security_group_id(),
rule_info, rule_info,
@ -822,7 +821,7 @@ class SGApp(df_base_app.DFlowApp):
# parameter of remote group. # parameter of remote group.
secrules = self.remote_secgroup_ref.get(secgroup_id) secrules = self.remote_secgroup_ref.get(secgroup_id)
if secrules: if secrules:
for rule_info in six.itervalues(secrules): for rule_info in secrules.values():
self._update_security_group_rule_flows_by_addresses( self._update_security_group_rule_flows_by_addresses(
rule_info.get_security_group_id(), rule_info.get_security_group_id(),
rule_info, rule_info,

View File

@ -12,7 +12,6 @@
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
import six
from dragonflow._i18n import _LI, _LE, _LW from dragonflow._i18n import _LI, _LE, _LW
from dragonflow.common import constants from dragonflow.common import constants
@ -301,7 +300,7 @@ class Topology(object):
new_ovs_to_lport_mapping = {} new_ovs_to_lport_mapping = {}
add_ovs_to_lport_mapping = {} add_ovs_to_lport_mapping = {}
delete_ovs_to_lport_mapping = self.ovs_to_lport_mapping delete_ovs_to_lport_mapping = self.ovs_to_lport_mapping
for key, ovs_port in six.iteritems(self.ovs_ports): for key, ovs_port in self.ovs_ports.items():
if ovs_port.get_type() == db_models.OvsPort.TYPE_VM: if ovs_port.get_type() == db_models.OvsPort.TYPE_VM:
lport_id = ovs_port.get_iface_id() lport_id = ovs_port.get_iface_id()
lport = self._get_lport(lport_id) lport = self._get_lport(lport_id)

View File

@ -17,8 +17,6 @@ import collections
import copy import copy
import threading import threading
import six
from dragonflow.db import models from dragonflow.db import models
@ -93,7 +91,7 @@ class DbStore(object):
def get(self, table_name, key, topic): def get(self, table_name, key, topic):
if topic: if topic:
return self.tenant_dbs[topic].get(table_name, key) return self.tenant_dbs[topic].get(table_name, key)
for tenant_db in six.itervalues(self.tenant_dbs): for tenant_db in self.tenant_dbs.values():
value = tenant_db.get(table_name, key) value = tenant_db.get(table_name, key)
if value: if value:
return value return value
@ -102,7 +100,7 @@ class DbStore(object):
if topic: if topic:
return self.tenant_dbs[topic].keys(table_name) return self.tenant_dbs[topic].keys(table_name)
result = [] result = []
for tenant_db in six.itervalues(self.tenant_dbs): for tenant_db in self.tenant_dbs.values():
result.extend(tenant_db.keys(table_name)) result.extend(tenant_db.keys(table_name))
return result return result
@ -110,7 +108,7 @@ class DbStore(object):
if topic: if topic:
return self.tenant_dbs[topic].values(table_name) return self.tenant_dbs[topic].values(table_name)
result = [] result = []
for tenant_db in six.itervalues(self.tenant_dbs): for tenant_db in self.tenant_dbs.values():
result.extend(tenant_db.values(table_name)) result.extend(tenant_db.values(table_name))
return result return result
@ -123,7 +121,7 @@ class DbStore(object):
if topic: if topic:
self.tenant_dbs[topic].pop(table_name, key) self.tenant_dbs[topic].pop(table_name, key)
else: else:
for tenant_db in six.itervalues(self.tenant_dbs): for tenant_db in self.tenant_dbs.values():
if tenant_db.pop(table_name, key): if tenant_db.pop(table_name, key):
break break
@ -362,7 +360,7 @@ class DbStore(object):
def clear(self, topic=None): def clear(self, topic=None):
if not topic: if not topic:
for tenant_db in six.itervalues(self.tenant_dbs): for tenant_db in self.tenant_dbs.values():
tenant_db.clear() tenant_db.clear()
else: else:
self.tenant_dbs[topic].clear() self.tenant_dbs[topic].clear()

View File

@ -15,7 +15,6 @@ import re
from oslo_log import log from oslo_log import log
from redis import client as redis_client from redis import client as redis_client
from redis import exceptions from redis import exceptions
import six
from dragonflow._i18n import _LE, _LW from dragonflow._i18n import _LE, _LW
from dragonflow.db import db_api from dragonflow.db import db_api
@ -59,7 +58,7 @@ class RedisDbDriver(db_api.DbApi):
def delete_table(self, table): def delete_table(self, table):
local_key = self._uuid_to_key(table, '*', '*') local_key = self._uuid_to_key(table, '*', '*')
for host, client in six.iteritems(self.clients): for host, client in self.clients.items():
local_keys = client.keys(local_key) local_keys = client.keys(local_key)
if len(local_keys) > 0: if len(local_keys) > 0:
for tmp_key in local_keys: for tmp_key in local_keys:
@ -178,7 +177,7 @@ class RedisDbDriver(db_api.DbApi):
local_key = self._uuid_to_key(table, key, '*') local_key = self._uuid_to_key(table, key, '*')
self._sync_master_list() self._sync_master_list()
try: try:
for host, client in six.iteritems(self.clients): for host, client in self.clients.items():
local_keys = client.keys(local_key) local_keys = client.keys(local_key)
if len(local_keys) == 1: if len(local_keys) == 1:
return self._execute_cmd("GET", local_keys[0]) return self._execute_cmd("GET", local_keys[0])
@ -232,7 +231,7 @@ class RedisDbDriver(db_api.DbApi):
if not topic: if not topic:
local_key = self._uuid_to_key(table, '*', '*') local_key = self._uuid_to_key(table, '*', '*')
try: try:
for host, client in six.iteritems(self.clients): for host, client in self.clients.items():
local_keys = client.keys(local_key) local_keys = client.keys(local_key)
if len(local_keys) > 0: if len(local_keys) > 0:
for tmp_key in local_keys: for tmp_key in local_keys:
@ -267,7 +266,7 @@ class RedisDbDriver(db_api.DbApi):
if not topic: if not topic:
local_key = self._uuid_to_key(table, '*', '*') local_key = self._uuid_to_key(table, '*', '*')
try: try:
for host, client in six.iteritems(self.clients): for host, client in self.clients.items():
ip_port = host ip_port = host
res.extend(client.keys(local_key)) res.extend(client.keys(local_key))
return [self._strip_table_name_from_key(key) for key in res] return [self._strip_table_name_from_key(key) for key in res]

View File

@ -126,7 +126,7 @@ class RedisMgt(object):
def get_cluster_topology_by_all_nodes(self): def get_cluster_topology_by_all_nodes(self):
# get redis cluster topology from local nodes cached in initialization # get redis cluster topology from local nodes cached in initialization
new_nodes = {} new_nodes = {}
for host, info in six.iteritems(self.cluster_nodes): for host, info in self.cluster_nodes.items():
ip_port = host.split(':') ip_port = host.split(':')
try: try:
node = self._init_node(ip_port[0], ip_port[1]) node = self._init_node(ip_port[0], ip_port[1])
@ -218,7 +218,7 @@ class RedisMgt(object):
def _parse_to_masterlist(self): def _parse_to_masterlist(self):
master_list = [] master_list = []
for host, info in six.iteritems(self.cluster_nodes): for host, info in self.cluster_nodes.items():
if 'master' == info['role']: if 'master' == info['role']:
slots = [] slots = []
if len(info['slots']) > 0: if len(info['slots']) > 0:
@ -269,8 +269,8 @@ class RedisMgt(object):
slave_cnt = 0 slave_cnt = 0
slot_changed = False slot_changed = False
for host, info in six.iteritems(old_nodes): for host, info in old_nodes.items():
for new_host, new_info in six.iteritems(new_nodes): for new_host, new_info in new_nodes.items():
if host == new_host and info['role'] == \ if host == new_host and info['role'] == \
new_info['role']: new_info['role']:
if info['slots'] != new_info['slots']: if info['slots'] != new_info['slots']:

View File

@ -32,7 +32,7 @@ def _parse_hosts(hosts):
return hosts.strip() return hosts.strip()
if isinstance(hosts, (dict)): if isinstance(hosts, (dict)):
host_ports = [] host_ports = []
for (k, v) in six.iteritems(hosts): for (k, v) in hosts.items():
host_ports.append("%s:%s" % (k, v)) host_ports.append("%s:%s" % (k, v))
hosts = host_ports hosts = host_ports
if isinstance(hosts, (list, set, tuple)): if isinstance(hosts, (list, set, tuple)):

View File

@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import six
from neutron.agent.ovsdb.native import commands from neutron.agent.ovsdb.native import commands
from neutron.agent.ovsdb.native import idlutils from neutron.agent.ovsdb.native import idlutils
from oslo_config import cfg from oslo_config import cfg
@ -138,7 +136,7 @@ class DeleteQos(commands.BaseCommand):
conditions = [('external_ids', '=', {'iface-id': self.port_id})] conditions = [('external_ids', '=', {'iface-id': self.port_id})]
rows_to_delete = [] rows_to_delete = []
for table in ['QoS', 'Queue']: for table in ['QoS', 'Queue']:
for r in six.itervalues(self.api._tables[table].rows): for r in self.api._tables[table].rows.values():
if idlutils.row_match(r, conditions): if idlutils.row_match(r, conditions):
rows_to_delete.append(r) rows_to_delete.append(r)
@ -155,7 +153,7 @@ class UpdateQos(commands.BaseCommand):
def run_idl(self, txn): def run_idl(self, txn):
conditions = [('external_ids', '=', {'iface-id': self.port_id})] conditions = [('external_ids', '=', {'iface-id': self.port_id})]
queue_table = self.api._tables['Queue'] queue_table = self.api._tables['Queue']
for r in six.itervalues(queue_table.rows): for r in queue_table.rows.values():
if idlutils.row_match(r, conditions): if idlutils.row_match(r, conditions):
dscp = self.qos.get_dscp_marking() dscp = self.qos.get_dscp_marking()
dscp = dscp if dscp else [] dscp = dscp if dscp else []
@ -169,7 +167,7 @@ class UpdateQos(commands.BaseCommand):
setattr(r, 'other_config', other_config) setattr(r, 'other_config', other_config)
qos_table = self.api._tables['QoS'] qos_table = self.api._tables['QoS']
for r in six.itervalues(qos_table.rows): for r in qos_table.rows.values():
if idlutils.row_match(r, conditions): if idlutils.row_match(r, conditions):
external_ids = getattr(r, 'external_ids', {}) external_ids = getattr(r, 'external_ids', {})
external_ids['version'] = str(self.qos.get_version()) external_ids['version'] = str(self.qos.get_version())

View File

@ -16,7 +16,6 @@ from neutron.agent.ovsdb import impl_idl
from neutron.agent.ovsdb.native import connection from neutron.agent.ovsdb.native import connection
from oslo_config import cfg from oslo_config import cfg
from ovs.db import idl from ovs.db import idl
import six
from dragonflow.common import constants from dragonflow.common import constants
from dragonflow.ovsdb import commands from dragonflow.ovsdb import commands
@ -108,7 +107,7 @@ class DFConnection(connection.Connection):
""" """
def update_schema_helper(self, helper): def update_schema_helper(self, helper):
tables = ovsdb_monitor_table_filter_default tables = ovsdb_monitor_table_filter_default
for table_name, columns in six.iteritems(tables): for table_name, columns in tables.items():
if columns == 'all': if columns == 'all':
helper.register_table(table_name) helper.register_table(table_name)
else: else:

View File

@ -11,7 +11,6 @@
# under the License. # under the License.
import netaddr import netaddr
import six
import time import time
from neutron.agent.common import utils as agent_utils from neutron.agent.common import utils as agent_utils
@ -341,7 +340,7 @@ class VMTestObj(object):
if self.server is None: if self.server is None:
return None return None
ips = self.nova.servers.ips(self.server) ips = self.nova.servers.ips(self.server)
for id, network in six.iteritems(ips): for id, network in ips.items():
for ip in network: for ip in network:
if int(ip['version']) == 4: if int(ip['version']) == 4:
return ip['addr'] return ip['addr']