fake_snapshot_id = "12345678-8888-8888-1234-1234567890ab"
fake_volume_id = "12345678-1234-1234-1234-1234567890ab"
fake_snapshot = {"id": fake_snapshot_id,
- "volume_id": fake_volume_id}
+ "volume_id": fake_volume_id,
+ "volume_size": 10}
fake_configure_data = [{"addr": "cms", "data": "FAKE"}]
self.drv.delete_snapshot(fake_snapshot)
def test_create_volume_from_snapshot(self):
- setattr(self.esm_mock, 'create_volume_from_snapshot',
- lambda *_: True)
- self.stubs.Set(CoraidDriver, '_get_repository',
- lambda *_: fake_repository_name)
- self.drv.create_volume_from_snapshot(fake_volume, fake_snapshot)
+ self.esm_mock.create_volume_from_snapshot(
+ fake_volume,
+ fake_snapshot).AndReturn(True)
+ mox.Replay(self.esm_mock)
+ self.esm_mock.create_volume_from_snapshot(fake_volume, fake_snapshot)
+ mox.Verify(self.esm_mock)
+
+ def test_create_volume_from_snapshot_bigger(self):
+ self.esm_mock.create_volume_from_snapshot(
+ fake_volume,
+ fake_snapshot).AndReturn(True)
+ self.esm_mock.resize_volume(fake_volume_name,
+ '20').AndReturn(True)
+ mox.Replay(self.esm_mock)
+ self.esm_mock.create_volume_from_snapshot(fake_volume, fake_snapshot)
+ self.esm_mock.resize_volume(fake_volume_name, '20')
+ mox.Verify(self.esm_mock)
+
+ def test_extend_volume(self):
+ self.esm_mock.resize_volume(fake_volume_name,
+ '20').AndReturn(True)
+ mox.Replay(self.esm_mock)
+ self.esm_mock.resize_volume(fake_volume_name, '20')
+ mox.Verify(self.esm_mock)
class TestCoraidRESTClient(test.TestCase):
self.drv.create_volume_from_snapshot(fake_volume_name,
fake_volume_name,
fake_repository_name)
+
+ def test_resize_volume(self):
+ setattr(self.rest_mock, 'resize_volume',
+ lambda *_: True)
+ self.stubs.Set(CoraidRESTClient, '_get_volume_info',
+ lambda *_: fake_volume_info)
+ self.stubs.Set(CoraidRESTClient, '_configure',
+ lambda *_: fake_esm_success)
+ self.drv.resize_volume(fake_volume_name,
+ '20')
volume_name, repository)
return self._configure(data)
+ def resize_volume(self, volume_name, volume_size):
+ volume_info = self._get_volume_info(volume_name)
+ repository = volume_info['repo']
+ data = '[{"addr":"cms","data":"{' \
+ '\\"lvName\\":\\"%s\\",' \
+ '\\"newLvSize\\":\\"%s\\"}",' \
+ '\\"repoName\\":\\"%s\\"}",' \
+ '"op":"orchStrLunMods",' \
+ '"args":"resizeVolume"}]' % (volume_name,
+ volume_size,
+ repository)
+ return self._configure(data)
+
class CoraidDriver(driver.VolumeDriver):
"""This is the Class to set in cinder.conf (volume_driver)."""
self.esm.create_volume_from_snapshot(snapshot_name,
volume['name'],
repository)
+ resize = volume['size'] > snapshot['volume_size']
+ if resize:
+ self.esm.resize_volume(volume['name'], volume['size'])
except Exception:
msg = _('Failed to Create Volume from Snapshot %(snapname)s')
LOG.debug(msg % dict(snapname=snapshot_name))
raise
return
+ def extend_volume(self, volume, new_size):
+ """Extend an Existing Volume."""
+ try:
+ self.esm.resize_volume(volume['name'], new_size)
+ except Exception:
+ msg = _('Failed to Extend Volume %(volname)s')
+ LOG.debug(msg % dict(volname=volume['name']))
+ raise
+ return
+
def initialize_connection(self, volume, connector):
"""Return connection information."""
try: