From 8508556da66bbd66c0739d1d0bf9e9cea796e74f Mon Sep 17 00:00:00 2001 From: James Carey Date: Thu, 6 Aug 2015 05:13:15 +0000 Subject: [PATCH] Fix order of parms in assertEqual for scheduler ut When assertEqual is used it should be assertEqual(expected, observed). Constant values are always the expected. This patch makes them the first parameter and fixes some other non-constant cases. Closes-Bug: #1482373 Change-Id: Iec771d35d1005434281f9efd8bed8d53134abc7f --- .../unit/scheduler/test_capacity_weigher.py | 15 ++++++--------- .../unit/scheduler/test_filter_scheduler.py | 10 +++++----- cinder/tests/unit/scheduler/test_host_manager.py | 16 ++++++++-------- .../unit/scheduler/test_volume_number_weigher.py | 12 ++++++------ 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/cinder/tests/unit/scheduler/test_capacity_weigher.py b/cinder/tests/unit/scheduler/test_capacity_weigher.py index 7776fd633..9d10f3b14 100644 --- a/cinder/tests/unit/scheduler/test_capacity_weigher.py +++ b/cinder/tests/unit/scheduler/test_capacity_weigher.py @@ -83,9 +83,8 @@ class CapacityWeigherTestCase(test.TestCase): # so, host2 should win: weighed_host = self._get_weighed_host(hostinfo_list) - self.assertEqual(weighed_host.weight, 1.0) - self.assertEqual( - utils.extract_host(weighed_host.obj.host), 'host2') + self.assertEqual(1.0, weighed_host.weight) + self.assertEqual('host2', utils.extract_host(weighed_host.obj.host)) def test_capacity_weight_multiplier1(self): self.flags(capacity_weight_multiplier=-1.0) @@ -111,9 +110,8 @@ class CapacityWeigherTestCase(test.TestCase): # so, host4 should win: weighed_host = self._get_weighed_host(hostinfo_list) - self.assertEqual(weighed_host.weight, 0.0) - self.assertEqual( - utils.extract_host(weighed_host.obj.host), 'host4') + self.assertEqual(0.0, weighed_host.weight) + self.assertEqual('host4', utils.extract_host(weighed_host.obj.host)) def test_capacity_weight_multiplier2(self): self.flags(capacity_weight_multiplier=2.0) @@ -139,6 +137,5 @@ class CapacityWeigherTestCase(test.TestCase): # so, host2 should win: weighed_host = self._get_weighed_host(hostinfo_list) - self.assertEqual(weighed_host.weight, 1.0 * 2) - self.assertEqual( - utils.extract_host(weighed_host.obj.host), 'host2') + self.assertEqual(1.0 * 2, weighed_host.weight) + self.assertEqual('host2', utils.extract_host(weighed_host.obj.host)) diff --git a/cinder/tests/unit/scheduler/test_filter_scheduler.py b/cinder/tests/unit/scheduler/test_filter_scheduler.py index d047e8f46..b2c7dfc43 100644 --- a/cinder/tests/unit/scheduler/test_filter_scheduler.py +++ b/cinder/tests/unit/scheduler/test_filter_scheduler.py @@ -288,7 +288,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): 'size': 1}} ret_host = sched.host_passes_filters(ctx, 'host1#lvm1', request_spec, {}) - self.assertEqual(utils.extract_host(ret_host.host), 'host1') + self.assertEqual('host1', utils.extract_host(ret_host.host)) self.assertTrue(_mock_service_get_topic.called) @mock.patch('cinder.db.service_get_all_by_topic') @@ -303,7 +303,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): 'size': 1}} ret_host = sched.host_passes_filters(ctx, 'host5#_pool0', request_spec, {}) - self.assertEqual(utils.extract_host(ret_host.host), 'host5') + self.assertEqual('host5', utils.extract_host(ret_host.host)) self.assertTrue(_mock_service_get_topic.called) @mock.patch('cinder.db.service_get_all_by_topic') @@ -338,7 +338,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): host_state = sched.find_retype_host(ctx, request_spec, filter_properties={}, migration_policy='never') - self.assertEqual(utils.extract_host(host_state.host), 'host4') + self.assertEqual('host4', utils.extract_host(host_state.host)) @mock.patch('cinder.db.service_get_all_by_topic') def test_retype_with_pool_policy_never_migrate_pass( @@ -359,7 +359,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): host_state = sched.find_retype_host(ctx, request_spec, filter_properties={}, migration_policy='never') - self.assertEqual(host_state.host, 'host3#lvm3') + self.assertEqual('host3#lvm3', host_state.host) @mock.patch('cinder.db.service_get_all_by_topic') def test_retype_policy_never_migrate_fail(self, _mock_service_get_topic): @@ -394,7 +394,7 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): host_state = sched.find_retype_host(ctx, request_spec, filter_properties={}, migration_policy='on-demand') - self.assertEqual(utils.extract_host(host_state.host), 'host1') + self.assertEqual('host1', utils.extract_host(host_state.host)) @mock.patch('cinder.db.service_get_all_by_topic') def test_retype_policy_demand_migrate_fail(self, _mock_service_get_topic): diff --git a/cinder/tests/unit/scheduler/test_host_manager.py b/cinder/tests/unit/scheduler/test_host_manager.py index d2490939d..732db311d 100644 --- a/cinder/tests/unit/scheduler/test_host_manager.py +++ b/cinder/tests/unit/scheduler/test_host_manager.py @@ -103,7 +103,7 @@ class HostManagerTestCase(test.TestCase): host3_volume_capabs) # Make sure dictionary isn't re-assigned - self.assertEqual(self.host_manager.service_states, service_states) + self.assertEqual(service_states, self.host_manager.service_states) # Make sure original dictionary wasn't copied self.assertEqual(1, host1_volume_capabs['timestamp']) @@ -114,7 +114,7 @@ class HostManagerTestCase(test.TestCase): expected = {'host1': host1_volume_capabs, 'host2': host2_volume_capabs, 'host3': host3_volume_capabs} - self.assertDictMatch(service_states, expected) + self.assertDictMatch(expected, service_states) @mock.patch('cinder.utils.service_is_up') @mock.patch('cinder.db.service_get_all_by_topic') @@ -257,7 +257,7 @@ class HostManagerTestCase(test.TestCase): for i in range(3): volume_node = services[i] host = volume_node['host'] - self.assertEqual(host_state_map[host].service, volume_node) + self.assertEqual(volume_node, host_state_map[host].service) # Second test: Now service_is_up returns False for host3 _mock_service_is_up.reset_mock() @@ -283,8 +283,8 @@ class HostManagerTestCase(test.TestCase): for i in range(2): volume_node = services[i] host = volume_node['host'] - self.assertEqual(host_state_map[host].service, - volume_node) + self.assertEqual(volume_node, + host_state_map[host].service) @mock.patch('cinder.db.service_get_all_by_topic') @mock.patch('cinder.utils.service_is_up') @@ -399,7 +399,7 @@ class HostStateTestCase(test.TestCase): # Test update for existing host state volume_capability.update(dict(total_capacity_gb=1000)) fake_host.update_from_volume_capability(volume_capability) - self.assertEqual(fake_host.pools['_pool0'].total_capacity_gb, 1000) + self.assertEqual(1000, fake_host.pools['_pool0'].total_capacity_gb) # Test update for existing host state with different backend name volume_capability.update(dict(volume_backend_name='magic')) @@ -552,8 +552,8 @@ class HostStateTestCase(test.TestCase): vol_cap = {'timestamp': None} fake_host.update_from_volume_capability(vol_cap) - self.assertEqual(fake_host.total_capacity_gb, 0) - self.assertEqual(fake_host.free_capacity_gb, None) + self.assertEqual(0, fake_host.total_capacity_gb) + self.assertEqual(None, fake_host.free_capacity_gb) # Pool stats has been updated self.assertEqual(0, fake_host.pools['_pool0'].total_capacity_gb) diff --git a/cinder/tests/unit/scheduler/test_volume_number_weigher.py b/cinder/tests/unit/scheduler/test_volume_number_weigher.py index 82b4a09d4..b5b81c41a 100644 --- a/cinder/tests/unit/scheduler/test_volume_number_weigher.py +++ b/cinder/tests/unit/scheduler/test_volume_number_weigher.py @@ -85,9 +85,9 @@ class VolumeNumberWeigherTestCase(test.TestCase): with mock.patch.object(api, 'volume_data_get_for_host', fake_volume_data_get_for_host): weighed_host = self._get_weighed_host(hostinfo_list) - self.assertEqual(weighed_host.weight, 0.0) - self.assertEqual(utils.extract_host(weighed_host.obj.host), - 'host1') + self.assertEqual(0.0, weighed_host.weight) + self.assertEqual('host1', + utils.extract_host(weighed_host.obj.host)) def test_volume_number_weight_multiplier2(self): self.flags(volume_number_multiplier=1.0) @@ -102,6 +102,6 @@ class VolumeNumberWeigherTestCase(test.TestCase): with mock.patch.object(api, 'volume_data_get_for_host', fake_volume_data_get_for_host): weighed_host = self._get_weighed_host(hostinfo_list) - self.assertEqual(weighed_host.weight, 1.0) - self.assertEqual(utils.extract_host(weighed_host.obj.host), - 'host5') + self.assertEqual(1.0, weighed_host.weight) + self.assertEqual('host5', + utils.extract_host(weighed_host.obj.host)) -- 2.45.2