Coverage for manila/tests/share/drivers/container/test_driver.py: 99%
416 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright 2016 Mirantis, Inc.
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"""Unit tests for the Container driver module."""
17import functools
18from unittest import mock
20import ddt
21from oslo_config import cfg
22from oslo_serialization import jsonutils
24from manila.common import constants as const
25from manila import context
26from manila import exception
27from manila.share import configuration
28from manila.share.drivers.container import driver
29from manila.share.drivers.container import protocol_helper
30from manila import test
31from manila.tests import db_utils
32from manila.tests import fake_utils
33from manila.tests.share.drivers.container import fakes as cont_fakes
36CONF = cfg.CONF
37CONF.import_opt('lvm_share_export_ips', 'manila.share.drivers.lvm')
40@ddt.ddt
41class ContainerShareDriverTestCase(test.TestCase):
42 """Tests ContainerShareDriver"""
44 def setUp(self):
45 super(ContainerShareDriverTestCase, self).setUp()
46 fake_utils.stub_out_utils_execute(self)
47 self._context = context.get_admin_context()
48 self._db = mock.Mock()
49 self.fake_conf = configuration.Configuration(None)
51 CONF.set_default('driver_handles_share_servers', True)
53 self._driver = driver.ContainerShareDriver(
54 configuration=self.fake_conf)
56 self.share = cont_fakes.fake_share()
57 self.access = cont_fakes.fake_access()
58 self.server = {
59 'public_address': self.fake_conf.lvm_share_export_ips,
60 'instance_id': 'LVM',
61 }
63 # Used only to test compatibility with share manager
64 self.share_server = "fake_share_server"
66 def fake_exec_sync(self, *args, **kwargs):
67 kwargs['execute_arguments'].append(args)
68 try:
69 ret_val = kwargs['ret_val']
70 except KeyError:
71 ret_val = None
72 return ret_val
74 def test__get_helper_ok(self):
75 share = cont_fakes.fake_share(share_proto='CIFS')
76 expected = protocol_helper.DockerCIFSHelper(None)
78 actual = self._driver._get_helper(share)
80 self.assertEqual(type(expected), type(actual))
82 def test__get_helper_existing_ok(self):
83 share = cont_fakes.fake_share(share_proto='CIFS')
84 expected = protocol_helper.DockerCIFSHelper
85 self._driver._helpers = {'CIFS': expected}
87 actual = self._driver._get_helper(share)
89 self.assertEqual(expected, type(actual))
91 def test__get_helper_not_ok(self):
92 share = cont_fakes.fake_share()
94 self.assertRaises(exception.InvalidShare, self._driver._get_helper,
95 share)
97 def test_update_share_stats(self):
98 self.mock_object(self._driver.storage, 'get_share_server_pools',
99 mock.Mock(return_value='test-pool'))
101 self._driver._update_share_stats()
103 self.assertEqual('Docker', self._driver._stats['share_backend_name'])
104 self.assertEqual('CIFS', self._driver._stats['storage_protocol'])
105 self.assertEqual(0, self._driver._stats['reserved_percentage'])
106 self.assertEqual(
107 0, self._driver._stats['reserved_snapshot_percentage'])
108 self.assertEqual(
109 0, self._driver._stats['reserved_share_extend_percentage'])
110 self.assertIsNone(self._driver._stats['consistency_group_support'])
111 self.assertEqual(False, self._driver._stats['snapshot_support'])
112 self.assertEqual('ContainerShareDriver',
113 self._driver._stats['driver_name'])
114 self.assertEqual('test-pool', self._driver._stats['pools'])
115 self.assertTrue(self._driver._stats['ipv4_support'])
116 self.assertFalse(self._driver._stats['ipv6_support'])
117 self.assertFalse(self._driver.
118 _stats['mount_point_name_support'])
120 def test_create_share(self):
122 share_server = {'id': 'fake'}
123 fake_container_name = 'manila_fake_container'
125 mock_provide_storage = self.mock_object(self._driver.storage,
126 'provide_storage')
127 mock_get_container_name = self.mock_object(
128 self._driver, '_get_container_name',
129 mock.Mock(return_value=fake_container_name))
130 mock_create_and_mount = self.mock_object(
131 self._driver, '_create_export_and_mount_storage',
132 mock.Mock(return_value='export_location'))
134 self.assertEqual('export_location',
135 self._driver.create_share(self._context, self.share,
136 share_server))
137 mock_provide_storage.assert_called_once_with(
138 self.share.share_id, self.share.size
139 )
140 mock_create_and_mount.assert_called_once_with(
141 self.share, fake_container_name, self.share.share_id
142 )
143 mock_get_container_name.assert_called_once_with(
144 share_server['id']
145 )
147 def test__create_export_and_mount_storage(self):
148 helper = mock.Mock()
149 server_id = 'fake_id'
150 share_name = 'fake_name'
152 mock_create_share = self.mock_object(
153 helper, 'create_share', mock.Mock(return_value='export_location'))
154 mock__get_helper = self.mock_object(
155 self._driver, "_get_helper", mock.Mock(return_value=helper))
156 self.mock_object(self._driver.storage, "_get_lv_device",
157 mock.Mock(return_value={}))
158 mock_execute = self.mock_object(self._driver.container, 'execute')
160 self.assertEqual('export_location',
161 self._driver._create_export_and_mount_storage(
162 self.share, server_id, share_name))
163 mock_create_share.assert_called_once_with(server_id)
164 mock__get_helper.assert_called_once_with(self.share)
165 mock_execute.assert_has_calls([
166 mock.call(server_id, ["mkdir", "-m", "750",
167 "/shares/%s" % share_name]),
168 mock.call(server_id, ["mount", {},
169 "/shares/%s" % share_name])
170 ])
172 def test__delete_export_and_umount_storage(self):
173 helper = mock.Mock()
174 server_id = 'fake_id'
175 share_name = 'fake_name'
176 mock__get_helper = self.mock_object(
177 self._driver, "_get_helper", mock.Mock(return_value=helper))
178 mock_delete_share = self.mock_object(helper, 'delete_share')
179 mock_execute = self.mock_object(self._driver.container, 'execute')
180 self._driver._delete_export_and_umount_storage(
181 self.share, server_id, share_name)
183 mock__get_helper.assert_called_once_with(self.share)
184 mock_delete_share.assert_called_once_with(
185 server_id, share_name, ignore_errors=False)
186 mock_execute.assert_has_calls([
187 mock.call(server_id, ["umount", "/shares/%s" % share_name],
188 ignore_errors=False),
189 mock.call(server_id, ["rm", "-fR", "/shares/%s" % share_name],
190 ignore_errors=True)]
191 )
193 def test_delete_share(self):
194 fake_server_id = "manila_container_name"
195 fake_share_name = "fake_share_name"
196 fake_share_server = {'id': 'fake'}
198 mock_get_container_name = self.mock_object(
199 self._driver, '_get_container_name',
200 mock.Mock(return_value=fake_server_id))
201 mock_get_share_name = self.mock_object(
202 self._driver, '_get_share_name',
203 mock.Mock(return_value=fake_share_name))
204 self.mock_object(self._driver.storage, 'remove_storage')
205 mock_delete_and_umount = self.mock_object(
206 self._driver, '_delete_export_and_umount_storage')
208 self._driver.delete_share(self._context, self.share, fake_share_server)
210 mock_get_container_name.assert_called_once_with(
211 fake_share_server['id']
212 )
213 mock_get_share_name.assert_called_with(
214 self.share
215 )
216 mock_delete_and_umount.assert_called_once_with(
217 self.share, fake_server_id, fake_share_name,
218 ignore_errors=True
219 )
221 @ddt.data(True, False)
222 def test__get_share_name(self, has_export_location):
224 if not has_export_location:
225 fake_share = cont_fakes.fake_share_no_export_location()
226 expected_result = fake_share.share_id
227 else:
228 fake_share = cont_fakes.fake_share()
229 expected_result = fake_share['export_location'].split('/')[-1]
231 result = self._driver._get_share_name(fake_share)
232 self.assertEqual(expected_result, result)
234 def test_extend_share(self):
235 fake_new_size = 2
236 fake_share_server = {'id': 'fake-server'}
237 share = cont_fakes.fake_share()
238 share_name = self._driver._get_share_name(share)
239 actual_arguments = []
240 expected_arguments = [
241 ('manila_fake_server', ['umount', '/shares/%s' % share_name]),
242 ('manila_fake_server',
243 ['mount', '/dev/manila_docker_volumes/%s' % share_name,
244 '/shares/%s' % share_name])
245 ]
246 mock_extend_share = self.mock_object(self._driver.storage,
247 "extend_share")
248 self._driver.container.execute = functools.partial(
249 self.fake_exec_sync, execute_arguments=actual_arguments,
250 ret_val='')
252 self._driver.extend_share(share, fake_new_size, fake_share_server)
254 self.assertEqual(expected_arguments, actual_arguments)
255 mock_extend_share.assert_called_once_with(share_name, fake_new_size,
256 fake_share_server)
258 def test_ensure_share(self):
259 # Does effectively nothing by design.
260 self.assertEqual(1, 1)
262 def test_update_access_access_rules_ok(self):
263 helper = mock.Mock()
264 fake_share_name = self._driver._get_share_name(self.share)
265 self.mock_object(self._driver, "_get_helper",
266 mock.Mock(return_value=helper))
268 self._driver.update_access(self._context, self.share,
269 [{'access_level': const.ACCESS_LEVEL_RW}],
270 [], [], [], {"id": "fake"})
272 helper.update_access.assert_called_with('manila_fake', fake_share_name,
273 [{'access_level': 'rw'}],
274 [], [])
276 def test_get_network_allocation_numer(self):
277 # Does effectively nothing by design.
278 self.assertEqual(1, self._driver.get_network_allocations_number())
280 def test__get_container_name(self):
281 self.assertEqual("manila_fake_server",
282 self._driver._get_container_name("fake-server"))
284 def test_do_setup(self):
285 # Does effectively nothing by design.
286 self.assertEqual(1, 1)
288 def test_check_for_setup_error_host_not_ok_class_ok(self):
289 setattr(self._driver.configuration.local_conf,
290 'neutron_host_id', None)
292 self.assertRaises(exception.ManilaException,
293 self._driver.check_for_setup_error)
295 def test_check_for_setup_error_host_not_ok_class_some_other(self):
296 setattr(self._driver.configuration.local_conf,
297 'neutron_host_id', None)
298 setattr(self._driver.configuration.local_conf,
299 'network_api_class',
300 'manila.share.drivers.container.driver.ContainerShareDriver')
301 self.mock_object(driver.LOG, "warning")
303 self._driver.check_for_setup_error()
305 setattr(self._driver.configuration.local_conf,
306 'network_api_class',
307 'manila.network.neutron.neutron_network_plugin.'
308 'NeutronNetworkPlugin')
310 self.assertTrue(driver.LOG.warning.called)
312 def test__connect_to_network(self):
313 network_info = cont_fakes.fake_network()[0]
314 helper = mock.Mock()
315 self.mock_object(self._driver, "_execute",
316 mock.Mock(return_value=helper))
317 self.mock_object(self._driver.container, "execute")
319 self._driver._connect_to_network("fake-server", network_info,
320 "fake-veth", "fake-host-bridge",
321 "fake0")
323 @ddt.data({'veth': ["fake_veth"], 'exception': None},
324 {'veth': ["fake_veth"], 'exception':
325 exception.ProcessExecutionError('fake')},
326 {'veth': ["fake_veth"], 'exception': None})
327 @ddt.unpack
328 def test__teardown_server(self, veth, exception):
329 fake_server_details = {"id": "b5afb5c1-6011-43c4-8a37-29820e6951a7"}
330 fake_networks = ["fake_docker_network_0"]
331 container_name = self._driver._get_container_name(
332 fake_server_details['id'])
333 mock_stop_container = self.mock_object(
334 self._driver.container, "stop_container")
335 mock_get_container_veths = self.mock_object(
336 self._driver.container, "get_container_veths",
337 mock.Mock(return_value=veth))
338 mock_get_container_networks = self.mock_object(
339 self._driver.container, "get_container_networks",
340 mock.Mock(return_value=fake_networks))
341 mock_execute = self.mock_object(self._driver, "_execute",
342 mock.Mock(side_effect=exception))
344 self._driver._teardown_server(
345 server_details=fake_server_details)
347 mock_stop_container.assert_called_once_with(
348 container_name
349 )
350 mock_get_container_veths.assert_called_once_with(
351 container_name
352 )
353 mock_get_container_networks.assert_called_once_with(
354 container_name
355 )
356 if exception is None and veth is not None:
357 mock_execute.assert_called_once_with(
358 "ovs-vsctl", "--", "del-port",
359 self._driver.configuration.container_ovs_bridge_name, veth[0],
360 run_as_root=True)
362 def test__setup_server_network(self):
363 fake_server_id = 'fake_container_id'
364 fake_network_info = cont_fakes.fake_network()
365 fake_existing_interfaces = []
366 fake_bridge = 'br-012345abcdef'
367 fake_veth = 'fake_veth'
369 self.mock_object(self._driver.container, 'fetch_container_interfaces',
370 mock.Mock(return_value=fake_existing_interfaces))
371 self.mock_object(driver.uuidutils, 'generate_uuid',
372 mock.Mock(return_value='fakeuuid'))
373 self.mock_object(self._driver.container, 'create_network')
374 self.mock_object(self._driver.container, 'connect_network')
375 self.mock_object(self._driver.container, 'get_network_bridge',
376 mock.Mock(return_value=fake_bridge))
377 self.mock_object(self._driver.container, 'get_veth_from_bridge',
378 mock.Mock(return_value=fake_veth))
379 self.mock_object(self._driver, '_connect_to_network')
381 self._driver._setup_server_network(fake_server_id, fake_network_info)
383 (self._driver.container.fetch_container_interfaces
384 .assert_called_once_with(fake_server_id))
385 self._driver.container.create_network.assert_called_with(
386 'manila-docker-network-fakeuuid')
387 self._driver.container.connect_network.assert_called_with(
388 'manila-docker-network-fakeuuid',
389 fake_server_id)
390 self._driver.container.get_network_bridge.assert_called_with(
391 'manila-docker-network-fakeuuid')
392 self._driver.container.get_veth_from_bridge.assert_called_with(
393 fake_bridge)
394 self._driver._connect_to_network.assert_called_with(
395 fake_server_id, fake_network_info[0], fake_veth, fake_bridge,
396 'eth0')
398 def test__setup_server_network_existing_interfaces(self):
399 fake_server_id = 'fake_container_id'
400 fake_network_info = cont_fakes.fake_network()
401 fake_existing_interfaces = cont_fakes.FAKE_IP_LINK_SHOW
402 fake_bridge = 'br-012345abcdef'
403 fake_veth = 'fake_veth'
405 self.mock_object(self._driver.container, 'fetch_container_interfaces',
406 mock.Mock(return_value=fake_existing_interfaces))
407 self.mock_object(driver.uuidutils, 'generate_uuid',
408 mock.Mock(return_value='fakeuuid'))
409 self.mock_object(self._driver.container, 'create_network')
410 self.mock_object(self._driver.container, 'connect_network')
411 self.mock_object(self._driver.container, 'get_network_bridge',
412 mock.Mock(return_value=fake_bridge))
413 self.mock_object(self._driver.container, 'get_veth_from_bridge',
414 mock.Mock(return_value=fake_veth))
415 self.mock_object(self._driver, '_connect_to_network')
417 self._driver._setup_server_network(fake_server_id, fake_network_info)
419 (self._driver.container.fetch_container_interfaces
420 .assert_called_once_with(fake_server_id))
421 self._driver.container.create_network.assert_called_with(
422 'manila-docker-network-fakeuuid')
423 self._driver.container.connect_network.assert_called_with(
424 'manila-docker-network-fakeuuid',
425 fake_server_id)
426 self._driver.container.get_network_bridge.assert_called_with(
427 'manila-docker-network-fakeuuid')
428 self._driver.container.get_veth_from_bridge.assert_called_with(
429 fake_bridge)
430 self._driver._connect_to_network.assert_called_with(
431 fake_server_id, fake_network_info[0], fake_veth, fake_bridge,
432 'eth2')
434 def test__setup_server_container_fails(self):
435 network_info = cont_fakes.fake_network()
436 self.mock_object(self._driver.container, 'start_container')
437 self._driver.container.start_container.side_effect = KeyError()
439 self.assertRaises(exception.ManilaException,
440 self._driver._setup_server, network_info)
442 def test__setup_server_ok(self):
443 fake_network_info = cont_fakes.fake_network()
445 self.mock_object(self._driver, '_get_container_name',
446 mock.Mock(return_value='fake_server_id'))
447 self.mock_object(self._driver.container, 'create_container')
448 self.mock_object(self._driver.container, 'start_container')
449 self.mock_object(self._driver, '_setup_server_network')
451 self.assertEqual(fake_network_info[0]['server_id'],
452 self._driver._setup_server(fake_network_info)['id'])
453 self._driver._get_container_name.assert_called_once_with(
454 fake_network_info[0]['server_id'])
455 self._driver.container.create_container.assert_called_once_with(
456 'fake_server_id')
457 self._driver.container.start_container.assert_called_once_with(
458 'fake_server_id')
459 self._driver._setup_server_network.assert_called_once_with(
460 fake_network_info[0]['server_id'], fake_network_info)
462 def test__setup_server_security_services(self):
463 fake_network_info = cont_fakes.fake_network_with_security_services()
465 self.mock_object(self._driver, '_get_container_name')
466 self.mock_object(self._driver.container, 'create_container')
467 self.mock_object(self._driver.container, 'start_container')
468 self.mock_object(self._driver, '_setup_server_network')
469 self.mock_object(self._driver, 'setup_security_services')
471 self._driver._setup_server(fake_network_info)
473 self._driver.setup_security_services.assert_called_once()
475 def test_manage_existing(self):
477 fake_container_name = "manila_fake_container"
478 fake_export_location = 'export_location'
479 expected_result = {
480 'size': 1,
481 'export_locations': fake_export_location
482 }
483 fake_share_server = cont_fakes.fake_share()
484 fake_share_name = self._driver._get_share_name(self.share)
485 mock_get_container_name = self.mock_object(
486 self._driver, '_get_container_name',
487 mock.Mock(return_value=fake_container_name))
488 mock_get_share_name = self.mock_object(
489 self._driver, '_get_share_name',
490 mock.Mock(return_value=fake_share_name))
491 mock_rename_storage = self.mock_object(
492 self._driver.storage, 'rename_storage')
493 mock_get_size = self.mock_object(
494 self._driver.storage, 'get_size', mock.Mock(return_value=1))
495 mock_delete_and_umount = self.mock_object(
496 self._driver, '_delete_export_and_umount_storage')
497 mock_create_and_mount = self.mock_object(
498 self._driver, '_create_export_and_mount_storage',
499 mock.Mock(return_value=fake_export_location)
500 )
502 result = self._driver.manage_existing_with_server(
503 self.share, {}, fake_share_server)
505 mock_rename_storage.assert_called_once_with(
506 fake_share_name, self.share.share_id
507 )
508 mock_get_size.assert_called_once_with(
509 fake_share_name
510 )
511 mock_delete_and_umount.assert_called_once_with(
512 self.share, fake_container_name, fake_share_name
513 )
514 mock_create_and_mount.assert_called_once_with(
515 self.share, fake_container_name, self.share.share_id
516 )
517 mock_get_container_name.assert_called_once_with(
518 fake_share_server['id']
519 )
520 mock_get_share_name.assert_called_with(
521 self.share
522 )
523 self.assertEqual(expected_result, result)
525 def test_manage_existing_no_share_server(self):
527 self.assertRaises(exception.ShareBackendException,
528 self._driver.manage_existing_with_server,
529 self.share, {})
531 def test_unmanage(self):
532 self.assertIsNone(self._driver.unmanage_with_server(self.share))
534 def test_get_share_server_network_info(self):
536 fake_share_server = cont_fakes.fake_share_server()
537 fake_id = cont_fakes.fake_identifier()
538 expected_result = ['veth11b2c34']
540 self.mock_object(self._driver, '_get_correct_container_old_name',
541 mock.Mock(return_value=fake_id))
542 self.mock_object(self._driver.container, 'fetch_container_addresses',
543 mock.Mock(return_value=expected_result))
545 result = self._driver.get_share_server_network_info(self._context,
546 fake_share_server,
547 fake_id, {})
548 self.assertEqual(expected_result, result)
550 def test_manage_server(self):
552 fake_id = cont_fakes.fake_identifier()
553 fake_share_server = cont_fakes.fake_share_server()
554 fake_container_name = "manila_fake_container"
555 fake_container_old_name = "fake_old_name"
557 mock_get_container_name = self.mock_object(
558 self._driver, '_get_container_name',
559 mock.Mock(return_value=fake_container_name))
560 mock_get_correct_container_old_name = self.mock_object(
561 self._driver, '_get_correct_container_old_name',
562 mock.Mock(return_value=fake_container_old_name)
563 )
564 mock_rename_container = self.mock_object(self._driver.container,
565 'rename_container')
566 expected_result = {'id': fake_share_server['id']}
568 new_identifier, new_backend_details = self._driver.manage_server(
569 self._context, fake_share_server, fake_id, {})
571 self.assertEqual(expected_result, new_backend_details)
572 self.assertEqual(fake_container_name, new_identifier)
573 mock_rename_container.assert_called_once_with(
574 fake_container_old_name, fake_container_name)
575 mock_get_container_name.assert_called_with(
576 fake_share_server['id']
577 )
578 mock_get_correct_container_old_name.assert_called_once_with(
579 fake_id
580 )
582 @ddt.data(True, False)
583 def test__get_correct_container_old_name(self, container_exists):
585 expected_name = 'fake-name'
586 fake_name = 'fake-name'
588 mock_container_exists = self.mock_object(
589 self._driver.container, 'container_exists',
590 mock.Mock(return_value=container_exists))
592 if not container_exists:
593 expected_name = 'manila_fake_name'
595 result = self._driver._get_correct_container_old_name(fake_name)
597 self.assertEqual(expected_name, result)
598 mock_container_exists.assert_called_once_with(
599 fake_name
600 )
602 def test_migration_complete(self):
603 share_server = {'id': 'fakeid'}
604 fake_container_name = 'manila_fake_container'
605 new_export_location = 'new_export_location'
607 mock_migraton_storage = self.mock_object(self._driver.storage,
608 'migration_complete')
609 mock_get_container_name = self.mock_object(
610 self._driver, '_get_container_name',
611 mock.Mock(return_value=fake_container_name))
613 mock_mount = self.mock_object(
614 self._driver, '_mount_storage',
615 mock.Mock(return_value=new_export_location))
617 mock_umount = self.mock_object(self._driver, '_umount_storage')
619 expected_location = {'export_locations': new_export_location}
620 self.assertEqual(expected_location,
621 self._driver.migration_complete(
622 self._context, self.share, self.share, None,
623 None, share_server, share_server))
625 mock_migraton_storage.assert_called_once_with(
626 self._context, self.share, self.share, None, None,
627 destination_share_server=share_server, share_server=share_server
628 )
629 mock_mount.assert_called_once_with(
630 self.share, fake_container_name, self.share.share_id
631 )
632 mock_umount.assert_called_once_with(
633 self.share, fake_container_name, self.share.share_id
634 )
635 mock_get_container_name.assert_called_with(
636 share_server['id']
637 )
639 def test_share_server_migration_complete(self):
640 source_server = {'id': 'source_fake_id', 'host': 'host@back1'}
641 dest_server = {'id': 'dest_fake_id', 'host': 'host@back2'}
642 fake_container_name = 'manila_fake_container'
643 new_export_location = 'new_export_location'
644 fake_pool_name = 'fake_vg'
645 shares_list = [self.share, self.share]
647 mock_get_container_name = self.mock_object(
648 self._driver, '_get_container_name',
649 mock.Mock(return_value=fake_container_name))
650 mock_umount = self.mock_object(self._driver, '_umount_storage')
651 mock_migraton_storage = self.mock_object(
652 self._driver.storage, 'share_server_migration_complete')
653 mock_mount = self.mock_object(
654 self._driver, '_mount_storage',
655 mock.Mock(return_value=new_export_location))
656 mock_get_pool = self.mock_object(
657 self._driver.storage, 'get_share_pool_name',
658 mock.Mock(return_value=fake_pool_name))
660 share_updates = {}
661 for fake_share in shares_list:
662 share_updates[fake_share['id']] = {
663 'export_locations': new_export_location,
664 'pool_name': fake_pool_name,
665 }
667 expected_result = {
668 'share_updates': share_updates,
669 }
670 self.assertDictEqual(expected_result,
671 self._driver.share_server_migration_complete(
672 self._context, source_server, dest_server,
673 shares_list, None, None))
674 mock_migraton_storage.assert_called_once_with(
675 self._context, source_server, dest_server, shares_list, None, None)
677 # assert shares
678 for fake_share in shares_list:
679 mock_get_pool.assert_any_call(fake_share['share_id'])
680 mock_umount.assert_any_call(fake_share, fake_container_name,
681 fake_share.share_id)
682 mock_mount.assert_any_call(fake_share, fake_container_name,
683 fake_share.share_id)
685 mock_get_container_name.assert_any_call(source_server['id'])
686 mock_get_container_name.assert_any_call(dest_server['id'])
688 def test__get_different_security_service_keys(self):
689 sec_service_keys = ['dns_ip', 'server', 'domain', 'user', 'password',
690 'ou']
691 current_security_service = {}
692 [current_security_service.update({key: key + '_1'})
693 for key in sec_service_keys]
694 new_security_service = {}
695 [new_security_service.update({key: key + '_2'})
696 for key in sec_service_keys]
698 db_utils.create_security_service(**current_security_service)
699 db_utils.create_security_service(**new_security_service)
701 different_keys = self._driver._get_different_security_service_keys(
702 current_security_service, new_security_service)
704 [self.assertIn(key, different_keys) for key in sec_service_keys]
706 @ddt.data(
707 (['dns_ip', 'server', 'domain', 'user', 'password', 'ou'], False),
708 (['user', 'password'], True)
709 )
710 @ddt.unpack
711 def test__check_if_all_fields_are_updatable(self, keys, expected_result):
713 current_security_service = db_utils.create_security_service()
714 new_security_service = db_utils.create_security_service()
716 mock_get_keys = self.mock_object(
717 self._driver, '_get_different_security_service_keys',
718 mock.Mock(return_value=keys))
720 result = self._driver._check_if_all_fields_are_updatable(
721 current_security_service, new_security_service)
723 self.assertEqual(expected_result, result)
724 mock_get_keys.assert_called_once_with(
725 current_security_service, new_security_service
726 )
728 @ddt.data(True, False)
729 def test_update_share_server_security_service(
730 self, with_current_service):
731 new_security_service = db_utils.create_security_service()
732 current_security_service = (
733 db_utils.create_security_service()
734 if with_current_service else None)
735 share_server = db_utils.create_share_server()
736 fake_container_name = 'fake_name'
737 network_info = {}
738 share_instances = []
739 share_instance_access_rules = []
741 mock_check_update = self.mock_object(
742 self._driver, 'check_update_share_server_security_service',
743 mock.Mock(return_value=True))
744 mock_get_container_name = self.mock_object(
745 self._driver, '_get_container_name',
746 mock.Mock(return_value=fake_container_name))
747 mock_setup = self.mock_object(self._driver, 'setup_security_services')
748 mock_update_sec_service = self.mock_object(
749 self._driver.security_service_helper, 'update_security_service')
751 self._driver.update_share_server_security_service(
752 self._context, share_server, network_info, share_instances,
753 share_instance_access_rules, new_security_service,
754 current_security_service=current_security_service)
756 mock_check_update.assert_called_once_with(
757 self._context, share_server, network_info, share_instances,
758 share_instance_access_rules, new_security_service,
759 current_security_service=current_security_service
760 )
761 mock_get_container_name.assert_called_once_with(share_server['id'])
762 if with_current_service:
763 mock_update_sec_service.assert_called_once_with(
764 fake_container_name, current_security_service,
765 new_security_service)
766 else:
767 mock_setup.assert_called_once_with(
768 fake_container_name, [new_security_service])
770 def test_update_share_server_security_service_not_supported(self):
771 new_security_service = db_utils.create_security_service()
772 current_security_service = db_utils.create_security_service()
773 share_server = db_utils.create_share_server()
774 share_instances = []
775 share_instance_access_rules = []
776 network_info = {}
778 mock_check_update = self.mock_object(
779 self._driver, 'check_update_share_server_security_service',
780 mock.Mock(return_value=False))
782 self.assertRaises(
783 exception.ManilaException,
784 self._driver.update_share_server_security_service,
785 self._context, share_server, network_info, share_instances,
786 share_instance_access_rules, new_security_service,
787 current_security_service=current_security_service)
789 mock_check_update.assert_called_once_with(
790 self._context, share_server, network_info, share_instances,
791 share_instance_access_rules, new_security_service,
792 current_security_service=current_security_service)
794 def test__form_share_server_update_return(self):
795 fake_share_server = cont_fakes.fake_share_server()
796 fake_current_network_allocations = (
797 cont_fakes.fake_current_network_allocations())
798 fake_new_network_allocations = (
799 cont_fakes.fake_new_network_allocations())
800 fake_share_instances = cont_fakes.fake_share_instances()
801 fake_server_id = 'fake_container_id'
802 fake_addresses = ['192.168.144.100', '10.0.0.100']
803 fake_subnet_allocations = {
804 'fake_id_current': '192.168.144.100',
805 'fake_id_new': '10.0.0.100'
806 }
807 fake_share_updates = {
808 'fakeid': [
809 {
810 'is_admin_only': False,
811 'path': '//%s/fakeshareid' % fake_addresses[0],
812 'preferred': False
813 },
814 {
815 'is_admin_only': False,
816 'path': '//%s/fakeshareid' % fake_addresses[1],
817 'preferred': False
818 }
819 ]
820 }
821 fake_server_details = {
822 'subnet_allocations': jsonutils.dumps(fake_subnet_allocations)
823 }
824 fake_return = {
825 'share_updates': fake_share_updates,
826 'server_details': fake_server_details
827 }
829 self.mock_object(self._driver, '_get_container_name',
830 mock.Mock(return_value=fake_server_id))
831 self.mock_object(self._driver.container, 'fetch_container_addresses',
832 mock.Mock(return_value=fake_addresses))
834 self.assertEqual(
835 fake_return, self._driver._form_share_server_update_return(
836 fake_share_server, fake_current_network_allocations,
837 fake_new_network_allocations, fake_share_instances))
838 self._driver._get_container_name.assert_called_once_with(
839 fake_share_server['id'])
840 (self._driver.container.fetch_container_addresses
841 .assert_called_once_with(fake_server_id, 'inet'))
843 def test_check_update_share_server_network_allocations(self):
844 fake_share_server = cont_fakes.fake_share_server()
845 self.mock_object(driver.LOG, 'debug')
847 self.assertTrue(
848 self._driver.check_update_share_server_network_allocations(
849 None, fake_share_server, None, None, None, None, None))
850 self.assertTrue(driver.LOG.debug.called)
852 def test_update_share_server_network_allocations(self):
853 fake_share_server = cont_fakes.fake_share_server()
854 fake_server_id = 'fake_container_id'
855 fake_return = 'fake_return'
857 self.mock_object(self._driver, '_get_container_name',
858 mock.Mock(return_value=fake_server_id))
859 self.mock_object(self._driver, '_setup_server_network')
860 self.mock_object(self._driver, '_form_share_server_update_return',
861 mock.Mock(return_value=fake_return))
863 self.assertEqual(fake_return,
864 self._driver.update_share_server_network_allocations(
865 None, fake_share_server, None, None, None, None,
866 None))