From af4a58d672cfa0c4b63015e7e783461570296c76 Mon Sep 17 00:00:00 2001 From: Jeff Applewhite Date: Mon, 24 Mar 2014 17:37:22 -0400 Subject: [PATCH] Netapp iscsi: allow snapshots with unspecified block range. Snapshots were failing to create in all cases in the NetApp iscsi driver. The clone lun function was never issuing the zapi call because the block count was set to 0. Closes-Bug: 1296881 Change-Id: Ic2bf67b57a566632103a3fa2ff032555f42a3961 --- .../tests/volume/drivers/netapp/test_iscsi.py | 81 +++++++++++++++++++ cinder/volume/drivers/netapp/iscsi.py | 4 + 2 files changed, 85 insertions(+) diff --git a/cinder/tests/volume/drivers/netapp/test_iscsi.py b/cinder/tests/volume/drivers/netapp/test_iscsi.py index fd35f0b72..007201cfa 100644 --- a/cinder/tests/volume/drivers/netapp/test_iscsi.py +++ b/cinder/tests/volume/drivers/netapp/test_iscsi.py @@ -77,6 +77,44 @@ class NetAppiSCSICModeTestCase(test.TestCase): self.assertEqual(2, self.driver.client.invoke_successfully.call_count) + def test_clone_lun_zero_block_count(self): + """Test for when clone lun is not passed a block count.""" + + self.driver._get_lun_attr = mock.Mock(return_value={'Volume': + 'fakeLUN'}) + self.driver.client.invoke_successfully = mock.Mock() + lun = ntapi.NaElement.create_node_with_children( + 'lun-info', + **{'alignment': 'indeterminate', + 'block-size': '512', + 'comment': '', + 'creation-timestamp': '1354536362', + 'is-space-alloc-enabled': 'false', + 'is-space-reservation-enabled': 'true', + 'mapped': 'false', + 'multiprotocol-type': 'linux', + 'online': 'true', + 'path': '/vol/fakeLUN/lun1', + 'prefix-size': '0', + 'qtree': '', + 'read-only': 'false', + 'serial-number': '2FfGI$APyN68', + 'share-state': 'none', + 'size': '20971520', + 'size-used': '0', + 'staging': 'false', + 'suffix-size': '0', + 'uuid': 'cec1f3d7-3d41-11e2-9cf4-123478563412', + 'volume': 'fakeLUN', + 'vserver': 'fake_vserver'}) + self.driver._get_lun_by_args = mock.Mock(return_value=[lun]) + self.driver._add_lun_to_table = mock.Mock() + self.driver._update_stale_vols = mock.Mock() + + self.driver._clone_lun('fakeLUN', 'newFakeLUN') + + self.assertEqual(1, self.driver.client.invoke_successfully.call_count) + class NetAppiSCSI7ModeTestCase(test.TestCase): """Test case for NetApp's 7-Mode iSCSI driver.""" @@ -136,3 +174,46 @@ class NetAppiSCSI7ModeTestCase(test.TestCase): self.driver._clone_lun('fakeLUN', 'newFakeLUN', block_count=bc) self.assertEqual(2, self.driver.client.invoke_successfully.call_count) + + def test_clone_lun_zero_block_count(self): + """Test for when clone lun is not passed a block count.""" + + self.driver._get_lun_attr = mock.Mock(return_value={'Volume': + 'fakeLUN', + 'Path': + '/vol/fake/lun1'}) + self.driver.client.invoke_successfully = mock.Mock( + return_value=mock.MagicMock()) + lun = ntapi.NaElement.create_node_with_children( + 'lun-info', + **{'alignment': 'indeterminate', + 'block-size': '512', + 'comment': '', + 'creation-timestamp': '1354536362', + 'is-space-alloc-enabled': 'false', + 'is-space-reservation-enabled': 'true', + 'mapped': 'false', + 'multiprotocol-type': 'linux', + 'online': 'true', + 'path': '/vol/fakeLUN/lun1', + 'prefix-size': '0', + 'qtree': '', + 'read-only': 'false', + 'serial-number': '2FfGI$APyN68', + 'share-state': 'none', + 'size': '20971520', + 'size-used': '0', + 'staging': 'false', + 'suffix-size': '0', + 'uuid': 'cec1f3d7-3d41-11e2-9cf4-123478563412', + 'volume': 'fakeLUN', + 'vserver': 'fake_vserver'}) + self.driver._get_lun_by_args = mock.Mock(return_value=[lun]) + self.driver._add_lun_to_table = mock.Mock() + self.driver._update_stale_vols = mock.Mock() + self.driver._check_clone_status = mock.Mock() + self.driver._set_space_reserve = mock.Mock() + + self.driver._clone_lun('fakeLUN', 'newFakeLUN') + + self.assertEqual(1, self.driver.client.invoke_successfully.call_count) diff --git a/cinder/volume/drivers/netapp/iscsi.py b/cinder/volume/drivers/netapp/iscsi.py index d5615207a..1dca09de9 100644 --- a/cinder/volume/drivers/netapp/iscsi.py +++ b/cinder/volume/drivers/netapp/iscsi.py @@ -963,6 +963,8 @@ class NetAppDirectCmodeISCSIDriver(NetAppDirectISCSIDriver): z_limit = br_limit * bc_limit # 256 GB z_calls = int(math.ceil(block_count / float(z_limit))) zbc = block_count + if z_calls == 0: + z_calls = 1 for call in range(0, z_calls): if zbc > z_limit: block_count = z_limit @@ -1340,6 +1342,8 @@ class NetAppDirect7modeISCSIDriver(NetAppDirectISCSIDriver): z_limit = br_limit * bc_limit # 256 GB z_calls = int(math.ceil(block_count / float(z_limit))) zbc = block_count + if z_calls == 0: + z_calls = 1 for call in range(0, z_calls): if zbc > z_limit: block_count = z_limit -- 2.45.2