Add update_host for backup in cinder-manager
As scaling backup is imported, if users sepecify backup_use_same_host, they have to manually update backups' host. Change-Id: Ic031cae16f4c58fa06d92e979fe2b83d244832fc
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user