# intentionally removed to make _retype more usable for other use cases.
RETYPE_DIFF = None
+ standard_login = [
+ mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
+ mock.call.setSSHOptions(
+ HP3PAR_SAN_IP,
+ HP3PAR_USER_NAME,
+ HP3PAR_USER_PASS,
+ privatekey=HP3PAR_SAN_SSH_PRIVATE,
+ port=HP3PAR_SAN_SSH_PORT,
+ conn_timeout=HP3PAR_SAN_SSH_CON_TIMEOUT)]
+
+ standard_logout = [
+ mock.call.logout()]
+
def setup_configuration(self):
configuration = mock.Mock()
configuration.hp3par_debug = False
self.ctxt = context.get_admin_context()
mock_client = self.setup_mock_client(driver=hpfcdriver.HP3PARFCDriver)
expected = [
- mock.call.setSSHOptions(
- HP3PAR_SAN_IP,
- HP3PAR_USER_NAME,
- HP3PAR_USER_PASS,
- privatekey=HP3PAR_SAN_SSH_PRIVATE,
- port=HP3PAR_SAN_SSH_PORT,
- conn_timeout=HP3PAR_SAN_SSH_CON_TIMEOUT),
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ mock.call.getCPG(HP3PAR_CPG2)]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch('hp3parclient.version', "3.1.1")
def test_ssh_options(self):
CONF.strict_ssh_host_key_policy = orig_strict_ssh_host_key_policy
expected = [
+ mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.setSSHOptions(
HP3PAR_SAN_IP,
HP3PAR_USER_NAME,
missing_key_policy="AutoAddPolicy",
port=HP3PAR_SAN_SSH_PORT,
conn_timeout=HP3PAR_SAN_SSH_CON_TIMEOUT),
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ mock.call.getCPG(HP3PAR_CPG2)]
+ mock_client.assert_has_calls(
+ expected +
+ self.standard_logout)
@mock.patch('hp3parclient.version', "3.1.1")
def test_ssh_options_strict(self):
CONF.strict_ssh_host_key_policy = orig_strict_ssh_host_key_policy
expected = [
+ mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.setSSHOptions(
HP3PAR_SAN_IP,
HP3PAR_USER_NAME,
missing_key_policy="RejectPolicy",
port=HP3PAR_SAN_SSH_PORT,
conn_timeout=HP3PAR_SAN_SSH_CON_TIMEOUT),
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ mock.call.getCPG(HP3PAR_CPG2)]
+ mock_client.assert_has_calls(expected + self.standard_logout)
def test_task_waiter(self):
task_id = 1234
interval = .001
- waiter = self.driver.common.TaskWaiter(mock_client, task_id, interval)
- status = waiter.wait_for_task()
- expected = [
- mock.call.getTask(task_id),
- mock.call.getTask(task_id),
- mock.call.getTask(task_id)
- ]
- mock_client.assert_has_calls(expected)
- self.assertEqual(status, self.STATUS_DONE)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ waiter = common.TaskWaiter(mock_client, task_id, interval)
+ status = waiter.wait_for_task()
+
+ expected = [
+ mock.call.getTask(task_id),
+ mock.call.getTask(task_id),
+ mock.call.getTask(task_id)
+ ]
+ mock_client.assert_has_calls(expected)
+ self.assertEqual(status, self.STATUS_DONE)
def test_create_volume(self):
-
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- self.driver.create_volume(self.volume)
- comment = (
- '{"display_name": "Foo Volume", "type": "OpenStack",'
- ' "name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7",'
- ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createVolume(
- self.VOLUME_3PAR_NAME,
- HP3PAR_CPG,
- 1907, {
- 'comment': comment,
- 'tpvv': True,
- 'snapCPG': HP3PAR_CPG_SNAP}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.create_volume(self.volume)
+ comment = (
+ '{"display_name": "Foo Volume", "type": "OpenStack",'
+ ' "name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7",'
+ ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+ expected = [
+ mock.call.createVolume(
+ self.VOLUME_3PAR_NAME,
+ HP3PAR_CPG,
+ 1907, {
+ 'comment': comment,
+ 'tpvv': True,
+ 'snapCPG': HP3PAR_CPG_SNAP})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_create_volume_in_pool(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- return_model = self.driver.create_volume(self.volume_pool)
- comment = (
- '{"display_name": "Foo Volume", "type": "OpenStack",'
- ' "name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7",'
- ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createVolume(
- self.VOLUME_3PAR_NAME,
- HP3PAR_CPG2,
- 1907, {
- 'comment': comment,
- 'tpvv': True,
- 'snapCPG': HP3PAR_CPG_SNAP}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
- self.assertEqual(return_model, None)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ return_model = self.driver.create_volume(self.volume_pool)
+ comment = (
+ '{"display_name": "Foo Volume", "type": "OpenStack",'
+ ' "name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7",'
+ ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+ expected = [
+ mock.call.createVolume(
+ self.VOLUME_3PAR_NAME,
+ HP3PAR_CPG2,
+ 1907, {
+ 'comment': comment,
+ 'tpvv': True,
+ 'snapCPG': HP3PAR_CPG_SNAP})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(return_model, None)
@mock.patch.object(volume_types, 'get_volume_type')
def test_get_snap_cpg_from_volume_type(self, _mock_volume_types):
- self.setup_driver()
+ mock_client = self.setup_driver()
expected_type_snap_cpg = "type_snap_cpg"
_mock_volume_types.return_value = {
'name': 'gold',
'snap_cpg': expected_type_snap_cpg,
'volume_type': self.volume_type}}
- result = self.driver.common.get_volume_settings_from_type_id(
- "mock", self.driver.configuration.hp3par_cpg)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ result = common.get_volume_settings_from_type_id(
+ "mock", self.driver.configuration.hp3par_cpg)
- self.assertEqual(expected_type_snap_cpg, result['snap_cpg'])
+ self.assertEqual(expected_type_snap_cpg, result['snap_cpg'])
@mock.patch.object(volume_types, 'get_volume_type')
def test_get_snap_cpg_from_volume_type_cpg(self, _mock_volume_types):
- self.setup_driver()
+ mock_client = self.setup_driver()
expected_cpg = 'use_extra_specs_cpg'
_mock_volume_types.return_value = {
'name': 'gold',
'cpg': expected_cpg,
'volume_type': self.volume_type}}
- result = self.driver.common.get_volume_settings_from_type_id(
- "mock", self.driver.configuration.hp3par_cpg)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ result = common.get_volume_settings_from_type_id(
+ "mock", self.driver.configuration.hp3par_cpg)
- self.assertEqual(expected_cpg, result['snap_cpg'])
+ self.assertEqual(expected_cpg, result['snap_cpg'])
@mock.patch.object(volume_types, 'get_volume_type')
def test_get_snap_cpg_from_volume_type_conf_snap_cpg(
conf = self.setup_configuration()
expected_snap_cpg = conf.hp3par_cpg_snap
- self.setup_driver(config=conf)
- result = self.driver.common.get_volume_settings_from_type_id(
- "mock", self.driver.configuration.hp3par_cpg)
+ mock_client = self.setup_driver(config=conf)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ result = common.get_volume_settings_from_type_id(
+ "mock", self.driver.configuration.hp3par_cpg)
self.assertEqual(expected_snap_cpg, result['snap_cpg'])
conf = self.setup_configuration()
conf.hp3par_cpg_snap = None
expected_cpg = conf.hp3par_cpg
- self.setup_driver(config=conf)
- result = self.driver.common.get_volume_settings_from_type_id(
- "mock", self.driver.configuration.hp3par_cpg)
+ mock_client = self.setup_driver(config=conf)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- self.assertEqual(expected_cpg, result['snap_cpg'])
+ result = common.get_volume_settings_from_type_id(
+ "mock", self.driver.configuration.hp3par_cpg)
+
+ self.assertEqual(expected_cpg, result['snap_cpg'])
@mock.patch.object(volume_types, 'get_volume_type')
def test_create_volume_qos(self, _mock_volume_types):
'tpvv': True,
'volume_type': self.volume_type}}
- return_model = self.driver.create_volume(self.volume_qos)
- comment = (
- '{"volume_type_name": "gold", "display_name": "Foo Volume"'
- ', "name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7'
- '", "volume_type_id": "gold", "volume_id": "d03338a9-91'
- '15-48a3-8dfc-35cdfcdc15a7", "qos": {}, "type": "OpenStack"}')
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getCPG(HP3PAR_CPG_QOS),
- mock.call.createVolume(
- self.VOLUME_3PAR_NAME,
- HP3PAR_CPG_QOS,
- 1907, {
- 'comment': comment,
- 'tpvv': True,
- 'snapCPG': HP3PAR_CPG_SNAP}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
- self.assertEqual(return_model,
- {'host': volume_utils.append_host(self.FAKE_HOST,
- HP3PAR_CPG_QOS)})
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ return_model = self.driver.create_volume(self.volume_qos)
+ comment = (
+ '{"volume_type_name": "gold", "display_name": "Foo Volume"'
+ ', "name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7'
+ '", "volume_type_id": "gold", "volume_id": "d03338a9-91'
+ '15-48a3-8dfc-35cdfcdc15a7", "qos": {}, "type": "OpenStack"}')
+
+ expected = [
+ mock.call.getCPG(HP3PAR_CPG_QOS),
+ mock.call.createVolume(
+ self.VOLUME_3PAR_NAME,
+ HP3PAR_CPG_QOS,
+ 1907, {
+ 'comment': comment,
+ 'tpvv': True,
+ 'snapCPG': HP3PAR_CPG_SNAP})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(return_model,
+ {'host': volume_utils.append_host(
+ self.FAKE_HOST,
+ HP3PAR_CPG_QOS)})
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_not_3par(self, _mock_volume_types):
_mock_volume_types.return_value = self.RETYPE_VOLUME_TYPE_1
mock_client = self.setup_driver(mock_conf=self.RETYPE_CONF)
- self.assertRaises(exception.InvalidHost,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_1,
- self.RETYPE_DIFF,
- self.RETYPE_HOST_NOT3PAR)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(exception.InvalidHost,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_1,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST_NOT3PAR)
+
+ expected = [mock.call.getVolume(self.VOLUME_3PAR_NAME)]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_volume_not_found(self, _mock_volume_types):
mock_client = self.setup_driver(mock_conf=self.RETYPE_CONF)
mock_client.getVolume.side_effect = hpexceptions.HTTPNotFound
- self.assertRaises(hpexceptions.HTTPNotFound,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_1,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(hpexceptions.HTTPNotFound,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_1,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ expected = [mock.call.getVolume(self.VOLUME_3PAR_NAME)]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_specs_error_reverts_snap_cpg(self, _mock_volume_types):
mock_client.addVolumeToVolumeSet.side_effect = \
hpexceptions.HTTPForbidden
- self.assertRaises(hpexceptions.HTTPForbidden,
- self.driver.retype,
- self.ctxt,
- {'id': self.VOLUME_ID},
- self.RETYPE_VOLUME_TYPE_0,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- old_settings = {
- 'snapCPG': self.RETYPE_VOLUME_INFO_0['snapCPG'],
- 'comment': self.RETYPE_VOLUME_INFO_0['comment']}
- new_settings = {
- 'snapCPG': self.RETYPE_VOLUME_TYPE_1['extra_specs']['snap_cpg'],
- 'comment': mock.ANY}
-
- expected = [
- mock.call.modifyVolume(self.VOLUME_3PAR_NAME, new_settings)
- ]
- mock_client.assert_has_calls(expected)
- expected = [
- mock.call.modifyVolume(self.VOLUME_3PAR_NAME, old_settings),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(hpexceptions.HTTPForbidden,
+ self.driver.retype,
+ self.ctxt,
+ {'id': self.VOLUME_ID},
+ self.RETYPE_VOLUME_TYPE_0,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ old_settings = {
+ 'snapCPG': self.RETYPE_VOLUME_INFO_0['snapCPG'],
+ 'comment': self.RETYPE_VOLUME_INFO_0['comment']}
+ new_settings = {
+ 'snapCPG': (
+ self.RETYPE_VOLUME_TYPE_1['extra_specs']['snap_cpg']),
+ 'comment': mock.ANY}
+
+ expected = [
+ mock.call.modifyVolume(self.VOLUME_3PAR_NAME, new_settings)
+ ]
+ mock_client.assert_has_calls(expected)
+ expected = [
+ mock.call.modifyVolume(self.VOLUME_3PAR_NAME, old_settings)
+ ]
+ mock_client.assert_has_calls(expected + self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_revert_comment(self, _mock_volume_types):
# Fail the QOS setting to test the revert of the snap CPG rename.
mock_client.deleteVolumeSet.side_effect = hpexceptions.HTTPForbidden
- self.assertRaises(hpexceptions.HTTPForbidden,
- self.driver.retype,
- self.ctxt,
- {'id': self.VOLUME_ID},
- self.RETYPE_VOLUME_TYPE_2,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- original = {
- 'snapCPG': self.RETYPE_VOLUME_INFO_1['snapCPG'],
- 'comment': self.RETYPE_VOLUME_INFO_1['comment']}
-
- expected = [
- mock.call.modifyVolume('osv-0DM4qZEVSKON-DXN-NwVpw', original),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(hpexceptions.HTTPForbidden,
+ self.driver.retype,
+ self.ctxt,
+ {'id': self.VOLUME_ID},
+ self.RETYPE_VOLUME_TYPE_2,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ original = {
+ 'snapCPG': self.RETYPE_VOLUME_INFO_1['snapCPG'],
+ 'comment': self.RETYPE_VOLUME_INFO_1['comment']}
+
+ expected = [
+ mock.call.modifyVolume('osv-0DM4qZEVSKON-DXN-NwVpw', original)]
+ mock_client.assert_has_calls(expected + self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_different_array(self, _mock_volume_types):
mock_client.getStorageSystemInfo.return_value = {
'serialNumber': 'XXXXXXX'}
- self.assertRaises(exception.InvalidHost,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_1,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.getStorageSystemInfo(),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(exception.InvalidHost,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_1,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ expected = [
+ mock.call.getVolume(self.VOLUME_3PAR_NAME),
+ mock.call.getStorageSystemInfo()]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_across_cpg_domains(self, _mock_volume_types):
{'domain': 'domain2'},
]
- self.assertRaises(exception.Invalid3PARDomain,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_1,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.getStorageSystemInfo(),
- mock.call.getCPG(self.RETYPE_VOLUME_INFO_0['userCPG']),
- mock.call.getCPG(self.RETYPE_VOLUME_TYPE_1['extra_specs']['cpg']),
- mock.call.logout()
- ]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(exception.Invalid3PARDomain,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_1,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ expected = [
+ mock.call.getVolume(self.VOLUME_3PAR_NAME),
+ mock.call.getStorageSystemInfo(),
+ mock.call.getCPG(self.RETYPE_VOLUME_INFO_0['userCPG']),
+ mock.call.getCPG(
+ self.RETYPE_VOLUME_TYPE_1['extra_specs']['cpg'])
+ ]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_across_snap_cpg_domains(self, _mock_volume_types):
{'domain': 'snap_cpg_domain_1'},
]
- self.assertRaises(exception.Invalid3PARDomain,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_1,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.getStorageSystemInfo(),
- mock.call.getCPG(self.RETYPE_VOLUME_INFO_0['userCPG']),
- mock.call.getCPG(self.RETYPE_VOLUME_TYPE_1['extra_specs']['cpg']),
- mock.call.getCPG(
- self.RETYPE_VOLUME_TYPE_1['extra_specs']['snap_cpg']),
- mock.call.logout()
- ]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(exception.Invalid3PARDomain,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_1,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ expected = [
+ mock.call.getVolume(self.VOLUME_3PAR_NAME),
+ mock.call.getStorageSystemInfo(),
+ mock.call.getCPG(self.RETYPE_VOLUME_INFO_0['userCPG']),
+ mock.call.getCPG(
+ self.RETYPE_VOLUME_TYPE_1['extra_specs']['cpg']),
+ mock.call.getCPG(
+ self.RETYPE_VOLUME_TYPE_1['extra_specs']['snap_cpg'])
+ ]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_to_bad_persona(self, _mock_volume_types):
_mock_volume_types.return_value = self.RETYPE_VOLUME_TYPE_BAD_PERSONA
mock_client = self.setup_driver(mock_conf=self.RETYPE_CONF)
- self.assertRaises(exception.InvalidInput,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_BAD_PERSONA,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.logout()
- ]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(exception.InvalidInput,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_BAD_PERSONA,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ expected = [mock.call.getVolume(self.VOLUME_3PAR_NAME)]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_to_bad_cpg(self, _mock_volume_types):
mock_client = self.setup_driver(mock_conf=self.RETYPE_CONF)
mock_client.getCPG.side_effect = hpexceptions.HTTPNotFound
- self.assertRaises(exception.InvalidInput,
- self.driver.retype,
- self.ctxt,
- self.RETYPE_VOLUME_INFO_0,
- self.RETYPE_VOLUME_TYPE_BAD_CPG,
- self.RETYPE_DIFF,
- self.RETYPE_HOST)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getCPG(
- self.RETYPE_VOLUME_TYPE_BAD_CPG['extra_specs']['cpg']),
- mock.call.logout()
- ]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.assertRaises(exception.InvalidInput,
+ self.driver.retype,
+ self.ctxt,
+ self.RETYPE_VOLUME_INFO_0,
+ self.RETYPE_VOLUME_TYPE_BAD_CPG,
+ self.RETYPE_DIFF,
+ self.RETYPE_HOST)
+
+ expected = [
+ mock.call.getCPG(
+ self.RETYPE_VOLUME_TYPE_BAD_CPG['extra_specs']['cpg'])
+ ]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_tune(self, _mock_volume_types):
volume = {'id': HP3PARBaseDriver.CLONE_ID}
- retyped = self.driver.retype(
- self.ctxt, volume, type_ref, None, self.RETYPE_HOST)
- self.assertTrue(retyped)
-
- expected = [
- mock.call.modifyVolume('osv-0DM4qZEVSKON-AAAAAAAAA',
- {'comment': mock.ANY,
- 'snapCPG': 'OpenStackCPGSnap'}),
- mock.call.deleteVolumeSet('vvs-0DM4qZEVSKON-AAAAAAAAA'),
- mock.call.addVolumeToVolumeSet('myvvs',
- 'osv-0DM4qZEVSKON-AAAAAAAAA'),
- mock.call.modifyVolume('osv-0DM4qZEVSKON-AAAAAAAAA',
- {'action': 6,
- 'userCPG': 'OpenStackCPG',
- 'conversionOperation': 1,
- 'tuneOperation': 1}),
- mock.call.getTask(1),
- mock.call.logout()
- ]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ retyped = self.driver.retype(
+ self.ctxt, volume, type_ref, None, self.RETYPE_HOST)
+ self.assertTrue(retyped)
+
+ expected = [
+ mock.call.modifyVolume('osv-0DM4qZEVSKON-AAAAAAAAA',
+ {'comment': mock.ANY,
+ 'snapCPG': 'OpenStackCPGSnap'}),
+ mock.call.deleteVolumeSet('vvs-0DM4qZEVSKON-AAAAAAAAA'),
+ mock.call.addVolumeToVolumeSet('myvvs',
+ 'osv-0DM4qZEVSKON-AAAAAAAAA'),
+ mock.call.modifyVolume('osv-0DM4qZEVSKON-AAAAAAAAA',
+ {'action': 6,
+ 'userCPG': 'OpenStackCPG',
+ 'conversionOperation': 1,
+ 'tuneOperation': 1}),
+ mock.call.getTask(1)
+ ]
+ mock_client.assert_has_calls(expected + self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_retype_qos_spec(self, _mock_volume_types):
cpg = "any_cpg"
snap_cpg = "any_cpg"
- self.driver.common._retype(self.volume,
- HP3PARBaseDriver.VOLUME_3PAR_NAME,
- "old_type", "old_type_id",
- HP3PARBaseDriver.RETYPE_HOST,
- None, cpg, cpg, snap_cpg, snap_cpg,
- True, True, None, None,
- self.QOS_SPECS, self.RETYPE_QOS_SPECS,
- "{}")
- expected = [
- mock.call.createVolumeSet('vvs-0DM4qZEVSKON-DXN-NwVpw', None),
- mock.call.createQoSRules(
- 'vvs-0DM4qZEVSKON-DXN-NwVpw',
- {'ioMinGoal': 100, 'ioMaxLimit': 1000,
- 'bwMinGoalKB': 25600, 'bwMaxLimitKB': 51200,
- 'priority': 3,
- 'latencyGoal': 25}
- ),
- mock.call.addVolumeToVolumeSet(
- 'vvs-0DM4qZEVSKON-DXN-NwVpw', 'osv-0DM4qZEVSKON-DXN-NwVpw')]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ common._retype(self.volume,
+ HP3PARBaseDriver.VOLUME_3PAR_NAME,
+ "old_type", "old_type_id",
+ HP3PARBaseDriver.RETYPE_HOST,
+ None, cpg, cpg, snap_cpg, snap_cpg,
+ True, True, None, None,
+ self.QOS_SPECS, self.RETYPE_QOS_SPECS,
+ "{}")
+
+ expected = [
+ mock.call.createVolumeSet('vvs-0DM4qZEVSKON-DXN-NwVpw', None),
+ mock.call.createQoSRules(
+ 'vvs-0DM4qZEVSKON-DXN-NwVpw',
+ {'ioMinGoal': 100, 'ioMaxLimit': 1000,
+ 'bwMinGoalKB': 25600, 'bwMaxLimitKB': 51200,
+ 'priority': 3,
+ 'latencyGoal': 25}
+ ),
+ mock.call.addVolumeToVolumeSet(
+ 'vvs-0DM4qZEVSKON-DXN-NwVpw',
+ 'osv-0DM4qZEVSKON-DXN-NwVpw')]
+ mock_client.assert_has_calls(expected)
def test_delete_volume(self):
-
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- self.driver.delete_volume(self.volume)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.delete_volume(self.volume)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.deleteVolume(self.VOLUME_3PAR_NAME),
- mock.call.logout()]
+ expected = [mock.call.deleteVolume(self.VOLUME_3PAR_NAME)]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_create_cloned_volume(self):
-
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
mock_client.copyVolume.return_value = {'taskid': 1}
-
- volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
- 'id': HP3PARBaseDriver.CLONE_ID,
- 'display_name': 'Foo Volume',
- 'size': 2,
- 'host': volume_utils.append_host(self.FAKE_HOST,
- HP3PAR_CPG2),
- 'source_volid': HP3PARBaseDriver.VOLUME_ID}
- src_vref = {}
- model_update = self.driver.create_cloned_volume(volume, src_vref)
- self.assertIsNone(model_update)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.copyVolume(
- self.VOLUME_3PAR_NAME,
- 'osv-0DM4qZEVSKON-AAAAAAAAA',
- HP3PAR_CPG2,
- {'snapCPG': 'OpenStackCPGSnap', 'tpvv': True,
- 'online': True}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
+ 'id': HP3PARBaseDriver.CLONE_ID,
+ 'display_name': 'Foo Volume',
+ 'size': 2,
+ 'host': volume_utils.append_host(self.FAKE_HOST,
+ HP3PAR_CPG2),
+ 'source_volid': HP3PARBaseDriver.VOLUME_ID}
+ src_vref = {}
+ model_update = self.driver.create_cloned_volume(volume, src_vref)
+ self.assertIsNone(model_update)
+
+ expected = [
+ mock.call.copyVolume(
+ self.VOLUME_3PAR_NAME,
+ 'osv-0DM4qZEVSKON-AAAAAAAAA',
+ HP3PAR_CPG2,
+ {'snapCPG': 'OpenStackCPGSnap', 'tpvv': True,
+ 'online': True})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_create_cloned_qos_volume(self, _mock_volume_types):
_mock_volume_types.return_value = self.RETYPE_VOLUME_TYPE_2
mock_client = self.setup_driver()
mock_client.copyVolume.return_value = {'taskid': 1}
-
- src_vref = {}
- volume = self.volume_qos.copy()
- host = "TEST_HOST"
- pool = "TEST_POOL"
- volume_host = volume_utils.append_host(host, pool)
- expected_cpg = self.RETYPE_VOLUME_TYPE_2['extra_specs']['cpg']
- expected_volume_host = volume_utils.append_host(host, expected_cpg)
- volume['id'] = HP3PARBaseDriver.CLONE_ID
- volume['host'] = volume_host
- volume['source_volid'] = HP3PARBaseDriver.VOLUME_ID
- model_update = self.driver.create_cloned_volume(volume, src_vref)
- self.assertEqual(model_update, {'host': expected_volume_host})
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getCPG(expected_cpg),
- mock.call.copyVolume(
- self.VOLUME_3PAR_NAME,
- 'osv-0DM4qZEVSKON-AAAAAAAAA',
- expected_cpg,
- {'snapCPG': 'OpenStackCPGSnap', 'tpvv': True,
- 'online': True}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ src_vref = {}
+ volume = self.volume_qos.copy()
+ host = "TEST_HOST"
+ pool = "TEST_POOL"
+ volume_host = volume_utils.append_host(host, pool)
+ expected_cpg = self.RETYPE_VOLUME_TYPE_2['extra_specs']['cpg']
+ expected_volume_host = volume_utils.append_host(host, expected_cpg)
+ volume['id'] = HP3PARBaseDriver.CLONE_ID
+ volume['host'] = volume_host
+ volume['source_volid'] = HP3PARBaseDriver.VOLUME_ID
+ model_update = self.driver.create_cloned_volume(volume, src_vref)
+ self.assertEqual(model_update, {'host': expected_volume_host})
+
+ expected = [
+ mock.call.getCPG(expected_cpg),
+ mock.call.copyVolume(
+ self.VOLUME_3PAR_NAME,
+ 'osv-0DM4qZEVSKON-AAAAAAAAA',
+ expected_cpg,
+ {'snapCPG': 'OpenStackCPGSnap', 'tpvv': True,
+ 'online': True})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_migrate_volume(self):
'status': 'available',
'host': HP3PARBaseDriver.FAKE_HOST,
'source_volid': HP3PARBaseDriver.VOLUME_ID}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ volume_name_3par = common._encode_name(volume['id'])
+
+ loc_info = 'HP3PARDriver:1234:CPG-FC1'
+ host = {'host': 'stack@3parfc1#CPG-FC1',
+ 'capabilities': {'location_info': loc_info}}
+
+ result = self.driver.migrate_volume(context.get_admin_context(),
+ volume, host)
+ self.assertIsNotNone(result)
+ self.assertEqual((True, None), result)
+
+ osv_matcher = 'osv-' + volume_name_3par
+
+ expected = [
+ mock.call.modifyVolume(
+ osv_matcher,
+ {'comment': '{"qos": {}, "display_name": "Foo Volume"}',
+ 'snapCPG': HP3PAR_CPG_SNAP}),
+ mock.call.modifyVolume(osv_matcher,
+ {'action': 6,
+ 'userCPG': 'CPG-FC1',
+ 'conversionOperation': 1,
+ 'tuneOperation': 1}),
+ mock.call.getTask(mock.ANY)
+ ]
- volume_name_3par = self.driver.common._encode_name(volume['id'])
-
- loc_info = 'HP3PARDriver:1234:CPG-FC1'
- host = {'host': 'stack@3parfc1#CPG-FC1',
- 'capabilities': {'location_info': loc_info}}
-
- result = self.driver.migrate_volume(context.get_admin_context(),
- volume, host)
- self.assertIsNotNone(result)
- self.assertEqual((True, None), result)
-
- osv_matcher = 'osv-' + volume_name_3par
-
- expected = [
- mock.call.modifyVolume(
- osv_matcher,
- {'comment': '{"qos": {}, "display_name": "Foo Volume"}',
- 'snapCPG': HP3PAR_CPG_SNAP}),
- mock.call.modifyVolume(osv_matcher,
- {'action': 6,
- 'userCPG': 'CPG-FC1',
- 'conversionOperation': 1,
- 'tuneOperation': 1}),
- mock.call.getTask(mock.ANY),
- mock.call.logout()
- ]
-
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected + self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_migrate_volume_with_type(self, _mock_volume_types):
'host': HP3PARBaseDriver.FAKE_HOST,
'source_volid': HP3PARBaseDriver.VOLUME_ID}
- volume_name_3par = self.driver.common._encode_name(volume['id'])
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- loc_info = 'HP3PARDriver:1234:CPG-FC1'
- host = {'host': 'stack@3parfc1#CPG-FC1',
- 'capabilities': {'location_info': loc_info}}
+ volume_name_3par = common._encode_name(volume['id'])
- result = self.driver.migrate_volume(context.get_admin_context(),
- volume, host)
- self.assertIsNotNone(result)
- expected_host = volume_utils.append_host(
- "stack@3parfc1",
- self.RETYPE_VOLUME_TYPE_2['extra_specs']['cpg'])
- self.assertEqual((True, {'host': expected_host}), result)
-
- osv_matcher = 'osv-' + volume_name_3par
-
- expected_comment = {
- "display_name": display_name,
- "volume_type_id": self.RETYPE_VOLUME_TYPE_2['id'],
- "volume_type_name": self.RETYPE_VOLUME_TYPE_2['name'],
- "vvs": self.RETYPE_VOLUME_TYPE_2['extra_specs']['vvs']
- }
- expected = [
- mock.call.modifyVolume(
- osv_matcher,
- {'comment': self.CommentMatcher(self.assertEqual,
- expected_comment),
- 'snapCPG': self.RETYPE_VOLUME_TYPE_2
- ['extra_specs']['snap_cpg']}),
- mock.call.modifyVolume(
- osv_matcher,
- {'action': 6,
- 'userCPG': self.RETYPE_VOLUME_TYPE_2['extra_specs']['cpg'],
- 'conversionOperation': 1,
- 'tuneOperation': 1}),
- mock.call.getTask(mock.ANY),
- mock.call.logout()
- ]
+ loc_info = 'HP3PARDriver:1234:CPG-FC1'
+ host = {'host': 'stack@3parfc1#CPG-FC1',
+ 'capabilities': {'location_info': loc_info}}
- mock_client.assert_has_calls(expected)
+ result = self.driver.migrate_volume(context.get_admin_context(),
+ volume, host)
+ self.assertIsNotNone(result)
+ expected_host = volume_utils.append_host(
+ "stack@3parfc1",
+ self.RETYPE_VOLUME_TYPE_2['extra_specs']['cpg'])
+ self.assertEqual((True, {'host': expected_host}), result)
+
+ osv_matcher = 'osv-' + volume_name_3par
+
+ expected_comment = {
+ "display_name": display_name,
+ "volume_type_id": self.RETYPE_VOLUME_TYPE_2['id'],
+ "volume_type_name": self.RETYPE_VOLUME_TYPE_2['name'],
+ "vvs": self.RETYPE_VOLUME_TYPE_2['extra_specs']['vvs']
+ }
+ expected = [
+ mock.call.modifyVolume(
+ osv_matcher,
+ {'comment': self.CommentMatcher(self.assertEqual,
+ expected_comment),
+ 'snapCPG': self.RETYPE_VOLUME_TYPE_2
+ ['extra_specs']['snap_cpg']}),
+ mock.call.modifyVolume(
+ osv_matcher,
+ {'action': 6,
+ 'userCPG': self.RETYPE_VOLUME_TYPE_2
+ ['extra_specs']['cpg'],
+ 'conversionOperation': 1,
+ 'tuneOperation': 1}),
+ mock.call.getTask(mock.ANY)
+ ]
+
+ mock_client.assert_has_calls(
+ expected +
+ self.standard_logout)
def test_migrate_volume_diff_host(self):
conf = {
'serialNumber': 'different'},
}
- self.setup_driver(mock_conf=conf)
+ mock_client = self.setup_driver(mock_conf=conf)
volume = {'name': HP3PARBaseDriver.VOLUME_NAME,
'id': HP3PARBaseDriver.CLONE_ID,
host = {'host': 'stack@3parfc1',
'capabilities': {'location_info': loc_info}}
- result = self.driver.migrate_volume(context.get_admin_context(),
- volume, host)
- self.assertIsNotNone(result)
- self.assertEqual((False, None), result)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ result = self.driver.migrate_volume(context.get_admin_context(),
+ volume, host)
+ self.assertIsNotNone(result)
+ self.assertEqual((False, None), result)
@mock.patch.object(volume_types, 'get_volume_type')
def test_migrate_volume_diff_domain(self, _mock_volume_types):
'host': HP3PARBaseDriver.FAKE_HOST,
'source_volid': HP3PARBaseDriver.VOLUME_ID}
- volume_name_3par = self.driver.common._encode_name(volume['id'])
-
- loc_info = 'HP3PARDriver:1234:CPG-FC1'
- host = {'host': 'stack@3parfc1#CPG-FC1',
- 'capabilities': {'location_info': loc_info}}
-
- result = self.driver.migrate_volume(context.get_admin_context(),
- volume, host)
- self.assertIsNotNone(result)
- self.assertEqual((True, None), result)
-
- osv_matcher = 'osv-' + volume_name_3par
-
- expected = [
- mock.call.modifyVolume(
- osv_matcher,
- {'comment': '{"qos": {}, "display_name": "Foo Volume"}',
- 'snapCPG': HP3PAR_CPG_SNAP}),
- mock.call.modifyVolume(osv_matcher,
- {'action': 6,
- 'userCPG': 'CPG-FC1',
- 'conversionOperation': 1,
- 'tuneOperation': 1}),
- mock.call.getTask(mock.ANY),
- mock.call.logout()
- ]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ volume_name_3par = common._encode_name(volume['id'])
+
+ loc_info = 'HP3PARDriver:1234:CPG-FC1'
+ host = {'host': 'stack@3parfc1#CPG-FC1',
+ 'capabilities': {'location_info': loc_info}}
+
+ result = self.driver.migrate_volume(context.get_admin_context(),
+ volume, host)
+ self.assertIsNotNone(result)
+ self.assertEqual((True, None), result)
+
+ osv_matcher = 'osv-' + volume_name_3par
+
+ expected = [
+ mock.call.modifyVolume(
+ osv_matcher,
+ {'comment': '{"qos": {}, "display_name": "Foo Volume"}',
+ 'snapCPG': HP3PAR_CPG_SNAP}),
+ mock.call.modifyVolume(osv_matcher,
+ {'action': 6,
+ 'userCPG': 'CPG-FC1',
+ 'conversionOperation': 1,
+ 'tuneOperation': 1}),
+ mock.call.getTask(mock.ANY),
+ ]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected + self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_migrate_volume_attached(self, _mock_volume_types):
'host': HP3PARBaseDriver.FAKE_HOST,
'source_volid': HP3PARBaseDriver.VOLUME_ID}
- volume_name_3par = self.driver.common._encode_name(volume['id'])
- osv_matcher = 'osv-' + volume_name_3par
-
- loc_info = 'HP3PARDriver:1234567:CPG-FC1'
-
- protocol = "FC"
- if self.properties['driver_volume_type'] == "iscsi":
- protocol = "iSCSI"
-
- host = {'host': 'stack@3parfc1',
- 'capabilities': {'location_info': loc_info,
- 'storage_protocol': protocol}}
-
- result = self.driver.migrate_volume(context.get_admin_context(),
- volume, host)
-
- new_comment = {"qos": {},
- "retype_test": "test comment"}
- expected = [
- mock.call.modifyVolume(osv_matcher,
- {'comment': self.CommentMatcher(
- self.assertEqual, new_comment),
- 'snapCPG': 'OpenStackCPGSnap'}),
- mock.call.modifyVolume(osv_matcher,
- {'action': 6,
- 'userCPG': 'OpenStackCPG',
- 'conversionOperation': 1,
- 'tuneOperation': 1}),
- mock.call.getTask(1),
- mock.call.logout()
- ]
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ volume_name_3par = common._encode_name(volume['id'])
+ osv_matcher = 'osv-' + volume_name_3par
+
+ loc_info = 'HP3PARDriver:1234567:CPG-FC1'
+
+ protocol = "FC"
+ if self.properties['driver_volume_type'] == "iscsi":
+ protocol = "iSCSI"
+
+ host = {'host': 'stack@3parfc1',
+ 'capabilities': {'location_info': loc_info,
+ 'storage_protocol': protocol}}
+
+ result = self.driver.migrate_volume(context.get_admin_context(),
+ volume, host)
+
+ new_comment = {"qos": {},
+ "retype_test": "test comment"}
+ expected = [
+ mock.call.modifyVolume(osv_matcher,
+ {'comment': self.CommentMatcher(
+ self.assertEqual, new_comment),
+ 'snapCPG': 'OpenStackCPGSnap'}),
+ mock.call.modifyVolume(osv_matcher,
+ {'action': 6,
+ 'userCPG': 'OpenStackCPG',
+ 'conversionOperation': 1,
+ 'tuneOperation': 1}),
+ mock.call.getTask(1),
+ mock.call.logout()
+ ]
+ mock_client.assert_has_calls(expected)
- self.assertIsNotNone(result)
- self.assertEqual((True, {'host': 'stack@3parfc1#OpenStackCPG'}),
- result)
+ self.assertIsNotNone(result)
+ self.assertEqual((True, {'host': 'stack@3parfc1#OpenStackCPG'}),
+ result)
@mock.patch.object(volume_types, 'get_volume_type')
def test_migrate_volume_attached_diff_protocol(self, _mock_volume_types):
mock_client.assert_has_calls(expected)
def test_attach_volume(self):
-
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- self.driver.attach_volume(context.get_admin_context(),
- self.volume,
- 'abcdef',
- 'newhost',
- '/dev/vdb')
-
- expected = [
- mock.call.setVolumeMetaData(
- self.VOLUME_3PAR_NAME,
- 'HPQ-CS-instance_uuid',
- 'abcdef')]
-
- mock_client.assert_has_calls(expected)
-
- # test the exception
- mock_client.setVolumeMetaData.side_effect = Exception('Custom ex')
- self.assertRaises(exception.CinderException,
- self.driver.attach_volume,
- context.get_admin_context(),
- self.volume,
- 'abcdef',
- 'newhost',
- '/dev/vdb')
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.attach_volume(context.get_admin_context(),
+ self.volume,
+ 'abcdef',
+ 'newhost',
+ '/dev/vdb')
+
+ expected = [
+ mock.call.setVolumeMetaData(
+ self.VOLUME_3PAR_NAME,
+ 'HPQ-CS-instance_uuid',
+ 'abcdef')]
+
+ mock_client.assert_has_calls(expected)
+
+ # test the exception
+ mock_client.setVolumeMetaData.side_effect = Exception('Custom ex')
+ self.assertRaises(exception.CinderException,
+ self.driver.attach_volume,
+ context.get_admin_context(),
+ self.volume,
+ 'abcdef',
+ 'newhost',
+ '/dev/vdb')
def test_detach_volume(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- self.driver.detach_volume(context.get_admin_context(), self.volume)
- expected = [
- mock.call.removeVolumeMetaData(
- self.VOLUME_3PAR_NAME,
- 'HPQ-CS-instance_uuid')]
-
- mock_client.assert_has_calls(expected)
-
- # test the exception
- mock_client.removeVolumeMetaData.side_effect = Exception('Custom ex')
- self.assertRaises(exception.CinderException,
- self.driver.detach_volume,
- context.get_admin_context(),
- self.volume)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.detach_volume(context.get_admin_context(), self.volume)
+ expected = [
+ mock.call.removeVolumeMetaData(
+ self.VOLUME_3PAR_NAME,
+ 'HPQ-CS-instance_uuid')]
+
+ mock_client.assert_has_calls(expected)
+
+ # test the exception
+ mock_client.removeVolumeMetaData.side_effect = Exception(
+ 'Custom ex')
+ self.assertRaises(exception.CinderException,
+ self.driver.detach_volume,
+ context.get_admin_context(),
+ self.volume)
def test_create_snapshot(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- self.driver.create_snapshot(self.snapshot)
-
- commet = (
- '{"volume_id": "761fc5e5-5191-4ec7-aeba-33e36de44156",'
- ' "display_name": "fakesnap",'
- ' "description": "test description name",'
- ' "volume_name": "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createSnapshot(
- 'oss-L4I73ONuTci9Fd4ceij-MQ',
- 'osv-dh-F5VGRTseuujPjbeRBVg',
- {
- 'comment': commet,
- 'readOnly': True}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.create_snapshot(self.snapshot)
+
+ comment = (
+ '{"volume_id": "761fc5e5-5191-4ec7-aeba-33e36de44156",'
+ ' "display_name": "fakesnap",'
+ ' "description": "test description name",'
+ ' "volume_name":'
+ ' "volume-d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+
+ expected = [
+ mock.call.createSnapshot(
+ 'oss-L4I73ONuTci9Fd4ceij-MQ',
+ 'osv-dh-F5VGRTseuujPjbeRBVg',
+ {
+ 'comment': comment,
+ 'readOnly': True})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_delete_snapshot(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.delete_snapshot(self.snapshot)
- self.driver.delete_snapshot(self.snapshot)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.deleteVolume('oss-L4I73ONuTci9Fd4ceij-MQ'),
- mock.call.logout()]
+ expected = [
+ mock.call.deleteVolume('oss-L4I73ONuTci9Fd4ceij-MQ')]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_delete_snapshot_in_use(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.create_snapshot(self.snapshot)
+ self.driver.create_volume_from_snapshot(self.volume, self.snapshot)
- self.driver.create_snapshot(self.snapshot)
- self.driver.create_volume_from_snapshot(self.volume, self.snapshot)
-
- ex = hpexceptions.HTTPConflict("In use")
- mock_client.deleteVolume = mock.Mock(side_effect=ex)
+ ex = hpexceptions.HTTPConflict("In use")
+ mock_client.deleteVolume = mock.Mock(side_effect=ex)
- # Deleting the snapshot that a volume is dependent on should fail
- self.assertRaises(exception.SnapshotIsBusy,
- self.driver.delete_snapshot,
- self.snapshot)
+ # Deleting the snapshot that a volume is dependent on should fail
+ self.assertRaises(exception.SnapshotIsBusy,
+ self.driver.delete_snapshot,
+ self.snapshot)
def test_delete_snapshot_not_found(self):
# setup_mock_client drive with default configuration
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- model_update = self.driver.create_volume_from_snapshot(self.volume,
- self.snapshot)
- self.assertIsNone(model_update)
-
- comment = (
- '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
- ' "display_name": "Foo Volume",'
- ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createSnapshot(
- self.VOLUME_3PAR_NAME,
- 'oss-L4I73ONuTci9Fd4ceij-MQ',
- {
- 'comment': comment,
- 'readOnly': False}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
-
- volume = self.volume.copy()
- volume['size'] = 1
- self.assertRaises(exception.InvalidInput,
- self.driver.create_volume_from_snapshot,
- volume, self.snapshot)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ model_update = self.driver.create_volume_from_snapshot(
+ self.volume,
+ self.snapshot)
+ self.assertIsNone(model_update)
+
+ comment = (
+ '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
+ ' "display_name": "Foo Volume",'
+ ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+
+ expected = [
+ mock.call.createSnapshot(
+ self.VOLUME_3PAR_NAME,
+ 'oss-L4I73ONuTci9Fd4ceij-MQ',
+ {
+ 'comment': comment,
+ 'readOnly': False})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+
+ volume = self.volume.copy()
+ volume['size'] = 1
+ self.assertRaises(exception.InvalidInput,
+ self.driver.create_volume_from_snapshot,
+ volume, self.snapshot)
def test_create_volume_from_snapshot_and_extend(self):
# setup_mock_client drive with default configuration
}
mock_client = self.setup_driver(mock_conf=conf)
-
- volume = self.volume.copy()
- volume['size'] = self.volume['size'] + 10
- model_update = self.driver.create_volume_from_snapshot(volume,
- self.snapshot)
- self.assertEqual(model_update,
- {'host': volume_utils.append_host(self.FAKE_HOST,
- HP3PAR_CPG)})
-
- comment = (
- '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
- ' "display_name": "Foo Volume",'
- ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
-
- volume_name_3par = self.driver.common._encode_name(volume['id'])
- osv_matcher = 'osv-' + volume_name_3par
- omv_matcher = 'omv-' + volume_name_3par
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createSnapshot(
- self.VOLUME_3PAR_NAME,
- 'oss-L4I73ONuTci9Fd4ceij-MQ',
- {
- 'comment': comment,
- 'readOnly': False}),
- mock.call.copyVolume(
- osv_matcher, omv_matcher, HP3PAR_CPG, mock.ANY),
- mock.call.getTask(mock.ANY),
- mock.call.getVolume(osv_matcher),
- mock.call.deleteVolume(osv_matcher),
- mock.call.modifyVolume(omv_matcher, {'newName': osv_matcher}),
- mock.call.growVolume(osv_matcher, 10 * 1024),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ volume = self.volume.copy()
+ volume['size'] = self.volume['size'] + 10
+ model_update = self.driver.create_volume_from_snapshot(
+ volume,
+ self.snapshot)
+ self.assertEqual(model_update,
+ {'host': volume_utils.append_host(self.FAKE_HOST,
+ HP3PAR_CPG)})
+
+ comment = (
+ '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
+ ' "display_name": "Foo Volume",'
+ ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+
+ volume_name_3par = common._encode_name(volume['id'])
+ osv_matcher = 'osv-' + volume_name_3par
+ omv_matcher = 'omv-' + volume_name_3par
+
+ expected = [
+ mock.call.createSnapshot(
+ self.VOLUME_3PAR_NAME,
+ 'oss-L4I73ONuTci9Fd4ceij-MQ',
+ {
+ 'comment': comment,
+ 'readOnly': False}),
+ mock.call.copyVolume(
+ osv_matcher, omv_matcher, HP3PAR_CPG, mock.ANY),
+ mock.call.getTask(mock.ANY),
+ mock.call.getVolume(osv_matcher),
+ mock.call.deleteVolume(osv_matcher),
+ mock.call.modifyVolume(omv_matcher, {'newName': osv_matcher}),
+ mock.call.growVolume(osv_matcher, 10 * 1024)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_create_volume_from_snapshot_and_extend_with_qos(
'tpvv': True,
'volume_type': self.volume_type}}
- volume = self.volume_qos.copy()
- volume['size'] = self.volume['size'] + 10
- model_update = self.driver.create_volume_from_snapshot(volume,
- self.snapshot)
- self.assertEqual(model_update,
- {'host': volume_utils.append_host(self.FAKE_HOST,
- HP3PAR_CPG_QOS)})
-
- comment = (
- '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
- ' "display_name": "Foo Volume",'
- ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
-
- volume_name_3par = self.driver.common._encode_name(volume['id'])
- osv_matcher = 'osv-' + volume_name_3par
- omv_matcher = 'omv-' + volume_name_3par
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createSnapshot(
- self.VOLUME_3PAR_NAME,
- 'oss-L4I73ONuTci9Fd4ceij-MQ',
- {
- 'comment': comment,
- 'readOnly': False}),
- mock.call.getCPG(HP3PAR_CPG_QOS),
- mock.call.copyVolume(
- osv_matcher, omv_matcher, HP3PAR_CPG_QOS, mock.ANY),
- mock.call.getTask(mock.ANY),
- mock.call.getVolume(osv_matcher),
- mock.call.deleteVolume(osv_matcher),
- mock.call.modifyVolume(omv_matcher, {'newName': osv_matcher}),
- mock.call.growVolume(osv_matcher, 10 * 1024),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ volume = self.volume_qos.copy()
+ volume['size'] = self.volume['size'] + 10
+ model_update = self.driver.create_volume_from_snapshot(
+ volume,
+ self.snapshot)
+ self.assertEqual(model_update,
+ {'host': volume_utils.append_host(
+ self.FAKE_HOST,
+ HP3PAR_CPG_QOS)})
+
+ comment = (
+ '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
+ ' "display_name": "Foo Volume",'
+ ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+
+ volume_name_3par = common._encode_name(volume['id'])
+ osv_matcher = 'osv-' + volume_name_3par
+ omv_matcher = 'omv-' + volume_name_3par
+
+ expected = [
+ mock.call.createSnapshot(
+ self.VOLUME_3PAR_NAME,
+ 'oss-L4I73ONuTci9Fd4ceij-MQ',
+ {
+ 'comment': comment,
+ 'readOnly': False}),
+ mock.call.getCPG(HP3PAR_CPG_QOS),
+ mock.call.copyVolume(
+ osv_matcher, omv_matcher, HP3PAR_CPG_QOS, mock.ANY),
+ mock.call.getTask(mock.ANY),
+ mock.call.getVolume(osv_matcher),
+ mock.call.deleteVolume(osv_matcher),
+ mock.call.modifyVolume(omv_matcher, {'newName': osv_matcher}),
+ mock.call.growVolume(osv_matcher, 10 * 1024)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_create_volume_from_snapshot_and_extend_copy_fail(self):
# setup_mock_client drive with default configuration
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- _mock_volume_types.return_value = {
- 'name': 'gold',
- 'extra_specs': {
- 'cpg': HP3PAR_CPG,
- 'snap_cpg': HP3PAR_CPG_SNAP,
- 'vvs_name': self.VVS_NAME,
- 'qos': self.QOS,
- 'tpvv': True,
- 'volume_type': self.volume_type}}
- self.driver.create_volume_from_snapshot(self.volume_qos, self.snapshot)
-
- comment = (
- '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
- ' "display_name": "Foo Volume",'
- ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.createSnapshot(
- self.VOLUME_3PAR_NAME,
- 'oss-L4I73ONuTci9Fd4ceij-MQ', {
- 'comment': comment,
- 'readOnly': False}),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
-
- volume = self.volume.copy()
- volume['size'] = 1
- self.assertRaises(exception.InvalidInput,
- self.driver.create_volume_from_snapshot,
- volume, self.snapshot)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ _mock_volume_types.return_value = {
+ 'name': 'gold',
+ 'extra_specs': {
+ 'cpg': HP3PAR_CPG,
+ 'snap_cpg': HP3PAR_CPG_SNAP,
+ 'vvs_name': self.VVS_NAME,
+ 'qos': self.QOS,
+ 'tpvv': True,
+ 'volume_type': self.volume_type}}
+ self.driver.create_volume_from_snapshot(
+ self.volume_qos,
+ self.snapshot)
+
+ comment = (
+ '{"snapshot_id": "2f823bdc-e36e-4dc8-bd15-de1c7a28ff31",'
+ ' "display_name": "Foo Volume",'
+ ' "volume_id": "d03338a9-9115-48a3-8dfc-35cdfcdc15a7"}')
+
+ expected = [
+ mock.call.createSnapshot(
+ self.VOLUME_3PAR_NAME,
+ 'oss-L4I73ONuTci9Fd4ceij-MQ', {
+ 'comment': comment,
+ 'readOnly': False})]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+
+ volume = self.volume.copy()
+ volume['size'] = 1
+ self.assertRaises(exception.InvalidInput,
+ self.driver.create_volume_from_snapshot,
+ volume, self.snapshot)
def test_terminate_connection(self):
# setup_mock_client drive with default configuration
'volumeName': self.VOLUME_3PAR_NAME,
'lun': None, 'type': 0}]
- self.driver.terminate_connection(
- self.volume,
- self.connector,
- force=True)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.deleteVLUN(
- self.VOLUME_3PAR_NAME,
- None,
- self.FAKE_HOST),
- mock.call.deleteHost(self.FAKE_HOST),
- mock.call.removeVolumeMetaData(
- self.VOLUME_3PAR_NAME, CHAP_USER_KEY),
- mock.call.removeVolumeMetaData(
- self.VOLUME_3PAR_NAME, CHAP_PASS_KEY),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ self.driver.terminate_connection(
+ self.volume,
+ self.connector,
+ force=True)
+
+ expected = [
+ mock.call.getHostVLUNs(self.FAKE_HOST),
+ mock.call.deleteVLUN(
+ self.VOLUME_3PAR_NAME,
+ None,
+ self.FAKE_HOST),
+ mock.call.deleteHost(self.FAKE_HOST),
+ mock.call.removeVolumeMetaData(
+ self.VOLUME_3PAR_NAME, CHAP_USER_KEY),
+ mock.call.removeVolumeMetaData(
+ self.VOLUME_3PAR_NAME, CHAP_PASS_KEY)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_update_volume_key_value_pair(self):
# setup_mock_client drive with default configuration
key = 'a'
value = 'b'
- self.driver.common.update_volume_key_value_pair(
- self.volume,
- key,
- value)
- expected = [
- mock.call.setVolumeMetaData(self.VOLUME_3PAR_NAME, key, value)]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ common.update_volume_key_value_pair(
+ self.volume,
+ key,
+ value)
- mock_client.assert_has_calls(expected)
+ expected = [
+ mock.call.setVolumeMetaData(self.VOLUME_3PAR_NAME, key, value)]
+
+ mock_client.assert_has_calls(expected)
- # check exception
- mock_client.setVolumeMetaData.side_effect = Exception('fake')
- self.assertRaises(exception.VolumeBackendAPIException,
- self.driver.common.update_volume_key_value_pair,
- self.volume,
- None,
- 'b')
+ # check exception
+ mock_client.setVolumeMetaData.side_effect = Exception('fake')
+ self.assertRaises(exception.VolumeBackendAPIException,
+ common.update_volume_key_value_pair,
+ self.volume,
+ None,
+ 'b')
def test_clear_volume_key_value_pair(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ key = 'a'
+ common = self.driver._login()
+ common.clear_volume_key_value_pair(self.volume, key)
- key = 'a'
- self.driver.common.clear_volume_key_value_pair(self.volume, key)
-
- expected = [
- mock.call.removeVolumeMetaData(self.VOLUME_3PAR_NAME, key)]
+ expected = [
+ mock.call.removeVolumeMetaData(self.VOLUME_3PAR_NAME, key)]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
- # check the exception
- mock_client.removeVolumeMetaData.side_effect = Exception('fake')
- self.assertRaises(exception.VolumeBackendAPIException,
- self.driver.common.clear_volume_key_value_pair,
- self.volume,
- None)
+ # check the exception
+ mock_client.removeVolumeMetaData.side_effect = Exception('fake')
+ self.assertRaises(exception.VolumeBackendAPIException,
+ common.clear_volume_key_value_pair,
+ self.volume,
+ None)
def test_extend_volume(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- grow_size = 3
- old_size = self.volume['size']
- new_size = old_size + grow_size
- self.driver.extend_volume(self.volume, str(new_size))
- growth_size_mib = grow_size * units.Ki
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ grow_size = 3
+ old_size = self.volume['size']
+ new_size = old_size + grow_size
+ self.driver.extend_volume(self.volume, str(new_size))
+ growth_size_mib = grow_size * units.Ki
- expected = [
- mock.call.growVolume(self.VOLUME_3PAR_NAME, growth_size_mib)]
+ expected = [
+ mock.call.growVolume(self.VOLUME_3PAR_NAME, growth_size_mib)]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
def test_extend_volume_non_base(self):
extend_ex = hpexceptions.HTTPForbidden(error={'code': 150})
}
mock_client = self.setup_driver(mock_conf=conf)
- grow_size = 3
- old_size = self.volume['size']
- new_size = old_size + grow_size
- self.driver.extend_volume(self.volume, str(new_size))
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ grow_size = 3
+ old_size = self.volume['size']
+ new_size = old_size + grow_size
+ self.driver.extend_volume(self.volume, str(new_size))
- self.assertEqual(2, mock_client.growVolume.call_count)
+ self.assertEqual(2, mock_client.growVolume.call_count)
def test_extend_volume_non_base_failure(self):
extend_ex = hpexceptions.HTTPForbidden(error={'code': 150})
'growVolume.side_effect': extend_ex
}
- self.setup_driver(mock_conf=conf)
- grow_size = 3
- old_size = self.volume['size']
- new_size = old_size + grow_size
- self.assertRaises(hpexceptions.HTTPForbidden,
- self.driver.extend_volume,
- self.volume,
- str(new_size))
+ mock_client = self.setup_driver(mock_conf=conf)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ grow_size = 3
+ old_size = self.volume['size']
+ new_size = old_size + grow_size
+ self.assertRaises(hpexceptions.HTTPForbidden,
+ self.driver.extend_volume,
+ self.volume,
+ str(new_size))
def test_get_ports(self):
# setup_mock_client drive with default configuration
'type': 2,
'portPos': {'node': 0, 'slot': 6, 'cardPort': 3}}]}
- ports = self.driver.common.get_ports()['members']
- self.assertEqual(len(ports), 3)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ ports = common.get_ports()['members']
+ self.assertEqual(len(ports), 3)
def test_get_by_qos_spec_with_scoping(self):
- self.setup_driver()
- qos_ref = qos_specs.create(self.ctxt, 'qos-specs-1', self.QOS)
- type_ref = volume_types.create(self.ctxt,
- "type1", {"qos:maxIOPS": "100",
- "qos:maxBWS": "50",
- "qos:minIOPS": "10",
- "qos:minBWS": "20",
- "qos:latency": "5",
- "qos:priority": "high"})
- qos_specs.associate_qos_with_type(self.ctxt,
- qos_ref['id'],
- type_ref['id'])
- type_ref = volume_types.get_volume_type(self.ctxt, type_ref['id'])
- qos = self.driver.common._get_qos_by_volume_type(type_ref)
- self.assertEqual(qos, {'maxIOPS': '1000', 'maxBWS': '50',
- 'minIOPS': '100', 'minBWS': '25',
- 'latency': '25', 'priority': 'low'})
+ mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ qos_ref = qos_specs.create(self.ctxt, 'qos-specs-1', self.QOS)
+ type_ref = volume_types.create(self.ctxt,
+ "type1", {"qos:maxIOPS": "100",
+ "qos:maxBWS": "50",
+ "qos:minIOPS": "10",
+ "qos:minBWS": "20",
+ "qos:latency": "5",
+ "qos:priority": "high"})
+ qos_specs.associate_qos_with_type(self.ctxt,
+ qos_ref['id'],
+ type_ref['id'])
+ type_ref = volume_types.get_volume_type(self.ctxt, type_ref['id'])
+ qos = common._get_qos_by_volume_type(type_ref)
+ self.assertEqual(qos, {'maxIOPS': '1000', 'maxBWS': '50',
+ 'minIOPS': '100', 'minBWS': '25',
+ 'latency': '25', 'priority': 'low'})
def test_get_by_qos_spec(self):
- self.setup_driver()
- qos_ref = qos_specs.create(self.ctxt, 'qos-specs-1', self.QOS_SPECS)
- type_ref = volume_types.create(self.ctxt,
- "type1", {"qos:maxIOPS": "100",
- "qos:maxBWS": "50",
- "qos:minIOPS": "10",
- "qos:minBWS": "20",
- "qos:latency": "5",
- "qos:priority": "high"})
- qos_specs.associate_qos_with_type(self.ctxt,
- qos_ref['id'],
- type_ref['id'])
- type_ref = volume_types.get_volume_type(self.ctxt, type_ref['id'])
- qos = self.driver.common._get_qos_by_volume_type(type_ref)
- self.assertEqual(qos, {'maxIOPS': '1000', 'maxBWS': '50',
- 'minIOPS': '100', 'minBWS': '25',
- 'latency': '25', 'priority': 'low'})
+ mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ qos_ref = qos_specs.create(
+ self.ctxt,
+ 'qos-specs-1',
+ self.QOS_SPECS)
+ type_ref = volume_types.create(self.ctxt,
+ "type1", {"qos:maxIOPS": "100",
+ "qos:maxBWS": "50",
+ "qos:minIOPS": "10",
+ "qos:minBWS": "20",
+ "qos:latency": "5",
+ "qos:priority": "high"})
+ qos_specs.associate_qos_with_type(self.ctxt,
+ qos_ref['id'],
+ type_ref['id'])
+ type_ref = volume_types.get_volume_type(self.ctxt, type_ref['id'])
+ qos = common._get_qos_by_volume_type(type_ref)
+ self.assertEqual(qos, {'maxIOPS': '1000', 'maxBWS': '50',
+ 'minIOPS': '100', 'minBWS': '25',
+ 'latency': '25', 'priority': 'low'})
def test_get_by_qos_by_type_only(self):
- self.setup_driver()
- type_ref = volume_types.create(self.ctxt,
- "type1", {"qos:maxIOPS": "100",
- "qos:maxBWS": "50",
- "qos:minIOPS": "10",
- "qos:minBWS": "20",
- "qos:latency": "5",
- "qos:priority": "high"})
- type_ref = volume_types.get_volume_type(self.ctxt, type_ref['id'])
- qos = self.driver.common._get_qos_by_volume_type(type_ref)
- self.assertEqual(qos, {'maxIOPS': '100', 'maxBWS': '50',
- 'minIOPS': '10', 'minBWS': '20',
- 'latency': '5', 'priority': 'high'})
+ mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ type_ref = volume_types.create(self.ctxt,
+ "type1", {"qos:maxIOPS": "100",
+ "qos:maxBWS": "50",
+ "qos:minIOPS": "10",
+ "qos:minBWS": "20",
+ "qos:latency": "5",
+ "qos:priority": "high"})
+ type_ref = volume_types.get_volume_type(self.ctxt, type_ref['id'])
+ qos = common._get_qos_by_volume_type(type_ref)
+ self.assertEqual(qos, {'maxIOPS': '100', 'maxBWS': '50',
+ 'minIOPS': '10', 'minBWS': '20',
+ 'latency': '5', 'priority': 'high'})
def test_create_vlun(self):
host = 'fake-host'
lun_id = 11
nsp = '1:2:3'
mock_client = self.setup_driver()
- location = ("%(name)s,%(lunid)s,%(host)s,%(nsp)s" %
- {'name': self.VOLUME_NAME,
- 'lunid': lun_id,
- 'host': host,
- 'nsp': nsp})
- mock_client.createVLUN.return_value = location
-
- expected_info = {'volume_name': self.VOLUME_NAME,
- 'lun_id': lun_id,
- 'host_name': host,
- 'nsp': nsp}
- vlun_info = self.driver.common._create_3par_vlun(self.VOLUME_NAME,
- host, nsp)
- self.assertEqual(expected_info, vlun_info)
-
- location = ("%(name)s,%(lunid)s,%(host)s" %
- {'name': self.VOLUME_NAME,
- 'lunid': lun_id,
- 'host': host})
- mock_client.createVLUN.return_value = location
- expected_info = {'volume_name': self.VOLUME_NAME,
- 'lun_id': lun_id,
- 'host_name': host}
- vlun_info = self.driver.common._create_3par_vlun(self.VOLUME_NAME,
- host, None)
- self.assertEqual(expected_info, vlun_info)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ location = ("%(name)s,%(lunid)s,%(host)s,%(nsp)s" %
+ {'name': self.VOLUME_NAME,
+ 'lunid': lun_id,
+ 'host': host,
+ 'nsp': nsp})
+ mock_client.createVLUN.return_value = location
+
+ expected_info = {'volume_name': self.VOLUME_NAME,
+ 'lun_id': lun_id,
+ 'host_name': host,
+ 'nsp': nsp}
+ common = self.driver._login()
+ vlun_info = common._create_3par_vlun(
+ self.VOLUME_NAME,
+ host,
+ nsp)
+ self.assertEqual(expected_info, vlun_info)
+
+ location = ("%(name)s,%(lunid)s,%(host)s" %
+ {'name': self.VOLUME_NAME,
+ 'lunid': lun_id,
+ 'host': host})
+ mock_client.createVLUN.return_value = location
+ expected_info = {'volume_name': self.VOLUME_NAME,
+ 'lun_id': lun_id,
+ 'host_name': host}
+ vlun_info = common._create_3par_vlun(
+ self.VOLUME_NAME,
+ host,
+ None)
+ self.assertEqual(expected_info, vlun_info)
def test__get_existing_volume_ref_name(self):
- self.setup_driver()
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
+ mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
- existing_ref = {'source-name': unm_matcher}
- result = self.driver.common._get_existing_volume_ref_name(existing_ref)
- self.assertEqual(unm_matcher, result)
+ existing_ref = {'source-name': unm_matcher}
+ result = common._get_existing_volume_ref_name(existing_ref)
+ self.assertEqual(unm_matcher, result)
- existing_ref = {'source-id': self.volume['id']}
- result = self.driver.common._get_existing_volume_ref_name(existing_ref)
- self.assertEqual(unm_matcher, result)
+ existing_ref = {'source-id': self.volume['id']}
+ result = common._get_existing_volume_ref_name(existing_ref)
+ self.assertEqual(unm_matcher, result)
- existing_ref = {'bad-key': 'foo'}
- self.assertRaises(
- exception.ManageExistingInvalidReference,
- self.driver.common._get_existing_volume_ref_name,
- existing_ref)
+ existing_ref = {'bad-key': 'foo'}
+ self.assertRaises(
+ exception.ManageExistingInvalidReference,
+ common._get_existing_volume_ref_name,
+ existing_ref)
@mock.patch.object(volume_types, 'get_volume_type')
def test_manage_existing(self, _mock_volume_types):
mock_client.modifyVolume.return_value = ("anyResponse", {'taskid': 1})
mock_client.getTask.return_value = self.STATUS_DONE
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- osv_matcher = self.driver.common._get_3par_vol_name(volume['id'])
- vvs_matcher = self.driver.common._get_3par_vvs_name(volume['id'])
- existing_ref = {'source-name': unm_matcher}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- obj = self.driver.manage_existing(volume, existing_ref)
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ osv_matcher = common._get_3par_vol_name(volume['id'])
+ vvs_matcher = common._get_3par_vvs_name(volume['id'])
+ existing_ref = {'source-name': unm_matcher}
- expected_obj = {'display_name': 'Foo Volume',
- 'host': 'my-stack1@3parxxx#fakepool'}
+ expected_obj = {'display_name': 'Foo Volume',
+ 'host': 'my-stack1@3parxxx#fakepool'}
- expected_manage = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.modifyVolume(existing_ref['source-name'],
- {'newName': osv_matcher,
- 'comment': self.CommentMatcher(
- self.assertEqual, new_comment)}),
- ]
+ obj = self.driver.manage_existing(volume, existing_ref)
- retype_comment_qos = {
- "display_name": "Foo Volume",
- "volume_type_name": self.volume_type['name'],
- "volume_type_id": self.volume_type['id'],
- "qos": {
- 'maxIOPS': '1000',
- 'maxBWS': '50',
- 'minIOPS': '100',
- 'minBWS': '25',
- 'latency': '25',
- 'priority': 'low'
+ expected_manage = [
+ mock.call.getVolume(existing_ref['source-name']),
+ mock.call.modifyVolume(existing_ref['source-name'],
+ {'newName': osv_matcher,
+ 'comment': self.CommentMatcher(
+ self.assertEqual, new_comment)}),
+ ]
+
+ retype_comment_qos = {
+ "display_name": "Foo Volume",
+ "volume_type_name": self.volume_type['name'],
+ "volume_type_id": self.volume_type['id'],
+ "qos": {
+ 'maxIOPS': '1000',
+ 'maxBWS': '50',
+ 'minIOPS': '100',
+ 'minBWS': '25',
+ 'latency': '25',
+ 'priority': 'low'
+ }
}
- }
- expected_snap_cpg = self.volume_type['extra_specs']['cpg']
- expected_retype_modify = [
- mock.call.modifyVolume(osv_matcher,
- {'comment': self.CommentMatcher(
- self.assertEqual, retype_comment_qos),
- 'snapCPG': expected_snap_cpg}),
- mock.call.deleteVolumeSet(vvs_matcher),
- ]
+ expected_snap_cpg = self.volume_type['extra_specs']['cpg']
+ expected_retype_modify = [
+ mock.call.modifyVolume(osv_matcher,
+ {'comment': self.CommentMatcher(
+ self.assertEqual,
+ retype_comment_qos),
+ 'snapCPG': expected_snap_cpg}),
+ mock.call.deleteVolumeSet(vvs_matcher),
+ ]
- expected_retype_specs = [
- mock.call.createVolumeSet(vvs_matcher, None),
- mock.call.createQoSRules(
- vvs_matcher,
- {'ioMinGoal': 100, 'ioMaxLimit': 1000,
- 'bwMinGoalKB': 25600, 'priority': 1, 'latencyGoal': 25,
- 'bwMaxLimitKB': 51200}),
- mock.call.addVolumeToVolumeSet(vvs_matcher, osv_matcher),
- mock.call.modifyVolume(
- osv_matcher,
- {'action': 6,
- 'userCPG': self.volume_type['extra_specs']['cpg'],
- 'conversionOperation': 1, 'tuneOperation': 1}),
- mock.call.getTask(1),
- mock.call.logout()
- ]
+ expected_retype_specs = [
+ mock.call.createVolumeSet(vvs_matcher, None),
+ mock.call.createQoSRules(
+ vvs_matcher,
+ {'ioMinGoal': 100, 'ioMaxLimit': 1000,
+ 'bwMinGoalKB': 25600, 'priority': 1, 'latencyGoal': 25,
+ 'bwMaxLimitKB': 51200}),
+ mock.call.addVolumeToVolumeSet(vvs_matcher, osv_matcher),
+ mock.call.modifyVolume(
+ osv_matcher,
+ {'action': 6,
+ 'userCPG': self.volume_type['extra_specs']['cpg'],
+ 'conversionOperation': 1, 'tuneOperation': 1}),
+ mock.call.getTask(1)
+ ]
- mock_client.assert_has_calls(expected_manage)
- mock_client.assert_has_calls(expected_retype_modify)
- mock_client.assert_has_calls(expected_retype_specs)
- self.assertEqual(expected_obj, obj)
+ mock_client.assert_has_calls(self.standard_login + expected_manage)
+ mock_client.assert_has_calls(expected_retype_modify)
+ mock_client.assert_has_calls(
+ expected_retype_specs +
+ self.standard_logout)
+ self.assertEqual(expected_obj, obj)
@mock.patch.object(volume_types, 'get_volume_type')
def test_manage_existing_vvs(self, _mock_volume_types):
'volume_type_id': 'acfa9fa4-54a0-4340-a3d8-bfcf19aea65e',
'id': id}
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- osv_matcher = self.driver.common._get_3par_vol_name(volume['id'])
- vvs_matcher = self.driver.common._get_3par_vvs_name(volume['id'])
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- existing_ref = {'source-name': unm_matcher}
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ osv_matcher = common._get_3par_vol_name(volume['id'])
+ vvs_matcher = common._get_3par_vvs_name(volume['id'])
- obj = self.driver.manage_existing(volume, existing_ref)
+ existing_ref = {'source-name': unm_matcher}
- expected_obj = {'display_name': 'Test Volume',
- 'host': 'my-stack1@3parxxx#qospool'}
- expected_manage = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.modifyVolume(existing_ref['source-name'],
- {'newName': osv_matcher,
- 'comment': self.CommentMatcher(
- self.assertEqual, new_comment)})
- ]
+ obj = self.driver.manage_existing(volume, existing_ref)
- retype_comment_vvs = {
- "display_name": "Foo Volume",
- "volume_type_name": test_volume_type['name'],
- "volume_type_id": test_volume_type['id'],
- "vvs": vvs
- }
+ expected_obj = {'display_name': 'Test Volume',
+ 'host': 'my-stack1@3parxxx#qospool'}
+ expected_manage = [
+ mock.call.getVolume(existing_ref['source-name']),
+ mock.call.modifyVolume(existing_ref['source-name'],
+ {'newName': osv_matcher,
+ 'comment': self.CommentMatcher(
+ self.assertEqual, new_comment)})
+ ]
- expected_retype = [
- mock.call.modifyVolume(osv_matcher,
- {'comment': self.CommentMatcher(
- self.assertEqual, retype_comment_vvs),
- 'snapCPG': 'OpenStackCPGSnap'}),
- mock.call.deleteVolumeSet(vvs_matcher),
- mock.call.addVolumeToVolumeSet(vvs, osv_matcher),
- mock.call.modifyVolume(osv_matcher,
- {'action': 6, 'userCPG':
- test_volume_type['extra_specs']['cpg'],
- 'conversionOperation': 1,
- 'tuneOperation': 1}),
- mock.call.getTask(1),
- mock.call.logout()
- ]
+ retype_comment_vvs = {
+ "display_name": "Foo Volume",
+ "volume_type_name": test_volume_type['name'],
+ "volume_type_id": test_volume_type['id'],
+ "vvs": vvs
+ }
- mock_client.assert_has_calls(expected_manage)
- mock_client.assert_has_calls(expected_retype)
- self.assertEqual(expected_obj, obj)
+ expected_retype = [
+ mock.call.modifyVolume(osv_matcher,
+ {'comment': self.CommentMatcher(
+ self.assertEqual,
+ retype_comment_vvs),
+ 'snapCPG': 'OpenStackCPGSnap'}),
+ mock.call.deleteVolumeSet(vvs_matcher),
+ mock.call.addVolumeToVolumeSet(vvs, osv_matcher),
+ mock.call.modifyVolume(osv_matcher,
+ {'action': 6, 'userCPG':
+ test_volume_type['extra_specs']['cpg'],
+ 'conversionOperation': 1,
+ 'tuneOperation': 1}),
+ mock.call.getTask(1)
+ ]
+
+ mock_client.assert_has_calls(self.standard_login + expected_manage)
+ mock_client.assert_has_calls(
+ expected_retype +
+ self.standard_logout)
+ self.assertEqual(expected_obj, obj)
def test_manage_existing_no_volume_type(self):
mock_client = self.setup_driver()
mock_client.getVolume.return_value = {'comment': comment}
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- osv_matcher = self.driver.common._get_3par_vol_name(volume['id'])
- existing_ref = {'source-name': unm_matcher}
-
- obj = self.driver.manage_existing(volume, existing_ref)
-
- expected_obj = {'display_name': 'Foo Volume'}
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.modifyVolume(existing_ref['source-name'],
- {'newName': osv_matcher,
- 'comment': new_comment}),
- mock.call.logout()
- ]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ osv_matcher = common._get_3par_vol_name(volume['id'])
+ existing_ref = {'source-name': unm_matcher}
+
+ obj = self.driver.manage_existing(volume, existing_ref)
+
+ expected_obj = {'display_name': 'Foo Volume'}
+ expected = [
+ mock.call.getVolume(existing_ref['source-name']),
+ mock.call.modifyVolume(existing_ref['source-name'],
+ {'newName': osv_matcher,
+ 'comment': new_comment})
+ ]
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_obj, obj)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(expected_obj, obj)
- volume['display_name'] = 'Test Volume'
+ volume['display_name'] = 'Test Volume'
- obj = self.driver.manage_existing(volume, existing_ref)
+ obj = self.driver.manage_existing(volume, existing_ref)
- expected_obj = {'display_name': 'Test Volume'}
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.modifyVolume(existing_ref['source-name'],
- {'newName': osv_matcher,
- 'comment': new_comment}),
- mock.call.logout()
- ]
+ expected_obj = {'display_name': 'Test Volume'}
+ expected = [
+ mock.call.getVolume(existing_ref['source-name']),
+ mock.call.modifyVolume(existing_ref['source-name'],
+ {'newName': osv_matcher,
+ 'comment': new_comment})
+ ]
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_obj, obj)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(expected_obj, obj)
- mock_client.getVolume.return_value = {}
- volume['display_name'] = None
+ mock_client.getVolume.return_value = {}
+ volume['display_name'] = None
+ common = self.driver._login()
- obj = self.driver.manage_existing(volume, existing_ref)
+ obj = self.driver.manage_existing(volume, existing_ref)
- expected_obj = {'display_name': None}
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.modifyVolume(existing_ref['source-name'],
- {'newName': osv_matcher,
- 'comment': new_comment}),
- mock.call.logout()
- ]
+ expected_obj = {'display_name': None}
+ expected = [
+ mock.call.getVolume(existing_ref['source-name']),
+ mock.call.modifyVolume(existing_ref['source-name'],
+ {'newName': osv_matcher,
+ 'comment': new_comment})
+ ]
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_obj, obj)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(expected_obj, obj)
def test_manage_existing_invalid_input(self):
mock_client = self.setup_driver()
mock_client.getVolume.side_effect = hpexceptions.HTTPNotFound('fake')
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- existing_ref = {'source-name': unm_matcher}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ existing_ref = {'source-name': unm_matcher}
- self.assertRaises(exception.InvalidInput,
- self.driver.manage_existing,
- volume=volume,
- existing_ref=existing_ref)
+ self.assertRaises(exception.InvalidInput,
+ self.driver.manage_existing,
+ volume=volume,
+ existing_ref=existing_ref)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.logout()
- ]
+ expected = [mock.call.getVolume(existing_ref['source-name'])]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_manage_existing_volume_type_exception(self):
mock_client = self.setup_driver()
mock_client.getVolume.return_value = {'comment': comment}
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- existing_ref = {'source-name': unm_matcher}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ existing_ref = {'source-name': unm_matcher}
- self.assertRaises(exception.ManageExistingVolumeTypeMismatch,
- self.driver.manage_existing,
- volume=volume,
- existing_ref=existing_ref)
+ self.assertRaises(exception.ManageExistingVolumeTypeMismatch,
+ self.driver.manage_existing,
+ volume=volume,
+ existing_ref=existing_ref)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.logout()
- ]
+ expected = [mock.call.getVolume(existing_ref['source-name'])]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch.object(volume_types, 'get_volume_type')
def test_manage_existing_retype_exception(self, _mock_volume_types):
{'domain': 'domain3'},
]
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- osv_matcher = self.driver.common._get_3par_vol_name(volume['id'])
-
- existing_ref = {'source-name': unm_matcher}
-
- self.assertRaises(exception.Invalid3PARDomain,
- self.driver.manage_existing,
- volume=volume,
- existing_ref=existing_ref)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(unm_matcher),
- mock.call.modifyVolume(
- unm_matcher, {'newName': osv_matcher, 'comment': mock.ANY}),
- mock.call.getCPG('OpenStackCPG'),
- mock.call.getVolume(osv_matcher),
- mock.call.getCPG('testUserCpg0'),
- mock.call.getCPG('OpenStackCPG'),
- mock.call.modifyVolume(
- osv_matcher, {'newName': unm_matcher,
- 'comment': self.MANAGE_VOLUME_INFO['comment']}),
- mock.call.logout()
- ]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ osv_matcher = common._get_3par_vol_name(volume['id'])
+
+ existing_ref = {'source-name': unm_matcher}
+
+ self.assertRaises(exception.Invalid3PARDomain,
+ self.driver.manage_existing,
+ volume=volume,
+ existing_ref=existing_ref)
+
+ expected = [
+
+ mock.call.getVolume(unm_matcher),
+ mock.call.modifyVolume(
+ unm_matcher, {
+ 'newName': osv_matcher,
+ 'comment': mock.ANY}),
+ mock.call.getCPG('OpenStackCPG'),
+ mock.call.getVolume(osv_matcher),
+ mock.call.getCPG('testUserCpg0'),
+ mock.call.getCPG('OpenStackCPG'),
+ mock.call.modifyVolume(
+ osv_matcher, {'newName': unm_matcher,
+ 'comment': self.MANAGE_VOLUME_INFO
+ ['comment']})
+ ]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_manage_existing_get_size(self):
mock_client = self.setup_driver()
mock_client.getVolume.return_value = {'sizeMiB': 2048}
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- volume = {}
- existing_ref = {'source-name': unm_matcher}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ volume = {}
+ existing_ref = {'source-name': unm_matcher}
- size = self.driver.manage_existing_get_size(volume, existing_ref)
+ size = self.driver.manage_existing_get_size(volume, existing_ref)
- expected_size = 2
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.logout()
- ]
+ expected_size = 2
+ expected = [mock.call.getVolume(existing_ref['source-name'])]
- mock_client.assert_has_calls(expected, True)
- self.assertEqual(expected_size, size)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(expected_size, size)
def test_manage_existing_get_size_invalid_reference(self):
mock_client = self.setup_driver()
- volume = {}
- existing_ref = {'source-name': self.VOLUME_3PAR_NAME}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ volume = {}
+ existing_ref = {'source-name': self.VOLUME_3PAR_NAME}
- self.assertRaises(exception.ManageExistingInvalidReference,
- self.driver.manage_existing_get_size,
- volume=volume,
- existing_ref=existing_ref)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.logout()
- ]
-
- mock_client.assert_has_calls(expected)
+ self.assertRaises(exception.ManageExistingInvalidReference,
+ self.driver.manage_existing_get_size,
+ volume=volume,
+ existing_ref=existing_ref)
- existing_ref = {}
+ mock_client.assert_has_calls(
+ self.standard_login +
+ self.standard_logout)
- self.assertRaises(exception.ManageExistingInvalidReference,
- self.driver.manage_existing_get_size,
- volume=volume,
- existing_ref=existing_ref)
+ existing_ref = {}
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.logout()
- ]
+ self.assertRaises(exception.ManageExistingInvalidReference,
+ self.driver.manage_existing_get_size,
+ volume=volume,
+ existing_ref=existing_ref)
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ self.standard_logout)
def test_manage_existing_get_size_invalid_input(self):
mock_client = self.setup_driver()
mock_client.getVolume.side_effect = hpexceptions.HTTPNotFound('fake')
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
- volume = {}
- existing_ref = {'source-name': unm_matcher}
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
+ volume = {}
+ existing_ref = {'source-name': unm_matcher}
- self.assertRaises(exception.InvalidInput,
- self.driver.manage_existing_get_size,
- volume=volume,
- existing_ref=existing_ref)
+ self.assertRaises(exception.InvalidInput,
+ self.driver.manage_existing_get_size,
+ volume=volume,
+ existing_ref=existing_ref)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(existing_ref['source-name']),
- mock.call.logout()
- ]
+ expected = [mock.call.getVolume(existing_ref['source-name'])]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_unmanage(self):
mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ self.driver.unmanage(self.volume)
- self.driver.unmanage(self.volume)
-
- osv_matcher = self.driver.common._get_3par_vol_name(self.volume['id'])
- unm_matcher = self.driver.common._get_3par_unm_name(self.volume['id'])
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.modifyVolume(osv_matcher, {'newName': unm_matcher}),
- mock.call.logout()]
+ osv_matcher = common._get_3par_vol_name(self.volume['id'])
+ unm_matcher = common._get_3par_unm_name(self.volume['id'])
- mock_client.assert_has_calls(expected)
+ expected = [
+ mock.call.modifyVolume(osv_matcher, {'newName': unm_matcher})
+ ]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test__safe_hostname(self):
long_hostname = "abc123abc123abc123abc123abc123abc123"
driver=hpfcdriver.HP3PARFCDriver)
expected = [
- mock.call.setSSHOptions(
- HP3PAR_SAN_IP,
- HP3PAR_USER_NAME,
- HP3PAR_USER_PASS,
- privatekey=HP3PAR_SAN_SSH_PRIVATE,
- port=HP3PAR_SAN_SSH_PORT,
- conn_timeout=HP3PAR_SAN_SSH_CON_TIMEOUT),
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ mock.call.getCPG(HP3PAR_CPG2)]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
mock_client.reset_mock()
return mock_client
'slot': 2},
'vendor': None,
'wwn': self.wwn[1]}]}]
- mock_client.findHost.return_value = self.FAKE_HOST
+ mock_client.queryHost.return_value = {
+ 'members': [{
+ 'name': self.FAKE_HOST
+ }]
+ }
mock_client.getHostVLUNs.return_value = [
{'active': True,
'volumeName': self.VOLUME_3PAR_NAME,
'nsp': 'something'})
mock_client.createVLUN.return_value = location
- result = self.driver.initialize_connection(self.volume, self.connector)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.ANY,
- mock.call.getHost(self.FAKE_HOST),
- mock.call.getPorts(),
- mock.call.createVLUN(
- self.VOLUME_3PAR_NAME,
- auto=True,
- hostname=self.FAKE_HOST),
- mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
-
- self.assertDictMatch(result, self.properties)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ result = self.driver.initialize_connection(
+ self.volume,
+ self.connector)
+
+ expected = [
+ mock.call.getVolume(self.VOLUME_3PAR_NAME),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.ANY,
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.getPorts(),
+ mock.call.createVLUN(
+ self.VOLUME_3PAR_NAME,
+ auto=True,
+ hostname=self.FAKE_HOST),
+ mock.call.getHostVLUNs(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+
+ self.assertDictMatch(result, self.properties)
@mock.patch('cinder.zonemanager.utils.create_lookup_service')
def test_initialize_connection_with_lookup_single_nsp(self, mock_lookup):
'slot': 2},
'vendor': None,
'wwn': self.wwn[0]}]}]
- mock_client.findHost.return_value = self.FAKE_HOST
+ mock_client.queryHost.return_value = {
+ 'members': [{
+ 'name': self.FAKE_HOST
+ }]
+ }
mock_client.getHostVLUNs.return_value = [
{'active': True,
'volumeName': self.VOLUME_3PAR_NAME,
['0987654321234']
}}}
- result = self.driver.initialize_connection(self.volume, connector)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.ANY,
- mock.call.getHost(self.FAKE_HOST),
- mock.call.getPorts(),
- mock.call.getPorts(),
- mock.call.createVLUN(
- self.VOLUME_3PAR_NAME,
- auto=True,
- hostname=self.FAKE_HOST,
- portPos={'node': 7, 'slot': 1, 'cardPort': 1}),
- mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
-
- self.assertDictMatch(result, expected_properties)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ result = self.driver.initialize_connection(self.volume, connector)
+
+ expected = [
+ mock.call.getVolume(self.VOLUME_3PAR_NAME),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.ANY,
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.getPorts(),
+ mock.call.getPorts(),
+ mock.call.createVLUN(
+ self.VOLUME_3PAR_NAME,
+ auto=True,
+ hostname=self.FAKE_HOST,
+ portPos={'node': 7, 'slot': 1, 'cardPort': 1}),
+ mock.call.getHostVLUNs(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+
+ self.assertDictMatch(result, expected_properties)
def test_terminate_connection(self):
# setup_mock_client drive with default configuration
mock_client.getHostVLUNs.side_effect = effects
expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getHostVLUNs(self.FAKE_HOST),
mock.call.deleteVLUN(
self.VOLUME_3PAR_NAME,
self.FAKE_HOST),
mock.call.deleteHost(self.FAKE_HOST),
mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.getPorts(),
- mock.call.logout()]
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expected)
- self.assertIn('data', conn_info)
- self.assertIn('initiator_target_map', conn_info['data'])
- mock_client.reset_mock()
-
- mock_client.getHostVLUNs.side_effect = effects
-
- # mock some deleteHost exceptions that are handled
- delete_with_vlun = hpexceptions.HTTPConflict(
- error={'message': "has exported VLUN"})
- delete_with_hostset = hpexceptions.HTTPConflict(
- error={'message': "host is a member of a set"})
- mock_client.deleteHost = mock.Mock(
- side_effect=[delete_with_vlun, delete_with_hostset])
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expected)
- mock_client.reset_mock()
- mock_client.getHostVLUNs.side_effect = effects
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expected)
+ mock.call.getPorts()]
+
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertIn('data', conn_info)
+ self.assertIn('initiator_target_map', conn_info['data'])
+ mock_client.reset_mock()
+
+ mock_client.getHostVLUNs.side_effect = effects
+
+ # mock some deleteHost exceptions that are handled
+ delete_with_vlun = hpexceptions.HTTPConflict(
+ error={'message': "has exported VLUN"})
+ delete_with_hostset = hpexceptions.HTTPConflict(
+ error={'message': "host is a member of a set"})
+ mock_client.deleteHost = mock.Mock(
+ side_effect=[delete_with_vlun, delete_with_hostset])
+
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ mock_client.reset_mock()
+ mock_client.getHostVLUNs.side_effect = effects
+
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
@mock.patch('cinder.zonemanager.utils.create_lookup_service')
def test_terminate_connection_with_lookup(self, mock_lookup):
mock_client.getHostVLUNs.side_effect = effects
expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getHostVLUNs(self.FAKE_HOST),
mock.call.deleteVLUN(
self.VOLUME_3PAR_NAME,
self.FAKE_HOST),
mock.call.deleteHost(self.FAKE_HOST),
mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.getPorts(),
- mock.call.logout()]
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expected)
- self.assertIn('data', conn_info)
- self.assertIn('initiator_target_map', conn_info['data'])
- mock_client.reset_mock()
-
- mock_client.getHostVLUNs.side_effect = effects
-
- # mock some deleteHost exceptions that are handled
- delete_with_vlun = hpexceptions.HTTPConflict(
- error={'message': "has exported VLUN"})
- delete_with_hostset = hpexceptions.HTTPConflict(
- error={'message': "host is a member of a set"})
- mock_client.deleteHost = mock.Mock(
- side_effect=[delete_with_vlun, delete_with_hostset])
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expected)
- mock_client.reset_mock()
- mock_client.getHostVLUNs.side_effect = effects
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expected)
+ mock.call.getPorts()]
+
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertIn('data', conn_info)
+ self.assertIn('initiator_target_map', conn_info['data'])
+ mock_client.reset_mock()
+
+ mock_client.getHostVLUNs.side_effect = effects
+
+ # mock some deleteHost exceptions that are handled
+ delete_with_vlun = hpexceptions.HTTPConflict(
+ error={'message': "has exported VLUN"})
+ delete_with_hostset = hpexceptions.HTTPConflict(
+ error={'message': "host is a member of a set"})
+ mock_client.deleteHost = mock.Mock(
+ side_effect=[delete_with_vlun, delete_with_hostset])
+
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ mock_client.reset_mock()
+ mock_client.getHostVLUNs.side_effect = effects
+
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
def test_terminate_connection_more_vols(self):
mock_client = self.setup_driver()
]
expect_less = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
mock.call.getHostVLUNs(self.FAKE_HOST),
mock.call.deleteVLUN(
self.VOLUME_3PAR_NAME,
None,
self.FAKE_HOST),
- mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.logout()]
-
- conn_info = self.driver.terminate_connection(self.volume,
- self.connector)
- mock_client.assert_has_calls(expect_less)
- self.assertNotIn('initiator_target_map', conn_info['data'])
+ mock.call.getHostVLUNs(self.FAKE_HOST)]
+
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ conn_info = self.driver.terminate_connection(self.volume,
+ self.connector)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expect_less +
+ self.standard_logout)
+ self.assertNotIn('initiator_target_map', conn_info['data'])
def test_get_volume_stats(self):
# setup_mock_client drive with default configuration
'freeCapacityMiB': 1024.0 * 2,
'totalCapacityMiB': 1024.0 * 123
}
- stats = self.driver.get_volume_stats(True)
- const = 0.0009765625
- self.assertEqual(stats['storage_protocol'], 'FC')
- self.assertEqual(stats['total_capacity_gb'], 0)
- self.assertEqual(stats['free_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['total_capacity_gb'], 123.0)
- self.assertEqual(stats['pools'][0]['free_capacity_gb'], 2.0)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getStorageSystemInfo(),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
- stats = self.driver.get_volume_stats(True)
- self.assertEqual(stats['storage_protocol'], 'FC')
- self.assertEqual(stats['total_capacity_gb'], 0)
- self.assertEqual(stats['free_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['total_capacity_gb'], 123.0)
- self.assertEqual(stats['pools'][0]['free_capacity_gb'], 2.0)
-
- cpg2 = self.cpgs[0].copy()
- cpg2.update({'SDGrowth': {'limitMiB': 8192}})
- mock_client.getCPG.return_value = cpg2
-
- stats = self.driver.get_volume_stats(True)
- self.assertEqual(stats['storage_protocol'], 'FC')
- total_capacity_gb = 8192 * const
- self.assertEqual(stats['total_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['total_capacity_gb'],
- total_capacity_gb)
- free_capacity_gb = int(
- (8192 - self.cpgs[0]['UsrUsage']['usedMiB']) * const)
- self.assertEqual(stats['free_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['free_capacity_gb'],
- free_capacity_gb)
- self.driver.common.client.deleteCPG(HP3PAR_CPG)
- self.driver.common.client.createCPG(HP3PAR_CPG, {})
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ stats = self.driver.get_volume_stats(True)
+ const = 0.0009765625
+ self.assertEqual(stats['storage_protocol'], 'FC')
+ self.assertEqual(stats['total_capacity_gb'], 0)
+ self.assertEqual(stats['free_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['total_capacity_gb'], 123.0)
+ self.assertEqual(stats['pools'][0]['free_capacity_gb'], 2.0)
+
+ expected = [
+ mock.call.getStorageSystemInfo(),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getCPG(HP3PAR_CPG2)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ stats = self.driver.get_volume_stats(True)
+ self.assertEqual(stats['storage_protocol'], 'FC')
+ self.assertEqual(stats['total_capacity_gb'], 0)
+ self.assertEqual(stats['free_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['total_capacity_gb'], 123.0)
+ self.assertEqual(stats['pools'][0]['free_capacity_gb'], 2.0)
+
+ cpg2 = self.cpgs[0].copy()
+ cpg2.update({'SDGrowth': {'limitMiB': 8192}})
+ mock_client.getCPG.return_value = cpg2
+
+ stats = self.driver.get_volume_stats(True)
+ self.assertEqual(stats['storage_protocol'], 'FC')
+ total_capacity_gb = 8192 * const
+ self.assertEqual(stats['total_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['total_capacity_gb'],
+ total_capacity_gb)
+ free_capacity_gb = int(
+ (8192 - self.cpgs[0]['UsrUsage']['usedMiB']) * const)
+ self.assertEqual(stats['free_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['free_capacity_gb'],
+ free_capacity_gb)
+ common.client.deleteCPG(HP3PAR_CPG)
+ common.client.createCPG(HP3PAR_CPG, {})
def test_create_host(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
-
mock_client.getVolume.return_value = {'userCPG': HP3PAR_CPG}
mock_client.getCPG.return_value = {}
mock_client.getHost.side_effect = [
'slot': 2},
'vendor': None,
'wwn': self.wwn[1]}]}]
- mock_client.findHost.return_value = None
+ mock_client.queryHost.return_value = None
mock_client.getVLUN.return_value = {'lun': 186}
-
- host = self.driver._create_host(self.volume, self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.findHost(wwn='123456789012345'),
- mock.call.findHost(wwn='123456789054321'),
- mock.call.createHost(
- self.FAKE_HOST,
- FCWwns=['123456789012345', '123456789054321'],
- optional={'domain': None, 'persona': 2}),
- mock.call.getHost(self.FAKE_HOST)]
-
- mock_client.assert_has_calls(expected)
-
- self.assertEqual(host['name'], self.FAKE_HOST)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host = self.driver._create_host(
+ common,
+ self.volume,
+ self.connector)
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.queryHost(['123456789012345', '123456789054321']),
+ mock.call.createHost(
+ self.FAKE_HOST,
+ FCWwns=['123456789012345', '123456789054321'],
+ optional={'domain': None, 'persona': 2}),
+ mock.call.getHost(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(expected)
+
+ self.assertEqual(host['name'], self.FAKE_HOST)
def test_create_invalid_host(self):
# setup_mock_client drive with default configuration
'name': 'fakehost.foo',
'FCPaths': [{'wwn': '123456789012345'}, {
'wwn': '123456789054321'}]}]
- mock_client.findHost.return_value = 'fakehost.foo'
+ mock_client.queryHost.return_value = {
+ 'members': [{
+ 'name': 'fakehost.foo'
+ }]
+ }
- host = self.driver._create_host(self.volume, self.connector)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host = self.driver._create_host(
+ common,
+ self.volume,
+ self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost('fakehost'),
- mock.call.findHost(wwn='123456789012345'),
- mock.call.getHost('fakehost.foo')]
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost('fakehost'),
+ mock.call.queryHost(['123456789012345', '123456789054321']),
+ mock.call.getHost('fakehost.foo')]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
- self.assertEqual(host['name'], 'fakehost.foo')
+ self.assertEqual(host['name'], 'fakehost.foo')
def test_create_modify_host(self):
# setup_mock_client drive with default configuration
'FCPaths': [{'wwn': '123456789012345'}, {
'wwn': '123456789054321'}]}]
- host = self.driver._create_host(self.volume, self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost('fakehost'),
- mock.call.modifyHost(
- 'fakehost', {
- 'FCWWNs': ['123456789012345', '123456789054321'],
- 'pathOperation': 1}),
- mock.call.getHost('fakehost')]
-
- mock_client.assert_has_calls(expected)
-
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(len(host['FCPaths']), 2)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host = self.driver._create_host(
+ common,
+ self.volume,
+ self.connector)
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost('fakehost'),
+ mock.call.modifyHost(
+ 'fakehost', {
+ 'FCWWNs': ['123456789012345', '123456789054321'],
+ 'pathOperation': 1}),
+ mock.call.getHost('fakehost')]
+
+ mock_client.assert_has_calls(expected)
+
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(len(host['FCPaths']), 2)
def test_modify_host_with_new_wwn(self):
# setup_mock_client drive with default configuration
{'wwn': '123456789054321'}]}
mock_client.getHost.side_effect = [getHost_ret1, getHost_ret2]
- host = self.driver._create_host(self.volume, self.connector)
-
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost('fakehost'),
- mock.call.modifyHost(
- 'fakehost', {
- 'FCWWNs': ['123456789012345'], 'pathOperation': 1}),
- mock.call.getHost('fakehost')]
-
- mock_client.assert_has_calls(expected)
-
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(len(host['FCPaths']), 2)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host = self.driver._create_host(
+ common,
+ self.volume,
+ self.connector)
+
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost('fakehost'),
+ mock.call.modifyHost(
+ 'fakehost', {
+ 'FCWWNs': ['123456789012345'], 'pathOperation': 1}),
+ mock.call.getHost('fakehost')]
+
+ mock_client.assert_has_calls(expected)
+
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(len(host['FCPaths']), 2)
def test_modify_host_with_unknown_wwn_and_new_wwn(self):
# setup_mock_client drive with default configuration
{'wwn': 'xxxxxxxxxxxxxxx'}]}
mock_client.getHost.side_effect = [getHost_ret1, getHost_ret2]
- host = self.driver._create_host(self.volume, self.connector)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host = self.driver._create_host(
+ common,
+ self.volume,
+ self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost('fakehost'),
- mock.call.modifyHost(
- 'fakehost', {
- 'FCWWNs': ['123456789012345'], 'pathOperation': 1}),
- mock.call.getHost('fakehost')]
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost('fakehost'),
+ mock.call.modifyHost(
+ 'fakehost', {
+ 'FCWWNs': ['123456789012345'], 'pathOperation': 1}),
+ mock.call.getHost('fakehost')]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(len(host['FCPaths']), 3)
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(len(host['FCPaths']), 3)
class TestHP3PARISCSIDriver(HP3PARBaseDriver, test.TestCase):
m_conf=mock_conf,
driver=hpdriver.HP3PARISCSIDriver)
- expected = [
- mock.call.setSSHOptions(
- HP3PAR_SAN_IP,
- HP3PAR_USER_NAME,
- HP3PAR_USER_PASS,
- privatekey=HP3PAR_SAN_SSH_PRIVATE,
- port=HP3PAR_SAN_SSH_PORT,
- conn_timeout=HP3PAR_SAN_SSH_CON_TIMEOUT),
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
+ expected_get_cpgs = [
mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout(),
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getPorts(),
- mock.call.logout()]
- mock_client.assert_has_calls(expected)
+ mock.call.getCPG(HP3PAR_CPG2)]
+ expected_get_ports = [mock.call.getPorts()]
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected_get_cpgs +
+ self.standard_logout +
+ self.standard_login +
+ expected_get_ports +
+ self.standard_logout)
mock_client.reset_mock()
return mock_client
'nsp': 'something'})
mock_client.createVLUN.return_value = location
- result = self.driver.initialize_connection(self.volume, self.connector)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume(self.VOLUME_3PAR_NAME),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.createVLUN(
- self.VOLUME_3PAR_NAME,
- auto=True,
- hostname='fakehost',
- portPos={'node': 8, 'slot': 1, 'cardPort': 1}),
- mock.call.getHostVLUNs(self.FAKE_HOST),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
-
- self.assertDictMatch(result, self.properties)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ result = self.driver.initialize_connection(
+ self.volume,
+ self.connector)
+
+ expected = [
+ mock.call.getVolume(self.VOLUME_3PAR_NAME),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.createVLUN(
+ self.VOLUME_3PAR_NAME,
+ auto=True,
+ hostname='fakehost',
+ portPos={'node': 8, 'slot': 1, 'cardPort': 1}),
+ mock.call.getHostVLUNs(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+
+ self.assertDictMatch(result, self.properties)
def test_get_volume_stats(self):
# setup_mock_client drive with default configuration
'freeCapacityMiB': 1024.0 * 2,
'totalCapacityMiB': 1024.0 * 123
}
- stats = self.driver.get_volume_stats(True)
- const = 0.0009765625
- self.assertEqual(stats['storage_protocol'], 'iSCSI')
- self.assertEqual(stats['total_capacity_gb'], 0)
- self.assertEqual(stats['free_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['total_capacity_gb'], 123.0)
- self.assertEqual(stats['pools'][0]['free_capacity_gb'], 2.0)
-
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getStorageSystemInfo(),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getCPG(HP3PAR_CPG2),
- mock.call.logout()]
-
- mock_client.assert_has_calls(expected)
- cpg2 = self.cpgs[0].copy()
- cpg2.update({'SDGrowth': {'limitMiB': 8192}})
- mock_client.getCPG.return_value = cpg2
-
- stats = self.driver.get_volume_stats(True)
- self.assertEqual(stats['storage_protocol'], 'iSCSI')
- total_capacity_gb = 8192 * const
- self.assertEqual(stats['total_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['total_capacity_gb'],
- total_capacity_gb)
- free_capacity_gb = int(
- (8192 - self.cpgs[0]['UsrUsage']['usedMiB']) * const)
- self.assertEqual(stats['free_capacity_gb'], 0)
- self.assertEqual(stats['pools'][0]['free_capacity_gb'],
- free_capacity_gb)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+
+ stats = self.driver.get_volume_stats(True)
+ const = 0.0009765625
+ self.assertEqual(stats['storage_protocol'], 'iSCSI')
+ self.assertEqual(stats['total_capacity_gb'], 0)
+ self.assertEqual(stats['free_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['total_capacity_gb'], 123.0)
+ self.assertEqual(stats['pools'][0]['free_capacity_gb'], 2.0)
+
+ expected = [
+ mock.call.getStorageSystemInfo(),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getCPG(HP3PAR_CPG2)]
+
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+
+ cpg2 = self.cpgs[0].copy()
+ cpg2.update({'SDGrowth': {'limitMiB': 8192}})
+ mock_client.getCPG.return_value = cpg2
+
+ stats = self.driver.get_volume_stats(True)
+ self.assertEqual(stats['storage_protocol'], 'iSCSI')
+ total_capacity_gb = 8192 * const
+ self.assertEqual(stats['total_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['total_capacity_gb'],
+ total_capacity_gb)
+ free_capacity_gb = int(
+ (8192 - self.cpgs[0]['UsrUsage']['usedMiB']) * const)
+ self.assertEqual(stats['free_capacity_gb'], 0)
+ self.assertEqual(stats['pools'][0]['free_capacity_gb'],
+ free_capacity_gb)
def test_create_host(self):
# setup_mock_client drive with default configuration
mock_client.findHost.return_value = None
mock_client.getVLUN.return_value = {'lun': self.TARGET_LUN}
- host, auth_username, auth_password = self.driver._create_host(
- self.volume, self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
- mock.call.createHost(
- self.FAKE_HOST,
- optional={'domain': None, 'persona': 2},
- iscsiNames=['iqn.1993-08.org.debian:01:222']),
- mock.call.getHost(self.FAKE_HOST)]
-
- mock_client.assert_has_calls(expected)
-
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(auth_username, None)
- self.assertEqual(auth_password, None)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host, auth_username, auth_password = self.driver._create_host(
+ common, self.volume, self.connector)
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
+ mock.call.createHost(
+ self.FAKE_HOST,
+ optional={'domain': None, 'persona': 2},
+ iscsiNames=['iqn.1993-08.org.debian:01:222']),
+ mock.call.getHost(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(expected)
+
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(auth_username, None)
+ self.assertEqual(auth_password, None)
def test_create_host_chap_enabled(self):
# setup_mock_client drive with CHAP enabled configuration
mock_client.getVolumeMetaData.side_effect = get_side_effect
- host, auth_username, auth_password = self.driver._create_host(
- self.volume, self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getVolumeMetaData(
- 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_USER_KEY),
- mock.call.getVolumeMetaData(
- 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_PASS_KEY),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
- mock.call.createHost(
- self.FAKE_HOST,
- optional={'domain': None, 'persona': 2},
- iscsiNames=['iqn.1993-08.org.debian:01:222']),
- mock.call.modifyHost(
- 'fakehost',
- expected_mod_request),
- mock.call.getHost(self.FAKE_HOST)
- ]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host, auth_username, auth_password = self.driver._create_host(
+ common, self.volume, self.connector)
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getVolumeMetaData(
+ 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_USER_KEY),
+ mock.call.getVolumeMetaData(
+ 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_PASS_KEY),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
+ mock.call.createHost(
+ self.FAKE_HOST,
+ optional={'domain': None, 'persona': 2},
+ iscsiNames=['iqn.1993-08.org.debian:01:222']),
+ mock.call.modifyHost(
+ 'fakehost',
+ expected_mod_request),
+ mock.call.getHost(self.FAKE_HOST)
+ ]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(auth_username, 'test-user')
- self.assertEqual(auth_password, 'test-pass')
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(auth_username, 'test-user')
+ self.assertEqual(auth_password, 'test-pass')
def test_create_invalid_host(self):
# setup_mock_client drive with default configuration
{'name': 'fakehost.foo'}]
mock_client.findHost.return_value = 'fakehost.foo'
- host, auth_username, auth_password = self.driver._create_host(
- self.volume, self.connector)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host, auth_username, auth_password = self.driver._create_host(
+ common, self.volume, self.connector)
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
- mock.call.getHost('fakehost.foo')]
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
+ mock.call.getHost('fakehost.foo')]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
- self.assertEqual(host['name'], 'fakehost.foo')
- self.assertEqual(auth_username, None)
- self.assertEqual(auth_password, None)
+ self.assertEqual(host['name'], 'fakehost.foo')
+ self.assertEqual(auth_username, None)
+ self.assertEqual(auth_password, None)
def test_create_invalid_host_chap_enabled(self):
# setup_mock_client drive with CHAP enabled configuration
'chapSecret': 'test-pass'
}
- host, auth_username, auth_password = self.driver._create_host(
- self.volume, self.connector)
-
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getVolumeMetaData(
- 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_USER_KEY),
- mock.call.getVolumeMetaData(
- 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_PASS_KEY),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
- mock.call.modifyHost(
- 'fakehost.foo',
- expected_mod_request),
- mock.call.getHost('fakehost.foo')
- ]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host, auth_username, auth_password = self.driver._create_host(
+ common, self.volume, self.connector)
+
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getVolumeMetaData(
+ 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_USER_KEY),
+ mock.call.getVolumeMetaData(
+ 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_PASS_KEY),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.findHost(iqn='iqn.1993-08.org.debian:01:222'),
+ mock.call.modifyHost(
+ 'fakehost.foo',
+ expected_mod_request),
+ mock.call.getHost('fakehost.foo')
+ ]
- mock_client.assert_has_calls(expected)
+ mock_client.assert_has_calls(expected)
- self.assertEqual(host['name'], 'fakehost.foo')
- self.assertEqual(auth_username, 'test-user')
- self.assertEqual(auth_password, 'test-pass')
+ self.assertEqual(host['name'], 'fakehost.foo')
+ self.assertEqual(auth_username, 'test-user')
+ self.assertEqual(auth_password, 'test-pass')
def test_create_modify_host(self):
# setup_mock_client drive with default configuration
'FCPaths': [{'wwn': '123456789012345'},
{'wwn': '123456789054321'}]}]
- host, auth_username, auth_password = self.driver._create_host(
- self.volume, self.connector)
-
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.modifyHost(
- self.FAKE_HOST,
- {'pathOperation': 1,
- 'iSCSINames': ['iqn.1993-08.org.debian:01:222']}),
- mock.call.getHost(self.FAKE_HOST)]
-
- mock_client.assert_has_calls(expected)
-
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(auth_username, None)
- self.assertEqual(auth_password, None)
- self.assertEqual(len(host['FCPaths']), 2)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host, auth_username, auth_password = self.driver._create_host(
+ common, self.volume, self.connector)
+
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.modifyHost(
+ self.FAKE_HOST,
+ {'pathOperation': 1,
+ 'iSCSINames': ['iqn.1993-08.org.debian:01:222']}),
+ mock.call.getHost(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(expected)
+
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(auth_username, None)
+ self.assertEqual(auth_password, None)
+ self.assertEqual(len(host['FCPaths']), 2)
def test_create_modify_host_chap_enabled(self):
# setup_mock_client drive with CHAP enabled configuration
'chapSecret': 'test-pass'
}
- host, auth_username, auth_password = self.driver._create_host(
- self.volume, self.connector)
-
- expected = [
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getCPG(HP3PAR_CPG),
- mock.call.getVolumeMetaData(
- 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_USER_KEY),
- mock.call.getVolumeMetaData(
- 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_PASS_KEY),
- mock.call.getHost(self.FAKE_HOST),
- mock.call.modifyHost(
- self.FAKE_HOST,
- {'pathOperation': 1,
- 'iSCSINames': ['iqn.1993-08.org.debian:01:222']}),
- mock.call.modifyHost(
- self.FAKE_HOST,
- expected_mod_request
- ),
- mock.call.getHost(self.FAKE_HOST)]
-
- mock_client.assert_has_calls(expected)
-
- self.assertEqual(host['name'], self.FAKE_HOST)
- self.assertEqual(auth_username, 'test-user')
- self.assertEqual(auth_password, 'test-pass')
- self.assertEqual(len(host['FCPaths']), 2)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ host, auth_username, auth_password = self.driver._create_host(
+ common, self.volume, self.connector)
+
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getCPG(HP3PAR_CPG),
+ mock.call.getVolumeMetaData(
+ 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_USER_KEY),
+ mock.call.getVolumeMetaData(
+ 'osv-0DM4qZEVSKON-DXN-NwVpw', CHAP_PASS_KEY),
+ mock.call.getHost(self.FAKE_HOST),
+ mock.call.modifyHost(
+ self.FAKE_HOST,
+ {'pathOperation': 1,
+ 'iSCSINames': ['iqn.1993-08.org.debian:01:222']}),
+ mock.call.modifyHost(
+ self.FAKE_HOST,
+ expected_mod_request
+ ),
+ mock.call.getHost(self.FAKE_HOST)]
+
+ mock_client.assert_has_calls(expected)
+
+ self.assertEqual(host['name'], self.FAKE_HOST)
+ self.assertEqual(auth_username, 'test-user')
+ self.assertEqual(auth_password, 'test-pass')
+ self.assertEqual(len(host['FCPaths']), 2)
def test_get_least_used_nsp_for_host_single(self):
# setup_mock_client drive with default configuration
mock_client.getPorts.return_value = PORTS_RET
mock_client.getVLUNs.return_value = VLUNS1_RET
- #Setup a single ISCSI IP
- iscsi_ips = ["10.10.220.253"]
- self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- self.driver.initialize_iscsi_ports()
+ #Setup a single ISCSI IP
+ iscsi_ips = ["10.10.220.253"]
+ self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
- nsp = self.driver._get_least_used_nsp_for_host('newhost')
- self.assertEqual(nsp, "1:8:1")
+ self.driver.initialize_iscsi_ports(common)
+
+ nsp = self.driver._get_least_used_nsp_for_host(common, 'newhost')
+ self.assertEqual(nsp, "1:8:1")
def test_get_least_used_nsp_for_host_new(self):
# setup_mock_client drive with default configuration
mock_client.getPorts.return_value = PORTS_RET
mock_client.getVLUNs.return_value = VLUNS1_RET
- #Setup two ISCSI IPs
- iscsi_ips = ["10.10.220.252", "10.10.220.253"]
- self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- self.driver.initialize_iscsi_ports()
+ #Setup two ISCSI IPs
+ iscsi_ips = ["10.10.220.252", "10.10.220.253"]
+ self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
- # Host 'newhost' does not yet have any iscsi paths,
- # so the 'least used' is returned
- nsp = self.driver._get_least_used_nsp_for_host('newhost')
- self.assertEqual(nsp, "1:8:2")
+ self.driver.initialize_iscsi_ports(common)
+
+ # Host 'newhost' does not yet have any iscsi paths,
+ # so the 'least used' is returned
+ nsp = self.driver._get_least_used_nsp_for_host(common, 'newhost')
+ self.assertEqual(nsp, "1:8:2")
def test_get_least_used_nsp_for_host_reuse(self):
# setup_mock_client drive with default configuration
mock_client.getPorts.return_value = PORTS_RET
mock_client.getVLUNs.return_value = VLUNS1_RET
- #Setup two ISCSI IPs
- iscsi_ips = ["10.10.220.252", "10.10.220.253"]
- self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
- self.driver.initialize_iscsi_ports()
+ #Setup two ISCSI IPs
+ iscsi_ips = ["10.10.220.252", "10.10.220.253"]
+ self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
- # hosts 'foo' and 'bar' already have active iscsi paths
- # the same one should be used
- nsp = self.driver._get_least_used_nsp_for_host('foo')
- self.assertEqual(nsp, "1:8:2")
+ self.driver.initialize_iscsi_ports(common)
- nsp = self.driver._get_least_used_nsp_for_host('bar')
- self.assertEqual(nsp, "1:8:1")
+ # hosts 'foo' and 'bar' already have active iscsi paths
+ # the same one should be used
+ nsp = self.driver._get_least_used_nsp_for_host(common, 'foo')
+ self.assertEqual(nsp, "1:8:2")
+
+ nsp = self.driver._get_least_used_nsp_for_host(common, 'bar')
+ self.assertEqual(nsp, "1:8:1")
def test_get_least_used_nps_for_host_fc(self):
# setup_mock_client drive with default configuration
iscsi_ips = ["10.10.220.252", "10.10.220.253"]
self.driver.configuration.hp3par_iscsi_ips = iscsi_ips
- self.driver.initialize_iscsi_ports()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ self.driver.initialize_iscsi_ports(common)
- nsp = self.driver._get_least_used_nsp_for_host('newhost')
- self.assertNotEqual(nsp, "0:6:3")
- self.assertEqual(nsp, "1:8:1")
+ nsp = self.driver._get_least_used_nsp_for_host(common, 'newhost')
+ self.assertNotEqual(nsp, "0:6:3")
+ self.assertEqual(nsp, "1:8:1")
def test_invalid_iscsi_ip(self):
config = self.setup_configuration()
{'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True}]
mock_client.getVLUNs.return_value = {'members': ports}
- # in use count
- vluns = self.driver.common.client.getVLUNs()
- nsp = self.driver._get_least_used_nsp(vluns['members'],
- ['0:2:1', '1:8:1'])
- self.assertEqual(nsp, '1:8:1')
-
- ports = [
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True}]
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ # in use count
+ vluns = common.client.getVLUNs()
+ nsp = self.driver._get_least_used_nsp(common, vluns['members'],
+ ['0:2:1', '1:8:1'])
+ self.assertEqual(nsp, '1:8:1')
+
+ ports = [
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True}]
- mock_client.getVLUNs.return_value = {'members': ports}
+ mock_client.getVLUNs.return_value = {'members': ports}
- # in use count
- vluns = self.driver.common.client.getVLUNs()
- nsp = self.driver._get_least_used_nsp(vluns['members'],
- ['0:2:1', '1:2:1'])
- self.assertEqual(nsp, '1:2:1')
+ # in use count
+ common = self.driver._login()
+ vluns = common.client.getVLUNs()
+ nsp = self.driver._get_least_used_nsp(common, vluns['members'],
+ ['0:2:1', '1:2:1'])
+ self.assertEqual(nsp, '1:2:1')
- ports = [
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True},
- {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1}, 'active': True}]
+ ports = [
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 1, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True},
+ {'portPos': {'node': 0, 'slot': 2, 'cardPort': 1},
+ 'active': True}]
- mock_client.getVLUNs.return_value = {'members': ports}
+ mock_client.getVLUNs.return_value = {'members': ports}
- # in use count
- vluns = self.driver.common.client.getVLUNs()
- nsp = self.driver._get_least_used_nsp(vluns['members'],
- ['1:1:1', '1:2:1'])
- self.assertEqual(nsp, '1:1:1')
+ # in use count
+ common = self.driver._login()
+ vluns = common.client.getVLUNs()
+ nsp = self.driver._get_least_used_nsp(common, vluns['members'],
+ ['1:1:1', '1:2:1'])
+ self.assertEqual(nsp, '1:1:1')
def test_set_3par_chaps(self):
# setup_mock_client drive with default configuration
# and return the mock HTTP 3PAR client
mock_client = self.setup_driver()
- expected = []
- self.driver._set_3par_chaps(
- 'test-host', 'test-vol', 'test-host', 'pass')
- mock_client.assert_has_calls(expected)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ expected = []
+ self.driver._set_3par_chaps(
+ common, 'test-host', 'test-vol', 'test-host', 'pass')
+ mock_client.assert_has_calls(expected)
# setup_mock_client drive with CHAP enabled configuration
# and return the mock HTTP 3PAR client
config.hp3par_iscsi_chap_enabled = True
mock_client = self.setup_driver(config=config)
- expected_mod_request = {
- 'chapOperation': mock_client.HOST_EDIT_ADD,
- 'chapOperationMode': mock_client.CHAP_INITIATOR,
- 'chapName': 'test-host',
- 'chapSecret': 'fake'
- }
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ expected_mod_request = {
+ 'chapOperation': mock_client.HOST_EDIT_ADD,
+ 'chapOperationMode': mock_client.CHAP_INITIATOR,
+ 'chapName': 'test-host',
+ 'chapSecret': 'fake'
+ }
- expected = [
- mock.call.modifyHost('test-host', expected_mod_request)
- ]
- self.driver._set_3par_chaps(
- 'test-host', 'test-vol', 'test-host', 'fake')
- mock_client.assert_has_calls(expected)
+ expected = [
+ mock.call.modifyHost('test-host', expected_mod_request)
+ ]
+ self.driver._set_3par_chaps(
+ common, 'test-host', 'test-vol', 'test-host', 'fake')
+ mock_client.assert_has_calls(expected)
@mock.patch('cinder.volume.utils.generate_password')
def test_do_export(self, mock_utils):
expected = []
expected_model = {'provider_auth': None}
- model = self.driver._do_export(volume)
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_model, model)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ model = self.driver._do_export(common, volume)
- mock_client.reset_mock()
+ mock_client.assert_has_calls(expected)
+ self.assertEqual(expected_model, model)
+
+ mock_client.reset_mock()
# setup_mock_client drive with CHAP enabled configuration
# and return the mock HTTP 3PAR client
]
expected_model = {'provider_auth': 'CHAP test-host random-pass'}
- model = self.driver._do_export(volume)
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_model, model)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ model = self.driver._do_export(common, volume)
+ mock_client.assert_has_calls(expected)
+ self.assertEqual(expected_model, model)
@mock.patch('cinder.volume.utils.generate_password')
def test_do_export_host_not_found(self, mock_utils):
'value': 'random-pass'
}
- config = self.setup_configuration()
- config.hp3par_iscsi_chap_enabled = True
-
expected = [
mock.call.getHostVLUNs('test-host'),
mock.call.setVolumeMetaData(
]
expected_model = {'provider_auth': 'CHAP test-host random-pass'}
- model = self.driver._do_export(volume)
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_model, model)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ model = self.driver._do_export(common, volume)
+ mock_client.assert_has_calls(expected)
+ self.assertEqual(expected_model, model)
@mock.patch('cinder.volume.utils.generate_password')
def test_do_export_host_chap_disabled(self, mock_utils):
'value': 'random-pass'
}
- mock_client.reset_mock()
-
- config = self.setup_configuration()
- config.hp3par_iscsi_chap_enabled = True
-
expected = [
mock.call.getHostVLUNs('test-host'),
mock.call.getHost('test-host'),
]
expected_model = {'provider_auth': 'CHAP test-host random-pass'}
- model = self.driver._do_export(volume)
- mock_client.assert_has_calls(expected)
- self.assertEqual(expected_model, model)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ model = self.driver._do_export(common, volume)
+ mock_client.assert_has_calls(expected)
+ self.assertEqual(expected_model, model)
@mock.patch('cinder.volume.utils.generate_password')
def test_do_export_no_active_vluns(self, mock_utils):
]
expected_model = {'provider_auth': 'CHAP test-host random-pass'}
- model = self.driver._do_export(volume)
- mock_client.assert_has_calls(expected)
- self.assertEqual(model, expected_model)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+ model = self.driver._do_export(common, volume)
+ mock_client.assert_has_calls(expected)
+ self.assertEqual(model, expected_model)
def test_ensure_export(self):
# setup_mock_client drive with default configuration
'members': []
}
- model = self.driver.ensure_export(None, volume)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ model = self.driver.ensure_export(None, volume)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getAllVolumeMetaData('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.logout()
- ]
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getAllVolumeMetaData('osv-0DM4qZEVSKON-DXN-NwVpw')
+ ]
- expected_model = {'provider_auth': None}
+ expected_model = {'provider_auth': None}
- mock_client.assert_has_calls(expected)
- self.assertEqual(model, expected_model)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(model, expected_model)
- mock_client.getAllVolumeMetaData.return_value = {
- 'total': 2,
- 'members': [
- {
- 'creationTimeSec': 1406074222,
- 'value': 'fake-host',
- 'key': CHAP_USER_KEY,
- 'creationTime8601': '2014-07-22T17:10:22-07:00'
- },
- {
- 'creationTimeSec': 1406074222,
- 'value': 'random-pass',
- 'key': CHAP_PASS_KEY,
- 'creationTime8601': '2014-07-22T17:10:22-07:00'
- }
- ]
- }
+ mock_client.getAllVolumeMetaData.return_value = {
+ 'total': 2,
+ 'members': [
+ {
+ 'creationTimeSec': 1406074222,
+ 'value': 'fake-host',
+ 'key': CHAP_USER_KEY,
+ 'creationTime8601': '2014-07-22T17:10:22-07:00'
+ },
+ {
+ 'creationTimeSec': 1406074222,
+ 'value': 'random-pass',
+ 'key': CHAP_PASS_KEY,
+ 'creationTime8601': '2014-07-22T17:10:22-07:00'
+ }
+ ]
+ }
- model = self.driver.ensure_export(None, volume)
+ model = self.driver.ensure_export(None, volume)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.getAllVolumeMetaData('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.logout()
- ]
+ expected = [
+ mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
+ mock.call.getAllVolumeMetaData('osv-0DM4qZEVSKON-DXN-NwVpw')
+ ]
- expected_model = {'provider_auth': "CHAP fake-host random-pass"}
+ expected_model = {'provider_auth': "CHAP fake-host random-pass"}
- mock_client.assert_has_calls(expected)
- self.assertEqual(model, expected_model)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(model, expected_model)
def test_ensure_export_missing_volume(self):
# setup_mock_client drive with default configuration
mock_client.getVolume.side_effect = hpexceptions.HTTPNotFound(
'fake')
- model = self.driver.ensure_export(None, volume)
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ model = self.driver.ensure_export(None, volume)
- expected = [
- mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS),
- mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw'),
- mock.call.logout()
- ]
+ expected = [mock.call.getVolume('osv-0DM4qZEVSKON-DXN-NwVpw')]
- expected_model = None
+ expected_model = None
- mock_client.assert_has_calls(expected)
- self.assertEqual(model, expected_model)
+ mock_client.assert_has_calls(
+ self.standard_login +
+ expected +
+ self.standard_logout)
+ self.assertEqual(model, expected_model)
@mock.patch.object(volume_types, 'get_volume_type')
def test_get_volume_settings_default_pool(self, _mock_volume_types):
'name': 'gold',
'id': 'gold-id',
'extra_specs': {}}
- self.setup_driver()
- volume = {'host': 'test-host@3pariscsi#pool_foo',
- 'id': 'd03338a9-9115-48a3-8dfc-35cdfcdc15a7'}
- pool = volume_utils.extract_host(volume['host'], 'pool')
- model = self.driver.common.get_volume_settings_from_type_id('gold-id',
- pool)
- self.assertEqual(model['cpg'], 'pool_foo')
+ mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ volume = {'host': 'test-host@3pariscsi#pool_foo',
+ 'id': 'd03338a9-9115-48a3-8dfc-35cdfcdc15a7'}
+ pool = volume_utils.extract_host(volume['host'], 'pool')
+ model = common.get_volume_settings_from_type_id('gold-id', pool)
+ self.assertEqual(model['cpg'], 'pool_foo')
def test_get_model_update(self):
- self.setup_driver()
- model_update = self.driver.common._get_model_update('xxx@yyy#zzz',
- 'CPG')
- self.assertEqual(model_update, {'host': 'xxx@yyy#CPG'})
+ mock_client = self.setup_driver()
+ with mock.patch.object(hpcommon.HP3PARCommon, '_create_client')\
+ as mock_create_client:
+ mock_create_client.return_value = mock_client
+ common = self.driver._login()
+
+ model_update = common._get_model_update('xxx@yyy#zzz', 'CPG')
+ self.assertEqual(model_update, {'host': 'xxx@yyy#CPG'})
VLUNS5_RET = ({'members':
[{'portPos': {'node': 0, 'slot': 8, 'cardPort': 2},