Coverage for manila/tests/share/drivers/dell_emc/common/enas/test_utils.py: 100%

71 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright (c) 2016 EMC Corporation. 

2# All Rights Reserved. 

3# 

4# Licensed under the Apache License, Version 2.0 (the "License"); you may 

5# not use this file except in compliance with the License. You may obtain 

6# a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

10# Unless required by applicable law or agreed to in writing, software 

11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

13# License for the specific language governing permissions and limitations 

14# under the License. 

15 

16import ssl 

17from unittest import mock 

18 

19import ddt 

20 

21from manila.share.drivers.dell_emc.common.enas import utils 

22from manila import test 

23 

24 

25@ddt.ddt 

26class ENASUtilsTestCase(test.TestCase): 

27 

28 @ddt.data({'full': ['cge-1-0', 'cge-1-1', 'cge-3-0', 

29 'cge-3-1', 'cge-12-3'], 

30 'matchers': ['cge-?-0', 'cge-3*', 'foo'], 

31 'matched': set(['cge-1-0', 'cge-3-0', 

32 'cge-3-1']), 

33 'unmatched': set(['cge-1-1', 'cge-12-3'])}, 

34 {'full': ['cge-1-0', 'cge-1-1'], 

35 'matchers': ['cge-1-0'], 

36 'matched': set(['cge-1-0']), 

37 'unmatched': set(['cge-1-1'])}, 

38 {'full': ['cge-1-0', 'cge-1-1'], 

39 'matchers': ['foo'], 

40 'matched': set([]), 

41 'unmatched': set(['cge-1-0', 'cge-1-1'])}) 

42 @ddt.unpack 

43 def test_do_match_any(self, full, matchers, matched, unmatched): 

44 real_matched, real_unmatched = utils.do_match_any( 

45 full, matchers) 

46 self.assertEqual(matched, real_matched) 

47 self.assertEqual(unmatched, real_unmatched) 

48 

49 

50class SslContextTestCase(test.TestCase): 

51 

52 def test_create_ssl_context(self): 

53 configuration = mock.Mock() 

54 configuration.emc_ssl_cert_verify = True 

55 configuration.emc_ssl_cert_path = "./cert_path/" 

56 self.mock_object(ssl, 'create_default_context') 

57 context = utils.create_ssl_context(configuration) 

58 self.assertIsNotNone(context) 

59 

60 def test_create_ssl_context_no_verify(self): 

61 configuration = mock.Mock() 

62 configuration.emc_ssl_cert_verify = False 

63 self.mock_object(ssl, 'create_default_context') 

64 context = utils.create_ssl_context(configuration) 

65 self.assertFalse(context.check_hostname) 

66 

67 def test_no_create_default_context(self): 

68 """Test scenario of running on python 2.7.8 or earlier.""" 

69 configuration = mock.Mock() 

70 configuration.emc_ssl_cert_verify = False 

71 self.mock_object(ssl, 'create_default_context', 

72 mock.Mock(side_effect=AttributeError)) 

73 context = utils.create_ssl_context(configuration) 

74 self.assertIsNone(context) 

75 

76 

77@ddt.ddt 

78class ParseIpaddrTestCase(test.TestCase): 

79 

80 @ddt.data({'lst_ipaddr': ['192.168.100.101', 

81 '192.168.100.102', 

82 '192.168.100.103']}, 

83 {'lst_ipaddr': ['[fdf8:f53b:82e4::57]', 

84 '[fdf8:f53b:82e4::54]', 

85 '[fdf8:f53b:82e4::55]']}, 

86 {'lst_ipaddr': ['[fdf8:f53b:82e4::57]', 

87 '[fdf8:f53b:82e4::54]', 

88 '192.168.100.103', 

89 '[fdf8:f53b:82e4::55]']}, 

90 {'lst_ipaddr': ['192.168.100.101', 

91 '[fdf8:f53b:82e4::57]', 

92 '[fdf8:f53b:82e4::54]', 

93 '192.168.100.101', 

94 '[fdf8:f53b:82e4::55]', 

95 '192.168.100.102']},) 

96 @ddt.unpack 

97 def test_parse_ipv4_addr(self, lst_ipaddr): 

98 self.assertEqual(lst_ipaddr, utils.parse_ipaddr(':'.join(lst_ipaddr))) 

99 

100 

101@ddt.ddt 

102class ConvertIPv6FormatTestCase(test.TestCase): 

103 

104 @ddt.data({'ip_addr': 'fdf8:f53b:82e4::55'}, 

105 {'ip_addr': 'fdf8:f53b:82e4::55/64'}, 

106 {'ip_addr': 'fdf8:f53b:82e4::55/128'}) 

107 @ddt.unpack 

108 def test_ipv6_addr(self, ip_addr): 

109 expected_ip_addr = '[%s]' % ip_addr 

110 self.assertEqual(expected_ip_addr, 

111 utils.convert_ipv6_format_if_needed(ip_addr)) 

112 

113 @ddt.data({'ip_addr': '192.168.1.100'}, 

114 {'ip_addr': '192.168.1.100/24'}, 

115 {'ip_addr': '192.168.1.100/32'}, 

116 {'ip_addr': '[fdf8:f53b:82e4::55]'}) 

117 @ddt.unpack 

118 def test_invalid_ipv6_addr(self, ip_addr): 

119 self.assertEqual(ip_addr, utils.convert_ipv6_format_if_needed(ip_addr)) 

120 

121 

122@ddt.ddt 

123class ExportUncPathTestCase(test.TestCase): 

124 

125 @ddt.data({'ip_addr': 'fdf8:f53b:82e4::55'}, 

126 {'ip_addr': 'fdf8:f53b:82e4::'}, 

127 {'ip_addr': '2018::'}) 

128 @ddt.unpack 

129 def test_ipv6_addr(self, ip_addr): 

130 expected_ip_addr = '%s.ipv6-literal.net' % ip_addr.replace(':', '-') 

131 self.assertEqual(expected_ip_addr, 

132 utils.export_unc_path(ip_addr)) 

133 

134 @ddt.data({'ip_addr': '192.168.1.100'}, 

135 {'ip_addr': '192.168.1.100/24'}, 

136 {'ip_addr': '192.168.1.100/32'}, 

137 {'ip_addr': 'fdf8:f53b:82e4::55/64'}, 

138 {'ip_addr': 'fdf8:f53b:82e4::55/128'}, 

139 {'ip_addr': '[fdf8:f53b:82e4::55]'}) 

140 @ddt.unpack 

141 def test_invalid_ipv6_addr(self, ip_addr): 

142 self.assertEqual(ip_addr, utils.export_unc_path(ip_addr)) 

143 

144 

145@ddt.ddt 

146class SizeToGbTestCase(test.TestCase): 

147 

148 @ddt.data({'size_in_bytes': 1073741824, 'size_in_gb': 1.0}, 

149 {'size_in_bytes': 5610301030, 'size_in_gb': 5.22}) 

150 @ddt.unpack 

151 def test_bytes_to_gb(self, size_in_bytes, size_in_gb): 

152 self.assertEqual(size_in_gb, utils.bytes_to_gb(size_in_bytes)) 

153 

154 @ddt.data({'size_in_mb': 1024, 'size_in_gb': 1.0}, 

155 {'size_in_mb': 5346, 'size_in_gb': 5.22}) 

156 @ddt.unpack 

157 def test_mb_to_gb(self, size_in_mb, size_in_gb): 

158 self.assertEqual(size_in_gb, utils.mb_to_gb(size_in_mb))