Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

import mock 

import LVHDoFCoESR 

import lvhdutil 

import SR 

import unittest 

import xs_errors 

import testlib 

 

class FakeFCoESR(LVHDoFCoESR.LVHDoFCoESR): 

    uuid = None 

    sr_ref = None 

    session = None 

    srcmd = None 

    host_ref = None 

 

    def __init__(self, srcmd, session, sr_ref, host_ref): 

        self.dconf = srcmd.dconf 

        self.srcmd = srcmd 

        self.original_srcmd = srcmd 

        self.session = session 

        self.sr_ref = sr_ref 

        self.host_ref = host_ref 

 

class TestFCoESR(unittest.TestCase): 

 

    def create_fcoesr(self, path="/dev/example", SCSIid="abcd", 

                      sr_uuid='asr_uuid', type="None", session = "sesion", 

                      sr_ref = "sr", host_ref = "host", params={}): 

        srcmd = mock.Mock() 

        srcmd.params = params 

        srcmd.dconf = { 

            'path': path, 

            'SCSIid': SCSIid, 

            'type': type 

        } 

 

        fcoesr = FakeFCoESR(srcmd, session, sr_ref, host_ref) 

        fcoesr.load(sr_uuid) 

        return fcoesr 

 

    @mock.patch('SR.driver', autospec=True) 

    @mock.patch('util.find_my_pbd', autospec=True) 

    @mock.patch('LVHDoFCoESR.LVHDoHBASR.HBASR.HBASR.print_devs', autospec=True) 

    @testlib.with_context 

    def test_load_no_scsiid(self, context, print_devs, find_my_pbd, driver): 

        context.setup_error_codes() 

        find_my_pbd.return_value = ['pbd_ref','pbd'] 

        parameters = {} 

        parameters['device_config'] = "" 

        self.assertRaises(SR.SROSError, self.create_fcoesr, SCSIid="", params=parameters) 

 

    @mock.patch('SR.driver', autospec=True) 

    @mock.patch('util.find_my_pbd', autospec=True) 

    @mock.patch('SR.SR._pathrefresh', autospec=True) 

    @mock.patch('LVHDoFCoESR.LVHDSR.LVHDSR.load', autospec=True) 

    def test_load_scsiid(self, lvhdsrload, pathrefresh, find_my_pbd, driver): 

        find_my_pbd.return_value = ['pbd_ref','pbd'] 

        parameters = {} 

        parameters['device_config'] = "" 

        self.create_fcoesr(params=parameters) 

 

    @mock.patch('SR.driver', autospec=True) 

    @mock.patch('util.find_my_pbd', autospec=True) 

    @mock.patch('SR.SR._pathrefresh', autospec=True) 

    @mock.patch('LVHDoFCoESR.LVHDSR.LVHDSR.load', autospec=True) 

    def test_load_pbd_exception(self, lvhdsrload, pathrefresh, find_my_pbd, driver): 

        find_my_pbd.side_effect = Exception('exception raised') 

        parameters = {} 

        parameters['device_config'] = "" 

        self.create_fcoesr(params=parameters) 

 

    @mock.patch('SR.driver', autospec=True) 

    @mock.patch('util.find_my_pbd', autospec=True) 

    @mock.patch('SR.SR._pathrefresh', autospec=True) 

    @mock.patch('LVHDoFCoESR.LVHDSR.LVHDSR.load', autospec=True) 

    def test_vdi(self, lvhdsrload, pathrefresh, find_my_pbd, driver): 

        sr_uuid = 'bsr_uuid' 

        find_my_pbd.return_value = ['pbd_ref', 'pbd'] 

        parameters = {} 

        parameters['device_config'] = "" 

        fcoesr = self.create_fcoesr(params=parameters) 

        def mock_init(self, sr, sr_uuid): 

            pass 

        with mock.patch('LVHDoFCoESR.LVHDoHBASR.LVHDoHBAVDI.__init__', new=mock_init): 

            fcoesr.vdi(sr_uuid)