LOG = logging.getLogger(__name__)
+GOODNESS_FUNCTION = \
+ "capabilities.capacity_utilization < 0.6? 100 : 25"
+FILTER_FUNCTION = \
+ "capabilities.total_volumes < 400 && capabilities.capacity_utilization"
+
class HPLeftHandBaseDriver():
driver_startup_call_stack = [
mock.call.login('foo1', 'bar2'),
mock.call.getClusterByName('CloudCluster1'),
- mock.call.getCluster(1)]
+ mock.call.getCluster(1),
+ ]
class TestHPLeftHandCLIQISCSIDriver(HPLeftHandBaseDriver, test.TestCase):
driver_startup_call_stack = [
mock.call.login('foo1', 'bar2'),
mock.call.getClusterByName('CloudCluster1'),
- mock.call.getCluster(1)]
+ mock.call.getCluster(1),
+ mock.call.getVolumes(
+ cluster='CloudCluster1',
+ fields=['members[id]', 'members[clusterName]']),
+ ]
def default_mock_conf(self):
mock_conf.hplefthand_iscsi_chap_enabled = False
mock_conf.hplefthand_debug = False
mock_conf.hplefthand_clustername = "CloudCluster1"
+ mock_conf.goodness_function = GOODNESS_FUNCTION
+ mock_conf.filter_function = FILTER_FUNCTION
return mock_conf
@mock.patch('hplefthandclient.client.HPLeftHandClient', spec=True)
self.driver = hp_lefthand_iscsi.HPLeftHandISCSIDriver(
configuration=config)
self.driver.do_setup(None)
+ self.cluster_name = config.hplefthand_clustername
return _mock_client.return_value
@mock.patch('hplefthandclient.version', "1.0.0")
# and return the mock HTTP LeftHand client
mock_client = self.setup_driver()
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
+
# mock return value of createVolume
mock_client.createVolume.return_value = {
'iscsiIqn': self.connector['initiator']}
# mock return value of createVolume
mock_client.createVolume.return_value = {
'iscsiIqn': self.connector['initiator']}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
# mock return value of getVolumeByName
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
# mock return value of getVolumeByName
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
'id': self.volume_id,
'iscsiSessions': None
}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
'id': self.volume_id,
'iscsiSessions': [{'server': {'uri': self.server_uri}}]
}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
'id': self.volume_id,
'iscsiSessions': None
}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
'id': self.server_id,
'name': self.serverName}
mock_client.findServerVolumes.return_value = [{'id': self.volume_id}]
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
mock_client.findServerVolumes.return_value = [
{'id': self.volume_id},
{'id': 99999}]
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
mock_client = self.setup_driver()
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
# execute create_snapshot
self.driver.create_snapshot(self.snapshot)
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
expected = self.driver_startup_call_stack + [
mock.call.getVolumeByName('fakevolume'),
mock_client = self.setup_driver()
mock_client.getSnapshotByName.return_value = {'id': self.snapshot_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
mock_client.getSnapshotByName.return_value = {'id': self.snapshot_id}
mock_client.cloneSnapshot.return_value = {
'iscsiIqn': self.connector['initiator']}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
mock_client.cloneVolume.return_value = {
'iscsiIqn': self.connector['initiator']}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
# setup drive with default configuration
# and return the mock HTTP LeftHand client
mock_client = self.setup_driver()
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
ctxt = context.get_admin_context()
# and return the mock HTTP LeftHand client
mock_client = self.setup_driver()
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
ctxt = context.get_admin_context()
# and return the mock HTTP LeftHand client
mock_client = self.setup_driver()
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
ctxt = context.get_admin_context()
# and return the mock HTTP LeftHand client
mock_client = self.setup_driver()
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
ctxt = context.get_admin_context()
"id": self.cluster_id}
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
location = (self.driver.proxy.DRIVER_LOCATION % {
'cluster': 'New_CloudCluster',
'iscsiSessions': None}
mock_client.getVolume.return_value = {'snapshots': {
'resource': None}}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
location = (self.driver.proxy.DRIVER_LOCATION % {
'cluster': 'New_CloudCluster',
'iscsiSessions': None}
mock_client.getVolume.return_value = {'snapshots': {
'resource': 'snapfoo'}}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
location = (self.driver.proxy.DRIVER_LOCATION % {
'cluster': 'New_CloudCluster',
# mock return value of createVolume
mock_client.createVolume.return_value = {
'iscsiIqn': self.connector['initiator']}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
# mock return value of createVolume
mock_client.createVolume.return_value = {
'iscsiIqn': self.connector['initiator']}
+ mock_client.getVolumes.return_value = {'total': 1, 'members': []}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
existing_ref = {'source-name': self.volume_name}
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
existing_ref = {'source-name': self.volume_name}
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
existing_ref = {'source-name': self.volume_name}
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
existing_ref = {'source-name': self.volume_name}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
volume = {}
existing_ref = {'source-name': self.volume_name}
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
'_create_client') as mock_do_setup:
mock_do_setup.return_value = mock_client
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
volume = {}
existing_ref = {'source-name': self.volume_name}
mock_client = self.setup_driver()
mock_client.getVolumeByName.return_value = {'id': self.volume_id}
+ # mock return value of getVolumes
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": self.volume_id,
+ "clusterName": self.cluster_name
+ }
+ }
+
self.driver.proxy.api_version = "1.1"
with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
self.driver.proxy.api_version = "1.0"
self.assertRaises(exception.InvalidInput,
- self.driver.proxy._check_api_version)
\ No newline at end of file
+ self.driver.proxy._check_api_version)
+
+ def test_get_volume_stats(self):
+
+ # set up driver with default config
+ mock_client = self.setup_driver()
+
+ # mock return value of getVolumes
+ mock_client.getVolumes.return_value = {
+ "type": "volume",
+ "total": 1,
+ "members": {
+ "id": 12345,
+ "clusterName": self.cluster_name
+ }
+ }
+
+ with mock.patch.object(hp_lefthand_rest_proxy.HPLeftHandRESTProxy,
+ '_create_client') as mock_do_setup:
+ mock_do_setup.return_value = mock_client
+
+ # execute driver
+ stats = self.driver.get_volume_stats(True)
+
+ self.assertEqual('iSCSI', stats['storage_protocol'])
+ self.assertEqual(GOODNESS_FUNCTION, stats['goodness_function'])
+ self.assertEqual(FILTER_FUNCTION, stats['filter_function'])
+ self.assertEqual(1, int(stats['total_volumes']))
+
+ cap_util = (
+ float(units.Gi * 500 - units.Gi * 250) / float(units.Gi * 500)
+ ) * 100
+
+ self.assertEqual(cap_util, float(stats['capacity_utilization']))
+
+ expected = self.driver_startup_call_stack + [
+ mock.call.getCluster(1),
+ mock.call.getVolumes(fields=['members[id]',
+ 'members[clusterName]'],
+ cluster=self.cluster_name),
+ mock.call.logout()]
+
+ mock_client.assert_has_calls(expected)