diff --git a/tempest/api/compute/admin/test_agents.py b/tempest/api/compute/admin/test_agents.py index 61359f1172..40cb5237bf 100644 --- a/tempest/api/compute/admin/test_agents.py +++ b/tempest/api/compute/admin/test_agents.py @@ -90,7 +90,8 @@ 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.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents) + self.assertGreater(len(agents), 0, + 'Cannot get any agents.(%s)' % agents) self.assertIn(body['agent_id'], map(lambda x: x['agent_id'], agents)) @test.idempotent_id('eabadde4-3cd7-4ec4-a4b5-5a936d2d4408') @@ -108,7 +109,8 @@ class AgentsAdminTestJSON(base.BaseV2ComputeAdminTest): agent_id_xen = agent_xen['agent_id'] agents = (self.client.list_agents(hypervisor=agent_xen['hypervisor']) ['agents']) - self.assertTrue(len(agents) > 0, 'Cannot get any agents.(%s)' % agents) + self.assertGreater(len(agents), 0, + '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_hosts.py b/tempest/api/compute/admin/test_hosts.py index 29e1eb84a6..3797b29900 100644 --- a/tempest/api/compute/admin/test_hosts.py +++ b/tempest/api/compute/admin/test_hosts.py @@ -28,7 +28,7 @@ class HostsAdminTestJSON(base.BaseV2ComputeAdminTest): @test.idempotent_id('9bfaf98d-e2cb-44b0-a07e-2558b2821e4f') def test_list_hosts(self): hosts = self.client.list_hosts()['hosts'] - self.assertTrue(len(hosts) >= 2, str(hosts)) + self.assertGreaterEqual(len(hosts), 2, str(hosts)) @test.idempotent_id('5dc06f5b-d887-47a2-bb2a-67762ef3c6de') def test_list_hosts_with_zone(self): diff --git a/tempest/api/compute/admin/test_hypervisor.py b/tempest/api/compute/admin/test_hypervisor.py index 92a9135da2..55134b1698 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.assertTrue(len(hypers) > 0, "No hypervisors found: %s" % hypers) + self.assertGreater(len(hypers), 0, "No hypervisors found: %s" % hypers) @test.idempotent_id('7f0ceacd-c64d-4e96-b8ee-d02943142cc5') def test_get_hypervisor_list(self): diff --git a/tempest/api/compute/keypairs/test_keypairs.py b/tempest/api/compute/keypairs/test_keypairs.py index be6f6150b0..562a508387 100644 --- a/tempest/api/compute/keypairs/test_keypairs.py +++ b/tempest/api/compute/keypairs/test_keypairs.py @@ -57,8 +57,8 @@ class KeyPairsV2TestJSON(base.BaseKeypairTest): self.assertEqual(key_name, k_name, "The created keypair name is not equal " "to the requested name") - self.assertTrue(private_key is not None, - "Field private_key is empty or not found.") + self.assertIsNotNone(private_key, + "Field private_key is empty or not found.") @test.idempotent_id('a4233d5d-52d8-47cc-9a25-e1864527e3df') def test_get_keypair_detail(self): @@ -72,8 +72,8 @@ class KeyPairsV2TestJSON(base.BaseKeypairTest): "The created keypair name is not equal " "to requested name") public_key = keypair_detail['public_key'] - self.assertTrue(public_key is not None, - "Field public_key is empty or not found.") + self.assertIsNotNone(public_key, + "Field public_key is empty or not found.") @test.idempotent_id('39c90c6a-304a-49dd-95ec-2366129def05') def test_keypair_create_with_pub_key(self): @@ -89,7 +89,7 @@ class KeyPairsV2TestJSON(base.BaseKeypairTest): "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws" "snSA8wzBx3A/8y9Pp1B nova@ubuntu") keypair = self._create_keypair(k_name, pub_key) - self.assertFalse('private_key' in keypair, + self.assertNotIn('private_key', keypair, "Field private_key is not empty!") key_name = keypair['name'] self.assertEqual(key_name, k_name, diff --git a/tempest/api/compute/servers/test_server_actions.py b/tempest/api/compute/servers/test_server_actions.py index 9077801ea9..50910ec8f3 100644 --- a/tempest/api/compute/servers/test_server_actions.py +++ b/tempest/api/compute/servers/test_server_actions.py @@ -131,8 +131,8 @@ class ServerActionsTestJSON(base.BaseV2ComputeTest): server=server, servers_client=self.client) new_boot_time = linux_client.get_boot_time() - self.assertTrue(new_boot_time > boot_time, - '%s > %s' % (new_boot_time, boot_time)) + self.assertGreater(new_boot_time, boot_time, + '%s > %s' % (new_boot_time, boot_time)) @test.attr(type='smoke') @test.idempotent_id('2cb1baf6-ac8d-4429-bf0d-ba8a0ba53e32') @@ -458,8 +458,8 @@ class ServerActionsTestJSON(base.BaseV2ComputeTest): # NOTE: This test tries to get full length console log, and the # length should be bigger than the one of test_get_console_output. - self.assertTrue(lines > 10, "Cannot get enough console log length." - " (lines: %s)" % lines) + self.assertGreater(lines, 10, "Cannot get enough console log " + "length. (lines: %s)" % lines) self.wait_for(_check_full_length_console_log) diff --git a/tempest/api/compute/volumes/test_volumes_get.py b/tempest/api/compute/volumes/test_volumes_get.py index d599431ed7..7549d4a1fc 100644 --- a/tempest/api/compute/volumes/test_volumes_get.py +++ b/tempest/api/compute/volumes/test_volumes_get.py @@ -54,8 +54,8 @@ class VolumesGetTestJSON(base.BaseV2ComputeTest): self.assertEqual(volume['displayName'], v_name, "The created volume name is not equal " "to the requested name") - self.assertTrue(volume['id'] is not None, - "Field volume id is empty or not found.") + self.assertIsNotNone(volume['id'], + "Field volume id is empty or not found.") # Wait for Volume status to become ACTIVE waiters.wait_for_volume_status(self.client, volume['id'], 'available') # GET Volume diff --git a/tempest/api/identity/admin/v2/test_services.py b/tempest/api/identity/admin/v2/test_services.py index 3ed51f0ddd..7973a03d2a 100644 --- a/tempest/api/identity/admin/v2/test_services.py +++ b/tempest/api/identity/admin/v2/test_services.py @@ -38,7 +38,7 @@ class ServicesTestJSON(base.BaseIdentityV2AdminTest): service_data = self.services_client.create_service( name=name, type=s_type, description=description)['OS-KSADM:service'] - self.assertFalse(service_data['id'] is None) + self.assertIsNotNone(service_data['id']) self.addCleanup(self._del_service, service_data['id']) # Verifying response body of create service self.assertIn('id', service_data) diff --git a/tempest/api/image/v1/test_images.py b/tempest/api/image/v1/test_images.py index 7d52695c3c..9fbdcd7870 100644 --- a/tempest/api/image/v1/test_images.py +++ b/tempest/api/image/v1/test_images.py @@ -238,7 +238,7 @@ class ListImagesTest(base.BaseV1ImageTest): def test_index_max_size(self): images_list = self.client.list_images(size_max=42)['images'] for image in images_list: - self.assertTrue(image['size'] <= 42) + self.assertLessEqual(image['size'], 42) result_set = set(map(lambda x: x['id'], images_list)) self.assertTrue(self.size42_set <= result_set) self.assertFalse(self.created_set - self.size42_set <= result_set) @@ -261,7 +261,7 @@ class ListImagesTest(base.BaseV1ImageTest): top_size = images_list[0]['size'] # We have non-zero sized images for image in images_list: size = image['size'] - self.assertTrue(size <= top_size) + self.assertLessEqual(size, top_size) top_size = size self.assertEqual(image['status'], 'active') diff --git a/tempest/api/image/v2/test_images.py b/tempest/api/image/v2/test_images.py index 6f8d2390ca..5cf8084557 100644 --- a/tempest/api/image/v2/test_images.py +++ b/tempest/api/image/v2/test_images.py @@ -224,9 +224,10 @@ class ListImagesTest(base.BaseV2ImageTest): image_size_list = map(lambda x: x['size'], images_list) for image_size in image_size_list: - self.assertTrue(image_size >= params['size_min'] and - image_size <= params['size_max'], - "Failed to get images by size_min and size_max") + self.assertGreaterEqual(image_size, params['size_min'], + "Failed to get images by size_min") + self.assertLessEqual(image_size, params['size_max'], + "Failed to get images by size_max") @test.idempotent_id('7fc9e369-0f58-4d05-9aa5-0969e2d59d15') def test_list_images_param_status(self): diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py index 33e5852063..eda4568536 100644 --- a/tempest/api/object_storage/test_account_services.py +++ b/tempest/api/object_storage/test_account_services.py @@ -121,7 +121,7 @@ class AccountTest(base.BaseObjectTest): self.assertHeaders(resp, 'Account', 'GET') self.assertIsNotNone(container_list) self.assertEqual(container_list.tag, 'account') - self.assertTrue('name' in container_list.keys()) + self.assertIn('name', container_list.keys()) self.assertEqual(container_list.find(".//container").tag, 'container') self.assertEqual(container_list.find(".//name").tag, 'name') self.assertEqual(container_list.find(".//count").tag, 'count') @@ -209,7 +209,8 @@ class AccountTest(base.BaseObjectTest): self.account_client.list_account_containers(params=params) self.assertHeaders(resp, 'Account', 'GET') - self.assertTrue(len(container_list) <= limit, str(container_list)) + self.assertLessEqual(len(container_list), limit, + str(container_list)) @test.idempotent_id('888a3f0e-7214-4806-8e50-5e0c9a69bb5e') def test_list_containers_with_limit_and_end_marker(self): diff --git a/tempest/api/object_storage/test_container_services.py b/tempest/api/object_storage/test_container_services.py index dbe8b4a8b6..9ce1b18500 100644 --- a/tempest/api/object_storage/test_container_services.py +++ b/tempest/api/object_storage/test_container_services.py @@ -205,7 +205,7 @@ class ContainerTest(base.BaseObjectTest): self.assertIsNotNone(object_list) self.assertEqual(object_list.tag, 'container') - self.assertTrue('name' in object_list.keys()) + self.assertIn('name', object_list.keys()) self.assertEqual(object_list.find(".//object").tag, 'object') self.assertEqual(object_list.find(".//name").tag, 'name') self.assertEqual(object_list.find(".//hash").tag, 'hash') diff --git a/tempest/api/orchestration/stacks/test_nova_keypair_resources.py b/tempest/api/orchestration/stacks/test_nova_keypair_resources.py index 160bf6fccf..16d8180c5d 100644 --- a/tempest/api/orchestration/stacks/test_nova_keypair_resources.py +++ b/tempest/api/orchestration/stacks/test_nova_keypair_resources.py @@ -83,7 +83,7 @@ class NovaKeyPairResourcesYAMLTest(base.BaseOrchestrationTest): output_map['KeyPairDontSavePrivate_PublicKey']) self.assertIn(u'KeyPairDontSavePrivate_PrivateKey', output_map) private_key = output_map['KeyPairDontSavePrivate_PrivateKey'] - self.assertTrue(len(private_key) == 0) + self.assertEqual(0, len(private_key)) class NovaKeyPairResourcesAWSTest(NovaKeyPairResourcesYAMLTest): diff --git a/tempest/api/volume/admin/test_multi_backend.py b/tempest/api/volume/admin/test_multi_backend.py index 120dbb1417..570331356d 100644 --- a/tempest/api/volume/admin/test_multi_backend.py +++ b/tempest/api/volume/admin/test_multi_backend.py @@ -129,7 +129,7 @@ class VolumeMultiBackendV2Test(base.BaseVolumeAdminTest): volume1_host = volume['os-vol-host-attr:host'] msg = ("multi-backend reporting incorrect values for volume %s" % volume_id) - self.assertTrue(len(volume1_host.split("@")) > 1, msg) + self.assertGreater(len(volume1_host.split("@")), 1, msg) def _test_backend_name_distinction(self, volume_id_list): # this test checks that the volumes created at setUp don't diff --git a/tempest/api/volume/admin/test_volume_hosts.py b/tempest/api/volume/admin/test_volume_hosts.py index b58c5255a3..f6de9a68b8 100644 --- a/tempest/api/volume/admin/test_volume_hosts.py +++ b/tempest/api/volume/admin/test_volume_hosts.py @@ -22,8 +22,8 @@ class VolumeHostsAdminV2TestsJSON(base.BaseVolumeAdminTest): @test.idempotent_id('d5f3efa2-6684-4190-9ced-1c2f526352ad') def test_list_hosts(self): hosts = self.admin_hosts_client.list_hosts()['hosts'] - self.assertTrue(len(hosts) >= 2, "No. of hosts are < 2," - "response of list hosts is: % s" % hosts) + self.assertGreaterEqual(len(hosts), 2, "No. of hosts are < 2," + "response of list hosts is: % s" % hosts) class VolumeHostsAdminV1TestsJSON(VolumeHostsAdminV2TestsJSON): diff --git a/tempest/api/volume/admin/test_volume_types.py b/tempest/api/volume/admin/test_volume_types.py index 99f0a6b984..eb6500c5e2 100644 --- a/tempest/api/volume/admin/test_volume_types.py +++ b/tempest/api/volume/admin/test_volume_types.py @@ -102,8 +102,8 @@ class VolumeTypesV2Test(base.BaseVolumeAdminTest): self.assertEqual(description, body['description'], "The created volume_type_description name is " "not equal to the requested name") - self.assertTrue(body['id'] is not None, - "Field volume_type id is empty or not found.") + self.assertIsNotNone(body['id'], + "Field volume_type id is empty or not found.") fetched_volume_type = self.admin_volume_types_client.show_volume_type( body['id'])['volume_type'] self.assertEqual(name, fetched_volume_type['name'], diff --git a/tempest/api/volume/test_volumes_get.py b/tempest/api/volume/test_volumes_get.py index 07f799b383..51de2be9d1 100644 --- a/tempest/api/volume/test_volumes_get.py +++ b/tempest/api/volume/test_volumes_get.py @@ -54,8 +54,8 @@ class VolumesV2GetTest(base.BaseVolumeTest): self.assertEqual(volume[self.name_field], v_name, "The created volume name is not equal " "to the requested name") - self.assertTrue(volume['id'] is not None, - "Field volume id is empty or not found.") + self.assertIsNotNone(volume['id'], + "Field volume id is empty or not found.") # Get Volume information fetched_volume = self.client.show_volume(volume['id'])['volume'] self.assertEqual(v_name, diff --git a/tempest/api/volume/v2/test_volumes_list.py b/tempest/api/volume/v2/test_volumes_list.py index 60a35b0095..771702781b 100644 --- a/tempest/api/volume/v2/test_volumes_list.py +++ b/tempest/api/volume/v2/test_volumes_list.py @@ -73,11 +73,9 @@ class VolumesV2ListTestJSON(base.BaseVolumeTest): val0 = fetched_volume[0][sort_key] val1 = fetched_volume[1][sort_key] if sort_dir == 'asc': - self.assertTrue(val0 < val1, - "%s < %s" % (val0, val1)) + self.assertLess(val0, val1, "%s < %s" % (val0, val1)) elif sort_dir == 'desc': - self.assertTrue(val0 > val1, - "%s > %s" % (val0, val1)) + self.assertGreater(val0, val1, "%s > %s" % (val0, val1)) _list_details_with_multiple_params() _list_details_with_multiple_params(sort_dir='desc') diff --git a/tempest/scenario/manager.py b/tempest/scenario/manager.py index dd1adc79c9..2215c80848 100644 --- a/tempest/scenario/manager.py +++ b/tempest/scenario/manager.py @@ -1019,7 +1019,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.assertTrue(len(sgs) > 0, msg) + self.assertGreater(len(sgs), 0, msg) return sgs[0] def _create_security_group_rule(self, secgroup=None, diff --git a/tempest/test.py b/tempest/test.py index b75ae481e5..93fbed3bb2 100644 --- a/tempest/test.py +++ b/tempest/test.py @@ -610,10 +610,10 @@ class BaseTestCase(testtools.testcase.WithAttributes, cred_provider, networks_client, CONF.compute.fixed_network_name) def assertEmpty(self, list, msg=None): - self.assertTrue(len(list) == 0, msg) + self.assertEqual(0, len(list), msg) def assertNotEmpty(self, list, msg=None): - self.assertTrue(len(list) > 0, msg) + self.assertGreater(len(list), 0, msg) call_until_true = debtcollector.moves.moved_function( diff --git a/tempest/tests/common/test_waiters.py b/tempest/tests/common/test_waiters.py index b113c04ceb..46f9526e21 100644 --- a/tempest/tests/common/test_waiters.py +++ b/tempest/tests/common/test_waiters.py @@ -37,7 +37,7 @@ class TestImageWaiters(base.TestCase): waiters.wait_for_image_status(self.client, 'fake_image_id', 'active') end_time = int(time.time()) # Ensure waiter returns before build_timeout - self.assertTrue((end_time - start_time) < 10) + self.assertLess((end_time - start_time), 10) def test_wait_for_image_status_timeout(self): time_mock = self.patch('time.time')