--- /dev/null
+# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+"""Fake HP client exceptions to use when mocking HP clients."""
+
+
+class HTTPConflict(Exception):
+ http_status = 409
+ message = "Conflict"
+
+
+class HTTPNotFound(Exception):
+ http_status = 404
+ message = "Not found"
+
+
+class HTTPForbidden(Exception):
+ http_status = 403
+ message = "Forbidden"
+
+ def __init__(self, error=None):
+ if error:
+ if 'code' in error:
+ self._error_code = error['code']
+
+ def get_code(self):
+ return self._error_code
+
+
+class HTTPBadRequest(Exception):
+ http_status = 400
+ message = "Bad request"
+
+
+class HTTPServerError(Exception):
+ http_status = 500
+ message = "Error"
+
+ def __init__(self, error=None):
+ if error:
+ if 'message' in error:
+ self._error_desc = error['message']
+
+ def get_description(self):
+ return self._error_desc
import mock
-from hp3parclient import client
-from hp3parclient import exceptions as hpexceptions
-
from cinder import context
from cinder import exception
from cinder.openstack.common import log as logging
from cinder import test
from cinder import units
+
+from cinder.tests import fake_hp_3par_client as hp3parclient
from cinder.volume.drivers.san.hp import hp_3par_fc as hpfcdriver
from cinder.volume.drivers.san.hp import hp_3par_iscsi as hpdriver
from cinder.volume import qos_specs
from cinder.volume import volume_types
+hpexceptions = hp3parclient.hpexceptions
+
LOG = logging.getLogger(__name__)
HP3PAR_CPG = 'OpenStackCPG'
'state': 1,
'uuid': '29c214aa-62b9-41c8-b198-543f6cf24edf'}]
+ mock_client_conf = {
+ 'PORT_MODE_TARGET': 2,
+ 'PORT_STATE_READY': 4,
+ 'PORT_PROTO_ISCSI': 2,
+ 'PORT_PROTO_FC': 1,
+ 'TASK_DONE': 1,
+ 'HOST_EDIT_ADD': 1,
+ 'getPorts.return_value': {
+ 'members': FAKE_FC_PORTS + [FAKE_ISCSI_PORT]
+ }
+ }
+
def setup_configuration(self):
configuration = mock.Mock()
configuration.hp3par_debug = False
@mock.patch(
'hp3parclient.client.HP3ParClient',
spec=True,
- PORT_MODE_TARGET=client.HP3ParClient.PORT_MODE_TARGET,
- PORT_STATE_READY=client.HP3ParClient.PORT_STATE_READY,
- PORT_PROTO_ISCSI=client.HP3ParClient.PORT_PROTO_ISCSI,
- PORT_PROTO_FC=client.HP3ParClient.PORT_PROTO_FC,
- TASK_DONE=client.HP3ParClient.TASK_DONE,
- HOST_EDIT_ADD=client.HP3ParClient.HOST_EDIT_ADD)
+ )
def setup_mock_client(self, _m_client, driver, conf=None, m_conf=None):
_m_client = _m_client.return_value
+
+ # Configure the base constants, defaults etc...
+ _m_client.configure_mock(**self.mock_client_conf)
+
+ # If m_conf, drop those over the top of the base_conf.
if m_conf is not None:
_m_client.configure_mock(**m_conf)
def test_migrate_volume(self):
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getStorageSystemInfo.return_value': {
'serialNumber': '1234'},
'getTask.return_value': {
def test_migrate_volume_diff_host(self):
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getStorageSystemInfo.return_value': {
'serialNumber': 'different'},
}
def test_migrate_volume_diff_domain(self):
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getStorageSystemInfo.return_value': {
'serialNumber': '1234'},
'getTask.return_value': {
self.assertEqual((False, None), result)
def test_migrate_volume_attached(self):
- conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
- 'getStorageSystemInfo.return_value': {
- 'serialNumber': '1234'},
- 'getTask.return_value': {
- 'status': 1}
- }
- mock_client = self.setup_driver(mock_conf=conf)
+ mock_client = self.setup_driver()
volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
'id': HP3PARBaseDriver.CLONE_ID,
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getTask.return_value': {
'status': 1},
'copyVolume.return_value': {'taskid': 1},
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getTask.return_value': {
'status': 4,
'failure message': 'out of disk space'},
def test_extend_volume_non_base(self):
extend_ex = hpexceptions.HTTPForbidden(error={'code': 150})
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getTask.return_value': {
'status': 1},
'getCPG.return_value': {},
def test_extend_volume_non_base_failure(self):
extend_ex = hpexceptions.HTTPForbidden(error={'code': 150})
conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]},
'getTask.return_value': {
'status': 1},
'getCPG.return_value': {},
{'active': True,
'volumeName': self.VOLUME_3PAR_NAME,
'lun': 90, 'type': 0}]
- mock_client.getPorts.return_value = {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]}
location = ("%(volume_name)s,%(lun_id)s,%(host)s,%(nsp)s" %
{'volume_name': self.VOLUME_3PAR_NAME,
'lun_id': 90,
{'active': True,
'volumeName': self.VOLUME_3PAR_NAME,
'lun': None, 'type': 0}]
- mock_client.getPorts.return_value = {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]}
self.driver.terminate_connection(
self.volume,
def setup_driver(self, config=None, mock_conf=None):
self.ctxt = context.get_admin_context()
- # setup_mock_client default config, if necessary
- if mock_conf is None:
- mock_conf = {
- 'getPorts.return_value': {
- 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]}}
mock_client = self.setup_mock_client(
conf=config,