Merge "Host selection when creating backup"
This commit is contained in:
commit
2aef8e4441
@ -40,6 +40,7 @@ from cinder import quota
|
||||
from cinder import quota_utils
|
||||
from cinder import utils
|
||||
import cinder.volume
|
||||
from cinder.volume import utils as volume_utils
|
||||
|
||||
backup_api_opts = [
|
||||
cfg.BoolOpt('backup_use_same_host',
|
||||
@ -231,8 +232,9 @@ class API(base.Base):
|
||||
raise exception.InvalidSnapshot(reason=msg)
|
||||
|
||||
previous_status = volume['status']
|
||||
volume_host = volume_utils.extract_host(volume.host, 'host')
|
||||
host = self._get_available_backup_service_host(
|
||||
None, volume.availability_zone)
|
||||
volume_host, volume.availability_zone)
|
||||
|
||||
# Reserve a quota before setting volume status and backup status
|
||||
try:
|
||||
|
@ -113,14 +113,15 @@ class BaseBackupTest(test.TestCase):
|
||||
display_description='this is a test volume',
|
||||
status='backing-up',
|
||||
previous_status='available',
|
||||
size=1):
|
||||
size=1,
|
||||
host='testhost'):
|
||||
"""Create a volume entry in the DB.
|
||||
|
||||
Return the entry ID
|
||||
"""
|
||||
vol = {}
|
||||
vol['size'] = size
|
||||
vol['host'] = 'testhost'
|
||||
vol['host'] = host
|
||||
vol['user_id'] = str(uuid.uuid4())
|
||||
vol['project_id'] = str(uuid.uuid4())
|
||||
vol['status'] = status
|
||||
@ -1471,6 +1472,20 @@ class BackupAPITestCase(BaseBackupTest):
|
||||
volume_id=volume_id,
|
||||
container='volumebackups')
|
||||
|
||||
@mock.patch('cinder.backup.rpcapi.BackupAPI.create_backup')
|
||||
@mock.patch('cinder.backup.api.API._is_backup_service_enabled')
|
||||
def test_create_backup_in_same_host(self, mock_is_enable,
|
||||
mock_create):
|
||||
self.override_config('backup_use_same_host', True)
|
||||
mock_is_enable.return_value = True
|
||||
self.ctxt.user_id = 'fake_user'
|
||||
self.ctxt.project_id = 'fake_project'
|
||||
volume_id = self._create_volume_db_entry(status='available',
|
||||
host='testhost#lvm',
|
||||
size=1)
|
||||
backup = self.api.create(self.ctxt, None, None, volume_id, None)
|
||||
self.assertEqual('testhost', backup.host)
|
||||
|
||||
@mock.patch('cinder.backup.api.API._get_available_backup_service_host')
|
||||
@mock.patch('cinder.backup.rpcapi.BackupAPI.restore_backup')
|
||||
def test_restore_volume(self,
|
||||
|
Loading…
x
Reference in New Issue
Block a user