From 52389188372b38ef237898e90cc533cf27d3eda1 Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Mon, 24 Feb 2014 11:35:32 -0800 Subject: [PATCH] Added 3par initiator target map for FCZM This patch adds the required initiator target map for the Fibre Channel Zone Manager. The FCZM looks for the initiator_target_map to try and automatically zone up the endpoints. Change-Id: I61aaf31752f8a5eebb672887c9a943584df66995 Closes-Bug: #1284275 --- cinder/tests/test_hp3par.py | 33 +++++++++++++++++- cinder/volume/drivers/san/hp/hp_3par_fc.py | 39 ++++++++++++++++++---- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/cinder/tests/test_hp3par.py b/cinder/tests/test_hp3par.py index 36d2ae624..ebce2f58d 100644 --- a/cinder/tests/test_hp3par.py +++ b/cinder/tests/test_hp3par.py @@ -794,7 +794,12 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): 'data': { 'target_lun': 90, 'target_wwn': ['0987654321234', '123456789000987'], - 'target_discovered': True}} + 'target_discovered': True, + 'initiator_target_map': {'123456789012345': + ['0987654321234', '123456789000987'], + '123456789054321': + ['0987654321234', '123456789000987'], + }}} def setUp(self): super(TestHP3PARFCDriver, self).setUp() @@ -876,6 +881,32 @@ class TestHP3PARFCDriver(HP3PARBaseDriver, test.TestCase): self.assertDictMatch(result, self.properties) + def test_terminate_connection(self): + # setup_mock_client drive with default configuration + # and return the mock HTTP 3PAR client + mock_client = self.setup_driver() + mock_client.getVLUN.return_value = {'lun': None, 'type': 0} + mock_client.getPorts.return_value = { + 'members': self.FAKE_FC_PORTS + [self.FAKE_ISCSI_PORT]} + + self.driver.terminate_connection( + self.volume, + self.connector, + force=True) + + expected = [ + mock.call.login(HP3PAR_USER_NAME, HP3PAR_USER_PASS), + mock.call.getVLUN(self.VOLUME_3PAR_NAME), + mock.call.deleteVLUN( + self.VOLUME_3PAR_NAME, + None, + self.FAKE_HOST), + mock.call.deleteHost(self.FAKE_HOST), + mock.call.getPorts(), + mock.call.logout()] + + mock_client.assert_has_calls(expected) + def test_get_volume_stats(self): # setup_mock_client drive with default configuration # and return the mock HTTP 3PAR client diff --git a/cinder/volume/drivers/san/hp/hp_3par_fc.py b/cinder/volume/drivers/san/hp/hp_3par_fc.py index f1e771275..e48051224 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_fc.py +++ b/cinder/volume/drivers/san/hp/hp_3par_fc.py @@ -57,10 +57,11 @@ class HP3PARFCDriver(cinder.volume.driver.FibreChannelDriver): 1.3.0 - Removed all SSH code. We rely on the hp3parclient now. 2.0.0 - Update hp3parclient API uses 3.0.x 2.0.2 - Add back-end assisted volume migrate + 2.0.3 - Added initiator-target map for FC Zone Manager """ - VERSION = "2.0.2" + VERSION = "2.0.3" def __init__(self, *args, **kwargs): super(HP3PARFCDriver, self).__init__(*args, **kwargs) @@ -203,16 +204,14 @@ class HP3PARFCDriver(cinder.volume.driver.FibreChannelDriver): # now that we have a host, create the VLUN vlun = self.common.create_vlun(volume, host) - fc_ports = self.common.get_active_fc_target_ports() - wwns = [] - - for port in fc_ports: - wwns.append(port['portWWN']) + target_wwns, init_targ_map = self._build_initiator_target_map( + connector) info = {'driver_volume_type': 'fibre_channel', 'data': {'target_lun': vlun['lun'], 'target_discovered': True, - 'target_wwn': wwns}} + 'target_wwn': target_wwns, + 'initiator_target_map': init_targ_map}} return info finally: self.common.client_logout() @@ -225,9 +224,35 @@ class HP3PARFCDriver(cinder.volume.driver.FibreChannelDriver): hostname = self.common._safe_hostname(connector['host']) self.common.terminate_connection(volume, hostname, wwn=connector['wwpns']) + + target_wwns, init_targ_map = self._build_initiator_target_map( + connector) + + info = {'driver_volume_type': 'fibre_channel', + 'data': {'target_wwn': target_wwns, + 'initiator_target_map': init_targ_map}} + return info + finally: self.common.client_logout() + def _build_initiator_target_map(self, connector): + """Build the target_wwns and the initiator target map.""" + + fc_ports = self.common.get_active_fc_target_ports() + target_wwns = [] + + for port in fc_ports: + target_wwns.append(port['portWWN']) + + initiator_wwns = connector['wwpns'] + + init_targ_map = {} + for initiator in initiator_wwns: + init_targ_map[initiator] = target_wwns + + return target_wwns, init_targ_map + def _create_3par_fibrechan_host(self, hostname, wwns, domain, persona_id): """Create a 3PAR host. -- 2.45.2