Create volume in the same availability zone as instance
Volume should be created in the same availability zone as an instance to prevent: > InvalidVolume: Instance and volume not in same availability_zone Change-Id: I121cbdb68ec06d9b358a12c857dc24b75d7973e4 Closes-Bug: #1380780
This commit is contained in:
		@@ -512,8 +512,8 @@ class TestDriverBlockDevice(test.NoDBTestCase):
 | 
			
		||||
 | 
			
		||||
        self.volume_api.get_snapshot(self.context,
 | 
			
		||||
                                     'fake-snapshot-id-1').AndReturn(snapshot)
 | 
			
		||||
        self.volume_api.create(self.context, 3,
 | 
			
		||||
                               '', '', snapshot).AndReturn(volume)
 | 
			
		||||
        self.volume_api.create(self.context, 3, '', '', snapshot,
 | 
			
		||||
                               availability_zone=None).AndReturn(volume)
 | 
			
		||||
        wait_func(self.context, 'fake-volume-id-2').AndReturn(None)
 | 
			
		||||
        instance, expected_conn_info = self._test_volume_attach(
 | 
			
		||||
               test_bdm, no_volume_snapshot, volume)
 | 
			
		||||
@@ -556,8 +556,8 @@ class TestDriverBlockDevice(test.NoDBTestCase):
 | 
			
		||||
 | 
			
		||||
        wait_func = self.mox.CreateMockAnything()
 | 
			
		||||
 | 
			
		||||
        self.volume_api.create(self.context, 1,
 | 
			
		||||
                               '', '', image_id=image['id']).AndReturn(volume)
 | 
			
		||||
        self.volume_api.create(self.context, 1, '', '', image_id=image['id'],
 | 
			
		||||
                               availability_zone=None).AndReturn(volume)
 | 
			
		||||
        wait_func(self.context, 'fake-volume-id-2').AndReturn(None)
 | 
			
		||||
        instance, expected_conn_info = self._test_volume_attach(
 | 
			
		||||
               test_bdm, no_volume_image, volume)
 | 
			
		||||
@@ -606,10 +606,9 @@ class TestDriverBlockDevice(test.NoDBTestCase):
 | 
			
		||||
            test_bdm.attach(self.context, instance, self.volume_api,
 | 
			
		||||
                            self.virt_driver)
 | 
			
		||||
 | 
			
		||||
            vol_create.assert_called_once_with(self.context,
 | 
			
		||||
                                               test_bdm.volume_size,
 | 
			
		||||
                                               'fake-uuid-blank-vol',
 | 
			
		||||
                                               '')
 | 
			
		||||
            vol_create.assert_called_once_with(
 | 
			
		||||
                self.context, test_bdm.volume_size, 'fake-uuid-blank-vol',
 | 
			
		||||
                '', availability_zone=instance.availability_zone)
 | 
			
		||||
            vol_attach.assert_called_once_with(self.context, instance,
 | 
			
		||||
                                               self.volume_api,
 | 
			
		||||
                                               self.virt_driver,
 | 
			
		||||
 
 | 
			
		||||
@@ -301,10 +301,11 @@ class DriverSnapshotBlockDevice(DriverVolumeBlockDevice):
 | 
			
		||||
               virt_driver, wait_func=None, do_check_attach=True):
 | 
			
		||||
 | 
			
		||||
        if not self.volume_id:
 | 
			
		||||
            av_zone = instance.availability_zone
 | 
			
		||||
            snapshot = volume_api.get_snapshot(context,
 | 
			
		||||
                                               self.snapshot_id)
 | 
			
		||||
            vol = volume_api.create(context, self.volume_size,
 | 
			
		||||
                                    '', '', snapshot)
 | 
			
		||||
            vol = volume_api.create(context, self.volume_size, '', '',
 | 
			
		||||
                                    snapshot, availability_zone=av_zone)
 | 
			
		||||
            if wait_func:
 | 
			
		||||
                wait_func(context, vol['id'])
 | 
			
		||||
 | 
			
		||||
@@ -324,8 +325,10 @@ class DriverImageBlockDevice(DriverVolumeBlockDevice):
 | 
			
		||||
    def attach(self, context, instance, volume_api,
 | 
			
		||||
               virt_driver, wait_func=None, do_check_attach=True):
 | 
			
		||||
        if not self.volume_id:
 | 
			
		||||
            av_zone = instance.availability_zone
 | 
			
		||||
            vol = volume_api.create(context, self.volume_size,
 | 
			
		||||
                                    '', '', image_id=self.image_id)
 | 
			
		||||
                                    '', '', image_id=self.image_id,
 | 
			
		||||
                                    availability_zone=av_zone)
 | 
			
		||||
            if wait_func:
 | 
			
		||||
                wait_func(context, vol['id'])
 | 
			
		||||
 | 
			
		||||
@@ -345,7 +348,9 @@ class DriverBlankBlockDevice(DriverVolumeBlockDevice):
 | 
			
		||||
               virt_driver, wait_func=None, do_check_attach=True):
 | 
			
		||||
        if not self.volume_id:
 | 
			
		||||
            vol_name = instance.uuid + '-blank-vol'
 | 
			
		||||
            vol = volume_api.create(context, self.volume_size, vol_name, '')
 | 
			
		||||
            av_zone = instance.availability_zone
 | 
			
		||||
            vol = volume_api.create(context, self.volume_size, vol_name, '',
 | 
			
		||||
                                    availability_zone=av_zone)
 | 
			
		||||
            if wait_func:
 | 
			
		||||
                wait_func(context, vol['id'])
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user