Python 3: do not index a dict_values object

In Python 3, dict.values() return a dict_values object instead of a list, as in
Python 2. This object cannot be indexed.

Change-Id: Ia4fdb4cafb1811c55dc8f14e303ab2db1b1110b3
Blueprint: neutron-python3
This commit is contained in:
Cyril Roelandt 2015-05-19 16:16:38 +00:00 committed by Cyril Roelandt
parent e95510f8d1
commit 38eae7acb3
3 changed files with 15 additions and 10 deletions

View File

@ -134,7 +134,7 @@ class OvsdbIdl(api.API):
@property
def _ovs(self):
return self._tables['Open_vSwitch'].rows.values()[0]
return list(self._tables['Open_vSwitch'].rows.values())[0]
def transaction(self, check_error=False, log_errors=True, **kwargs):
return Transaction(self, OvsdbIdl.ovsdb_connection,

View File

@ -144,7 +144,7 @@ class DbGetCommand(DbCommand):
DbCommand.result.fset(self, val)
# DbCommand will return [{'column': value}] and we just want value.
if self._result:
self._result = self._result[0].values()[0]
self._result = list(self._result[0].values())[0]
class BrExistsCommand(DbCommand):

View File

@ -1636,12 +1636,16 @@ PORTS = {'tap_port1': 'port1', 'tap_port2': 'port2'}
MACS = {'tap_port1': '12:34:56:78:9A:BC', 'tap_port2': '12:34:56:78:9A:BD'}
IPS = {'tap_port1': '10.0.0.3/32', 'tap_port2': '10.0.0.4/32'}
IPTABLES_ARG['port1'] = PORTS.values()[0]
IPTABLES_ARG['port2'] = PORTS.values()[1]
IPTABLES_ARG['mac1'] = MACS.values()[0]
IPTABLES_ARG['mac2'] = MACS.values()[1]
IPTABLES_ARG['ip1'] = IPS.values()[0]
IPTABLES_ARG['ip2'] = IPS.values()[1]
ports_values = list(PORTS.values())
macs_values = list(MACS.values())
ips_values = list(IPS.values())
IPTABLES_ARG['port1'] = ports_values[0]
IPTABLES_ARG['port2'] = ports_values[1]
IPTABLES_ARG['mac1'] = macs_values[0]
IPTABLES_ARG['mac2'] = macs_values[1]
IPTABLES_ARG['ip1'] = ips_values[0]
IPTABLES_ARG['ip2'] = ips_values[1]
IPTABLES_ARG['chains'] = CHAINS_NAT
IPTABLES_RAW_DEFAULT = """# Generated by iptables_manager
@ -2128,6 +2132,7 @@ COMMIT
# TestSecurityGroupAgentWithIptables() to ensure that the ordering
# is consistent regardless of hashseed value
REVERSE_PORT_ORDER = {'tap_port1': False, 'tap_port2': True}
reverse_port_order_values = list(REVERSE_PORT_ORDER.values())
IPTABLES_FILTER_2_2 = """# Generated by iptables_manager
*filter
@ -2161,7 +2166,7 @@ IPTABLES_FILTER_2_2 = """# Generated by iptables_manager
--dport 68 -j RETURN
[0:0] -A %(bn)s-i_%(port1)s -p tcp -m tcp --dport 22 -j RETURN
""" % IPTABLES_ARG
if (REVERSE_PORT_ORDER.values()[0] is True):
if reverse_port_order_values[0]:
IPTABLES_FILTER_2_2 += ("[0:0] -A %(bn)s-i_%(port1)s -s %(ip2)s "
"-j RETURN\n"
% IPTABLES_ARG)
@ -2192,7 +2197,7 @@ IPTABLES_FILTER_2_2 += """[0:0] -A %(bn)s-i_%(port1)s -j %(bn)s-sg-fallback
--dport 68 -j RETURN
[0:0] -A %(bn)s-i_%(port2)s -p tcp -m tcp --dport 22 -j RETURN
""" % IPTABLES_ARG
if (REVERSE_PORT_ORDER.values()[0] is False):
if not reverse_port_order_values[0]:
IPTABLES_FILTER_2_2 += ("[0:0] -A %(bn)s-i_%(port2)s -s %(ip1)s "
"-j RETURN\n"
% IPTABLES_ARG)