Use more pythonic approach
Some functional and unit tests uses range and len built-in functions to iterate over items. Those can be replaced by enumerate which makes the code more readable. Change-Id: Icb507681578dbb50128aaf017bd598d98c26a6d4
This commit is contained in:
parent
c32a5f2192
commit
701214481f
@ -202,18 +202,18 @@ class TcFiltersTestCase(functional_base.BaseSudoTestCase):
|
||||
self.mac_vxlan = []
|
||||
self.ip = ['10.100.0.1/24', '10.100.0.2/24']
|
||||
self.ip_vxlan = ['10.200.0.1/24', '10.200.0.2/24']
|
||||
for i in range(len(self.ns)):
|
||||
priv_ip_lib.create_netns(self.ns[i])
|
||||
self.addCleanup(self._remove_ns, self.ns[i])
|
||||
ip_wrapper = ip_lib.IPWrapper(self.ns[i])
|
||||
for i, ns in enumerate(self.ns):
|
||||
priv_ip_lib.create_netns(ns)
|
||||
self.addCleanup(self._remove_ns, ns)
|
||||
ip_wrapper = ip_lib.IPWrapper(ns)
|
||||
if i == 0:
|
||||
ip_wrapper.add_veth(self.device[0], self.device[1], self.ns[1])
|
||||
ip_wrapper.add_vxlan(self.device_vxlan[i], self.vxlan_id,
|
||||
dev=self.device[i])
|
||||
ip_device = ip_lib.IPDevice(self.device[i], self.ns[i])
|
||||
ip_device = ip_lib.IPDevice(self.device[i], ns)
|
||||
ip_device.link.set_up()
|
||||
ip_device.addr.add(self.ip[i])
|
||||
ip_device_vxlan = ip_lib.IPDevice(self.device_vxlan[i], self.ns[i])
|
||||
ip_device_vxlan = ip_lib.IPDevice(self.device_vxlan[i], ns)
|
||||
self.mac_vxlan.append(ip_device_vxlan.link.address)
|
||||
ip_device_vxlan.link.set_up()
|
||||
ip_device_vxlan.addr.add(self.ip_vxlan[i])
|
||||
|
@ -382,8 +382,8 @@ class TestAutoSchedule(test_dhcp_sch.TestDhcpSchedulerBaseTestCase,
|
||||
name='network-%s' % i)
|
||||
for i in range(self.network_count)
|
||||
]
|
||||
for i in range(len(self._networks)):
|
||||
self._networks[i].create()
|
||||
for net in self._networks:
|
||||
net.create()
|
||||
network_ids = [net.id for net in self._networks]
|
||||
|
||||
# pre schedule the networks to the agents defined in
|
||||
|
@ -769,12 +769,12 @@ class TestMl2HostSegmentMappingOVS(HostSegmentMappingTestCase):
|
||||
physical_networks = ['phys_net1', 'phys_net2']
|
||||
networks = []
|
||||
segments = []
|
||||
for i in range(len(physical_networks)):
|
||||
for i, phy_net in enumerate(physical_networks):
|
||||
with self.network() as network:
|
||||
networks.append(network['network'])
|
||||
segments.append(self._test_create_segment(
|
||||
network_id=networks[i]['id'],
|
||||
physical_network=physical_networks[i],
|
||||
physical_network=phy_net,
|
||||
segmentation_id=200,
|
||||
network_type=constants.TYPE_VLAN)['segment'])
|
||||
self._register_agent(host, mappings={physical_networks[0]: 'br-eth-1',
|
||||
|
Loading…
Reference in New Issue
Block a user