From 3283ce500493d4908e91e002dc82b81e4468b26e Mon Sep 17 00:00:00 2001 From: Ollie Leahy Date: Thu, 4 Jul 2013 13:58:08 +0000 Subject: [PATCH] Scheduler should not select down volume managers Currently volume managers that are not disabled, but are not running may be selected by the scheduler for volume creation operations. Change-Id: Ia06a3da8b31eef918d55aaaf71f863683c721026 Fixes: bug #1197741 --- cinder/scheduler/host_manager.py | 1 + cinder/tests/scheduler/test_host_manager.py | 29 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cinder/scheduler/host_manager.py b/cinder/scheduler/host_manager.py index f1f51487b..2683f8715 100644 --- a/cinder/scheduler/host_manager.py +++ b/cinder/scheduler/host_manager.py @@ -263,6 +263,7 @@ class HostManager(object): # Get resource usage across the available volume nodes: topic = CONF.volume_topic volume_services = db.service_get_all_by_topic(context, topic) + self.host_state_map.clear() for service in volume_services: host = service['host'] if not utils.service_is_up(service) or service['disabled']: diff --git a/cinder/tests/scheduler/test_host_manager.py b/cinder/tests/scheduler/test_host_manager.py index 960d59bd6..c6588785f 100644 --- a/cinder/tests/scheduler/test_host_manager.py +++ b/cinder/tests/scheduler/test_host_manager.py @@ -141,9 +141,28 @@ class HostManagerTestCase(test.TestCase): self.mox.StubOutWithMock(db, 'service_get_all_by_topic') self.mox.StubOutWithMock(host_manager.LOG, 'warn') + self.mox.StubOutWithMock(host_manager.utils, 'service_is_up') ret_services = fakes.VOLUME_SERVICES db.service_get_all_by_topic(context, topic).AndReturn(ret_services) + host_manager.utils.service_is_up(ret_services[0]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[1]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[2]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[3]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[4]).AndReturn(True) + # Disabled service + host_manager.LOG.warn("volume service is down or disabled. " + "(host: host5)") + + db.service_get_all_by_topic(context, topic).AndReturn(ret_services) + host_manager.utils.service_is_up(ret_services[0]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[1]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[2]).AndReturn(True) + host_manager.utils.service_is_up(ret_services[3]).AndReturn(False) + # Stopped service + host_manager.LOG.warn("volume service is down or disabled. " + "(host: host4)") + host_manager.utils.service_is_up(ret_services[4]).AndReturn(True) # Disabled service host_manager.LOG.warn("volume service is down or disabled. " "(host: host5)") @@ -160,6 +179,16 @@ class HostManagerTestCase(test.TestCase): self.assertEqual(host_state_map[host].service, volume_node) + self.host_manager.get_all_host_states(context) + host_state_map = self.host_manager.host_state_map + + self.assertEqual(len(host_state_map), 3) + for i in xrange(3): + volume_node = fakes.VOLUME_SERVICES[i] + host = volume_node['host'] + self.assertEqual(host_state_map[host].service, + volume_node) + class HostStateTestCase(test.TestCase): """Test case for HostState class""" -- 2.45.2