Should not raise Exception before connection close

Currently VmdkReadHandle.close() raises a VimException before
the read connection is closed, this patch let's add a `finally`
to close it.

Change-Id: Ib5b388f7eeb9f26de66c308a89f70c85ba6dc7a9
This commit is contained in:
Javeme 2016-02-17 20:05:01 +08:00
parent aef1f4a0a2
commit 8ec8c09417
2 changed files with 12 additions and 1 deletions

View File

@ -617,7 +617,8 @@ class VmdkReadHandle(FileHandle):
self._url,
exc_info=True)
raise
super(VmdkReadHandle, self).close()
finally:
super(VmdkReadHandle, self).close()
LOG.debug("Closed VMDK read handle for %s.", self._url)
def __str__(self):

View File

@ -341,6 +341,16 @@ class VmdkReadHandleTest(base.TestCase):
handle.close()
self.assertEqual(2, session.invoke_api.call_count)
def test_close_with_error(self):
session = self._create_mock_session()
handle = rw_handles.VmdkReadHandle(session, '10.1.2.3', 443,
'vm-1', '[ds] disk1.vmdk',
100)
session.invoke_api.side_effect = exceptions.VimException(None)
self.assertRaises(exceptions.VimException, handle.close)
self._resp.close.assert_called_once_with()
class ImageReadHandleTest(base.TestCase):
"""Tests for ImageReadHandle."""