"""
Unit tests for OpenStack Cinder volume drivers
"""
+import ast
import mox
import shutil
import tempfile
VOLUME_ID_SNAP = '761fc5e5-5191-4ec7-aeba-33e36de44156'
FAKE_DESC = 'test description name'
FAKE_FC_PORTS = ['0987654321234', '123456789000987']
- QOS = "{'qos:maxIOPS': 1000, 'qos:maxBWS': 50}"
+ QOS = {'qos:maxIOPS': '1000', 'qos:maxBWS': '50'}
FAKE_ISCSI_PORTS = {'1.1.1.2': {'nsp': '8:1:1',
'iqn': ('iqn.2000-05.com.3pardata:'
'21810002ac00383d'),
self.fake_create_3par_vlun)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_ports",
self.fake_get_ports)
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpfcdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
def fake_create_client(self):
return FakeHP3ParClient(self.driver.configuration.hp3par_api_url)
+ def fake_get_cpg(self, volume):
+ return HP3PAR_CPG
+
def fake_get_domain(self, cpg):
return HP3PAR_DOMAIN
def fake_copy_volume(self, src_name, dest_name):
pass
- def fake_get_volume_state(self, vol_name):
+ def fake_get_volume_stats(self, vol_name):
return "normal"
def test_create_volume(self):
self.flags(lock_path=self.tempdir)
- model_update = self.driver.create_volume(self.volume)
- metadata = model_update['metadata']
- self.assertFalse(metadata['3ParName'] is None)
- self.assertEqual(metadata['CPG'], HP3PAR_CPG)
- self.assertEqual(metadata['snapCPG'], HP3PAR_CPG_SNAP)
+ self.driver.create_volume(self.volume)
+ volume = self.driver.common.client.getVolume(self.VOLUME_3PAR_NAME)
+ self.assertEqual(volume['name'], self.VOLUME_3PAR_NAME)
def test_create_volume_qos(self):
self.flags(lock_path=self.tempdir)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon,
"_add_volume_to_volume_set",
self.fake_add_volume_to_volume_set)
- model_update = self.driver.create_volume(self.volume_qos)
- metadata = model_update['metadata']
- self.assertFalse(metadata['3ParName'] is None)
- self.assertEqual(metadata['CPG'], HP3PAR_CPG)
- self.assertEqual(metadata['snapCPG'], HP3PAR_CPG_SNAP)
- self.assertEqual(metadata['qos'], True)
+ self.driver.create_volume(self.volume_qos)
+ volume = self.driver.common.client.getVolume(self.VOLUME_3PAR_NAME)
+
+ self.assertEqual(volume['name'], self.VOLUME_3PAR_NAME)
+ self.assertNotIn(self.QOS, dict(ast.literal_eval(volume['comment'])))
def test_delete_volume(self):
self.flags(lock_path=self.tempdir)
self.driver.common.client.getVolume,
self.VOLUME_ID)
+ def test_create_cloned_volume(self):
+ self.flags(lock_path=self.tempdir)
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_volume_stats",
+ self.fake_get_volume_stats)
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_copy_volume",
+ self.fake_copy_volume)
+ self.state_tries = 0
+ volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
+ 'id': HP3PARBaseDriver.CLONE_ID,
+ 'display_name': 'Foo Volume',
+ 'size': 2,
+ 'host': HP3PARBaseDriver.FAKE_HOST,
+ 'source_volid': HP3PARBaseDriver.VOLUME_ID}
+ src_vref = {}
+ model_update = self.driver.create_cloned_volume(volume, src_vref)
+ self.assertTrue(model_update is not None)
+
def test_create_snapshot(self):
self.flags(lock_path=self.tempdir)
self.driver.create_snapshot(self.snapshot)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon,
"_add_volume_to_volume_set",
self.fake_add_volume_to_volume_set)
- model_update = self.driver.create_volume_from_snapshot(self.volume_qos,
- self.snapshot)
- metadata = model_update['metadata']
- self.assertEqual(metadata['qos'], True)
+ self.driver.create_volume_from_snapshot(self.volume_qos, self.snapshot)
snap_vol = self.driver.common.client.getVolume(self.VOLUME_3PAR_NAME)
self.assertEqual(snap_vol['name'], self.VOLUME_3PAR_NAME)
+ self.assertNotIn(self.QOS, dict(ast.literal_eval(snap_vol['comment'])))
volume = self.volume.copy()
volume['size'] = 1
self.assertEquals(self.VOLUME_3PAR_NAME, vlun['volumeName'])
self.assertEquals(self.FAKE_HOST, vlun['hostname'])
- def test_create_cloned_volume(self):
- self.flags(lock_path=self.tempdir)
- self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_copy_volume",
- self.fake_copy_volume)
- self.state_tries = 0
- volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
- 'id': HP3PARBaseDriver.CLONE_ID,
- 'display_name': 'Foo Volume',
- 'size': 2,
- 'host': HP3PARBaseDriver.FAKE_HOST,
- 'source_volid': HP3PARBaseDriver.VOLUME_ID}
- src_vref = {}
- model_update = self.driver.create_cloned_volume(volume, src_vref)
- self.assertTrue(model_update is not None)
- metadata = model_update['metadata']
- self.assertFalse(metadata['3ParName'] is None)
- self.assertEqual(metadata['CPG'], HP3PAR_CPG)
- self.assertEqual(metadata['snapCPG'], HP3PAR_CPG_SNAP)
-
def test_get_volume_stats(self):
self.flags(lock_path=self.tempdir)
#record
self.clear_mox()
+ self.stubs.Set(hpfcdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpfcdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
_run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh)
#record
self.clear_mox()
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
_run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh)
#record
self.clear_mox()
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
_run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh)
self.assertEquals(self.VOLUME_3PAR_NAME, vlun['volumeName'])
self.assertEquals(self.FAKE_HOST, vlun['hostname'])
- def test_create_cloned_volume(self):
- self.flags(lock_path=self.tempdir)
- self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "_copy_volume",
- self.fake_copy_volume)
- self.state_tries = 0
- volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
- 'id': HP3PARBaseDriver.CLONE_ID,
- 'display_name': 'Foo Volume',
- 'size': 2,
- 'host': HP3PARBaseDriver.FAKE_HOST,
- 'source_volid': HP3PARBaseDriver.VOLUME_ID}
- src_vref = {}
- model_update = self.driver.create_cloned_volume(volume, src_vref)
- self.assertTrue(model_update is not None)
- metadata = model_update['metadata']
- self.assertFalse(metadata['3ParName'] is None)
- self.assertEqual(metadata['CPG'], HP3PAR_CPG)
- self.assertEqual(metadata['snapCPG'], HP3PAR_CPG_SNAP)
-
def test_get_volume_stats(self):
self.flags(lock_path=self.tempdir)
#record
self.clear_mox()
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
_run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh)
#record
self.clear_mox()
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
_run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh)
#record
self.clear_mox()
+ self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_cpg",
+ self.fake_get_cpg)
self.stubs.Set(hpdriver.hpcommon.HP3PARCommon, "get_domain",
self.fake_get_domain)
_run_ssh = self.mox.CreateMock(hpdriver.hpcommon.HP3PARCommon._run_ssh)
array.
"""
-
+import ast
import base64
import json
import paramiko
def _remove_volume_from_volume_set(self, volume_name, vvs_name):
self._cli_run('removevvset -f %s %s' % (vvs_name, volume_name), None)
+ def get_cpg(self, volume):
+ volume_name = self._get_3par_vol_name(volume['id'])
+ vol = self.client.getVolume(volume_name)
+ return vol['userCPG']
+
+ def _get_3par_vol_comment(self, volume_name):
+ vol = self.client.getVolume(volume_name)
+ return vol['comment']
+
def get_persona_type(self, volume, hp3par_keys=None):
default_persona = self.valid_persona_values[0]
type_id = volume.get('volume_type_id', None)
vvs_name = None
hp3par_keys = {}
qos = {}
- qos_on_volume = False
type_id = volume.get('volume_type_id', None)
if type_id is not None:
volume_type = self._get_volume_type(type_id)
vvs_name = self._get_key_value(hp3par_keys, 'vvs')
if vvs_name is None:
qos = self._get_qos_by_volume_type(volume_type)
- if qos:
- qos_on_volume = True
cpg = self._get_key_value(hp3par_keys, 'cpg',
self.config.hp3par_cpg)
LOG.error(str(ex))
raise exception.CinderException(ex.get_description())
- metadata = {'3ParName': volume_name, 'CPG': cpg,
- 'snapCPG': extras['snapCPG'], 'qos': qos_on_volume,
- 'vvs': vvs_name}
- return metadata
-
def _copy_volume(self, src_name, dest_name):
self._cli_run('createvvcopy -p %s %s' % (src_name, dest_name), None)
word = re.search(search_string.strip(' ') + ' ([^ ]*)', s)
return word.groups()[0].strip(' ')
- def get_volume_metadata_value(self, volume, key):
- metadata = volume.get('volume_metadata')
- if metadata:
- for i in volume['volume_metadata']:
- if i['key'] == key:
- return i['value']
+ def _get_3par_vol_comment_value(self, vol_comment, key):
+ comment_dict = dict(ast.literal_eval(vol_comment))
+ if key in comment_dict:
+ return comment_dict[key]
return None
def create_cloned_volume(self, volume, src_vref):
def delete_volume(self, volume):
try:
volume_name = self._get_3par_vol_name(volume['id'])
- qos = self.get_volume_metadata_value(volume, 'qos')
- vvs_name = self.get_volume_metadata_value(volume, 'vvs')
+ vol_comment = self._get_3par_vol_comment(volume_name)
+ qos = self._get_3par_vol_comment_value(vol_comment, 'qos')
+ vvs_name = self._get_3par_vol_comment_value(vol_comment, 'vvs')
if vvs_name is not None:
self._remove_volume_from_volume_set(volume_name, vvs_name)
- elif qos:
+ elif qos is not None:
self._remove_volume_set(self._get_3par_vvs_name(volume['id']))
self.client.deleteVolume(volume_name)
except hpexceptions.HTTPNotFound as ex:
type_id = volume.get('volume_type_id', None)
vvs_name = None
qos = {}
- qos_on_volume = False
hp3par_keys = {}
if type_id is not None:
volume_type = self._get_volume_type(type_id)
vvs_name = self._get_key_value(hp3par_keys, 'vvs')
if vvs_name is None:
qos = self._get_qos_by_volume_type(volume_type)
- if qos:
- qos_on_volume = True
name = snapshot.get('display_name', None)
if name:
LOG.error(str(ex))
raise exception.CinderException(ex.get_description())
- metadata = {'3ParName': volume_name, 'qos': qos_on_volume,
- 'vvs': vvs_name}
- return metadata
-
def create_snapshot(self, snapshot):
LOG.debug("Create Snapshot\n%s" % pprint.pformat(snapshot))