-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CA-128095: [UnitTest] Unhandled exception in LVMoISCSISR.load()
Signed-off-by: Kostas Ladopoulos <konstantinos.ladopoulos@citrix.com>
- Loading branch information
1 parent
d26108d
commit 27a7502
Showing
1 changed file
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import unittest | ||
import mock | ||
import LVHDoISCSISR | ||
|
||
|
||
class RandomException(Exception): | ||
pass | ||
|
||
|
||
class NonInitingLVHDoISCSISR(LVHDoISCSISR.LVHDoISCSISR): | ||
|
||
""" Helper class; Creates dummy LVHDoISCSISR object. | ||
Add attributes/methods as appropriate. | ||
""" | ||
|
||
def __init__(self, extra_dconf=None, extra_params=None): | ||
|
||
from SRCommand import SRCommand | ||
from DummySR import DRIVER_INFO | ||
|
||
self.mpath = "false" | ||
self.dconf = { | ||
'target': 'target', | ||
'localIQN': 'localIQN', | ||
'targetIQN': 'targetIQN', | ||
'SCSIid': 'SCSIid' | ||
} | ||
|
||
self.srcmd = mock.Mock(spec=SRCommand(DRIVER_INFO)) | ||
self.srcmd.dconf = self.dconf | ||
|
||
self.original_srcmd = self.srcmd | ||
|
||
self.srcmd.params = {'command': 'command'} | ||
|
||
self.srcmd.dconf.update(extra_dconf or {}) | ||
self.srcmd.params.update(extra_params or {}) | ||
|
||
|
||
class TestLVHDoISCSISR(unittest.TestCase): | ||
|
||
@mock.patch('iscsilib.ensure_daemon_running_ok') | ||
@mock.patch('util._convertDNS') | ||
@mock.patch('SR.driver') | ||
@mock.patch('util.gen_uuid') | ||
def test_load_reraise_unhandled_exceptions( | ||
self, | ||
mock_util_gen_uuid, | ||
mock_SR_driver, | ||
mock_util__convertDNS, | ||
mock_iscsilib_ensure_daemon_running_ok): | ||
|
||
""" Asserts that all unhandled exceptions are reraised. | ||
In LVHDoISCSISR.load() there is a big try/except block that | ||
doesn't handle all exceptions. Specifically, it logs the | ||
exception and tries to continue after the block, almost certainly | ||
resulting in an "IndexError" exception because the "self.iscsiSRs" | ||
list is empty. This test asserts that all such exceptions are | ||
reraised. | ||
""" | ||
|
||
mock_util_gen_uuid.return_value = 'deadbeef' | ||
mock_util__convertDNS.return_value = '127.0.0.1' | ||
mock_iscsilib_ensure_daemon_running_ok.side_effect = \ | ||
RandomException('test_load_reraise_unhandled_exceptions') | ||
|
||
lvhd_o_iscsi_sr = NonInitingLVHDoISCSISR( | ||
{'targetIQN': '*'}, | ||
{'command': 'sr_create'} | ||
) | ||
|
||
try: | ||
lvhd_o_iscsi_sr.load(None) | ||
except Exception, e: | ||
self.assertTrue(isinstance(e, RandomException)) | ||
self.assertEqual(str(e), 'test_load_reraise_unhandled_exceptions') |