Merge "Added update-host for CGs in cinder-manage"

This commit is contained in:
Jenkins 2016-10-05 11:16:25 +00:00 committed by Gerrit Code Review
commit a99e98663e
3 changed files with 51 additions and 0 deletions

View File

@ -597,10 +597,33 @@ class ClusterCommands(BaseCommand):
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 = {
'backup': BackupCommands,
'config': ConfigCommands,
'cluster': ClusterCommands,
'cg': ConsistencyGroupCommands,
'db': DbCommands,
'host': HostCommands,
'logs': GetLogCommands,

View File

@ -562,6 +562,31 @@ class TestCinderManageCmd(test.TestCase):
backup_update.assert_called_once_with(ctxt, fake.BACKUP_ID,
{'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.db.service_get_all')
@mock.patch('cinder.context.get_admin_context')

View File

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