Skip to content

Commit

Permalink
Merge 27a7502 into a11482a
Browse files Browse the repository at this point in the history
  • Loading branch information
kostaslambda committed Dec 19, 2014
2 parents a11482a + 27a7502 commit 6886ce6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/LVHDoISCSISR.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def load(self, sr_uuid):
self.session.xenapi.PBD.set_device_config(pbd, dconf)
except:
util.logException("LVHDoISCSISR.load")
raise
self.iscsi = self.iscsiSRs[0]

# Be extremely careful not to throw exceptions here since this function
Expand Down
77 changes: 77 additions & 0 deletions tests/test_LVHDoISCSISR.py
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')

0 comments on commit 6886ce6

Please sign in to comment.