From 67520e5eb2de79cbb270c7703e715a73c187ec09 Mon Sep 17 00:00:00 2001 From: PranaliD Date: Mon, 20 Jun 2016 02:21:41 -0400 Subject: [PATCH] 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 --- cinder/cmd/manage.py | 23 +++++++++++++++++ cinder/tests/unit/test_cmd.py | 25 +++++++++++++++++++ ...istency_group_manage-d30a2ad8917a7a86.yaml | 3 +++ 3 files changed, 51 insertions(+) create mode 100644 releasenotes/notes/consistency_group_manage-d30a2ad8917a7a86.yaml diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 8f814837f23..681e63956fc 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 c95fa28ac41..718c9640e35 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 00000000000..c763d520791 --- /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.