take into consideration created volume size in cinder backend

cinder can create bigger volumes than requested.
also cinder can extend volume to bigger size than requested.
cinder driver should take in into consideration.

Closes-Bug: #1644177
Change-Id: Ic0c0bc31193eaa28fb32fb5e13c4bceeeb11ae2b
This commit is contained in:
Andrey Pavlov 2016-11-23 17:02:14 +03:00
parent 2689a350c3
commit f1afda393d
2 changed files with 11 additions and 3 deletions

View File

@ -660,6 +660,7 @@ class Store(glance_store.driver.Store):
volume = client.volumes.create(size_gb, name=name, metadata=metadata,
volume_type=volume_type)
volume = self._wait_volume_status(volume, 'creating', 'available')
size_gb = volume.size
failed = True
need_extend = True
@ -694,6 +695,7 @@ class Store(glance_store.driver.Store):
volume = self._wait_volume_status(volume,
'extending',
'available')
size_gb = volume.size
except exceptions.BackendException:
raise exceptions.StorageFull()

View File

@ -308,12 +308,16 @@ class TestCinderStore(base.StoreBaseTest,
volume_type='some_type')
def test_cinder_add(self):
fake_volume = mock.MagicMock(id=str(uuid.uuid4()), status='available')
fake_volume = mock.MagicMock(id=str(uuid.uuid4()),
status='available',
size=1)
volume_file = six.BytesIO()
self._test_cinder_add(fake_volume, volume_file)
def test_cinder_add_with_verifier(self):
fake_volume = mock.MagicMock(id=str(uuid.uuid4()), status='available')
fake_volume = mock.MagicMock(id=str(uuid.uuid4()),
status='available',
size=1)
volume_file = six.BytesIO()
verifier = mock.MagicMock()
self._test_cinder_add(fake_volume, volume_file, 1, verifier)
@ -323,7 +327,9 @@ class TestCinderStore(base.StoreBaseTest,
e = IOError()
volume_file = six.BytesIO()
e.errno = errno.ENOSPC
fake_volume = mock.MagicMock(id=str(uuid.uuid4()), status='available')
fake_volume = mock.MagicMock(id=str(uuid.uuid4()),
status='available',
size=1)
with mock.patch.object(volume_file, 'write', side_effect=e):
self.assertRaises(exceptions.StorageFull,
self._test_cinder_add, fake_volume, volume_file)