diff --git a/cinder/tests/unit/volume/drivers/test_qnap.py b/cinder/tests/unit/volume/drivers/test_qnap.py index cf88e07b82a..e7de6d1078d 100644 --- a/cinder/tests/unit/volume/drivers/test_qnap.py +++ b/cinder/tests/unit/volume/drivers/test_qnap.py @@ -31,6 +31,7 @@ from six.moves import urllib from cinder import exception from cinder import test from cinder import utils +from cinder.volume import driver from cinder.volume.drivers import qnap CONF = cfg.CONF @@ -1263,6 +1264,7 @@ class QnapDriverLoginTestCase(QnapDriverBaseTestCase): self.assertEqual(ssl, self.driver.api_executor.ssl) +@ddt class QnapDriverVolumeTestCase(QnapDriverBaseTestCase): """Tests volume related api's.""" @@ -2369,6 +2371,77 @@ class QnapDriverVolumeTestCase(QnapDriverBaseTestCase): fake_volume, fake_new_volume, 'fakeOriginalVolumeStatus') + @data({ + 'fake_spec': {}, + 'expect_spec': { + 'force': False, + 'ignore_errors': False, + 'remote': False + } + }, { + 'fake_spec': { + 'force': mock.sentinel.force, + 'ignore_errors': mock.sentinel.ignore_errors, + 'remote': mock.sentinel.remote + }, + 'expect_spec': { + 'force': mock.sentinel.force, + 'ignore_errors': mock.sentinel.ignore_errors, + 'remote': mock.sentinel.remote + } + }) + @unpack + @mock.patch.object(driver.BaseVD, '_detach_volume') + @mock.patch('cinder.volume.drivers.qnap.QnapAPIExecutor') + def test_detach_volume( + self, + mock_api_executor, + mock_detach_volume, + fake_spec, expect_spec): + """Test detach volume.""" + + mock_detach_volume.return_value = None + mock_api_executor.return_value.get_basic_info.return_value = ( + 'ES1640dc ', 'ES1640dc ', '1.1.3') + self.driver = qnap.QnapISCSIDriver( + configuration=create_configuration( + 'admin', + 'qnapadmin', + 'http://1.2.3.4:8080', + '1.2.3.4', + 'Pool1', + True)) + self.driver.do_setup('context') + self.driver._detach_volume('context', + 'attach_info', 'volume', + 'property', **fake_spec) + mock_detach_volume.assert_called_once_with( + 'context', 'attach_info', 'volume', 'property', **expect_spec) + + @mock.patch.object(driver.BaseVD, '_attach_volume') + @mock.patch('cinder.volume.drivers.qnap.QnapAPIExecutor') + def test_attach_volume( + self, + mock_api_executor, + mock_attach_volume): + """Test attach volume.""" + + mock_attach_volume.return_value = None + mock_api_executor.return_value.get_basic_info.return_value = ( + 'ES1640dc ', 'ES1640dc ', '1.1.3') + self.driver = qnap.QnapISCSIDriver( + configuration=create_configuration( + 'admin', + 'qnapadmin', + 'http://1.2.3.4:8080', + '1.2.3.4', + 'Pool1', + True)) + self.driver.do_setup('context') + self.driver._attach_volume('context', 'volume', 'properties') + mock_attach_volume.assert_called_once_with( + 'context', 'volume', 'properties', False) + class QnapAPIExecutorEsTestCase(QnapDriverBaseTestCase): """Tests QnapAPIExecutor.""" diff --git a/cinder/volume/drivers/qnap.py b/cinder/volume/drivers/qnap.py index a26be84d6b6..551d093cbde 100644 --- a/cinder/volume/drivers/qnap.py +++ b/cinder/volume/drivers/qnap.py @@ -1083,10 +1083,13 @@ class QnapISCSIDriver(san.SanISCSIDriver): @utils.synchronized('_attach_volume') def _detach_volume(self, context, attach_info, volume, properties, - force=False, remote=False): - super(QnapISCSIDriver, self)._detach_volume(context, attach_info, - volume, properties, - force, remote) + force=False, remote=False, ignore_errors=False): + super(QnapISCSIDriver, self)._detach_volume( + context, attach_info, + volume, properties, + force=force, remote=remote, + ignore_errors=ignore_errors + ) @utils.synchronized('_attach_volume') def _attach_volume(self, context, volume, properties, remote=False): diff --git a/releasenotes/notes/bug-1766768-qnap-fix-upload-volume-detach-fail-33cbee59f1381bda.yaml b/releasenotes/notes/bug-1766768-qnap-fix-upload-volume-detach-fail-33cbee59f1381bda.yaml new file mode 100644 index 00000000000..0ea8d312632 --- /dev/null +++ b/releasenotes/notes/bug-1766768-qnap-fix-upload-volume-detach-fail-33cbee59f1381bda.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed QNAP driver failures to detach iscsi device while uploading volume + to image.