]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix order of parms in assertEqual for scheduler ut
authorJames Carey <jecarey@us.ibm.com>
Thu, 6 Aug 2015 05:13:15 +0000 (05:13 +0000)
committerJames Carey <jecarey@us.ibm.com>
Tue, 11 Aug 2015 05:25:24 +0000 (05:25 +0000)
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

cinder/tests/unit/scheduler/test_capacity_weigher.py
cinder/tests/unit/scheduler/test_filter_scheduler.py
cinder/tests/unit/scheduler/test_host_manager.py
cinder/tests/unit/scheduler/test_volume_number_weigher.py

index 7776fd633e783941344c1adc9a3b6dad0533d3b1..9d10f3b141819d04938be445f3a973c9f4d16c56 100644 (file)
@@ -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))
index d047e8f46785eca22eda0da6b4a4b8e4256e8e0e..b2c7dfc43b7639ef624ba04df0db1db64b27b6fd 100644 (file)
@@ -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):
index d2490939d826e60004edf8f69cc09024d5d10b04..732db311d17afc0cb6f890624487c6dc10a76385 100644 (file)
@@ -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)
index 82b4a09d4235bcfc8c97d63f0201a39d7a507a5c..b5b81c41a5c2e9414910b073f4c7f10c04c9a745 100644 (file)
@@ -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))