Fix "use a generator" warnings

Fix code to silence consider-using-generator and
use-a-generator warnings. Functionality unchanged.

TrivialFix

Change-Id: Ia22805f026955cdb88d0ee07686af5a3b9dfdd28
This commit is contained in:
Brian Haley 2023-12-02 11:29:18 -05:00
parent fd98ee34e1
commit 3233407d77
7 changed files with 10 additions and 11 deletions

View File

@ -182,9 +182,8 @@ def router_append_interface(router, count=1,
ra_mode=None, addr_mode=None, dual_stack=False,
same_port=False):
interfaces = router[lib_constants.INTERFACE_KEY]
current = sum(
[netaddr.IPNetwork(subnet['cidr']).version == ip_version
for p in interfaces for subnet in p['subnets']])
current = sum(netaddr.IPNetwork(subnet['cidr']).version == ip_version
for p in interfaces for subnet in p['subnets'])
# If dual_stack=True, create IPv4 and IPv6 subnets on each port
# If same_port=True, create ip_version number of subnets on a single port

View File

@ -118,7 +118,7 @@ class BaseFullStackTestCase(testlib_api.MySQLTestCaseMixin,
futures.wait(restarts, timeout=restart_timeout)
self.assertTrue(all([r.done() for r in restarts]))
self.assertTrue(all(r.done() for r in restarts))
LOG.debug("Restarting agents - done")
# It is necessary to give agents time to initialize

View File

@ -173,7 +173,7 @@ class L3AgentTestCase(framework.L3AgentTestFramework):
# l3 agent should be able to rebuild the ns when it is deleted
self.manage_router(self.agent, router_info)
# Assert the router ports are there in namespace
self.assertTrue(all([port.exists() for port in router_ports]))
self.assertTrue(all(port.exists() for port in router_ports))
self._delete_router(self.agent, router.router_id)

View File

@ -305,7 +305,7 @@ class OVSBridgeTestCase(OVSBridgeTestBase):
vif_ports = [self.create_ovs_vif_port() for i in range(3)]
ports = self.br.get_vif_ports()
self.assertEqual(3, len(ports))
self.assertTrue(all([isinstance(x, ovs_lib.VifPort) for x in ports]))
self.assertTrue(all(isinstance(x, ovs_lib.VifPort) for x in ports))
self.assertEqual(sorted([x.port_name for x in vif_ports]),
sorted([x.port_name for x in ports]))
@ -321,7 +321,7 @@ class OVSBridgeTestCase(OVSBridgeTestBase):
new=new_port_name_list).start()
ports = self.br.get_vif_ports()
self.assertEqual(3, len(ports))
self.assertTrue(all([isinstance(x, ovs_lib.VifPort) for x in ports]))
self.assertTrue(all(isinstance(x, ovs_lib.VifPort) for x in ports))
self.assertEqual(sorted([x.port_name for x in vif_ports]),
sorted([x.port_name for x in ports]))

View File

@ -152,7 +152,7 @@ class NetnsCleanupTest(base.BaseSudoTestCase):
def _get_num_spawned_procs():
cmd = ['ps', '-f', '-u', 'root']
out = utils.execute(cmd, run_as_root=True)
return sum([1 for line in out.splitlines() if 'process_spawn' in line])
return sum(1 for line in out.splitlines() if 'process_spawn' in line)
class TestNETNSCLIConfig(basetest.BaseTestCase):

View File

@ -3193,8 +3193,8 @@ class TestDnsmasq(TestBase):
for alloc in FakeDhcpPort().fixed_ips]
options, idx_map = dm._generate_opts_per_subnet()
contains_metadata_ip = any(['%s' % constants.METADATA_CIDR in line
for line in options])
contains_metadata_ip = any('%s' % constants.METADATA_CIDR in line
for line in options)
self.assertEqual(expected_mdt_ip, contains_metadata_ip)
def test__generate_opts_per_subnet_no_metadata(self):

View File

@ -4366,7 +4366,7 @@ class TestOvsDvrNeutronAgent(object):
self.agent.rpc_loop(polling_manager=mock.Mock())
except TypeError:
pass
self.assertTrue(all([x.called for x in reset_mocks]))
self.assertTrue(all(x.called for x in reset_mocks))
def test_rpc_loop_survives_error_in_check_canary_table(self):
with mock.patch.object(self.agent.int_br,