From f9009b486946dbe38507b1a6b8c73e4dcad9a0ed Mon Sep 17 00:00:00 2001 From: Masayuki Igawa Date: Mon, 10 Apr 2017 14:49:29 +0900 Subject: [PATCH] Use assert(Not)Empty,IsNotNone instead of assert(Not)Equal,GreaterEqual(0, len(.. This commit makes to use assert(Not)Empty() or assertIsNotNone() instead of assert(Not)Equal(0, len(LIST),..) or assertGreaterEqual(0, len()...). The original code asserts the specified list is empty or not. And we already have assert(Not)Empty() for it. The method names "assert(Not)Empty" are straightforward and easy to understand. It makes the code clean and the assert message could be easier to understand what is happen than original ones. Change-Id: I715ec84d9139b1d196275e91212ab40d52a545e1 --- tempest/api/compute/admin/test_agents.py | 6 ++---- tempest/api/compute/admin/test_availability_zone.py | 4 ++-- tempest/api/compute/admin/test_floating_ips_bulk.py | 2 +- tempest/api/compute/admin/test_hosts.py | 4 ++-- tempest/api/compute/admin/test_hypervisor.py | 8 ++++---- tempest/api/compute/admin/test_hypervisor_negative.py | 8 ++++---- .../compute/admin/test_security_group_default_rules.py | 2 +- tempest/api/compute/admin/test_services.py | 4 ++-- tempest/api/compute/admin/test_services_negative.py | 4 ++-- .../api/compute/floating_ips/test_list_floating_ips.py | 4 ++-- tempest/api/compute/limits/test_absolute_limits.py | 2 +- .../compute/security_groups/test_security_group_rules.py | 2 +- tempest/api/compute/servers/test_availability_zone.py | 2 +- tempest/api/compute/servers/test_list_server_filters.py | 2 +- tempest/api/compute/servers/test_list_servers_negative.py | 2 +- tempest/api/compute/servers/test_virtual_interfaces.py | 2 +- tempest/api/identity/admin/v2/test_endpoints.py | 2 +- tempest/api/identity/admin/v2/test_users.py | 4 ++-- tempest/api/identity/admin/v3/test_credentials.py | 2 +- tempest/api/identity/admin/v3/test_domains.py | 2 +- tempest/api/identity/admin/v3/test_endpoints.py | 2 +- tempest/api/identity/admin/v3/test_list_users.py | 2 +- tempest/api/identity/admin/v3/test_policies.py | 2 +- tempest/api/identity/admin/v3/test_regions.py | 2 +- tempest/api/identity/admin/v3/test_users.py | 2 +- tempest/api/identity/v3/test_tokens.py | 6 ++---- tempest/api/image/v1/test_image_members.py | 2 +- tempest/api/network/admin/test_metering_extensions.py | 4 ++-- tempest/api/volume/admin/test_volume_services.py | 8 ++++---- tempest/api/volume/test_availability_zone.py | 2 +- tempest/api/volume/test_volumes_negative.py | 8 ++++---- tempest/scenario/manager.py | 4 ++-- 32 files changed, 54 insertions(+), 58 deletions(-) diff --git a/tempest/api/compute/admin/test_agents.py b/tempest/api/compute/admin/test_agents.py index 31976ec7ab..69cbfb5dab 100644 --- a/tempest/api/compute/admin/test_agents.py +++ b/tempest/api/compute/admin/test_agents.py @@ -86,8 +86,7 @@ class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): body = self.client.create_agent(**self.params_agent)['agent'] self.addCleanup(self.client.delete_agent, body['agent_id']) agents = self.client.list_agents()['agents'] - self.assertGreater(len(agents), 0, - 'Cannot get any agents.(%s)' % agents) + self.assertNotEmpty(agents, 'Cannot get any agents.(%s)' % agents) self.assertIn(body['agent_id'], map(lambda x: x['agent_id'], agents)) @decorators.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408') @@ -105,8 +104,7 @@ class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): agent_id_xen = agent_xen['agent_id'] agents = (self.client.list_agents(hypervisor=agent_xen['hypervisor']) ['agents']) - self.assertGreater(len(agents), 0, - 'Cannot get any agents.(%s)' % agents) + self.assertNotEmpty(agents, 'Cannot get any agents.(%s)' % agents) self.assertIn(agent_id_xen, map(lambda x: x['agent_id'], agents)) self.assertNotIn(body['agent_id'], map(lambda x: x['agent_id'], agents)) diff --git a/tempest/api/compute/admin/test_availability_zone.py b/tempest/api/compute/admin/test_availability_zone.py index 50dec28b3c..bbd39b6859 100644 --- a/tempest/api/compute/admin/test_availability_zone.py +++ b/tempest/api/compute/admin/test_availability_zone.py @@ -29,10 +29,10 @@ class AZAdminV2TestJSON(base.BaseV2ComputeAdminTest): def test_get_availability_zone_list(self): # List of availability zone availability_zone = self.client.list_availability_zones() - self.assertGreater(len(availability_zone['availabilityZoneInfo']), 0) + self.assertNotEmpty(availability_zone['availabilityZoneInfo']) @decorators.idempotent_id('ef726c58-530f-44c2-968c-c7bed22d5b8c') def test_get_availability_zone_list_detail(self): # List of availability zones and available services availability_zone = self.client.list_availability_zones(detail=True) - self.assertGreater(len(availability_zone['availabilityZoneInfo']), 0) + self.assertNotEmpty(availability_zone['availabilityZoneInfo']) diff --git a/tempest/api/compute/admin/test_floating_ips_bulk.py b/tempest/api/compute/admin/test_floating_ips_bulk.py index 056b4bdc02..496f119949 100644 --- a/tempest/api/compute/admin/test_floating_ips_bulk.py +++ b/tempest/api/compute/admin/test_floating_ips_bulk.py @@ -73,7 +73,7 @@ class FloatingIPsBulkAdminTestJSON(base.BaseV2ComputeAdminTest): self.client.delete_floating_ips_bulk, self.ip_range) self.assertEqual(self.ip_range, body['ip_range']) ips_list = self.client.list_floating_ips_bulk()['floating_ip_info'] - self.assertNotEqual(0, len(ips_list)) + self.assertNotEmpty(ips_list) for ip in netaddr.IPNetwork(self.ip_range).iter_hosts(): self.assertIn(str(ip), map(lambda x: x['address'], ips_list)) body = (self.client.delete_floating_ips_bulk(self.ip_range) diff --git a/tempest/api/compute/admin/test_hosts.py b/tempest/api/compute/admin/test_hosts.py index 8e2f6edf57..5b3bb2c0ff 100644 --- a/tempest/api/compute/admin/test_hosts.py +++ b/tempest/api/compute/admin/test_hosts.py @@ -44,14 +44,14 @@ class HostsAdminTestJSON(base.BaseV2ComputeAdminTest): # If send the request with a blank zone, the request will be successful # and it will return all the hosts list hosts = self.client.list_hosts(zone='')['hosts'] - self.assertNotEqual(0, len(hosts)) + self.assertNotEmpty(hosts) @decorators.idempotent_id('c6ddbadb-c94e-4500-b12f-8ffc43843ff8') def test_list_hosts_with_nonexistent_zone(self): # If send the request with a nonexistent zone, the request will be # successful and no hosts will be returned hosts = self.client.list_hosts(zone='xxx')['hosts'] - self.assertEqual(0, len(hosts)) + self.assertEmpty(hosts) @decorators.idempotent_id('38adbb12-aee2-4498-8aec-329c72423aa4') def test_show_host_detail(self): diff --git a/tempest/api/compute/admin/test_hypervisor.py b/tempest/api/compute/admin/test_hypervisor.py index 4544267d01..0db802cf51 100644 --- a/tempest/api/compute/admin/test_hypervisor.py +++ b/tempest/api/compute/admin/test_hypervisor.py @@ -31,7 +31,7 @@ class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest): return hypers def assertHypervisors(self, hypers): - self.assertGreater(len(hypers), 0, "No hypervisors found: %s" % hypers) + self.assertNotEmpty(hypers, "No hypervisors found: %s" % hypers) @decorators.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5') def test_get_hypervisor_list(self): @@ -52,7 +52,7 @@ class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest): self.assertHypervisors(hypers) details = self.client.show_hypervisor(hypers[0]['id'])['hypervisor'] - self.assertGreater(len(details), 0) + self.assertNotEmpty(details) self.assertEqual(details['hypervisor_hostname'], hypers[0]['hypervisor_hostname']) @@ -65,14 +65,14 @@ class HypervisorAdminTestJSON(base.BaseV2ComputeAdminTest): hostname = hypers[0]['hypervisor_hostname'] hypervisors = (self.client.list_servers_on_hypervisor(hostname) ['hypervisors']) - self.assertGreater(len(hypervisors), 0) + self.assertNotEmpty(hypervisors) @decorators.idempotent_id('797e4f28-b6e0-454d-a548-80cc77c00816') def test_get_hypervisor_stats(self): # Verify the stats of the all hypervisor stats = (self.client.show_hypervisor_statistics() ['hypervisor_statistics']) - self.assertGreater(len(stats), 0) + self.assertNotEmpty(stats) @decorators.idempotent_id('91a50d7d-1c2b-4f24-b55a-a1fe20efca70') def test_get_hypervisor_uptime(self): diff --git a/tempest/api/compute/admin/test_hypervisor_negative.py b/tempest/api/compute/admin/test_hypervisor_negative.py index af872871fa..431e823bb4 100644 --- a/tempest/api/compute/admin/test_hypervisor_negative.py +++ b/tempest/api/compute/admin/test_hypervisor_negative.py @@ -47,7 +47,7 @@ class HypervisorAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @decorators.idempotent_id('51e663d0-6b89-4817-a465-20aca0667d03') def test_show_hypervisor_with_non_admin_user(self): hypers = self._list_hypervisors() - self.assertGreater(len(hypers), 0) + self.assertNotEmpty(hypers) self.assertRaises( lib_exc.Forbidden, @@ -58,7 +58,7 @@ class HypervisorAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @decorators.idempotent_id('2a0a3938-832e-4859-95bf-1c57c236b924') def test_show_servers_with_non_admin_user(self): hypers = self._list_hypervisors() - self.assertGreater(len(hypers), 0) + self.assertNotEmpty(hypers) self.assertRaises( lib_exc.Forbidden, @@ -96,7 +96,7 @@ class HypervisorAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @decorators.idempotent_id('6c3461f9-c04c-4e2a-bebb-71dc9cb47df2') def test_get_hypervisor_uptime_with_non_admin_user(self): hypers = self._list_hypervisors() - self.assertGreater(len(hypers), 0) + self.assertNotEmpty(hypers) self.assertRaises( lib_exc.Forbidden, @@ -131,7 +131,7 @@ class HypervisorAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @decorators.idempotent_id('5b6a6c79-5dc1-4fa5-9c58-9c8085948e74') def test_search_hypervisor_with_non_admin_user(self): hypers = self._list_hypervisors() - self.assertGreater(len(hypers), 0) + self.assertNotEmpty(hypers) self.assertRaises( lib_exc.Forbidden, diff --git a/tempest/api/compute/admin/test_security_group_default_rules.py b/tempest/api/compute/admin/test_security_group_default_rules.py index 6c7cde2709..f2f3b573e2 100644 --- a/tempest/api/compute/admin/test_security_group_default_rules.py +++ b/tempest/api/compute/admin/test_security_group_default_rules.py @@ -111,7 +111,7 @@ class SecurityGroupDefaultRulesTest(base.BaseV2ComputeAdminTest): rule['id']) rules = (self.adm_client.list_security_group_default_rules() ['security_group_default_rules']) - self.assertNotEqual(0, len(rules)) + self.assertNotEmpty(rules) self.assertIn(rule, rules) @decorators.idempotent_id('15cbb349-86b4-4f71-a048-04b7ef3f150b') diff --git a/tempest/api/compute/admin/test_services.py b/tempest/api/compute/admin/test_services.py index 1dfc13e6ae..f3eb597f95 100644 --- a/tempest/api/compute/admin/test_services.py +++ b/tempest/api/compute/admin/test_services.py @@ -29,13 +29,13 @@ class ServicesAdminTestJSON(base.BaseV2ComputeAdminTest): @decorators.idempotent_id('5be41ef4-53d1-41cc-8839-5c2a48a1b283') def test_list_services(self): services = self.client.list_services()['services'] - self.assertNotEqual(0, len(services)) + self.assertNotEmpty(services) @decorators.idempotent_id('f345b1ec-bc6e-4c38-a527-3ca2bc00bef5') def test_get_service_by_service_binary_name(self): binary_name = 'nova-compute' services = self.client.list_services(binary=binary_name)['services'] - self.assertNotEqual(0, len(services)) + self.assertNotEmpty(services) for service in services: self.assertEqual(binary_name, service['binary']) diff --git a/tempest/api/compute/admin/test_services_negative.py b/tempest/api/compute/admin/test_services_negative.py index 38bb5ec93e..201670ab29 100644 --- a/tempest/api/compute/admin/test_services_negative.py +++ b/tempest/api/compute/admin/test_services_negative.py @@ -48,7 +48,7 @@ class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): host_name = services[0]['host'] services = self.client.list_services(host=host_name, binary='xxx')['services'] - self.assertEqual(0, len(services)) + self.assertEmpty(services) @decorators.attr(type=['negative']) @decorators.idempotent_id('64e7e7fb-69e8-4cb6-a71d-8d5eb0c98655') @@ -57,4 +57,4 @@ class ServicesAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): binary_name = services[0]['binary'] services = self.client.list_services(host='xxx', binary=binary_name)['services'] - self.assertEqual(0, len(services)) + self.assertEmpty(services) diff --git a/tempest/api/compute/floating_ips/test_list_floating_ips.py b/tempest/api/compute/floating_ips/test_list_floating_ips.py index 74d2dc475d..913b992da5 100644 --- a/tempest/api/compute/floating_ips/test_list_floating_ips.py +++ b/tempest/api/compute/floating_ips/test_list_floating_ips.py @@ -58,7 +58,7 @@ class FloatingIPDetailsTestJSON(base.BaseV2ComputeTest): # Positive test:Should return the list of floating IPs body = self.client.list_floating_ips()['floating_ips'] floating_ips = body - self.assertNotEqual(0, len(floating_ips), + self.assertNotEmpty(floating_ips, "Expected floating IPs. Got zero.") for i in range(3): self.assertIn(self.floating_ip[i], floating_ips) @@ -90,5 +90,5 @@ class FloatingIPDetailsTestJSON(base.BaseV2ComputeTest): def test_list_floating_ip_pools(self): # Positive test:Should return the list of floating IP Pools floating_ip_pools = self.pools_client.list_floating_ip_pools() - self.assertNotEqual(0, len(floating_ip_pools['floating_ip_pools']), + self.assertNotEmpty(floating_ip_pools['floating_ip_pools'], "Expected floating IP Pools. Got zero.") diff --git a/tempest/api/compute/limits/test_absolute_limits.py b/tempest/api/compute/limits/test_absolute_limits.py index 58352bd90d..0585fec3d9 100644 --- a/tempest/api/compute/limits/test_absolute_limits.py +++ b/tempest/api/compute/limits/test_absolute_limits.py @@ -42,6 +42,6 @@ class AbsoluteLimitsTestJSON(base.BaseV2ComputeTest): # check whether all expected elements exist missing_elements =\ [ele for ele in expected_elements if ele not in absolute_limits] - self.assertEqual(0, len(missing_elements), + self.assertEmpty(missing_elements, "Failed to find element %s in absolute limits list" % ', '.join(ele for ele in missing_elements)) diff --git a/tempest/api/compute/security_groups/test_security_group_rules.py b/tempest/api/compute/security_groups/test_security_group_rules.py index 3378ef8f40..b568f7d09b 100644 --- a/tempest/api/compute/security_groups/test_security_group_rules.py +++ b/tempest/api/compute/security_groups/test_security_group_rules.py @@ -186,4 +186,4 @@ class SecurityGroupRulesTestJSON(base.BaseSecurityGroupsTest): rules = (self.security_groups_client.show_security_group(sg1_id) ['security_group']['rules']) # The group1 has no rules because group2 has deleted - self.assertEqual(0, len(rules)) + self.assertEmpty(rules) diff --git a/tempest/api/compute/servers/test_availability_zone.py b/tempest/api/compute/servers/test_availability_zone.py index 82e74ed9bc..36828d6b4b 100644 --- a/tempest/api/compute/servers/test_availability_zone.py +++ b/tempest/api/compute/servers/test_availability_zone.py @@ -29,4 +29,4 @@ class AZV2TestJSON(base.BaseV2ComputeTest): def test_get_availability_zone_list_with_non_admin_user(self): # List of availability zone with non-administrator user availability_zone = self.client.list_availability_zones() - self.assertGreater(len(availability_zone['availabilityZoneInfo']), 0) + self.assertNotEmpty(availability_zone['availabilityZoneInfo']) diff --git a/tempest/api/compute/servers/test_list_server_filters.py b/tempest/api/compute/servers/test_list_server_filters.py index 1ad153a87d..921b7da494 100644 --- a/tempest/api/compute/servers/test_list_server_filters.py +++ b/tempest/api/compute/servers/test_list_server_filters.py @@ -142,7 +142,7 @@ class ListServerFiltersTestJSON(base.BaseV2ComputeTest): # Verify only the expected number of servers are returned params = {'limit': 0} servers = self.client.list_servers(**params) - self.assertEqual(0, len(servers['servers'])) + self.assertEmpty(servers['servers']) @decorators.idempotent_id('37791bbd-90c0-4de0-831e-5f38cba9c6b3') def test_list_servers_filter_by_exceed_limit(self): diff --git a/tempest/api/compute/servers/test_list_servers_negative.py b/tempest/api/compute/servers/test_list_servers_negative.py index 0c402409e9..6c9b28772b 100644 --- a/tempest/api/compute/servers/test_list_servers_negative.py +++ b/tempest/api/compute/servers/test_list_servers_negative.py @@ -122,7 +122,7 @@ class ListServersNegativeTestJSON(base.BaseV2ComputeTest): # Return an empty list when a date in the future is passed changes_since = {'changes-since': '2051-01-01T12:34:00Z'} body = self.client.list_servers(**changes_since) - self.assertEqual(0, len(body['servers'])) + self.assertEmpty(body['servers']) @decorators.attr(type=['negative']) @decorators.idempotent_id('93055106-2d34-46fe-af68-d9ddbf7ee570') diff --git a/tempest/api/compute/servers/test_virtual_interfaces.py b/tempest/api/compute/servers/test_virtual_interfaces.py index 610121b04d..6b625d935f 100644 --- a/tempest/api/compute/servers/test_virtual_interfaces.py +++ b/tempest/api/compute/servers/test_virtual_interfaces.py @@ -58,7 +58,7 @@ class VirtualInterfacesTestJSON(base.BaseV2ComputeTest): output = self.client.list_virtual_interfaces(self.server['id']) self.assertIsNotNone(output) virt_ifaces = output - self.assertNotEqual(0, len(virt_ifaces['virtual_interfaces']), + self.assertNotEmpty(virt_ifaces['virtual_interfaces'], 'Expected virtual interfaces, got 0 ' 'interfaces.') for virt_iface in virt_ifaces['virtual_interfaces']: diff --git a/tempest/api/identity/admin/v2/test_endpoints.py b/tempest/api/identity/admin/v2/test_endpoints.py index db32f5a4db..59fc4d8c7f 100644 --- a/tempest/api/identity/admin/v2/test_endpoints.py +++ b/tempest/api/identity/admin/v2/test_endpoints.py @@ -62,7 +62,7 @@ class EndPointsTestJSON(base.BaseIdentityV2AdminTest): # Asserting LIST endpoints missing_endpoints =\ [e for e in self.setup_endpoints if e not in fetched_endpoints] - self.assertEqual(0, len(missing_endpoints), + self.assertEmpty(missing_endpoints, "Failed to find endpoint %s in fetched list" % ', '.join(str(e) for e in missing_endpoints)) diff --git a/tempest/api/identity/admin/v2/test_users.py b/tempest/api/identity/admin/v2/test_users.py index 2711a2dea7..0d98af5fa4 100644 --- a/tempest/api/identity/admin/v2/test_users.py +++ b/tempest/api/identity/admin/v2/test_users.py @@ -141,7 +141,7 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest): # verifying the user Id in the list missing_users =\ [user for user in user_ids if user not in fetched_user_ids] - self.assertEqual(0, len(missing_users), + self.assertEmpty(missing_users, "Failed to find user %s in fetched list" % ', '.join(m_user for m_user in missing_users)) @@ -169,7 +169,7 @@ class UsersTestJSON(base.BaseIdentityV2AdminTest): # verifying the user Id in the list missing_users = [missing_user for missing_user in user_ids if missing_user not in fetched_user_ids] - self.assertEqual(0, len(missing_users), + self.assertEmpty(missing_users, "Failed to find user %s in fetched list" % ', '.join(m_user for m_user in missing_users)) diff --git a/tempest/api/identity/admin/v3/test_credentials.py b/tempest/api/identity/admin/v3/test_credentials.py index 75e877a4d8..15b20081eb 100644 --- a/tempest/api/identity/admin/v3/test_credentials.py +++ b/tempest/api/identity/admin/v3/test_credentials.py @@ -107,6 +107,6 @@ class CredentialsTestJSON(base.BaseIdentityV3AdminTest): fetched_cred_ids.append(i['id']) missing_creds = [c for c in created_cred_ids if c not in fetched_cred_ids] - self.assertEqual(0, len(missing_creds), + self.assertEmpty(missing_creds, "Failed to find cred %s in fetched list" % ', '.join(m_cred for m_cred in missing_creds)) diff --git a/tempest/api/identity/admin/v3/test_domains.py b/tempest/api/identity/admin/v3/test_domains.py index cddba538cd..9fe978c9da 100644 --- a/tempest/api/identity/admin/v3/test_domains.py +++ b/tempest/api/identity/admin/v3/test_domains.py @@ -57,7 +57,7 @@ class DomainsTestJSON(base.BaseIdentityV3AdminTest): fetched_ids.append(d['id']) missing_doms = [d for d in self.setup_domains if d['id'] not in fetched_ids] - self.assertEqual(0, len(missing_doms)) + self.assertEmpty(missing_doms) @decorators.idempotent_id('c6aee07b-4981-440c-bb0b-eb598f58ffe9') def test_list_domains_filter_by_name(self): diff --git a/tempest/api/identity/admin/v3/test_endpoints.py b/tempest/api/identity/admin/v3/test_endpoints.py index 09f92e2a75..b1ae2aa9e2 100644 --- a/tempest/api/identity/admin/v3/test_endpoints.py +++ b/tempest/api/identity/admin/v3/test_endpoints.py @@ -64,7 +64,7 @@ class EndPointsTestJSON(base.BaseIdentityV3AdminTest): # Asserting LIST endpoints missing_endpoints =\ [e for e in self.setup_endpoints if e not in fetched_endpoints] - self.assertEqual(0, len(missing_endpoints), + self.assertEmpty(missing_endpoints, "Failed to find endpoint %s in fetched list" % ', '.join(str(e) for e in missing_endpoints)) diff --git a/tempest/api/identity/admin/v3/test_list_users.py b/tempest/api/identity/admin/v3/test_list_users.py index bcbf6b6faa..47a3580684 100644 --- a/tempest/api/identity/admin/v3/test_list_users.py +++ b/tempest/api/identity/admin/v3/test_list_users.py @@ -93,7 +93,7 @@ class UsersV3TestJSON(base.BaseIdentityV3AdminTest): fetched_ids = [u['id'] for u in body] missing_users = [u['id'] for u in self.users if u['id'] not in fetched_ids] - self.assertEqual(0, len(missing_users), + self.assertEmpty(missing_users, "Failed to find user %s in fetched list" % ', '.join(m_user for m_user in missing_users)) diff --git a/tempest/api/identity/admin/v3/test_policies.py b/tempest/api/identity/admin/v3/test_policies.py index 730d4698c4..960e2cb125 100644 --- a/tempest/api/identity/admin/v3/test_policies.py +++ b/tempest/api/identity/admin/v3/test_policies.py @@ -41,7 +41,7 @@ class PoliciesTestJSON(base.BaseIdentityV3AdminTest): for p in body: fetched_ids.append(p['id']) missing_pols = [p for p in policy_ids if p not in fetched_ids] - self.assertEqual(0, len(missing_pols)) + self.assertEmpty(missing_pols) @decorators.attr(type='smoke') @decorators.idempotent_id('e544703a-2f03-4cf2-9b0f-350782fdb0d3') diff --git a/tempest/api/identity/admin/v3/test_regions.py b/tempest/api/identity/admin/v3/test_regions.py index ac550a73ae..d00e408118 100644 --- a/tempest/api/identity/admin/v3/test_regions.py +++ b/tempest/api/identity/admin/v3/test_regions.py @@ -98,7 +98,7 @@ class RegionsTestJSON(base.BaseIdentityV3AdminTest): missing_regions =\ [e for e in self.setup_regions if e not in fetched_regions] # Asserting List Regions response - self.assertEqual(0, len(missing_regions), + self.assertEmpty(missing_regions, "Failed to find region %s in fetched list" % ', '.join(str(e) for e in missing_regions)) diff --git a/tempest/api/identity/admin/v3/test_users.py b/tempest/api/identity/admin/v3/test_users.py index 751962fc4f..409d4f8376 100644 --- a/tempest/api/identity/admin/v3/test_users.py +++ b/tempest/api/identity/admin/v3/test_users.py @@ -131,7 +131,7 @@ class UsersV3TestJSON(base.BaseIdentityV3AdminTest): missing_projects =\ [p for p in assigned_project_ids if p not in fetched_project_ids] - self.assertEqual(0, len(missing_projects), + self.assertEmpty(missing_projects, "Failed to find project %s in fetched list" % ', '.join(m_project for m_project in missing_projects)) diff --git a/tempest/api/identity/v3/test_tokens.py b/tempest/api/identity/v3/test_tokens.py index c9d7a4d1a5..042c821b94 100644 --- a/tempest/api/identity/v3/test_tokens.py +++ b/tempest/api/identity/v3/test_tokens.py @@ -54,15 +54,13 @@ class TokensV3Test(base.BaseIdentityV3Test): self.assertEqual(subject_id, user_id) else: # Expect a user ID, but don't know what it will be. - self.assertGreaterEqual(len(subject_id), 0, - 'Expected user ID in token.') + self.assertIsNotNone(subject_id, 'Expected user ID in token.') subject_name = resp['user']['name'] if username: self.assertEqual(subject_name, username) else: # Expect a user name, but don't know what it will be. - self.assertGreaterEqual(len(subject_name), 0, - 'Expected user name in token.') + self.assertIsNotNone(subject_name, 'Expected user name in token.') self.assertEqual(resp['methods'][0], 'password') diff --git a/tempest/api/image/v1/test_image_members.py b/tempest/api/image/v1/test_image_members.py index 4902316b1a..bf2e510ed5 100644 --- a/tempest/api/image/v1/test_image_members.py +++ b/tempest/api/image/v1/test_image_members.py @@ -54,6 +54,6 @@ class ImageMembersTest(base.BaseV1ImageMembersTest): self.alt_tenant_id) body = self.image_member_client.list_image_members(image_id) members = body['members'] - self.assertEqual(0, len(members), str(members)) + self.assertEmpty(members) self.assertRaises( lib_exc.NotFound, self.alt_img_cli.show_image, image_id) diff --git a/tempest/api/network/admin/test_metering_extensions.py b/tempest/api/network/admin/test_metering_extensions.py index 3f94868970..2b789e74c2 100644 --- a/tempest/api/network/admin/test_metering_extensions.py +++ b/tempest/api/network/admin/test_metering_extensions.py @@ -89,7 +89,7 @@ class MeteringTestJSON(base.BaseAdminNetworkTest): # Verify label filtering body = self.admin_metering_labels_client.list_metering_labels(id=33) metering_labels = body['metering_labels'] - self.assertEqual(0, len(metering_labels)) + self.assertEmpty(metering_labels) @decorators.idempotent_id('ec8e15ff-95d0-433b-b8a6-b466bddb1e50') def test_create_delete_metering_label_with_filters(self): @@ -126,7 +126,7 @@ class MeteringTestJSON(base.BaseAdminNetworkTest): # Verify rule filtering body = client.list_metering_label_rules(id=33) metering_label_rules = body['metering_label_rules'] - self.assertEqual(0, len(metering_label_rules)) + self.assertEmpty(metering_label_rules) @decorators.idempotent_id('f4d547cd-3aee-408f-bf36-454f8825e045') def test_create_delete_metering_label_rule_with_filters(self): diff --git a/tempest/api/volume/admin/test_volume_services.py b/tempest/api/volume/admin/test_volume_services.py index 4aab9c1f75..293af81ca4 100644 --- a/tempest/api/volume/admin/test_volume_services.py +++ b/tempest/api/volume/admin/test_volume_services.py @@ -41,13 +41,13 @@ class VolumesServicesTestJSON(base.BaseVolumeAdminTest): def test_list_services(self): services = (self.admin_volume_services_client.list_services() ['services']) - self.assertNotEqual(0, len(services)) + self.assertNotEmpty(services) @decorators.idempotent_id('63a3e1ca-37ee-4983-826d-83276a370d25') def test_get_service_by_service_binary_name(self): services = (self.admin_volume_services_client.list_services( binary=self.binary_name)['services']) - self.assertNotEqual(0, len(services)) + self.assertNotEmpty(services) for service in services: self.assertEqual(self.binary_name, service['binary']) @@ -76,7 +76,7 @@ class VolumesServicesTestJSON(base.BaseVolumeAdminTest): services = (self.admin_volume_services_client.list_services( host=hostname, binary='cinder-volume')['services']) - self.assertNotEqual(0, len(services), + self.assertNotEmpty(services, 'cinder-volume not found on host %s' % hostname) self.assertEqual(hostname, _get_host(services[0]['host'])) self.assertEqual('cinder-volume', services[0]['binary']) @@ -87,6 +87,6 @@ class VolumesServicesTestJSON(base.BaseVolumeAdminTest): services = (self.admin_volume_services_client.list_services( host=self.host_name, binary=self.binary_name))['services'] - self.assertNotEqual(0, len(services)) + self.assertNotEmpty(services) self.assertEqual(self.host_name, _get_host(services[0]['host'])) self.assertEqual(self.binary_name, services[0]['binary']) diff --git a/tempest/api/volume/test_availability_zone.py b/tempest/api/volume/test_availability_zone.py index 666efdf486..d0a87db591 100644 --- a/tempest/api/volume/test_availability_zone.py +++ b/tempest/api/volume/test_availability_zone.py @@ -30,4 +30,4 @@ class AvailabilityZoneTestJSON(base.BaseVolumeTest): # List of availability zone availability_zone = (self.client.list_availability_zones() ['availabilityZoneInfo']) - self.assertGreater(len(availability_zone), 0) + self.assertNotEmpty(availability_zone) diff --git a/tempest/api/volume/test_volumes_negative.py b/tempest/api/volume/test_volumes_negative.py index fc3bcab5db..9180088b8f 100644 --- a/tempest/api/volume/test_volumes_negative.py +++ b/tempest/api/volume/test_volumes_negative.py @@ -261,7 +261,7 @@ class VolumesNegativeTest(base.BaseVolumeTest): params = {'name': v_name} fetched_volume = self.volumes_client.list_volumes( params=params)['volumes'] - self.assertEqual(0, len(fetched_volume)) + self.assertEmpty(fetched_volume) @decorators.attr(type=['negative']) @decorators.idempotent_id('9ca17820-a0e7-4cbd-a7fa-f4468735e359') @@ -271,7 +271,7 @@ class VolumesNegativeTest(base.BaseVolumeTest): fetched_volume = \ self.volumes_client.list_volumes( detail=True, params=params)['volumes'] - self.assertEqual(0, len(fetched_volume)) + self.assertEmpty(fetched_volume) @decorators.attr(type=['negative']) @decorators.idempotent_id('143b279b-7522-466b-81be-34a87d564a7c') @@ -279,7 +279,7 @@ class VolumesNegativeTest(base.BaseVolumeTest): params = {'status': 'null'} fetched_volume = self.volumes_client.list_volumes( params=params)['volumes'] - self.assertEqual(0, len(fetched_volume)) + self.assertEmpty(fetched_volume) @decorators.attr(type=['negative']) @decorators.idempotent_id('ba94b27b-be3f-496c-a00e-0283b373fa75') @@ -288,7 +288,7 @@ class VolumesNegativeTest(base.BaseVolumeTest): fetched_volume = \ self.volumes_client.list_volumes(detail=True, params=params)['volumes'] - self.assertEqual(0, len(fetched_volume)) + self.assertEmpty(fetched_volume) @decorators.attr(type=['negative']) @decorators.idempotent_id('5b810c91-0ad1-47ce-aee8-615f789be78f') diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index a486a29cf3..1ca9365327 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -811,7 +811,7 @@ class NetworkScenarioTest(ScenarioTest): if inactive: LOG.warning("Instance has ports that are not ACTIVE: %s", inactive) - self.assertNotEqual(0, len(port_map), + self.assertNotEmpty(port_map, "No IPv4 addresses found in: %s" % ports) self.assertEqual(len(port_map), 1, "Found multiple IPv4 addresses: %s. " @@ -1029,7 +1029,7 @@ class NetworkScenarioTest(ScenarioTest): if sg['tenant_id'] == tenant_id and sg['name'] == 'default' ] msg = "No default security group for tenant %s." % (tenant_id) - self.assertGreater(len(sgs), 0, msg) + self.assertNotEmpty(sgs, msg) return sgs[0] def _create_security_group_rule(self, secgroup=None,