Added update-host for CGs in cinder-manage

Currently in cinder-manage, "update_host" command for consistency
groups is missing.

Hence, in a similar way like volumes and backups, 'update_host'
is added for Consistency Groups as well, because if host
configuration is changed then even if we change volumes and
backups using cinder-manage, we would have to go to the DB to
change our CGs.

Change-Id: I820ae9d17460a5aa7b3b2e41afc861e8bc0265a3
Closes-Bug: 1591153
This commit is contained in:
PranaliD 2016-06-20 02:21:41 -04:00
parent 0db18b8351
commit 67520e5eb2
3 changed files with 51 additions and 0 deletions

View File

@ -597,10 +597,33 @@ class ClusterCommands(BaseCommand):
return 2 return 2
class ConsistencyGroupCommands(object):
"""Methods for managing consistency groups."""
@args('--currenthost', required=True, help='Existing CG host name')
@args('--newhost', required=True, help='New CG host name')
def update_cg_host(self, currenthost, newhost):
"""Modify the host name associated with a Consistency Group.
Particularly to recover from cases where one has moved
a host from single backend to multi-backend, or changed the host
configuration option, or modified the backend_name in a multi-backend
config.
"""
ctxt = context.get_admin_context()
groups = objects.ConsistencyGroupList.get_all(
ctxt, {'host': currenthost})
for gr in groups:
gr.host = newhost
gr.save()
CATEGORIES = { CATEGORIES = {
'backup': BackupCommands, 'backup': BackupCommands,
'config': ConfigCommands, 'config': ConfigCommands,
'cluster': ClusterCommands, 'cluster': ClusterCommands,
'cg': ConsistencyGroupCommands,
'db': DbCommands, 'db': DbCommands,
'host': HostCommands, 'host': HostCommands,
'logs': GetLogCommands, 'logs': GetLogCommands,

View File

@ -751,6 +751,31 @@ class TestCinderManageCmd(test.TestCase):
backup_update.assert_called_once_with(ctxt, fake.BACKUP_ID, backup_update.assert_called_once_with(ctxt, fake.BACKUP_ID,
{'host': 'fake_host2'}) {'host': 'fake_host2'})
@mock.patch('cinder.db.consistencygroup_update')
@mock.patch('cinder.db.consistencygroup_get_all')
@mock.patch('cinder.context.get_admin_context')
def test_update_consisgroup_host(self, get_admin_context,
consisgroup_get_all,
consisgroup_update):
ctxt = context.RequestContext(fake.USER_ID, fake.PROJECT_ID)
get_admin_context.return_value = ctxt
consisgroup = {'id': fake.CONSISTENCY_GROUP_ID,
'user_id': fake.USER_ID,
'project_id': fake.PROJECT_ID,
'host': 'fake-host',
'status': fields.ConsistencyGroupStatus.AVAILABLE
}
consisgroup_get_all.return_value = [consisgroup]
consisgrup_cmds = cinder_manage.ConsistencyGroupCommands()
consisgrup_cmds.update_cg_host('fake_host', 'fake_host2')
get_admin_context.assert_called_once_with()
consisgroup_get_all.assert_called_once_with(
ctxt, filters={'host': 'fake_host'}, limit=None, marker=None,
offset=None, sort_dirs=None, sort_keys=None)
consisgroup_update.assert_called_once_with(
ctxt, fake.CONSISTENCY_GROUP_ID, {'host': 'fake_host2'})
@mock.patch('cinder.utils.service_is_up') @mock.patch('cinder.utils.service_is_up')
@mock.patch('cinder.db.service_get_all') @mock.patch('cinder.db.service_get_all')
@mock.patch('cinder.context.get_admin_context') @mock.patch('cinder.context.get_admin_context')

View File

@ -0,0 +1,3 @@
---
features:
- Added update-host command for consistency groups in cinder-manage.