Merge "Add disabled kwarg to service_get_all_by_topic"
This commit is contained in:
commit
07f231c5ef
|
@ -88,10 +88,12 @@ class API(base.Base):
|
|||
"""Check if there is a backup service available."""
|
||||
topic = CONF.backup_topic
|
||||
ctxt = context.get_admin_context()
|
||||
services = self.db.service_get_all_by_topic(ctxt, topic)
|
||||
services = self.db.service_get_all_by_topic(ctxt,
|
||||
topic,
|
||||
disabled=False)
|
||||
for srv in services:
|
||||
if (srv['availability_zone'] == volume['availability_zone'] and
|
||||
srv['host'] == volume_host and not srv['disabled'] and
|
||||
srv['host'] == volume_host and
|
||||
utils.service_is_up(srv)):
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -99,9 +99,9 @@ def service_get_all(context, disabled=None):
|
|||
return IMPL.service_get_all(context, disabled)
|
||||
|
||||
|
||||
def service_get_all_by_topic(context, topic):
|
||||
def service_get_all_by_topic(context, topic, disabled=None):
|
||||
"""Get all services for a given topic."""
|
||||
return IMPL.service_get_all_by_topic(context, topic)
|
||||
return IMPL.service_get_all_by_topic(context, topic, disabled=disabled)
|
||||
|
||||
|
||||
def service_get_all_by_host(context, host):
|
||||
|
|
|
@ -279,12 +279,15 @@ def service_get_all(context, disabled=None):
|
|||
|
||||
|
||||
@require_admin_context
|
||||
def service_get_all_by_topic(context, topic):
|
||||
return model_query(
|
||||
def service_get_all_by_topic(context, topic, disabled=None):
|
||||
query = model_query(
|
||||
context, models.Service, read_deleted="no").\
|
||||
filter_by(disabled=False).\
|
||||
filter_by(topic=topic).\
|
||||
all()
|
||||
filter_by(topic=topic)
|
||||
|
||||
if disabled is not None:
|
||||
query = query.filter_by(disabled=disabled)
|
||||
|
||||
return query.all()
|
||||
|
||||
|
||||
@require_admin_context
|
||||
|
|
|
@ -289,13 +289,14 @@ 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)
|
||||
volume_services = db.service_get_all_by_topic(context,
|
||||
topic,
|
||||
disabled=False)
|
||||
active_hosts = set()
|
||||
for service in volume_services:
|
||||
host = service['host']
|
||||
if not utils.service_is_up(service) or service['disabled']:
|
||||
LOG.warn(_("volume service is down or disabled. "
|
||||
"(host: %s)") % host)
|
||||
if not utils.service_is_up(service):
|
||||
LOG.warn(_("volume service is down. (host: %s)") % host)
|
||||
continue
|
||||
capabilities = self.service_states.get(host, None)
|
||||
host_state = self.host_state_map.get(host)
|
||||
|
|
|
@ -512,10 +512,7 @@ class BackupsAPITestCase(test.TestCase):
|
|||
az_not_match = [{'availability_zone': "strange_az", 'host': test_host,
|
||||
'disabled': 0, 'updated_at': timeutils.utcnow()}]
|
||||
#service disabled
|
||||
disabled_service = [{'availability_zone': "fake_az",
|
||||
'host': test_host,
|
||||
'disabled': 1,
|
||||
'updated_at': timeutils.utcnow()}]
|
||||
disabled_service = []
|
||||
|
||||
#dead service that last reported at 20th century
|
||||
dead_service = [{'availability_zone': "fake_az", 'host': alt_host,
|
||||
|
|
|
@ -66,7 +66,7 @@ class FakeHostState(host_manager.HostState):
|
|||
setattr(self, key, val)
|
||||
|
||||
|
||||
def mock_host_manager_db_calls(mock_obj):
|
||||
def mock_host_manager_db_calls(mock_obj, disabled=None):
|
||||
services = [
|
||||
dict(id=1, host='host1', topic='volume', disabled=False,
|
||||
availability_zone='zone1', updated_at=timeutils.utcnow()),
|
||||
|
@ -80,4 +80,8 @@ def mock_host_manager_db_calls(mock_obj):
|
|||
dict(id=5, host='host5', topic='volume', disabled=True,
|
||||
availability_zone='zone4', updated_at=timeutils.utcnow()),
|
||||
]
|
||||
mock_obj.return_value = services
|
||||
if disabled is None:
|
||||
mock_obj.return_value = services
|
||||
else:
|
||||
mock_obj.return_value = [service for service in services
|
||||
if service['disabled'] == disabled]
|
||||
|
|
|
@ -42,12 +42,13 @@ class AllocatedCapacityWeigherTestCase(test.TestCase):
|
|||
weight_properties)[0]
|
||||
|
||||
@mock.patch('cinder.db.sqlalchemy.api.service_get_all_by_topic')
|
||||
def _get_all_hosts(self, _mock_service_get_all_by_topic):
|
||||
def _get_all_hosts(self, _mock_service_get_all_by_topic, disabled=False):
|
||||
ctxt = context.get_admin_context()
|
||||
fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
|
||||
fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic,
|
||||
disabled=disabled)
|
||||
host_states = self.host_manager.get_all_host_states(ctxt)
|
||||
_mock_service_get_all_by_topic.assert_called_once_with(
|
||||
ctxt, CONF.volume_topic)
|
||||
ctxt, CONF.volume_topic, disabled=disabled)
|
||||
return host_states
|
||||
|
||||
def test_default_of_spreading_first(self):
|
||||
|
|
|
@ -43,12 +43,13 @@ class CapacityWeigherTestCase(test.TestCase):
|
|||
weight_properties)[0]
|
||||
|
||||
@mock.patch('cinder.db.sqlalchemy.api.service_get_all_by_topic')
|
||||
def _get_all_hosts(self, _mock_service_get_all_by_topic):
|
||||
def _get_all_hosts(self, _mock_service_get_all_by_topic, disabled=False):
|
||||
ctxt = context.get_admin_context()
|
||||
fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic)
|
||||
fakes.mock_host_manager_db_calls(_mock_service_get_all_by_topic,
|
||||
disabled=disabled)
|
||||
host_states = self.host_manager.get_all_host_states(ctxt)
|
||||
_mock_service_get_all_by_topic.assert_called_once_with(
|
||||
ctxt, CONF.volume_topic)
|
||||
ctxt, CONF.volume_topic, disabled=disabled)
|
||||
return host_states
|
||||
|
||||
def test_default_of_spreading_first(self):
|
||||
|
|
|
@ -133,9 +133,6 @@ class HostManagerTestCase(test.TestCase):
|
|||
availability_zone='zone2', updated_at=timeutils.utcnow()),
|
||||
dict(id=4, host='host4', topic='volume', disabled=False,
|
||||
availability_zone='zone3', updated_at=timeutils.utcnow()),
|
||||
# service on host5 is disabled
|
||||
dict(id=5, host='host5', topic='volume', disabled=True,
|
||||
availability_zone='zone4', updated_at=timeutils.utcnow()),
|
||||
]
|
||||
|
||||
# First test: service_is_up is always True, host5 is disabled
|
||||
|
@ -144,15 +141,15 @@ class HostManagerTestCase(test.TestCase):
|
|||
_mock_warning = mock.Mock()
|
||||
host_manager.LOG.warn = _mock_warning
|
||||
|
||||
# Get all states, make sure host5 is reported as down/disabled
|
||||
# Get all states
|
||||
self.host_manager.get_all_host_states(context)
|
||||
_mock_service_get_all_by_topic.assert_called_with(context, topic)
|
||||
_mock_service_get_all_by_topic.assert_called_with(context,
|
||||
topic,
|
||||
disabled=False)
|
||||
expected = []
|
||||
for service in services:
|
||||
expected.append(mock.call(service))
|
||||
self.assertEqual(expected, _mock_service_is_up.call_args_list)
|
||||
_mock_warning.assert_called_with("volume service is down or disabled. "
|
||||
"(host: host5)")
|
||||
|
||||
# Get host_state_map and make sure we have the first 4 hosts
|
||||
host_state_map = self.host_manager.host_state_map
|
||||
|
@ -164,20 +161,22 @@ class HostManagerTestCase(test.TestCase):
|
|||
|
||||
# Second test: Now service_is_up returns False for host4
|
||||
_mock_service_is_up.reset_mock()
|
||||
_mock_service_is_up.side_effect = [True, True, True, False, True]
|
||||
_mock_service_is_up.side_effect = [True, True, True, False]
|
||||
_mock_service_get_all_by_topic.reset_mock()
|
||||
_mock_warning.reset_mock()
|
||||
|
||||
# Get all states, make sure hosts 4 and 5 is reported as down/disabled
|
||||
# Get all states, make sure host 4 is reported as down
|
||||
self.host_manager.get_all_host_states(context)
|
||||
_mock_service_get_all_by_topic.assert_called_with(context, topic)
|
||||
_mock_service_get_all_by_topic.assert_called_with(context,
|
||||
topic,
|
||||
disabled=False)
|
||||
expected = []
|
||||
for service in services:
|
||||
expected.append(mock.call(service))
|
||||
self.assertEqual(expected, _mock_service_is_up.call_args_list)
|
||||
expected = []
|
||||
for num in ['4', '5']:
|
||||
expected.append(mock.call("volume service is down or disabled. "
|
||||
for num in ['4']:
|
||||
expected.append(mock.call("volume service is down. "
|
||||
"(host: host" + num + ")"))
|
||||
self.assertEqual(expected, _mock_warning.call_args_list)
|
||||
|
||||
|
|
|
@ -188,11 +188,11 @@ class DBAPIServiceTestCase(BaseTest):
|
|||
values = [
|
||||
{'host': 'host1', 'topic': 't1'},
|
||||
{'host': 'host2', 'topic': 't1'},
|
||||
{'disabled': True, 'topic': 't1'},
|
||||
{'host': 'host4', 'disabled': True, 'topic': 't1'},
|
||||
{'host': 'host3', 'topic': 't2'}
|
||||
]
|
||||
services = [self._create_service(vals) for vals in values]
|
||||
expected = services[:2]
|
||||
expected = services[:3]
|
||||
real = db.service_get_all_by_topic(self.ctxt, 't1')
|
||||
self._assertEqualListsOfObjects(expected, real)
|
||||
|
||||
|
|
|
@ -793,7 +793,9 @@ class API(base.Base):
|
|||
# Make sure the host is in the list of available hosts
|
||||
elevated = context.elevated()
|
||||
topic = CONF.volume_topic
|
||||
services = self.db.service_get_all_by_topic(elevated, topic)
|
||||
services = self.db.service_get_all_by_topic(elevated,
|
||||
topic,
|
||||
disabled=False)
|
||||
found = False
|
||||
for service in services:
|
||||
if utils.service_is_up(service) and service['host'] == host:
|
||||
|
|
Loading…
Reference in New Issue