@mock.patch('cinder.volume.rpcapi.VolumeAPI.manage_existing_snapshot')
@mock.patch('cinder.volume.api.API.create_snapshot_in_db')
- @mock.patch('cinder.db.service_get_by_host_and_topic')
+ @mock.patch('cinder.db.service_get_by_args')
def test_manage_snapshot_ok(self, mock_db,
mock_create_snapshot, mock_rpcapi):
"""Test successful manage volume execution.
code to the caller.
"""
ctxt = context.RequestContext('admin', 'fake', True)
- mock_db.return_value = fake_service.fake_service_obj(ctxt)
+ mock_db.return_value = fake_service.fake_service_obj(
+ ctxt,
+ binary='cinder-volume')
body = {'snapshot': {'volume_id': 'fake_volume_id', 'ref': 'fake_ref'}}
res = self._get_resp(body)
elevated = context.elevated()
try:
svc_host = volume_utils.extract_host(host, 'backend')
- service = objects.Service.get_by_host_and_topic(
- elevated, svc_host, CONF.volume_topic)
+ service = objects.Service.get_by_args(
+ elevated, svc_host, 'cinder-volume')
except exception.ServiceNotFound:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Unable to find service: %(service)s for '
'given host: %(host)s.'),
{'service': CONF.volume_topic, 'host': host})
+ if service.disabled:
+ LOG.error(_LE('Unable to manage_existing volume on a disabled '
+ 'service.'))
+ raise exception.ServiceUnavailable()
+
availability_zone = service.get('availability_zone')
manage_what = {
metadata=None):
host = volume_utils.extract_host(volume['host'])
try:
- objects.Service.get_by_host_and_topic(context.elevated(), host,
- CONF.volume_topic)
+ # NOTE(jdg): We don't use this, we just make sure it's valid
+ # and exists before sending off the call
+ service = objects.Service.get_by_args(
+ context.elevated(), host, 'cinder-volume')
except exception.ServiceNotFound:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Unable to find service: %(service)s for '
'given host: %(host)s.'),
{'service': CONF.volume_topic, 'host': host})
+ if service.disabled:
+ LOG.error(_LE('Unable to manage_existing snapshot on a disabled '
+ 'service.'))
+ raise exception.ServiceUnavailable()
snapshot_object = self.create_snapshot_in_db(context, volume, name,
description, False,
svc_host = volume_utils.extract_host(host, 'backend')
service = objects.Service.get_by_args(
- ctxt, svc_host, CONF.volume_topic)
+ ctxt, svc_host, 'cinder-volume')
expected = {'replication_status': [fields.ReplicationStatus.ENABLED,
fields.ReplicationStatus.FAILED_OVER]}
result = service.conditional_update(
ctxt = context.get_admin_context()
svc_host = volume_utils.extract_host(host, 'backend')
- # NOTE(jdg): get_by_host_and_topic filters out disabled
service = objects.Service.get_by_args(
- ctxt, svc_host, CONF.volume_topic)
+ ctxt, svc_host, 'cinder-volume')
expected = {'frozen': False}
result = service.conditional_update(
{'frozen': True}, expected)
ctxt = context.get_admin_context()
svc_host = volume_utils.extract_host(host, 'backend')
- # NOTE(jdg): get_by_host_and_topic filters out disabled
service = objects.Service.get_by_args(
- ctxt, svc_host, CONF.volume_topic)
+ ctxt, svc_host, 'cinder-volume')
expected = {'frozen': True}
result = service.conditional_update(
{'frozen': False}, expected)
curr_active_backend_id = None
svc_host = vol_utils.extract_host(self.host, 'backend')
try:
- service = objects.Service.get_by_host_and_topic(
- context.get_admin_context(), svc_host,
- CONF.volume_topic)
+ service = objects.Service.get_by_args(
+ context.get_admin_context(),
+ svc_host,
+ 'cinder-volume')
except exception.ServiceNotFound:
# NOTE(jdg): This is to solve problems with unit tests
LOG.info(_LI("Service not found for updating "
try:
# NOTE(jdg): may be some things to think about here in failover
# scenarios
- service = objects.Service.get_by_host_and_topic(
- context.get_admin_context(), svc_host,
- CONF.volume_topic)
+ service = objects.Service.get_by_args(
+ context.get_admin_context(),
+ svc_host,
+ 'cinder-volume')
except exception.ServiceNotFound:
# FIXME(jdg): no idea what we'd do if we hit this case
LOG.info(_LI("Service not found for updating "
"""
svc_host = vol_utils.extract_host(self.host, 'backend')
- # NOTE(jdg): get_by_host_and_topic filters out disabled
service = objects.Service.get_by_args(
- context, svc_host,
- CONF.volume_topic)
+ context,
+ svc_host,
+ 'cinder-volume')
volumes = objects.VolumeList.get_all_by_host(context, self.host)
exception_encountered = False
'notification to driver has failed.'))
svc_host = vol_utils.extract_host(self.host, 'backend')
- # NOTE(jdg): get_by_host_and_topic filters out disabled
service = objects.Service.get_by_args(
- context, svc_host,
- CONF.volume_topic)
+ context,
+ svc_host,
+ 'cinder-volume')
service.disabled = True
service.disabled_reason = "frozen"
service.save()
return False
svc_host = vol_utils.extract_host(self.host, 'backend')
- # NOTE(jdg): get_by_host_and_topic filters out disabled
service = objects.Service.get_by_args(
- context, svc_host,
- CONF.volume_topic)
+ context,
+ svc_host,
+ 'cinder-volume')
service.disabled = False
service.disabled_reason = ""
service.save()