]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add update_host for backup in cinder-manager
authorLisaLi <xiaoyan.li@intel.com>
Fri, 19 Feb 2016 08:39:38 +0000 (16:39 +0800)
committerTom Barron <tpb@dyncloud.net>
Wed, 16 Mar 2016 17:42:37 +0000 (13:42 -0400)
As scaling backup is imported, if users sepecify backup_use_same_host,
they have to manually update backups' host.

Change-Id: Ic031cae16f4c58fa06d92e979fe2b83d244832fc

cinder/cmd/manage.py
cinder/tests/unit/test_cmd.py

index 758c8d1b647fedb8f30f9dc622a62fdb20aa1aa8..a983dda6e902dc2041a04de2cbb0a633b4c027f5 100644 (file)
@@ -414,6 +414,20 @@ class BackupCommands(object):
                          backup['size'],
                          object_count))
 
+    @args('--currenthost', required=True, help='Existing backup host name')
+    @args('--newhost', required=True, help='New backup host name')
+    def update_backup_host(self, currenthost, newhost):
+        """Modify the host name associated with a backup.
+
+        Particularly to recover from cases where one has moved
+        their Cinder Backup node, and not set backup_use_same_backend.
+        """
+        ctxt = context.get_admin_context()
+        backups = objects.BackupList.get_all_by_host(ctxt, currenthost)
+        for bk in backups:
+            bk.host = newhost
+            bk.save()
+
 
 class ServiceCommands(object):
     """Methods for managing services."""
index cbcccb849734ae151c921479be9c79b9cf613601..a095caa9f16512a43ecb569a71a7272730df10f0 100644 (file)
@@ -39,6 +39,7 @@ from cinder import context
 from cinder import exception
 from cinder.objects import fields
 from cinder import test
+from cinder.tests.unit import fake_constants
 from cinder.tests.unit import fake_volume
 from cinder import version
 
@@ -665,6 +666,34 @@ class TestCinderManageCmd(test.TestCase):
                                                    None, None, None)
             self.assertEqual(expected_out, fake_out.getvalue())
 
+    @mock.patch('cinder.db.backup_update')
+    @mock.patch('cinder.db.backup_get_all_by_host')
+    @mock.patch('cinder.context.get_admin_context')
+    def test_update_backup_host(self, get_admin_context,
+                                backup_get_by_host,
+                                backup_update):
+        ctxt = context.RequestContext('fake-user', 'fake-project')
+        get_admin_context.return_value = ctxt
+        backup = {'id': fake_constants.backup_id,
+                  'user_id': 'fake-user-id',
+                  'project_id': 'fake-project-id',
+                  'host': 'fake-host',
+                  'display_name': 'fake-display-name',
+                  'container': 'fake-container',
+                  'status': fields.BackupStatus.AVAILABLE,
+                  'size': 123,
+                  'object_count': 1,
+                  'volume_id': 'fake-volume-id',
+                  }
+        backup_get_by_host.return_value = [backup]
+        backup_cmds = cinder_manage.BackupCommands()
+        backup_cmds.update_backup_host('fake_host', 'fake_host2')
+
+        get_admin_context.assert_called_once_with()
+        backup_get_by_host.assert_called_once_with(ctxt, 'fake_host')
+        backup_update.assert_called_once_with(ctxt, fake_constants.backup_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')