diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 8f814837f..681e63956 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -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, diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index c95fa28ac..718c9640e 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -751,6 +751,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') diff --git a/releasenotes/notes/consistency_group_manage-d30a2ad8917a7a86.yaml b/releasenotes/notes/consistency_group_manage-d30a2ad8917a7a86.yaml new file mode 100644 index 000000000..c763d5207 --- /dev/null +++ b/releasenotes/notes/consistency_group_manage-d30a2ad8917a7a86.yaml @@ -0,0 +1,3 @@ +--- +features: + - Added update-host command for consistency groups in cinder-manage.