From 19f3fa013f34dd40159eb9f78501659951910850 Mon Sep 17 00:00:00 2001 From: Ryan Lucio Date: Tue, 17 Nov 2015 16:08:42 -0800 Subject: [PATCH] Updated violin driver check for volume objects Fixed bug where both vmem 6000 drivers were trying to export luns as snapshots when using the base volume driver's copy_volume_data() function. Bug was observed during recent CI runs. Change-Id: I254102f4d3f8a80bf7801b677e7fe6199bc723a2 Closes-Bug: 1517240 --- cinder/tests/unit/test_v6000_fcp.py | 11 ++++++----- cinder/tests/unit/test_v6000_iscsi.py | 13 +++++++------ cinder/volume/drivers/violin/v6000_fcp.py | 14 +++++++------- cinder/volume/drivers/violin/v6000_iscsi.py | 13 ++++++------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/cinder/tests/unit/test_v6000_fcp.py b/cinder/tests/unit/test_v6000_fcp.py index 280df3d93..190aecb86 100644 --- a/cinder/tests/unit/test_v6000_fcp.py +++ b/cinder/tests/unit/test_v6000_fcp.py @@ -21,8 +21,9 @@ import mock from oslo_utils import units from cinder import context -from cinder.db.sqlalchemy import models from cinder import exception +from cinder.objects import snapshot as csnap +from cinder.objects import volume as cvol from cinder import test from cinder.tests.unit import fake_vmem_client as vmemclient from cinder.volume import configuration as conf @@ -210,7 +211,7 @@ class V6000FCPDriverTestCase(test.TestCase): igroup = None target_wwns = self.driver.gateway_fc_wwns init_targ_map = {} - volume = mock.Mock(spec=models.Volume) + volume = mock.Mock(spec=cvol.Volume) self.driver.common.vip = self.setup_mock_vshare() self.driver._export_lun = mock.Mock(return_value=lun_id) @@ -234,7 +235,7 @@ class V6000FCPDriverTestCase(test.TestCase): igroup = None target_wwns = self.driver.gateway_fc_wwns init_targ_map = {} - snapshot = mock.Mock(spec=models.Snapshot) + snapshot = mock.Mock(spec=csnap.Snapshot) self.driver.common.vip = self.setup_mock_vshare() self.driver._export_snapshot = mock.Mock(return_value=lun_id) @@ -257,7 +258,7 @@ class V6000FCPDriverTestCase(test.TestCase): def test_terminate_connection(self): target_wwns = self.driver.gateway_fc_wwns init_targ_map = {} - volume = mock.Mock(spec=models.Volume) + volume = mock.Mock(spec=cvol.Volume) self.driver.common.vip = self.setup_mock_vshare() self.driver._unexport_lun = mock.Mock() @@ -281,7 +282,7 @@ class V6000FCPDriverTestCase(test.TestCase): def test_terminate_connection_snapshot_object(self): target_wwns = self.driver.gateway_fc_wwns init_targ_map = {} - snapshot = mock.Mock(spec=models.Snapshot) + snapshot = mock.Mock(spec=csnap.Snapshot) self.driver.common.vip = self.setup_mock_vshare() self.driver._unexport_snapshot = mock.Mock() diff --git a/cinder/tests/unit/test_v6000_iscsi.py b/cinder/tests/unit/test_v6000_iscsi.py index ae5841392..d12dd76d4 100644 --- a/cinder/tests/unit/test_v6000_iscsi.py +++ b/cinder/tests/unit/test_v6000_iscsi.py @@ -21,8 +21,9 @@ import mock from oslo_utils import units from cinder import context -from cinder.db.sqlalchemy import models from cinder import exception +from cinder.objects import snapshot as csnap +from cinder.objects import volume as cvol from cinder import test from cinder.tests.unit import fake_vmem_client as vmemclient from cinder.volume import configuration as conf @@ -244,7 +245,7 @@ class V6000ISCSIDriverTestCase(test.TestCase): tgt = self.driver.array_info[0] iqn = "%s%s:%s" % (self.conf.iscsi_target_prefix, tgt['node'], target_name) - volume = mock.MagicMock(spec=models.Volume) + volume = mock.MagicMock(spec=cvol.Volume) def getitem(name): return VOLUME[name] @@ -273,7 +274,7 @@ class V6000ISCSIDriverTestCase(test.TestCase): tgt = self.driver.array_info[0] iqn = "%s%s:%s" % (self.conf.iscsi_target_prefix, tgt['node'], target_name) - snapshot = mock.MagicMock(spec=models.Snapshot) + snapshot = mock.MagicMock(spec=csnap.Snapshot) def getitem(name): return SNAPSHOT[name] @@ -303,7 +304,7 @@ class V6000ISCSIDriverTestCase(test.TestCase): tgt = self.driver.array_info[0] iqn = "%s%s:%s" % (self.conf.iscsi_target_prefix, tgt['node'], target_name) - volume = mock.MagicMock(spec=models.Volume) + volume = mock.MagicMock(spec=cvol.Volume) def getitem(name): return VOLUME[name] @@ -332,7 +333,7 @@ class V6000ISCSIDriverTestCase(test.TestCase): self.assertEqual(volume['id'], props['data']['volume_id']) def test_terminate_connection(self): - volume = mock.MagicMock(spec=models.Volume) + volume = mock.MagicMock(spec=cvol.Volume) self.driver.common.vip = self.setup_mock_vshare() self.driver._unexport_lun = mock.Mock() @@ -344,7 +345,7 @@ class V6000ISCSIDriverTestCase(test.TestCase): self.assertTrue(result is None) def test_terminate_connection_with_snapshot_object(self): - snapshot = mock.MagicMock(spec=models.Snapshot) + snapshot = mock.MagicMock(spec=csnap.Snapshot) self.driver.common.vip = self.setup_mock_vshare() self.driver._unexport_snapshot = mock.Mock() diff --git a/cinder/volume/drivers/violin/v6000_fcp.py b/cinder/volume/drivers/violin/v6000_fcp.py index 5054f6c05..f3adcffb5 100644 --- a/cinder/volume/drivers/violin/v6000_fcp.py +++ b/cinder/volume/drivers/violin/v6000_fcp.py @@ -40,7 +40,6 @@ from oslo_utils import units from six.moves import range from cinder import context -from cinder.db.sqlalchemy import models from cinder import exception from cinder.i18n import _, _LE, _LI, _LW from cinder import utils @@ -155,10 +154,11 @@ class V6000FCDriver(driver.FibreChannelDriver): igroup = self.common._get_igroup(volume, connector) self._add_igroup_member(connector, igroup) - if isinstance(volume, models.Volume): - lun_id = self._export_lun(volume, connector, igroup) - else: + if hasattr(volume, 'volume_id'): lun_id = self._export_snapshot(volume, connector, igroup) + else: + lun_id = self._export_lun(volume, connector, igroup) + self.common.vip.basic.save_config() target_wwns, init_targ_map = self._build_initiator_target_map( @@ -179,10 +179,10 @@ class V6000FCDriver(driver.FibreChannelDriver): def terminate_connection(self, volume, connector, force=False, **kwargs): """Terminates the connection (target<-->initiator).""" - if isinstance(volume, models.Volume): - self._unexport_lun(volume) - else: + if hasattr(volume, 'volume_id'): self._unexport_snapshot(volume) + else: + self._unexport_lun(volume) self.common.vip.basic.save_config() diff --git a/cinder/volume/drivers/violin/v6000_iscsi.py b/cinder/volume/drivers/violin/v6000_iscsi.py index 726d29400..2b69d95f9 100644 --- a/cinder/volume/drivers/violin/v6000_iscsi.py +++ b/cinder/volume/drivers/violin/v6000_iscsi.py @@ -41,7 +41,6 @@ from oslo_service import loopingcall from oslo_utils import units from cinder import context -from cinder.db.sqlalchemy import models from cinder import exception from cinder.i18n import _, _LE, _LI, _LW from cinder import utils @@ -183,10 +182,10 @@ class V6000ISCSIDriver(driver.ISCSIDriver): tgt = self._get_iscsi_target() target_name = self.TARGET_GROUP_NAME - if isinstance(volume, models.Volume): - lun = self._export_lun(volume, connector, igroup) - else: + if hasattr(volume, 'volume_id'): lun = self._export_snapshot(volume, connector, igroup) + else: + lun = self._export_lun(volume, connector, igroup) iqn = "%s%s:%s" % (self.configuration.iscsi_target_prefix, tgt['node'], target_name) @@ -207,10 +206,10 @@ class V6000ISCSIDriver(driver.ISCSIDriver): def terminate_connection(self, volume, connector, force=False, **kwargs): """Terminates the connection (target<-->initiator).""" - if isinstance(volume, models.Volume): - self._unexport_lun(volume) - else: + if hasattr(volume, 'volume_id'): self._unexport_snapshot(volume) + else: + self._unexport_lun(volume) self.common.vip.basic.save_config() def get_volume_stats(self, refresh=False): -- 2.45.2