"Fossies" - the Fresh Open Source Software Archive 
Member "manila-8.1.4/manila/tests/share/drivers/dell_emc/common/enas/test_utils.py" (19 Nov 2020, 6052 Bytes) of package /linux/misc/openstack/manila-8.1.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "test_utils.py":
8.1.3_vs_8.1.4.
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
16 import ddt
17 import mock
18 import ssl
19
20 from manila.share.drivers.dell_emc.common.enas import utils
21 from manila import test
22
23
24 @ddt.ddt
25 class ENASUtilsTestCase(test.TestCase):
26
27 @ddt.data({'full': ['cge-1-0', 'cge-1-1', 'cge-3-0',
28 'cge-3-1', 'cge-12-3'],
29 'matchers': ['cge-?-0', 'cge-3*', 'foo'],
30 'matched': set(['cge-1-0', 'cge-3-0',
31 'cge-3-1']),
32 'unmatched': set(['cge-1-1', 'cge-12-3'])},
33 {'full': ['cge-1-0', 'cge-1-1'],
34 'matchers': ['cge-1-0'],
35 'matched': set(['cge-1-0']),
36 'unmatched': set(['cge-1-1'])},
37 {'full': ['cge-1-0', 'cge-1-1'],
38 'matchers': ['foo'],
39 'matched': set([]),
40 'unmatched': set(['cge-1-0', 'cge-1-1'])})
41 @ddt.unpack
42 def test_do_match_any(self, full, matchers, matched, unmatched):
43 real_matched, real_unmatched = utils.do_match_any(
44 full, matchers)
45 self.assertEqual(matched, real_matched)
46 self.assertEqual(unmatched, real_unmatched)
47
48
49 class SslContextTestCase(test.TestCase):
50
51 def test_create_ssl_context(self):
52 configuration = mock.Mock()
53 configuration.emc_ssl_cert_verify = True
54 configuration.emc_ssl_cert_path = "./cert_path/"
55 self.mock_object(ssl, 'create_default_context')
56 context = utils.create_ssl_context(configuration)
57 self.assertIsNotNone(context)
58
59 def test_create_ssl_context_no_verify(self):
60 configuration = mock.Mock()
61 configuration.emc_ssl_cert_verify = False
62 self.mock_object(ssl, 'create_default_context')
63 context = utils.create_ssl_context(configuration)
64 self.assertFalse(context.check_hostname)
65
66 def test_no_create_default_context(self):
67 """Test scenario of running on python 2.7.8 or earlier."""
68 configuration = mock.Mock()
69 configuration.emc_ssl_cert_verify = False
70 self.mock_object(ssl, 'create_default_context',
71 mock.Mock(side_effect=AttributeError))
72 context = utils.create_ssl_context(configuration)
73 self.assertIsNone(context)
74
75
76 @ddt.ddt
77 class ParseIpaddrTestCase(test.TestCase):
78
79 @ddt.data({'lst_ipaddr': ['192.168.100.101',
80 '192.168.100.102',
81 '192.168.100.103']},
82 {'lst_ipaddr': ['[fdf8:f53b:82e4::57]',
83 '[fdf8:f53b:82e4::54]',
84 '[fdf8:f53b:82e4::55]']},
85 {'lst_ipaddr': ['[fdf8:f53b:82e4::57]',
86 '[fdf8:f53b:82e4::54]',
87 '192.168.100.103',
88 '[fdf8:f53b:82e4::55]']},
89 {'lst_ipaddr': ['192.168.100.101',
90 '[fdf8:f53b:82e4::57]',
91 '[fdf8:f53b:82e4::54]',
92 '192.168.100.101',
93 '[fdf8:f53b:82e4::55]',
94 '192.168.100.102']},)
95 @ddt.unpack
96 def test_parse_ipv4_addr(self, lst_ipaddr):
97 self.assertEqual(lst_ipaddr, utils.parse_ipaddr(':'.join(lst_ipaddr)))
98
99
100 @ddt.ddt
101 class ConvertIPv6FormatTestCase(test.TestCase):
102
103 @ddt.data({'ip_addr': 'fdf8:f53b:82e4::55'},
104 {'ip_addr': 'fdf8:f53b:82e4::55/64'},
105 {'ip_addr': 'fdf8:f53b:82e4::55/128'})
106 @ddt.unpack
107 def test_ipv6_addr(self, ip_addr):
108 expected_ip_addr = '[%s]' % ip_addr
109 self.assertEqual(expected_ip_addr,
110 utils.convert_ipv6_format_if_needed(ip_addr))
111
112 @ddt.data({'ip_addr': '192.168.1.100'},
113 {'ip_addr': '192.168.1.100/24'},
114 {'ip_addr': '192.168.1.100/32'},
115 {'ip_addr': '[fdf8:f53b:82e4::55]'})
116 @ddt.unpack
117 def test_invalid_ipv6_addr(self, ip_addr):
118 self.assertEqual(ip_addr, utils.convert_ipv6_format_if_needed(ip_addr))
119
120
121 @ddt.ddt
122 class ExportUncPathTestCase(test.TestCase):
123
124 @ddt.data({'ip_addr': 'fdf8:f53b:82e4::55'},
125 {'ip_addr': 'fdf8:f53b:82e4::'},
126 {'ip_addr': '2018::'})
127 @ddt.unpack
128 def test_ipv6_addr(self, ip_addr):
129 expected_ip_addr = '%s.ipv6-literal.net' % ip_addr.replace(':', '-')
130 self.assertEqual(expected_ip_addr,
131 utils.export_unc_path(ip_addr))
132
133 @ddt.data({'ip_addr': '192.168.1.100'},
134 {'ip_addr': '192.168.1.100/24'},
135 {'ip_addr': '192.168.1.100/32'},
136 {'ip_addr': 'fdf8:f53b:82e4::55/64'},
137 {'ip_addr': 'fdf8:f53b:82e4::55/128'},
138 {'ip_addr': '[fdf8:f53b:82e4::55]'})
139 @ddt.unpack
140 def test_invalid_ipv6_addr(self, ip_addr):
141 self.assertEqual(ip_addr, utils.export_unc_path(ip_addr))
142
143
144 @ddt.ddt
145 class SizeToGbTestCase(test.TestCase):
146
147 @ddt.data({'size_in_bytes': 1073741824, 'size_in_gb': 1.0},
148 {'size_in_bytes': 5610301030, 'size_in_gb': 5.22})
149 @ddt.unpack
150 def test_bytes_to_gb(self, size_in_bytes, size_in_gb):
151 self.assertEqual(size_in_gb, utils.bytes_to_gb(size_in_bytes))
152
153 @ddt.data({'size_in_mb': 1024, 'size_in_gb': 1.0},
154 {'size_in_mb': 5346, 'size_in_gb': 5.22})
155 @ddt.unpack
156 def test_mb_to_gb(self, size_in_mb, size_in_gb):
157 self.assertEqual(size_in_gb, utils.mb_to_gb(size_in_mb))