Coverage for manila/tests/share/drivers/dell_emc/plugins/vnx/test_object_manager.py: 100%
1501 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 (c) 2015 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.
16import copy
17import time
18from unittest import mock
21import ddt
22from lxml import builder
24from oslo_concurrency import processutils
26from manila.common import constants as const
27from manila import exception
28from manila.share.drivers.dell_emc.common.enas import connector
29from manila.share.drivers.dell_emc.common.enas import constants
30from manila.share.drivers.dell_emc.common.enas import xml_api_parser as parser
31from manila.share.drivers.dell_emc.plugins.vnx import object_manager as manager
32from manila import test
33from manila.tests.share.drivers.dell_emc.common.enas import fakes
34from manila.tests.share.drivers.dell_emc.common.enas import utils
37class StorageObjectManagerTestCase(test.TestCase):
38 @mock.patch.object(connector, "XMLAPIConnector", mock.Mock())
39 @mock.patch.object(connector, "SSHConnector", mock.Mock())
40 def setUp(self):
41 super(StorageObjectManagerTestCase, self).setUp()
43 emd_share_driver = fakes.FakeEMCShareDriver()
45 self.manager = manager.StorageObjectManager(
46 emd_share_driver.configuration)
48 def test_get_storage_context(self):
49 type_map = {
50 'FileSystem': manager.FileSystem,
51 'StoragePool': manager.StoragePool,
52 'MountPoint': manager.MountPoint,
53 'Mover': manager.Mover,
54 'VDM': manager.VDM,
55 'Snapshot': manager.Snapshot,
56 'MoverInterface': manager.MoverInterface,
57 'DNSDomain': manager.DNSDomain,
58 'CIFSServer': manager.CIFSServer,
59 'CIFSShare': manager.CIFSShare,
60 'NFSShare': manager.NFSShare,
61 }
63 for key, value in type_map.items():
64 self.assertTrue(
65 isinstance(self.manager.getStorageContext(key), value))
67 for key in self.manager.context.keys():
68 self.assertIn(key, type_map)
70 def test_get_storage_context_invalid_type(self):
72 fake_type = 'fake_type'
74 self.assertRaises(exception.EMCVnxXMLAPIError,
75 self.manager.getStorageContext,
76 fake_type)
79class StorageObjectTestCaseBase(test.TestCase):
80 @mock.patch.object(connector, "XMLAPIConnector", mock.Mock())
81 @mock.patch.object(connector, "SSHConnector", mock.Mock())
82 def setUp(self):
83 super(StorageObjectTestCaseBase, self).setUp()
85 emd_share_driver = fakes.FakeEMCShareDriver()
87 self.manager = manager.StorageObjectManager(
88 emd_share_driver.configuration)
89 self.base = fakes.StorageObjectTestData()
90 self.pool = fakes.PoolTestData()
91 self.vdm = fakes.VDMTestData()
92 self.mover = fakes.MoverTestData()
93 self.fs = fakes.FileSystemTestData()
94 self.mount = fakes.MountPointTestData()
95 self.snap = fakes.SnapshotTestData()
96 self.cifs_share = fakes.CIFSShareTestData()
97 self.nfs_share = fakes.NFSShareTestData()
98 self.cifs_server = fakes.CIFSServerTestData()
99 self.dns = fakes.DNSDomainTestData()
102class StorageObjectTestCase(StorageObjectTestCaseBase):
104 def test_xml_api_retry(self):
105 hook = utils.RequestSideEffect()
106 hook.append(self.base.resp_need_retry())
107 hook.append(self.base.resp_task_succeed())
108 elt_maker = builder.ElementMaker(nsmap={None: constants.XML_NAMESPACE})
109 xml_parser = parser.XMLAPIParser()
110 storage_object = manager.StorageObject(self.manager.connectors,
111 elt_maker, xml_parser,
112 self.manager)
113 storage_object.conn['XML'].request = utils.EMCMock(side_effect=hook)
114 fake_req = storage_object._build_task_package(
115 elt_maker.StartFake(name='foo')
116 )
117 self.mock_object(time, 'sleep')
118 resp = storage_object._send_request(fake_req)
119 self.assertEqual('ok', resp['maxSeverity'])
121 expected_calls = [
122 mock.call(self.base.req_fake_start_task()),
123 mock.call(self.base.req_fake_start_task())
124 ]
125 storage_object.conn['XML'].request.assert_has_calls(expected_calls)
128class FileSystemTestCase(StorageObjectTestCaseBase):
129 def setUp(self):
130 super(FileSystemTestCase, self).setUp()
131 self.hook = utils.RequestSideEffect()
132 self.ssh_hook = utils.SSHSideEffect()
134 def test_create_file_system_on_vdm(self):
135 self.hook.append(self.pool.resp_get_succeed())
136 self.hook.append(self.vdm.resp_get_succeed())
137 self.hook.append(self.fs.resp_task_succeed())
139 context = self.manager.getStorageContext('FileSystem')
140 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
142 context.create(name=self.fs.filesystem_name,
143 size=self.fs.filesystem_size,
144 pool_name=self.pool.pool_name,
145 mover_name=self.vdm.vdm_name,
146 is_vdm=True)
148 expected_calls = [
149 mock.call(self.pool.req_get()),
150 mock.call(self.vdm.req_get()),
151 mock.call(self.fs.req_create_on_vdm()),
152 ]
153 context.conn['XML'].request.assert_has_calls(expected_calls)
155 def test_create_file_system_on_mover(self):
156 self.hook.append(self.pool.resp_get_succeed())
157 self.hook.append(self.mover.resp_get_ref_succeed())
158 self.hook.append(self.fs.resp_task_succeed())
160 context = self.manager.getStorageContext('FileSystem')
161 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
163 context.create(name=self.fs.filesystem_name,
164 size=self.fs.filesystem_size,
165 pool_name=self.pool.pool_name,
166 mover_name=self.mover.mover_name,
167 is_vdm=False)
169 expected_calls = [
170 mock.call(self.pool.req_get()),
171 mock.call(self.mover.req_get_ref()),
172 mock.call(self.fs.req_create_on_mover()),
173 ]
174 context.conn['XML'].request.assert_has_calls(expected_calls)
176 def test_create_file_system_but_already_exist(self):
177 self.hook.append(self.pool.resp_get_succeed())
178 self.hook.append(self.vdm.resp_get_succeed())
179 self.hook.append(self.fs.resp_create_but_already_exist())
181 context = self.manager.getStorageContext('FileSystem')
182 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
184 context.create(name=self.fs.filesystem_name,
185 size=self.fs.filesystem_size,
186 pool_name=self.pool.pool_name,
187 mover_name=self.vdm.vdm_name,
188 is_vdm=True)
190 expected_calls = [
191 mock.call(self.pool.req_get()),
192 mock.call(self.vdm.req_get()),
193 mock.call(self.fs.req_create_on_vdm()),
194 ]
195 context.conn['XML'].request.assert_has_calls(expected_calls)
197 @mock.patch('time.sleep')
198 def test_create_file_system_invalid_mover_id(self, sleep_mock):
199 self.hook.append(self.pool.resp_get_succeed())
200 self.hook.append(self.mover.resp_get_ref_succeed())
201 self.hook.append(self.fs.resp_invalid_mover_id())
202 self.hook.append(self.mover.resp_get_ref_succeed())
203 self.hook.append(self.fs.resp_task_succeed())
205 context = self.manager.getStorageContext('FileSystem')
206 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
208 context.create(name=self.fs.filesystem_name,
209 size=self.fs.filesystem_size,
210 pool_name=self.pool.pool_name,
211 mover_name=self.mover.mover_name,
212 is_vdm=False)
214 expected_calls = [
215 mock.call(self.pool.req_get()),
216 mock.call(self.mover.req_get_ref()),
217 mock.call(self.fs.req_create_on_mover()),
218 mock.call(self.mover.req_get_ref()),
219 mock.call(self.fs.req_create_on_mover()),
220 ]
221 context.conn['XML'].request.assert_has_calls(expected_calls)
223 self.assertTrue(sleep_mock.called)
225 def test_create_file_system_with_error(self):
226 self.hook.append(self.pool.resp_get_succeed())
227 self.hook.append(self.vdm.resp_get_succeed())
228 self.hook.append(self.fs.resp_task_error())
230 context = self.manager.getStorageContext('FileSystem')
231 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
233 self.assertRaises(exception.EMCVnxXMLAPIError,
234 context.create,
235 name=self.fs.filesystem_name,
236 size=self.fs.filesystem_size,
237 pool_name=self.pool.pool_name,
238 mover_name=self.vdm.vdm_name,
239 is_vdm=True)
241 expected_calls = [
242 mock.call(self.pool.req_get()),
243 mock.call(self.vdm.req_get()),
244 mock.call(self.fs.req_create_on_vdm()),
245 ]
246 context.conn['XML'].request.assert_has_calls(expected_calls)
248 def test_get_file_system(self):
249 self.hook.append(self.fs.resp_get_succeed())
251 context = self.manager.getStorageContext('FileSystem')
252 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
254 status, out = context.get(self.fs.filesystem_name)
255 self.assertEqual(constants.STATUS_OK, status)
256 self.assertIn(self.fs.filesystem_name, context.filesystem_map)
257 property_map = [
258 'name',
259 'pools_id',
260 'volume_id',
261 'size',
262 'id',
263 'type',
264 'dataServicePolicies',
265 ]
266 for prop in property_map:
267 self.assertIn(prop, out)
269 id = context.get_id(self.fs.filesystem_name)
270 self.assertEqual(self.fs.filesystem_id, id)
272 expected_calls = [mock.call(self.fs.req_get())]
273 context.conn['XML'].request.assert_has_calls(expected_calls)
275 def test_get_file_system_but_not_found(self):
276 self.hook.append(self.fs.resp_get_but_not_found())
277 self.hook.append(self.fs.resp_get_without_value())
278 self.hook.append(self.fs.resp_get_error())
279 self.hook.append(self.fs.resp_get_but_not_found())
281 context = self.manager.getStorageContext('FileSystem')
282 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
284 status, out = context.get(self.fs.filesystem_name)
285 self.assertEqual(constants.STATUS_NOT_FOUND, status)
287 status, out = context.get(self.fs.filesystem_name)
288 self.assertEqual(constants.STATUS_NOT_FOUND, status)
290 status, out = context.get(self.fs.filesystem_name)
291 self.assertEqual(constants.STATUS_ERROR, status)
293 self.assertRaises(exception.EMCVnxXMLAPIError,
294 context.get_id,
295 self.fs.filesystem_name)
297 expected_calls = [
298 mock.call(self.fs.req_get()),
299 mock.call(self.fs.req_get()),
300 mock.call(self.fs.req_get()),
301 mock.call(self.fs.req_get()),
302 ]
303 context.conn['XML'].request.assert_has_calls(expected_calls)
305 def test_get_file_system_but_miss_property(self):
306 self.hook.append(self.fs.resp_get_but_miss_property())
308 context = self.manager.getStorageContext('FileSystem')
309 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
311 status, out = context.get(self.fs.filesystem_name)
312 self.assertEqual(constants.STATUS_OK, status)
313 self.assertIn(self.fs.filesystem_name, context.filesystem_map)
314 property_map = [
315 'name',
316 'pools_id',
317 'volume_id',
318 'size',
319 'id',
320 'type',
321 'dataServicePolicies',
322 ]
323 for prop in property_map:
324 self.assertIn(prop, out)
326 self.assertIsNone(out['dataServicePolicies'])
328 id = context.get_id(self.fs.filesystem_name)
329 self.assertEqual(self.fs.filesystem_id, id)
331 expected_calls = [mock.call(self.fs.req_get())]
332 context.conn['XML'].request.assert_has_calls(expected_calls)
334 def test_delete_file_system(self):
335 self.hook.append(self.fs.resp_get_succeed())
336 self.hook.append(self.fs.resp_task_succeed())
338 context = self.manager.getStorageContext('FileSystem')
339 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
341 context.delete(self.fs.filesystem_name)
342 self.assertNotIn(self.fs.filesystem_name, context.filesystem_map)
344 expected_calls = [
345 mock.call(self.fs.req_get()),
346 mock.call(self.fs.req_delete()),
347 ]
348 context.conn['XML'].request.assert_has_calls(expected_calls)
350 self.assertNotIn(self.fs.filesystem_name, context.filesystem_map)
352 def test_delete_file_system_but_not_found(self):
353 self.hook.append(self.fs.resp_get_but_not_found())
355 context = self.manager.getStorageContext('FileSystem')
356 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
358 context.delete(self.fs.filesystem_name)
360 expected_calls = [mock.call(self.fs.req_get())]
361 context.conn['XML'].request.assert_has_calls(expected_calls)
363 def test_delete_file_system_but_get_file_system_error(self):
364 self.hook.append(self.fs.resp_get_error())
366 context = self.manager.getStorageContext('FileSystem')
367 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
369 self.assertRaises(exception.EMCVnxXMLAPIError,
370 context.delete,
371 self.fs.filesystem_name)
373 expected_calls = [mock.call(self.fs.req_get())]
374 context.conn['XML'].request.assert_has_calls(expected_calls)
376 def test_delete_file_system_with_error(self):
377 self.hook.append(self.fs.resp_get_succeed())
378 self.hook.append(self.fs.resp_delete_but_failed())
380 context = self.manager.getStorageContext('FileSystem')
381 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
383 self.assertRaises(exception.EMCVnxXMLAPIError,
384 context.delete,
385 self.fs.filesystem_name)
387 expected_calls = [
388 mock.call(self.fs.req_get()),
389 mock.call(self.fs.req_delete()),
390 ]
391 context.conn['XML'].request.assert_has_calls(expected_calls)
393 self.assertIn(self.fs.filesystem_name, context.filesystem_map)
395 def test_extend_file_system(self):
396 self.hook.append(self.fs.resp_get_succeed())
397 self.hook.append(self.pool.resp_get_succeed())
398 self.hook.append(self.fs.resp_task_succeed())
400 context = self.manager.getStorageContext('FileSystem')
401 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
403 context.extend(name=self.fs.filesystem_name,
404 pool_name=self.pool.pool_name,
405 new_size=self.fs.filesystem_new_size)
407 expected_calls = [
408 mock.call(self.fs.req_get()),
409 mock.call(self.pool.req_get()),
410 mock.call(self.fs.req_extend()),
411 ]
412 context.conn['XML'].request.assert_has_calls(expected_calls)
414 def test_extend_file_system_but_not_found(self):
415 self.hook.append(self.fs.resp_get_but_not_found())
417 context = self.manager.getStorageContext('FileSystem')
418 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
420 self.assertRaises(exception.EMCVnxXMLAPIError,
421 context.extend,
422 name=self.fs.filesystem_name,
423 pool_name=self.fs.pool_name,
424 new_size=self.fs.filesystem_new_size)
426 expected_calls = [mock.call(self.fs.req_get())]
427 context.conn['XML'].request.assert_has_calls(expected_calls)
429 def test_extend_file_system_with_small_size(self):
430 self.hook.append(self.fs.resp_get_succeed())
432 context = self.manager.getStorageContext('FileSystem')
433 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
435 self.assertRaises(exception.EMCVnxXMLAPIError,
436 context.extend,
437 name=self.fs.filesystem_name,
438 pool_name=self.pool.pool_name,
439 new_size=1)
441 expected_calls = [mock.call(self.fs.req_get())]
442 context.conn['XML'].request.assert_has_calls(expected_calls)
444 def test_extend_file_system_with_same_size(self):
445 self.hook.append(self.fs.resp_get_succeed())
447 context = self.manager.getStorageContext('FileSystem')
448 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
450 context.extend(name=self.fs.filesystem_name,
451 pool_name=self.pool.pool_name,
452 new_size=self.fs.filesystem_size)
454 expected_calls = [mock.call(self.fs.req_get())]
455 context.conn['XML'].request.assert_has_calls(expected_calls)
457 def test_extend_file_system_with_error(self):
458 self.hook.append(self.fs.resp_get_succeed())
459 self.hook.append(self.pool.resp_get_succeed())
460 self.hook.append(self.fs.resp_extend_but_error())
462 context = self.manager.getStorageContext('FileSystem')
463 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
465 self.assertRaises(exception.EMCVnxXMLAPIError,
466 context.extend,
467 name=self.fs.filesystem_name,
468 pool_name=self.pool.pool_name,
469 new_size=self.fs.filesystem_new_size)
471 expected_calls = [
472 mock.call(self.fs.req_get()),
473 mock.call(self.pool.req_get()),
474 mock.call(self.fs.req_extend()),
475 ]
476 context.conn['XML'].request.assert_has_calls(expected_calls)
478 def test_create_filesystem_from_snapshot(self):
479 self.ssh_hook.append()
480 self.ssh_hook.append()
481 self.ssh_hook.append(self.fs.output_copy_ckpt)
482 self.ssh_hook.append(self.fs.output_info())
483 self.ssh_hook.append()
484 self.ssh_hook.append()
485 self.ssh_hook.append()
487 context = self.manager.getStorageContext('FileSystem')
488 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
490 context.create_from_snapshot(self.fs.filesystem_name,
491 self.snap.src_snap_name,
492 self.fs.src_fileystems_name,
493 self.pool.pool_name,
494 self.vdm.vdm_name,
495 self.mover.interconnect_id,)
497 ssh_calls = [
498 mock.call(self.fs.cmd_create_from_ckpt(), False),
499 mock.call(self.mount.cmd_server_mount('ro'), False),
500 mock.call(self.fs.cmd_copy_ckpt(), True),
501 mock.call(self.fs.cmd_nas_fs_info(), False),
502 mock.call(self.mount.cmd_server_umount(), False),
503 mock.call(self.fs.cmd_delete(), False),
504 mock.call(self.mount.cmd_server_mount('rw'), False),
505 ]
506 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
508 def test_create_filesystem_from_snapshot_with_error(self):
509 self.ssh_hook.append()
510 self.ssh_hook.append()
511 self.ssh_hook.append(ex=processutils.ProcessExecutionError(
512 stdout=self.fs.fake_output, stderr=None))
513 self.ssh_hook.append(self.fs.output_info())
514 self.ssh_hook.append()
515 self.ssh_hook.append()
516 self.ssh_hook.append()
518 context = self.manager.getStorageContext('FileSystem')
519 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
521 context.create_from_snapshot(
522 self.fs.filesystem_name,
523 self.snap.src_snap_name,
524 self.fs.src_fileystems_name,
525 self.pool.pool_name,
526 self.vdm.vdm_name,
527 self.mover.interconnect_id, )
529 ssh_calls = [
530 mock.call(self.fs.cmd_create_from_ckpt(), False),
531 mock.call(self.mount.cmd_server_mount('ro'), False),
532 mock.call(self.fs.cmd_copy_ckpt(), True),
533 mock.call(self.fs.cmd_nas_fs_info(), False),
534 mock.call(self.mount.cmd_server_umount(), False),
535 mock.call(self.fs.cmd_delete(), False),
536 mock.call(self.mount.cmd_server_mount('rw'), False),
537 ]
538 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
541class MountPointTestCase(StorageObjectTestCaseBase):
542 def setUp(self):
543 super(MountPointTestCase, self).setUp()
544 self.hook = utils.RequestSideEffect()
546 def test_create_mount_point_on_vdm(self):
547 self.hook.append(self.fs.resp_get_succeed())
548 self.hook.append(self.vdm.resp_get_succeed())
549 self.hook.append(self.mount.resp_task_succeed())
551 context = self.manager.getStorageContext('MountPoint')
552 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
554 context.create(mount_path=self.mount.path,
555 fs_name=self.fs.filesystem_name,
556 mover_name=self.vdm.vdm_name,
557 is_vdm=True)
559 expected_calls = [
560 mock.call(self.fs.req_get()),
561 mock.call(self.vdm.req_get()),
562 mock.call(self.mount.req_create(self.vdm.vdm_id, True)),
563 ]
564 context.conn['XML'].request.assert_has_calls(expected_calls)
566 def test_create_mount_point_on_mover(self):
567 self.hook.append(self.fs.resp_get_succeed())
568 self.hook.append(self.mover.resp_get_ref_succeed())
569 self.hook.append(self.mount.resp_task_succeed())
571 context = self.manager.getStorageContext('MountPoint')
572 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
574 context.create(mount_path=self.mount.path,
575 fs_name=self.fs.filesystem_name,
576 mover_name=self.mover.mover_name,
577 is_vdm=False)
579 expected_calls = [
580 mock.call(self.fs.req_get()),
581 mock.call(self.mover.req_get_ref()),
582 mock.call(self.mount.req_create(self.mover.mover_id, False)),
583 ]
584 context.conn['XML'].request.assert_has_calls(expected_calls)
586 def test_create_mount_point_but_already_exist(self):
587 self.hook.append(self.fs.resp_get_succeed())
588 self.hook.append(self.vdm.resp_get_succeed())
589 self.hook.append(self.mount.resp_create_but_already_exist())
591 context = self.manager.getStorageContext('MountPoint')
592 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
594 context.create(mount_path=self.mount.path,
595 fs_name=self.fs.filesystem_name,
596 mover_name=self.vdm.vdm_name,
597 is_vdm=True)
599 expected_calls = [
600 mock.call(self.fs.req_get()),
601 mock.call(self.vdm.req_get()),
602 mock.call(self.mount.req_create(self.vdm.vdm_id)),
603 ]
604 context.conn['XML'].request.assert_has_calls(expected_calls)
606 @mock.patch('time.sleep')
607 def test_create_mount_point_invalid_mover_id(self, sleep_mock):
608 self.hook.append(self.fs.resp_get_succeed())
609 self.hook.append(self.mover.resp_get_ref_succeed())
610 self.hook.append(self.mount.resp_invalid_mover_id())
611 self.hook.append(self.mover.resp_get_ref_succeed())
612 self.hook.append(self.mount.resp_task_succeed())
614 context = self.manager.getStorageContext('MountPoint')
615 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
617 context.create(mount_path=self.mount.path,
618 fs_name=self.fs.filesystem_name,
619 mover_name=self.mover.mover_name,
620 is_vdm=False)
622 expected_calls = [
623 mock.call(self.fs.req_get()),
624 mock.call(self.mover.req_get_ref()),
625 mock.call(self.mount.req_create(self.mover.mover_id, False)),
626 mock.call(self.mover.req_get_ref()),
627 mock.call(self.mount.req_create(self.mover.mover_id, False)),
628 ]
629 context.conn['XML'].request.assert_has_calls(expected_calls)
631 self.assertTrue(sleep_mock.called)
633 def test_create_mount_point_with_error(self):
634 self.hook.append(self.fs.resp_get_succeed())
635 self.hook.append(self.vdm.resp_get_succeed())
636 self.hook.append(self.mount.resp_task_error())
638 context = self.manager.getStorageContext('MountPoint')
639 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
641 self.assertRaises(exception.EMCVnxXMLAPIError,
642 context.create,
643 mount_path=self.mount.path,
644 fs_name=self.fs.filesystem_name,
645 mover_name=self.vdm.vdm_name,
646 is_vdm=True)
648 expected_calls = [
649 mock.call(self.fs.req_get()),
650 mock.call(self.vdm.req_get()),
651 mock.call(self.mount.req_create(self.vdm.vdm_id)),
652 ]
653 context.conn['XML'].request.assert_has_calls(expected_calls)
655 def test_delete_mount_point_on_vdm(self):
656 self.hook.append(self.vdm.resp_get_succeed())
657 self.hook.append(self.mount.resp_task_succeed())
659 context = self.manager.getStorageContext('MountPoint')
660 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
662 context.delete(mount_path=self.mount.path,
663 mover_name=self.vdm.vdm_name,
664 is_vdm=True)
666 expected_calls = [
667 mock.call(self.vdm.req_get()),
668 mock.call(self.mount.req_delete(self.vdm.vdm_id)),
669 ]
670 context.conn['XML'].request.assert_has_calls(expected_calls)
672 def test_delete_mount_point_on_mover(self):
673 self.hook.append(self.mover.resp_get_ref_succeed())
674 self.hook.append(self.mount.resp_task_succeed())
676 context = self.manager.getStorageContext('MountPoint')
677 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
679 context.delete(mount_path=self.mount.path,
680 mover_name=self.mover.mover_name,
681 is_vdm=False)
683 expected_calls = [
684 mock.call(self.mover.req_get_ref()),
685 mock.call(self.mount.req_delete(self.mover.mover_id, False)),
686 ]
687 context.conn['XML'].request.assert_has_calls(expected_calls)
689 def test_delete_mount_point_but_nonexistent(self):
690 self.hook.append(self.vdm.resp_get_succeed())
691 self.hook.append(self.mount.resp_delete_but_nonexistent())
693 context = self.manager.getStorageContext('MountPoint')
694 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
696 context.delete(mount_path=self.mount.path,
697 mover_name=self.vdm.vdm_name,
698 is_vdm=True)
700 expected_calls = [
701 mock.call(self.vdm.req_get()),
702 mock.call(self.mount.req_delete(self.vdm.vdm_id)),
703 ]
704 context.conn['XML'].request.assert_has_calls(expected_calls)
706 @mock.patch('time.sleep')
707 def test_delete_mount_point_invalid_mover_id(self, sleep_mock):
708 self.hook.append(self.mover.resp_get_ref_succeed())
709 self.hook.append(self.mount.resp_invalid_mover_id())
710 self.hook.append(self.mover.resp_get_ref_succeed())
711 self.hook.append(self.mount.resp_task_succeed())
713 context = self.manager.getStorageContext('MountPoint')
714 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
716 context.delete(mount_path=self.mount.path,
717 mover_name=self.mover.mover_name,
718 is_vdm=False)
720 expected_calls = [
721 mock.call(self.mover.req_get_ref()),
722 mock.call(self.mount.req_delete(self.mover.mover_id, False)),
723 mock.call(self.mover.req_get_ref()),
724 mock.call(self.mount.req_delete(self.mover.mover_id, False)),
725 ]
726 context.conn['XML'].request.assert_has_calls(expected_calls)
728 self.assertTrue(sleep_mock.called)
730 def test_delete_mount_point_with_error(self):
731 self.hook.append(self.vdm.resp_get_succeed())
732 self.hook.append(self.mount.resp_task_error())
734 context = self.manager.getStorageContext('MountPoint')
735 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
737 self.assertRaises(exception.EMCVnxXMLAPIError,
738 context.delete,
739 mount_path=self.mount.path,
740 mover_name=self.vdm.vdm_name,
741 is_vdm=True)
743 expected_calls = [
744 mock.call(self.vdm.req_get()),
745 mock.call(self.mount.req_delete(self.vdm.vdm_id)),
746 ]
747 context.conn['XML'].request.assert_has_calls(expected_calls)
749 def test_get_mount_points(self):
750 self.hook.append(self.vdm.resp_get_succeed())
751 self.hook.append(self.mount.resp_get_succeed(self.vdm.vdm_id))
752 self.hook.append(self.mover.resp_get_ref_succeed())
753 self.hook.append(self.mount.resp_get_succeed(self.mover.mover_id,
754 False))
756 context = self.manager.getStorageContext('MountPoint')
757 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
759 status, out = context.get(self.vdm.vdm_name)
760 self.assertEqual(constants.STATUS_OK, status)
761 property_map = [
762 'path',
763 'mover',
764 'moverIdIsVdm',
765 'fileSystem',
766 ]
767 for item in out:
768 for prop in property_map:
769 self.assertIn(prop, item)
771 status, out = context.get(self.mover.mover_name, False)
772 self.assertEqual(constants.STATUS_OK, status)
773 property_map = [
774 'path',
775 'mover',
776 'moverIdIsVdm',
777 'fileSystem',
778 ]
779 for item in out:
780 for prop in property_map:
781 self.assertIn(prop, item)
783 expected_calls = [
784 mock.call(self.vdm.req_get()),
785 mock.call(self.mount.req_get(self.vdm.vdm_id)),
786 mock.call(self.mover.req_get_ref()),
787 mock.call(self.mount.req_get(self.mover.mover_id, False)),
788 ]
789 context.conn['XML'].request.assert_has_calls(expected_calls)
791 def test_get_mount_points_but_not_found(self):
792 self.hook.append(self.mover.resp_get_ref_succeed())
793 self.hook.append(self.mount.resp_get_without_value())
795 context = self.manager.getStorageContext('MountPoint')
796 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
798 status, out = context.get(self.mover.mover_name, False)
799 self.assertEqual(constants.STATUS_NOT_FOUND, status)
801 expected_calls = [
802 mock.call(self.mover.req_get_ref()),
803 mock.call(self.mount.req_get(self.mover.mover_id, False)),
804 ]
805 context.conn['XML'].request.assert_has_calls(expected_calls)
807 @mock.patch('time.sleep')
808 def test_get_mount_points_invalid_mover_id(self, sleep_mock):
809 self.hook.append(self.mover.resp_get_ref_succeed())
810 self.hook.append(self.mount.resp_invalid_mover_id())
811 self.hook.append(self.mover.resp_get_ref_succeed())
812 self.hook.append(self.mount.resp_get_succeed(self.mover.mover_id,
813 False))
815 context = self.manager.getStorageContext('MountPoint')
816 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
818 status, out = context.get(self.mover.mover_name, False)
819 self.assertEqual(constants.STATUS_OK, status)
821 property_map = [
822 'path',
823 'mover',
824 'moverIdIsVdm',
825 'fileSystem',
826 ]
827 for item in out:
828 for prop in property_map:
829 self.assertIn(prop, item)
831 expected_calls = [
832 mock.call(self.mover.req_get_ref()),
833 mock.call(self.mount.req_get(self.mover.mover_id, False)),
834 mock.call(self.mover.req_get_ref()),
835 mock.call(self.mount.req_get(self.mover.mover_id, False)),
836 ]
837 context.conn['XML'].request.assert_has_calls(expected_calls)
839 self.assertTrue(sleep_mock.called)
841 def test_get_mount_points_with_error(self):
842 self.hook.append(self.mover.resp_get_ref_succeed())
843 self.hook.append(self.mount.resp_get_error())
845 context = self.manager.getStorageContext('MountPoint')
846 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
848 status, out = context.get(self.mover.mover_name, False)
849 self.assertEqual(constants.STATUS_ERROR, status)
851 expected_calls = [
852 mock.call(self.mover.req_get_ref()),
853 mock.call(self.mount.req_get(self.mover.mover_id, False)),
854 ]
855 context.conn['XML'].request.assert_has_calls(expected_calls)
858@ddt.ddt
859class VDMTestCase(StorageObjectTestCaseBase):
860 def setUp(self):
861 super(VDMTestCase, self).setUp()
862 self.hook = utils.RequestSideEffect()
863 self.ssh_hook = utils.SSHSideEffect()
865 def test_create_vdm(self):
866 self.hook.append(self.mover.resp_get_ref_succeed())
867 self.hook.append(self.vdm.resp_task_succeed())
869 context = self.manager.getStorageContext('VDM')
870 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
872 context.create(self.vdm.vdm_name, self.mover.mover_name)
874 expected_calls = [
875 mock.call(self.mover.req_get_ref()),
876 mock.call(self.vdm.req_create()),
877 ]
878 context.conn['XML'].request.assert_has_calls(expected_calls)
880 def test_create_vdm_but_already_exist(self):
881 self.hook.append(self.mover.resp_get_ref_succeed())
882 self.hook.append(self.vdm.resp_create_but_already_exist())
884 context = self.manager.getStorageContext('VDM')
885 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
887 # Create VDM which already exists.
888 context.create(self.vdm.vdm_name, self.mover.mover_name)
890 expected_calls = [
891 mock.call(self.mover.req_get_ref()),
892 mock.call(self.vdm.req_create()),
893 ]
894 context.conn['XML'].request.assert_has_calls(expected_calls)
896 @mock.patch('time.sleep')
897 def test_create_vdm_invalid_mover_id(self, sleep_mock):
898 self.hook.append(self.mover.resp_get_ref_succeed())
899 self.hook.append(self.vdm.resp_invalid_mover_id())
900 self.hook.append(self.mover.resp_get_ref_succeed())
901 self.hook.append(self.vdm.resp_task_succeed())
903 context = self.manager.getStorageContext('VDM')
904 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
906 # Create VDM with invalid mover ID
907 context.create(self.vdm.vdm_name, self.mover.mover_name)
909 expected_calls = [
910 mock.call(self.mover.req_get_ref()),
911 mock.call(self.vdm.req_create()),
912 mock.call(self.mover.req_get_ref()),
913 mock.call(self.vdm.req_create()),
914 ]
915 context.conn['XML'].request.assert_has_calls(expected_calls)
917 self.assertTrue(sleep_mock.called)
919 def test_create_vdm_with_error(self):
920 self.hook.append(self.mover.resp_get_ref_succeed())
921 self.hook.append(self.vdm.resp_task_error())
923 context = self.manager.getStorageContext('VDM')
924 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
926 # Create VDM with invalid mover ID
927 self.assertRaises(exception.EMCVnxXMLAPIError,
928 context.create,
929 name=self.vdm.vdm_name,
930 mover_name=self.mover.mover_name)
932 expected_calls = [
933 mock.call(self.mover.req_get_ref()),
934 mock.call(self.vdm.req_create()),
935 ]
936 context.conn['XML'].request.assert_has_calls(expected_calls)
938 def test_get_vdm(self):
939 self.hook.append(self.vdm.resp_get_succeed())
941 context = self.manager.getStorageContext('VDM')
942 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
944 status, out = context.get(self.vdm.vdm_name)
945 self.assertEqual(constants.STATUS_OK, status)
946 self.assertIn(self.vdm.vdm_name, context.vdm_map)
947 property_map = [
948 'name',
949 'id',
950 'state',
951 'host_mover_id',
952 'interfaces',
953 ]
954 for prop in property_map:
955 self.assertIn(prop, out)
957 expected_calls = [mock.call(self.vdm.req_get())]
958 context.conn['XML'].request.assert_has_calls(expected_calls)
960 def test_get_vdm_with_error(self):
961 self.hook.append(self.vdm.resp_get_error())
963 context = self.manager.getStorageContext('VDM')
964 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
966 # Get VDM with error
967 status, out = context.get(self.vdm.vdm_name)
968 self.assertEqual(constants.STATUS_ERROR, status)
970 expected_calls = [mock.call(self.vdm.req_get())]
971 context.conn['XML'].request.assert_has_calls(expected_calls)
973 def test_get_vdm_but_not_found(self):
974 self.hook.append(self.vdm.resp_get_without_value())
975 self.hook.append(self.vdm.resp_get_succeed('fake'))
977 context = self.manager.getStorageContext('VDM')
978 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
980 # Get VDM which does not exist
981 status, out = context.get(self.vdm.vdm_name)
982 self.assertEqual(constants.STATUS_NOT_FOUND, status)
984 status, out = context.get(self.vdm.vdm_name)
985 self.assertEqual(constants.STATUS_NOT_FOUND, status)
987 expected_calls = [
988 mock.call(self.vdm.req_get()),
989 mock.call(self.vdm.req_get()),
990 ]
991 context.conn['XML'].request.assert_has_calls(expected_calls)
993 def test_get_vdm_id_with_error(self):
994 self.hook.append(self.vdm.resp_get_error())
996 context = self.manager.getStorageContext('VDM')
997 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
999 self.assertRaises(exception.EMCVnxXMLAPIError,
1000 context.get_id,
1001 self.vdm.vdm_name)
1003 expected_calls = [mock.call(self.vdm.req_get())]
1004 context.conn['XML'].request.assert_has_calls(expected_calls)
1006 def test_delete_vdm(self):
1007 self.hook.append(self.vdm.resp_get_succeed())
1008 self.hook.append(self.vdm.resp_task_succeed())
1010 context = self.manager.getStorageContext('VDM')
1011 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1013 context.delete(self.vdm.vdm_name)
1015 expected_calls = [
1016 mock.call(self.vdm.req_get()),
1017 mock.call(self.vdm.req_delete()),
1018 ]
1019 context.conn['XML'].request.assert_has_calls(expected_calls)
1021 def test_delete_vdm_but_not_found(self):
1022 self.hook.append(self.vdm.resp_get_but_not_found())
1024 context = self.manager.getStorageContext('VDM')
1025 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1027 context.delete(self.vdm.vdm_name)
1029 expected_calls = [mock.call(self.vdm.req_get())]
1030 context.conn['XML'].request.assert_has_calls(expected_calls)
1032 def test_delete_vdm_but_failed_to_get_vdm(self):
1033 self.hook.append(self.vdm.resp_get_error())
1035 context = self.manager.getStorageContext('VDM')
1036 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1038 self.assertRaises(exception.EMCVnxXMLAPIError,
1039 context.delete,
1040 self.vdm.vdm_name)
1042 expected_calls = [mock.call(self.vdm.req_get())]
1043 context.conn['XML'].request.assert_has_calls(expected_calls)
1045 def test_delete_vdm_with_error(self):
1046 self.hook.append(self.vdm.resp_get_succeed())
1047 self.hook.append(self.vdm.resp_task_error())
1049 context = self.manager.getStorageContext('VDM')
1050 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1052 self.assertRaises(exception.EMCVnxXMLAPIError,
1053 context.delete,
1054 self.vdm.vdm_name)
1056 expected_calls = [
1057 mock.call(self.vdm.req_get()),
1058 mock.call(self.vdm.req_delete()),
1059 ]
1060 context.conn['XML'].request.assert_has_calls(expected_calls)
1062 def test_attach_detach_nfs_interface(self):
1063 self.ssh_hook.append()
1064 self.ssh_hook.append()
1066 context = self.manager.getStorageContext('VDM')
1067 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
1069 context.attach_nfs_interface(self.vdm.vdm_name,
1070 self.mover.interface_name2)
1071 context.detach_nfs_interface(self.vdm.vdm_name,
1072 self.mover.interface_name2)
1074 ssh_calls = [
1075 mock.call(self.vdm.cmd_attach_nfs_interface(), False),
1076 mock.call(self.vdm.cmd_detach_nfs_interface(), True),
1077 ]
1078 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
1080 def test_detach_nfs_interface_with_error(self):
1081 self.ssh_hook.append(ex=processutils.ProcessExecutionError(
1082 stdout=self.vdm.fake_output))
1083 self.ssh_hook.append(self.vdm.output_get_interfaces_vdm(
1084 self.mover.interface_name2))
1085 self.ssh_hook.append(ex=processutils.ProcessExecutionError(
1086 stdout=self.vdm.fake_output))
1087 self.ssh_hook.append(self.vdm.output_get_interfaces_vdm(
1088 nfs_interface=fakes.FakeData.interface_name1))
1090 context = self.manager.getStorageContext('VDM')
1091 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
1093 self.assertRaises(exception.EMCVnxXMLAPIError,
1094 context.detach_nfs_interface,
1095 self.vdm.vdm_name,
1096 self.mover.interface_name2)
1098 context.detach_nfs_interface(self.vdm.vdm_name,
1099 self.mover.interface_name2)
1101 ssh_calls = [
1102 mock.call(self.vdm.cmd_detach_nfs_interface(), True),
1103 mock.call(self.vdm.cmd_get_interfaces(), False),
1104 mock.call(self.vdm.cmd_detach_nfs_interface(), True),
1105 mock.call(self.vdm.cmd_get_interfaces(), False),
1106 ]
1107 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
1109 @ddt.data(fakes.VDMTestData().output_get_interfaces_vdm(),
1110 fakes.VDMTestData().output_get_interfaces_nfs())
1111 def test_get_cifs_nfs_interface(self, fake_output):
1112 self.ssh_hook.append(fake_output)
1114 context = self.manager.getStorageContext('VDM')
1115 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
1117 interfaces = context.get_interfaces(self.vdm.vdm_name)
1118 self.assertIsNotNone(interfaces['cifs'])
1119 self.assertIsNotNone(interfaces['nfs'])
1121 ssh_calls = [mock.call(self.vdm.cmd_get_interfaces(), False)]
1122 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
1125class StoragePoolTestCase(StorageObjectTestCaseBase):
1126 def setUp(self):
1127 super(StoragePoolTestCase, self).setUp()
1128 self.hook = utils.RequestSideEffect()
1130 def test_get_pool(self):
1131 self.hook.append(self.pool.resp_get_succeed())
1133 context = self.manager.getStorageContext('StoragePool')
1134 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1136 status, out = context.get(self.pool.pool_name)
1137 self.assertEqual(constants.STATUS_OK, status)
1138 self.assertIn(self.pool.pool_name, context.pool_map)
1139 property_map = [
1140 'name',
1141 'movers_id',
1142 'total_size',
1143 'used_size',
1144 'diskType',
1145 'dataServicePolicies',
1146 'id',
1147 ]
1148 for prop in property_map:
1149 self.assertIn(prop, out)
1151 expected_calls = [mock.call(self.pool.req_get())]
1152 context.conn['XML'].request.assert_has_calls(expected_calls)
1154 def test_get_pool_with_error(self):
1155 self.hook.append(self.pool.resp_get_error())
1156 self.hook.append(self.pool.resp_get_without_value())
1157 self.hook.append(self.pool.resp_get_succeed(name='other'))
1159 context = self.manager.getStorageContext('StoragePool')
1160 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1162 status, out = context.get(self.pool.pool_name)
1163 self.assertEqual(constants.STATUS_ERROR, status)
1165 status, out = context.get(self.pool.pool_name)
1166 self.assertEqual(constants.STATUS_NOT_FOUND, status)
1168 status, out = context.get(self.pool.pool_name)
1169 self.assertEqual(constants.STATUS_NOT_FOUND, status)
1171 expected_calls = [
1172 mock.call(self.pool.req_get()),
1173 mock.call(self.pool.req_get()),
1174 mock.call(self.pool.req_get()),
1175 ]
1176 context.conn['XML'].request.assert_has_calls(expected_calls)
1178 def test_get_pool_id_with_error(self):
1179 self.hook.append(self.pool.resp_get_error())
1181 context = self.manager.getStorageContext('StoragePool')
1182 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1184 self.assertRaises(exception.EMCVnxXMLAPIError,
1185 context.get_id,
1186 self.pool.pool_name)
1188 expected_calls = [mock.call(self.pool.req_get())]
1189 context.conn['XML'].request.assert_has_calls(expected_calls)
1192class MoverTestCase(StorageObjectTestCaseBase):
1193 def setUp(self):
1194 super(MoverTestCase, self).setUp()
1195 self.hook = utils.RequestSideEffect()
1196 self.ssh_hook = utils.SSHSideEffect()
1198 def test_get_mover(self):
1199 self.hook.append(self.mover.resp_get_ref_succeed())
1200 self.hook.append(self.mover.resp_get_succeed())
1201 self.hook.append(self.mover.resp_get_ref_succeed())
1202 self.hook.append(self.mover.resp_get_succeed())
1204 context = self.manager.getStorageContext('Mover')
1205 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1207 status, out = context.get(self.mover.mover_name)
1208 self.assertEqual(constants.STATUS_OK, status)
1209 self.assertIn(self.mover.mover_name, context.mover_map)
1210 property_map = [
1211 'name',
1212 'id',
1213 'Status',
1214 'version',
1215 'uptime',
1216 'role',
1217 'interfaces',
1218 'devices',
1219 'dns_domain',
1220 ]
1221 for prop in property_map:
1222 self.assertIn(prop, out)
1224 status, out = context.get(self.mover.mover_name)
1225 self.assertEqual(constants.STATUS_OK, status)
1227 status, out = context.get(self.mover.mover_name, True)
1228 self.assertEqual(constants.STATUS_OK, status)
1230 expected_calls = [
1231 mock.call(self.mover.req_get_ref()),
1232 mock.call(self.mover.req_get()),
1233 mock.call(self.mover.req_get_ref()),
1234 mock.call(self.mover.req_get()),
1235 ]
1236 context.conn['XML'].request.assert_has_calls(expected_calls)
1238 def test_get_mover_ref_not_found(self):
1239 self.hook.append(self.mover.resp_get_ref_succeed(name='other'))
1241 context = self.manager.getStorageContext('Mover')
1242 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1244 status, out = context.get_ref(self.mover.mover_name)
1245 self.assertEqual(constants.STATUS_NOT_FOUND, status)
1247 expected_calls = [mock.call(self.mover.req_get_ref())]
1248 context.conn['XML'].request.assert_has_calls(expected_calls)
1250 def test_get_mover_ref_with_error(self):
1251 self.hook.append(self.mover.resp_get_error())
1253 context = self.manager.getStorageContext('Mover')
1254 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1256 status, out = context.get_ref(self.mover.mover_name)
1257 self.assertEqual(constants.STATUS_ERROR, status)
1259 expected_calls = [mock.call(self.mover.req_get_ref())]
1260 context.conn['XML'].request.assert_has_calls(expected_calls)
1262 def test_get_mover_ref_and_mover(self):
1263 self.hook.append(self.mover.resp_get_ref_succeed())
1264 self.hook.append(self.mover.resp_get_succeed())
1266 context = self.manager.getStorageContext('Mover')
1267 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1269 status, out = context.get_ref(self.mover.mover_name)
1270 self.assertEqual(constants.STATUS_OK, status)
1271 property_map = ['name', 'id']
1272 for prop in property_map:
1273 self.assertIn(prop, out)
1275 status, out = context.get(self.mover.mover_name)
1276 self.assertEqual(constants.STATUS_OK, status)
1277 self.assertIn(self.mover.mover_name, context.mover_map)
1278 property_map = [
1279 'name',
1280 'id',
1281 'Status',
1282 'version',
1283 'uptime',
1284 'role',
1285 'interfaces',
1286 'devices',
1287 'dns_domain',
1288 ]
1289 for prop in property_map:
1290 self.assertIn(prop, out)
1292 expected_calls = [
1293 mock.call(self.mover.req_get_ref()),
1294 mock.call(self.mover.req_get()),
1295 ]
1296 context.conn['XML'].request.assert_has_calls(expected_calls)
1298 def test_get_mover_failed_to_get_mover_ref(self):
1299 self.hook.append(self.mover.resp_get_error())
1301 context = self.manager.getStorageContext('Mover')
1302 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1304 self.assertRaises(exception.EMCVnxXMLAPIError,
1305 context.get,
1306 self.mover.mover_name)
1308 expected_calls = [mock.call(self.mover.req_get_ref())]
1309 context.conn['XML'].request.assert_has_calls(expected_calls)
1311 def test_get_mover_but_not_found(self):
1312 self.hook.append(self.mover.resp_get_ref_succeed())
1313 self.hook.append(self.mover.resp_get_without_value())
1315 context = self.manager.getStorageContext('Mover')
1316 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1318 status, out = context.get(name=self.mover.mover_name, force=True)
1319 self.assertEqual(constants.STATUS_NOT_FOUND, status)
1321 expected_calls = [
1322 mock.call(self.mover.req_get_ref()),
1323 mock.call(self.mover.req_get()),
1324 ]
1325 context.conn['XML'].request.assert_has_calls(expected_calls)
1327 def test_get_mover_with_error(self):
1328 self.hook.append(self.mover.resp_get_ref_succeed())
1329 self.hook.append(self.mover.resp_get_error())
1331 context = self.manager.getStorageContext('Mover')
1332 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1334 status, out = context.get(self.mover.mover_name)
1335 self.assertEqual(constants.STATUS_ERROR, status)
1337 expected_calls = [
1338 mock.call(self.mover.req_get_ref()),
1339 mock.call(self.mover.req_get()),
1340 ]
1341 context.conn['XML'].request.assert_has_calls(expected_calls)
1343 def test_get_interconnect_id(self):
1344 self.ssh_hook.append(self.mover.output_get_interconnect_id())
1346 context = self.manager.getStorageContext('Mover')
1347 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
1349 conn_id = context.get_interconnect_id(self.mover.mover_name,
1350 self.mover.mover_name)
1351 self.assertEqual(self.mover.interconnect_id, conn_id)
1353 ssh_calls = [mock.call(self.mover.cmd_get_interconnect_id(), False)]
1354 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
1356 def test_get_physical_devices(self):
1357 self.ssh_hook.append(self.mover.output_get_physical_devices())
1359 context = self.manager.getStorageContext('Mover')
1360 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
1362 devices = context.get_physical_devices(self.mover.mover_name)
1363 self.assertIn(self.mover.device_name, devices)
1365 ssh_calls = [mock.call(self.mover.cmd_get_physical_devices(), False)]
1366 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
1369class SnapshotTestCase(StorageObjectTestCaseBase):
1370 def setUp(self):
1371 super(SnapshotTestCase, self).setUp()
1372 self.hook = utils.RequestSideEffect()
1374 def test_create_snapshot(self):
1375 self.hook.append(self.fs.resp_get_succeed())
1376 self.hook.append(self.snap.resp_task_succeed())
1378 context = self.manager.getStorageContext('Snapshot')
1379 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1381 context.create(name=self.snap.snapshot_name,
1382 fs_name=self.fs.filesystem_name,
1383 pool_id=self.pool.pool_id)
1385 expected_calls = [
1386 mock.call(self.fs.req_get()),
1387 mock.call(self.snap.req_create()),
1388 ]
1389 context.conn['XML'].request.assert_has_calls(expected_calls)
1391 def test_create_snapshot_but_already_exist(self):
1392 self.hook.append(self.fs.resp_get_succeed())
1393 self.hook.append(self.snap.resp_create_but_already_exist())
1395 context = self.manager.getStorageContext('Snapshot')
1396 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1398 context.create(name=self.snap.snapshot_name,
1399 fs_name=self.fs.filesystem_name,
1400 pool_id=self.pool.pool_id,
1401 ckpt_size=self.snap.snapshot_size)
1403 expected_calls = [
1404 mock.call(self.fs.req_get()),
1405 mock.call(self.snap.req_create_with_size()),
1406 ]
1407 context.conn['XML'].request.assert_has_calls(expected_calls)
1409 def test_create_snapshot_with_error(self):
1410 self.hook.append(self.fs.resp_get_succeed())
1411 self.hook.append(self.snap.resp_task_error())
1413 context = self.manager.getStorageContext('Snapshot')
1414 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1416 self.assertRaises(exception.EMCVnxXMLAPIError,
1417 context.create,
1418 name=self.snap.snapshot_name,
1419 fs_name=self.fs.filesystem_name,
1420 pool_id=self.pool.pool_id,
1421 ckpt_size=self.snap.snapshot_size)
1423 expected_calls = [
1424 mock.call(self.fs.req_get()),
1425 mock.call(self.snap.req_create_with_size()),
1426 ]
1427 context.conn['XML'].request.assert_has_calls(expected_calls)
1429 def test_get_snapshot(self):
1430 self.hook.append(self.snap.resp_get_succeed())
1432 context = self.manager.getStorageContext('Snapshot')
1433 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1435 status, out = context.get(self.snap.snapshot_name)
1436 self.assertEqual(constants.STATUS_OK, status)
1437 self.assertIn(self.snap.snapshot_name, context.snap_map)
1438 property_map = [
1439 'name',
1440 'id',
1441 'checkpointOf',
1442 'state',
1443 ]
1444 for prop in property_map:
1445 self.assertIn(prop, out)
1447 expected_calls = [mock.call(self.snap.req_get())]
1448 context.conn['XML'].request.assert_has_calls(expected_calls)
1450 def test_get_snapshot_but_not_found(self):
1451 self.hook.append(self.snap.resp_get_without_value())
1453 context = self.manager.getStorageContext('Snapshot')
1454 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1456 status, out = context.get(self.snap.snapshot_name)
1457 self.assertEqual(constants.STATUS_NOT_FOUND, status)
1459 expected_calls = [mock.call(self.snap.req_get())]
1460 context.conn['XML'].request.assert_has_calls(expected_calls)
1462 def test_get_snapshot_with_error(self):
1463 self.hook.append(self.snap.resp_get_error())
1465 context = self.manager.getStorageContext('Snapshot')
1466 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1468 status, out = context.get(self.snap.snapshot_name)
1469 self.assertEqual(constants.STATUS_ERROR, status)
1471 expected_calls = [mock.call(self.snap.req_get())]
1472 context.conn['XML'].request.assert_has_calls(expected_calls)
1474 def test_delete_snapshot(self):
1475 self.hook.append(self.snap.resp_get_succeed())
1476 self.hook.append(self.snap.resp_task_succeed())
1478 context = self.manager.getStorageContext('Snapshot')
1479 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1481 context.delete(self.snap.snapshot_name)
1482 self.assertNotIn(self.snap.snapshot_name, context.snap_map)
1484 expected_calls = [
1485 mock.call(self.snap.req_get()),
1486 mock.call(self.snap.req_delete()),
1487 ]
1488 context.conn['XML'].request.assert_has_calls(expected_calls)
1490 def test_delete_snapshot_failed_to_get_snapshot(self):
1491 self.hook.append(self.snap.resp_get_error())
1493 context = self.manager.getStorageContext('Snapshot')
1494 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1496 self.assertRaises(exception.EMCVnxXMLAPIError,
1497 context.delete,
1498 self.snap.snapshot_name)
1500 expected_calls = [mock.call(self.snap.req_get())]
1501 context.conn['XML'].request.assert_has_calls(expected_calls)
1503 def test_delete_snapshot_but_not_found(self):
1504 self.hook.append(self.snap.resp_get_without_value())
1506 context = self.manager.getStorageContext('Snapshot')
1507 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1509 context.delete(self.snap.snapshot_name)
1510 self.assertNotIn(self.snap.snapshot_name, context.snap_map)
1512 expected_calls = [mock.call(self.snap.req_get())]
1513 context.conn['XML'].request.assert_has_calls(expected_calls)
1515 def test_delete_snapshot_with_error(self):
1516 self.hook.append(self.snap.resp_get_succeed())
1517 self.hook.append(self.snap.resp_task_error())
1519 context = self.manager.getStorageContext('Snapshot')
1520 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1522 self.assertRaises(exception.EMCVnxXMLAPIError,
1523 context.delete,
1524 self.snap.snapshot_name)
1526 expected_calls = [
1527 mock.call(self.snap.req_get()),
1528 mock.call(self.snap.req_delete()),
1529 ]
1530 context.conn['XML'].request.assert_has_calls(expected_calls)
1532 def test_get_snapshot_id(self):
1533 self.hook.append(self.snap.resp_get_succeed())
1535 context = self.manager.getStorageContext('Snapshot')
1536 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1538 id = context.get_id(self.snap.snapshot_name)
1539 self.assertEqual(self.snap.snapshot_id, id)
1541 expected_calls = [mock.call(self.snap.req_get())]
1542 context.conn['XML'].request.assert_has_calls(expected_calls)
1544 def test_get_snapshot_id_with_error(self):
1545 self.hook.append(self.snap.resp_get_error())
1547 context = self.manager.getStorageContext('Snapshot')
1548 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1550 self.assertRaises(exception.EMCVnxXMLAPIError,
1551 context.get_id,
1552 self.snap.snapshot_name)
1554 expected_calls = [mock.call(self.snap.req_get())]
1555 context.conn['XML'].request.assert_has_calls(expected_calls)
1558@ddt.ddt
1559class MoverInterfaceTestCase(StorageObjectTestCaseBase):
1560 def setUp(self):
1561 super(MoverInterfaceTestCase, self).setUp()
1562 self.hook = utils.RequestSideEffect()
1564 def test_create_mover_interface(self):
1565 self.hook.append(self.mover.resp_get_ref_succeed())
1566 self.hook.append(self.mover.resp_task_succeed())
1567 self.hook.append(self.mover.resp_task_succeed())
1569 context = self.manager.getStorageContext('MoverInterface')
1570 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1572 interface = {
1573 'name': self.mover.interface_name1,
1574 'device_name': self.mover.device_name,
1575 'ip': self.mover.ip_address1,
1576 'mover_name': self.mover.mover_name,
1577 'net_mask': self.mover.net_mask,
1578 'vlan_id': self.mover.vlan_id,
1579 }
1580 context.create(interface)
1582 interface['name'] = self.mover.long_interface_name
1583 context.create(interface)
1585 expected_calls = [
1586 mock.call(self.mover.req_get_ref()),
1587 mock.call(self.mover.req_create_interface()),
1588 mock.call(self.mover.req_create_interface(
1589 self.mover.long_interface_name[:31])),
1590 ]
1591 context.conn['XML'].request.assert_has_calls(expected_calls)
1593 def test_create_mover_interface_name_already_exist(self):
1594 self.hook.append(self.mover.resp_get_ref_succeed())
1595 self.hook.append(
1596 self.mover.resp_create_interface_but_name_already_exist())
1598 context = self.manager.getStorageContext('MoverInterface')
1599 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1601 interface = {
1602 'name': self.mover.interface_name1,
1603 'device_name': self.mover.device_name,
1604 'ip': self.mover.ip_address1,
1605 'mover_name': self.mover.mover_name,
1606 'net_mask': self.mover.net_mask,
1607 'vlan_id': self.mover.vlan_id,
1608 }
1609 context.create(interface)
1611 expected_calls = [
1612 mock.call(self.mover.req_get_ref()),
1613 mock.call(self.mover.req_create_interface()),
1614 ]
1615 context.conn['XML'].request.assert_has_calls(expected_calls)
1617 def test_create_mover_interface_ip_already_exist(self):
1618 self.hook.append(self.mover.resp_get_ref_succeed())
1619 self.hook.append(
1620 self.mover.resp_create_interface_but_ip_already_exist())
1622 context = self.manager.getStorageContext('MoverInterface')
1623 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1625 interface = {
1626 'name': self.mover.interface_name1,
1627 'device_name': self.mover.device_name,
1628 'ip': self.mover.ip_address1,
1629 'mover_name': self.mover.mover_name,
1630 'net_mask': self.mover.net_mask,
1631 'vlan_id': self.mover.vlan_id,
1632 }
1633 context.create(interface)
1635 expected_calls = [
1636 mock.call(self.mover.req_get_ref()),
1637 mock.call(self.mover.req_create_interface()),
1638 ]
1639 context.conn['XML'].request.assert_has_calls(expected_calls)
1641 @ddt.data(fakes.MoverTestData().resp_task_succeed(),
1642 fakes.MoverTestData().resp_task_error())
1643 def test_create_mover_interface_with_conflict_vlan_id(self, xml_resp):
1644 self.hook.append(self.mover.resp_get_ref_succeed())
1645 self.hook.append(
1646 self.mover.resp_create_interface_with_conflicted_vlan_id())
1647 self.hook.append(xml_resp)
1649 context = self.manager.getStorageContext('MoverInterface')
1650 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1652 interface = {
1653 'name': self.mover.interface_name1,
1654 'device_name': self.mover.device_name,
1655 'ip': self.mover.ip_address1,
1656 'mover_name': self.mover.mover_name,
1657 'net_mask': self.mover.net_mask,
1658 'vlan_id': self.mover.vlan_id,
1659 }
1660 self.assertRaises(exception.EMCVnxXMLAPIError,
1661 context.create,
1662 interface)
1664 expected_calls = [
1665 mock.call(self.mover.req_get_ref()),
1666 mock.call(self.mover.req_create_interface()),
1667 mock.call(self.mover.req_delete_interface()),
1668 ]
1669 context.conn['XML'].request.assert_has_calls(expected_calls)
1671 @mock.patch('time.sleep')
1672 def test_create_mover_interface_invalid_mover_id(self, sleep_mock):
1673 self.hook.append(self.mover.resp_get_ref_succeed())
1674 self.hook.append(self.mover.resp_invalid_mover_id())
1675 self.hook.append(self.mover.resp_get_ref_succeed())
1676 self.hook.append(self.mover.resp_task_succeed())
1678 context = self.manager.getStorageContext('MoverInterface')
1679 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1681 interface = {
1682 'name': self.mover.interface_name1,
1683 'device_name': self.mover.device_name,
1684 'ip': self.mover.ip_address1,
1685 'mover_name': self.mover.mover_name,
1686 'net_mask': self.mover.net_mask,
1687 'vlan_id': self.mover.vlan_id,
1688 }
1689 context.create(interface)
1691 expected_calls = [
1692 mock.call(self.mover.req_get_ref()),
1693 mock.call(self.mover.req_create_interface()),
1694 mock.call(self.mover.req_get_ref()),
1695 mock.call(self.mover.req_create_interface()),
1696 ]
1697 context.conn['XML'].request.assert_has_calls(expected_calls)
1699 self.assertTrue(sleep_mock.called)
1701 def test_create_mover_interface_with_error(self):
1702 self.hook.append(self.mover.resp_get_ref_succeed())
1703 self.hook.append(self.mover.resp_task_error())
1705 context = self.manager.getStorageContext('MoverInterface')
1706 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1708 interface = {
1709 'name': self.mover.interface_name1,
1710 'device_name': self.mover.device_name,
1711 'ip': self.mover.ip_address1,
1712 'mover_name': self.mover.mover_name,
1713 'net_mask': self.mover.net_mask,
1714 'vlan_id': self.mover.vlan_id,
1715 }
1716 self.assertRaises(exception.EMCVnxXMLAPIError,
1717 context.create,
1718 interface)
1720 expected_calls = [
1721 mock.call(self.mover.req_get_ref()),
1722 mock.call(self.mover.req_create_interface()),
1723 ]
1724 context.conn['XML'].request.assert_has_calls(expected_calls)
1726 def test_get_mover_interface(self):
1727 self.hook.append(self.mover.resp_get_ref_succeed())
1728 self.hook.append(self.mover.resp_get_succeed())
1729 self.hook.append(self.mover.resp_get_ref_succeed())
1730 self.hook.append(self.mover.resp_get_succeed())
1732 context = self.manager.getStorageContext('MoverInterface')
1733 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1735 status, out = context.get(name=self.mover.interface_name1,
1736 mover_name=self.mover.mover_name)
1737 self.assertEqual(constants.STATUS_OK, status)
1738 property_map = [
1739 'name',
1740 'device',
1741 'up',
1742 'ipVersion',
1743 'netMask',
1744 'ipAddress',
1745 'vlanid',
1746 ]
1747 for prop in property_map:
1748 self.assertIn(prop, out)
1750 context.get(name=self.mover.long_interface_name,
1751 mover_name=self.mover.mover_name)
1753 expected_calls = [
1754 mock.call(self.mover.req_get_ref()),
1755 mock.call(self.mover.req_get()),
1756 mock.call(self.mover.req_get_ref()),
1757 mock.call(self.mover.req_get()),
1758 ]
1759 context.conn['XML'].request.assert_has_calls(expected_calls)
1761 def test_get_mover_interface_not_found(self):
1762 self.hook.append(self.mover.resp_get_ref_succeed())
1763 self.hook.append(self.mover.resp_get_without_value())
1765 context = self.manager.getStorageContext('MoverInterface')
1766 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1768 status, out = context.get(name=self.mover.interface_name1,
1769 mover_name=self.mover.mover_name)
1770 self.assertEqual(constants.STATUS_NOT_FOUND, status)
1772 expected_calls = [
1773 mock.call(self.mover.req_get_ref()),
1774 mock.call(self.mover.req_get()),
1775 ]
1776 context.conn['XML'].request.assert_has_calls(expected_calls)
1778 def test_delete_mover_interface(self):
1779 self.hook.append(self.mover.resp_get_ref_succeed())
1780 self.hook.append(self.mover.resp_task_succeed())
1782 context = self.manager.getStorageContext('MoverInterface')
1783 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1785 context.delete(ip_addr=self.mover.ip_address1,
1786 mover_name=self.mover.mover_name)
1788 expected_calls = [
1789 mock.call(self.mover.req_get_ref()),
1790 mock.call(self.mover.req_delete_interface()),
1791 ]
1792 context.conn['XML'].request.assert_has_calls(expected_calls)
1794 def test_delete_mover_interface_but_nonexistent(self):
1795 self.hook.append(self.mover.resp_get_ref_succeed())
1796 self.hook.append(self.mover.resp_delete_interface_but_nonexistent())
1798 context = self.manager.getStorageContext('MoverInterface')
1799 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1801 context.delete(ip_addr=self.mover.ip_address1,
1802 mover_name=self.mover.mover_name)
1804 expected_calls = [
1805 mock.call(self.mover.req_get_ref()),
1806 mock.call(self.mover.req_delete_interface()),
1807 ]
1808 context.conn['XML'].request.assert_has_calls(expected_calls)
1810 @mock.patch('time.sleep')
1811 def test_delete_mover_interface_invalid_mover_id(self, sleep_mock):
1812 self.hook.append(self.mover.resp_get_ref_succeed())
1813 self.hook.append(self.mover.resp_invalid_mover_id())
1814 self.hook.append(self.mover.resp_get_ref_succeed())
1815 self.hook.append(self.mover.resp_task_succeed())
1817 context = self.manager.getStorageContext('MoverInterface')
1818 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1820 context.delete(ip_addr=self.mover.ip_address1,
1821 mover_name=self.mover.mover_name)
1823 expected_calls = [
1824 mock.call(self.mover.req_get_ref()),
1825 mock.call(self.mover.req_delete_interface()),
1826 mock.call(self.mover.req_get_ref()),
1827 mock.call(self.mover.req_delete_interface()),
1828 ]
1829 context.conn['XML'].request.assert_has_calls(expected_calls)
1831 self.assertTrue(sleep_mock.called)
1833 def test_delete_mover_interface_with_error(self):
1834 self.hook.append(self.mover.resp_get_ref_succeed())
1835 self.hook.append(self.mover.resp_task_error())
1837 context = self.manager.getStorageContext('MoverInterface')
1838 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1840 self.assertRaises(exception.EMCVnxXMLAPIError,
1841 context.delete,
1842 ip_addr=self.mover.ip_address1,
1843 mover_name=self.mover.mover_name)
1845 expected_calls = [
1846 mock.call(self.mover.req_get_ref()),
1847 mock.call(self.mover.req_delete_interface()),
1848 ]
1849 context.conn['XML'].request.assert_has_calls(expected_calls)
1852class DNSDomainTestCase(StorageObjectTestCaseBase):
1853 def setUp(self):
1854 super(DNSDomainTestCase, self).setUp()
1855 self.hook = utils.RequestSideEffect()
1857 def test_create_dns_domain(self):
1858 self.hook.append(self.mover.resp_get_ref_succeed())
1859 self.hook.append(self.dns.resp_task_succeed())
1861 context = self.manager.getStorageContext('DNSDomain')
1862 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1864 context.create(mover_name=self.mover.mover_name,
1865 name=self.dns.domain_name,
1866 servers=self.dns.dns_ip_address)
1868 expected_calls = [
1869 mock.call(self.mover.req_get_ref()),
1870 mock.call(self.dns.req_create()),
1871 ]
1872 context.conn['XML'].request.assert_has_calls(expected_calls)
1874 @mock.patch('time.sleep')
1875 def test_create_dns_domain_invalid_mover_id(self, sleep_mock):
1876 self.hook.append(self.mover.resp_get_ref_succeed())
1877 self.hook.append(self.dns.resp_invalid_mover_id())
1878 self.hook.append(self.mover.resp_get_ref_succeed())
1879 self.hook.append(self.dns.resp_task_succeed())
1881 context = self.manager.getStorageContext('DNSDomain')
1882 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1884 context.create(mover_name=self.mover.mover_name,
1885 name=self.dns.domain_name,
1886 servers=self.dns.dns_ip_address)
1888 expected_calls = [
1889 mock.call(self.mover.req_get_ref()),
1890 mock.call(self.dns.req_create()),
1891 mock.call(self.mover.req_get_ref()),
1892 mock.call(self.dns.req_create()),
1893 ]
1894 context.conn['XML'].request.assert_has_calls(expected_calls)
1896 self.assertTrue(sleep_mock.called)
1898 def test_create_dns_domain_with_error(self):
1899 self.hook.append(self.mover.resp_get_ref_succeed())
1900 self.hook.append(self.dns.resp_task_error())
1902 context = self.manager.getStorageContext('DNSDomain')
1903 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1905 self.assertRaises(exception.EMCVnxXMLAPIError,
1906 context.create,
1907 mover_name=self.mover.mover_name,
1908 name=self.mover.domain_name,
1909 servers=self.dns.dns_ip_address)
1911 expected_calls = [
1912 mock.call(self.mover.req_get_ref()),
1913 mock.call(self.dns.req_create()),
1914 ]
1915 context.conn['XML'].request.assert_has_calls(expected_calls)
1917 def test_delete_dns_domain(self):
1918 self.hook.append(self.mover.resp_get_ref_succeed())
1919 self.hook.append(self.dns.resp_task_succeed())
1920 self.hook.append(self.dns.resp_task_error())
1922 context = self.manager.getStorageContext('DNSDomain')
1923 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1925 context.delete(mover_name=self.mover.mover_name,
1926 name=self.mover.domain_name)
1928 context.delete(mover_name=self.mover.mover_name,
1929 name=self.mover.domain_name)
1931 expected_calls = [
1932 mock.call(self.mover.req_get_ref()),
1933 mock.call(self.dns.req_delete()),
1934 mock.call(self.dns.req_delete()),
1935 ]
1936 context.conn['XML'].request.assert_has_calls(expected_calls)
1938 @mock.patch('time.sleep')
1939 def test_delete_dns_domain_invalid_mover_id(self, sleep_mock):
1940 self.hook.append(self.mover.resp_get_ref_succeed())
1941 self.hook.append(self.dns.resp_invalid_mover_id())
1942 self.hook.append(self.mover.resp_get_ref_succeed())
1943 self.hook.append(self.dns.resp_task_succeed())
1945 context = self.manager.getStorageContext('DNSDomain')
1946 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1948 context.delete(mover_name=self.mover.mover_name,
1949 name=self.mover.domain_name)
1951 expected_calls = [
1952 mock.call(self.mover.req_get_ref()),
1953 mock.call(self.dns.req_delete()),
1954 mock.call(self.mover.req_get_ref()),
1955 mock.call(self.dns.req_delete()),
1956 ]
1957 context.conn['XML'].request.assert_has_calls(expected_calls)
1959 self.assertTrue(sleep_mock.called)
1962class CIFSServerTestCase(StorageObjectTestCaseBase):
1963 def setUp(self):
1964 super(CIFSServerTestCase, self).setUp()
1965 self.hook = utils.RequestSideEffect()
1967 def test_create_cifs_server(self):
1968 self.hook.append(self.mover.resp_get_ref_succeed())
1969 self.hook.append(self.cifs_server.resp_task_succeed())
1970 self.hook.append(self.vdm.resp_get_succeed())
1971 self.hook.append(self.cifs_server.resp_task_succeed())
1972 self.hook.append(self.cifs_server.resp_task_error())
1973 self.hook.append(self.cifs_server.resp_get_succeed(
1974 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
1976 context = self.manager.getStorageContext('CIFSServer')
1977 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
1979 # Create CIFS server on mover
1980 cifs_server_args = {
1981 'name': self.cifs_server.cifs_server_name,
1982 'interface_ip': self.cifs_server.ip_address1,
1983 'domain_name': self.cifs_server.domain_name,
1984 'user_name': self.cifs_server.domain_user,
1985 'password': self.cifs_server.domain_password,
1986 'mover_name': self.mover.mover_name,
1987 'is_vdm': False,
1988 }
1989 context.create(cifs_server_args)
1991 # Create CIFS server on VDM
1992 cifs_server_args = {
1993 'name': self.cifs_server.cifs_server_name,
1994 'interface_ip': self.cifs_server.ip_address1,
1995 'domain_name': self.cifs_server.domain_name,
1996 'user_name': self.cifs_server.domain_user,
1997 'password': self.cifs_server.domain_password,
1998 'mover_name': self.vdm.vdm_name,
1999 'is_vdm': True,
2000 }
2001 context.create(cifs_server_args)
2003 # Create CIFS server on VDM
2004 cifs_server_args = {
2005 'name': self.cifs_server.cifs_server_name,
2006 'interface_ip': self.cifs_server.ip_address1,
2007 'domain_name': self.cifs_server.domain_name,
2008 'user_name': self.cifs_server.domain_user,
2009 'password': self.cifs_server.domain_password,
2010 'mover_name': self.vdm.vdm_name,
2011 'is_vdm': True,
2012 }
2013 context.create(cifs_server_args)
2015 expected_calls = [
2016 mock.call(self.mover.req_get_ref()),
2017 mock.call(self.cifs_server.req_create(self.mover.mover_id, False)),
2018 mock.call(self.vdm.req_get()),
2019 mock.call(self.cifs_server.req_create(self.vdm.vdm_id)),
2020 mock.call(self.cifs_server.req_create(self.vdm.vdm_id)),
2021 mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
2022 ]
2023 context.conn['XML'].request.assert_has_calls(expected_calls)
2025 def test_create_cifs_server_already_exist(self):
2026 self.hook.append(self.vdm.resp_get_succeed())
2027 self.hook.append(self.cifs_server.resp_task_error())
2028 self.hook.append(self.cifs_server.resp_get_succeed(
2029 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
2031 context = self.manager.getStorageContext('CIFSServer')
2032 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2034 @mock.patch('time.sleep')
2035 def test_create_cifs_server_invalid_mover_id(self, sleep_mock):
2036 self.hook.append(self.mover.resp_get_ref_succeed())
2037 self.hook.append(self.cifs_server.resp_invalid_mover_id())
2038 self.hook.append(self.mover.resp_get_ref_succeed())
2039 self.hook.append(self.cifs_server.resp_task_succeed())
2041 context = self.manager.getStorageContext('CIFSServer')
2042 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2044 # Create CIFS server on mover
2045 cifs_server_args = {
2046 'name': self.cifs_server.cifs_server_name,
2047 'interface_ip': self.cifs_server.ip_address1,
2048 'domain_name': self.cifs_server.domain_name,
2049 'user_name': self.cifs_server.domain_user,
2050 'password': self.cifs_server.domain_password,
2051 'mover_name': self.mover.mover_name,
2052 'is_vdm': False,
2053 }
2054 context.create(cifs_server_args)
2056 expected_calls = [
2057 mock.call(self.mover.req_get_ref()),
2058 mock.call(self.cifs_server.req_create(self.mover.mover_id, False)),
2059 mock.call(self.mover.req_get_ref()),
2060 mock.call(self.cifs_server.req_create(self.mover.mover_id, False)),
2061 ]
2062 context.conn['XML'].request.assert_has_calls(expected_calls)
2064 self.assertTrue(sleep_mock.called)
2066 def test_create_cifs_server_with_error(self):
2067 self.hook.append(self.vdm.resp_get_succeed())
2068 self.hook.append(self.cifs_server.resp_task_error())
2069 self.hook.append(self.cifs_server.resp_get_error())
2071 context = self.manager.getStorageContext('CIFSServer')
2072 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2074 # Create CIFS server on VDM
2075 cifs_server_args = {
2076 'name': self.cifs_server.cifs_server_name,
2077 'interface_ip': self.cifs_server.ip_address1,
2078 'domain_name': self.cifs_server.domain_name,
2079 'user_name': self.cifs_server.domain_user,
2080 'password': self.cifs_server.domain_password,
2081 'mover_name': self.vdm.vdm_name,
2082 'is_vdm': True,
2083 }
2084 self.assertRaises(exception.EMCVnxXMLAPIError,
2085 context.create,
2086 cifs_server_args)
2088 expected_calls = [
2089 mock.call(self.vdm.req_get()),
2090 mock.call(self.cifs_server.req_create(self.vdm.vdm_id)),
2091 mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
2092 ]
2093 context.conn['XML'].request.assert_has_calls(expected_calls)
2095 def test_get_all_cifs_server(self):
2096 self.hook.append(self.vdm.resp_get_succeed())
2097 self.hook.append(self.cifs_server.resp_get_succeed(
2098 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
2099 self.hook.append(self.cifs_server.resp_get_succeed(
2100 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
2102 context = self.manager.getStorageContext('CIFSServer')
2103 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2105 status, out = context.get_all(self.vdm.vdm_name)
2106 self.assertEqual(constants.STATUS_OK, status)
2107 self.assertIn(self.vdm.vdm_name, context.cifs_server_map)
2109 # Get CIFS server from the cache
2110 status, out = context.get_all(self.vdm.vdm_name)
2111 self.assertEqual(constants.STATUS_OK, status)
2112 self.assertIn(self.vdm.vdm_name, context.cifs_server_map)
2114 expected_calls = [
2115 mock.call(self.vdm.req_get()),
2116 mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
2117 mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
2118 ]
2119 context.conn['XML'].request.assert_has_calls(expected_calls)
2121 @mock.patch('time.sleep')
2122 def test_get_all_cifs_server_invalid_mover_id(self, sleep_mock):
2123 self.hook.append(self.mover.resp_get_ref_succeed())
2124 self.hook.append(self.cifs_server.resp_invalid_mover_id())
2125 self.hook.append(self.mover.resp_get_ref_succeed())
2126 self.hook.append(self.cifs_server.resp_get_succeed(
2127 mover_id=self.mover.mover_id, is_vdm=False, join_domain=True))
2129 context = self.manager.getStorageContext('CIFSServer')
2130 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2132 status, out = context.get_all(self.mover.mover_name, False)
2133 self.assertEqual(constants.STATUS_OK, status)
2134 self.assertIn(self.mover.mover_name, context.cifs_server_map)
2136 expected_calls = [
2137 mock.call(self.mover.req_get_ref()),
2138 mock.call(self.cifs_server.req_get(self.mover.mover_id, False)),
2139 mock.call(self.mover.req_get_ref()),
2140 mock.call(self.cifs_server.req_get(self.mover.mover_id, False)),
2141 ]
2142 context.conn['XML'].request.assert_has_calls(expected_calls)
2144 self.assertTrue(sleep_mock.called)
2146 def test_get_cifs_server(self):
2147 self.hook.append(self.vdm.resp_get_succeed())
2148 self.hook.append(self.cifs_server.resp_get_succeed(
2149 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
2151 context = self.manager.getStorageContext('CIFSServer')
2152 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2154 status, out = context.get(name=self.cifs_server.cifs_server_name,
2155 mover_name=self.vdm.vdm_name)
2156 self.assertEqual(constants.STATUS_OK, status)
2157 property_map = {
2158 'name',
2159 'compName',
2160 'Aliases',
2161 'type',
2162 'interfaces',
2163 'domain',
2164 'domainJoined',
2165 'mover',
2166 'moverIdIsVdm',
2167 }
2168 for prop in property_map:
2169 self.assertIn(prop, out)
2171 context.get(name=self.cifs_server.cifs_server_name,
2172 mover_name=self.vdm.vdm_name)
2174 expected_calls = [
2175 mock.call(self.vdm.req_get()),
2176 mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
2177 ]
2178 context.conn['XML'].request.assert_has_calls(expected_calls)
2180 def test_modify_cifs_server(self):
2181 self.hook.append(self.mover.resp_get_ref_succeed())
2182 self.hook.append(self.cifs_server.resp_task_succeed())
2183 self.hook.append(self.vdm.resp_get_succeed())
2184 self.hook.append(self.cifs_server.resp_task_succeed())
2186 context = self.manager.getStorageContext('CIFSServer')
2187 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2189 cifs_server_args = {
2190 'name': self.cifs_server.cifs_server_name[-14:],
2191 'join_domain': True,
2192 'user_name': self.cifs_server.domain_user,
2193 'password': self.cifs_server.domain_password,
2194 'mover_name': self.mover.mover_name,
2195 'is_vdm': False,
2196 }
2197 context.modify(cifs_server_args)
2199 cifs_server_args = {
2200 'name': self.cifs_server.cifs_server_name[-14:],
2201 'join_domain': False,
2202 'user_name': self.cifs_server.domain_user,
2203 'password': self.cifs_server.domain_password,
2204 'mover_name': self.vdm.vdm_name,
2205 }
2206 context.modify(cifs_server_args)
2208 expected_calls = [
2209 mock.call(self.mover.req_get_ref()),
2210 mock.call(self.cifs_server.req_modify(
2211 mover_id=self.mover.mover_id, is_vdm=False, join_domain=True)),
2212 mock.call(self.vdm.req_get()),
2213 mock.call(self.cifs_server.req_modify(
2214 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False)),
2215 ]
2216 context.conn['XML'].request.assert_has_calls(expected_calls)
2218 def test_modify_cifs_server_but_unjoin_domain(self):
2219 self.hook.append(self.vdm.resp_get_succeed())
2220 self.hook.append(self.cifs_server.resp_modify_but_unjoin_domain())
2222 context = self.manager.getStorageContext('CIFSServer')
2223 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2225 cifs_server_args = {
2226 'name': self.cifs_server.cifs_server_name[-14:],
2227 'join_domain': False,
2228 'user_name': self.cifs_server.domain_user,
2229 'password': self.cifs_server.domain_password,
2230 'mover_name': self.vdm.vdm_name,
2231 }
2233 context.modify(cifs_server_args)
2235 expected_calls = [
2236 mock.call(self.vdm.req_get()),
2237 mock.call(self.cifs_server.req_modify(
2238 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False)),
2239 ]
2240 context.conn['XML'].request.assert_has_calls(expected_calls)
2242 def test_modify_cifs_server_but_already_join_domain(self):
2243 self.hook.append(self.vdm.resp_get_succeed())
2244 self.hook.append(
2245 self.cifs_server.resp_modify_but_already_join_domain())
2247 context = self.manager.getStorageContext('CIFSServer')
2248 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2250 cifs_server_args = {
2251 'name': self.cifs_server.cifs_server_name[-14:],
2252 'join_domain': True,
2253 'user_name': self.cifs_server.domain_user,
2254 'password': self.cifs_server.domain_password,
2255 'mover_name': self.vdm.vdm_name,
2256 }
2258 context.modify(cifs_server_args)
2260 expected_calls = [
2261 mock.call(self.vdm.req_get()),
2262 mock.call(self.cifs_server.req_modify(
2263 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True)),
2264 ]
2265 context.conn['XML'].request.assert_has_calls(expected_calls)
2267 @mock.patch('time.sleep')
2268 def test_modify_cifs_server_invalid_mover_id(self, sleep_mock):
2269 self.hook.append(self.mover.resp_get_ref_succeed())
2270 self.hook.append(self.cifs_server.resp_invalid_mover_id())
2271 self.hook.append(self.mover.resp_get_ref_succeed())
2272 self.hook.append(self.cifs_server.resp_task_succeed())
2274 context = self.manager.getStorageContext('CIFSServer')
2275 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2277 cifs_server_args = {
2278 'name': self.cifs_server.cifs_server_name[-14:],
2279 'join_domain': True,
2280 'user_name': self.cifs_server.domain_user,
2281 'password': self.cifs_server.domain_password,
2282 'mover_name': self.mover.mover_name,
2283 'is_vdm': False,
2284 }
2285 context.modify(cifs_server_args)
2287 expected_calls = [
2288 mock.call(self.mover.req_get_ref()),
2289 mock.call(self.cifs_server.req_modify(
2290 mover_id=self.mover.mover_id, is_vdm=False, join_domain=True)),
2291 mock.call(self.mover.req_get_ref()),
2292 mock.call(self.cifs_server.req_modify(
2293 mover_id=self.mover.mover_id, is_vdm=False, join_domain=True)),
2294 ]
2295 context.conn['XML'].request.assert_has_calls(expected_calls)
2297 self.assertTrue(sleep_mock.called)
2299 def test_modify_cifs_server_with_error(self):
2300 self.hook.append(self.vdm.resp_get_succeed())
2301 self.hook.append(self.cifs_server.resp_task_error())
2303 context = self.manager.getStorageContext('CIFSServer')
2304 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2306 cifs_server_args = {
2307 'name': self.cifs_server.cifs_server_name[-14:],
2308 'join_domain': False,
2309 'user_name': self.cifs_server.domain_user,
2310 'password': self.cifs_server.domain_password,
2311 'mover_name': self.vdm.vdm_name,
2312 }
2313 self.assertRaises(exception.EMCVnxXMLAPIError,
2314 context.modify,
2315 cifs_server_args)
2317 expected_calls = [
2318 mock.call(self.vdm.req_get()),
2319 mock.call(self.cifs_server.req_modify(
2320 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False)),
2321 ]
2322 context.conn['XML'].request.assert_has_calls(expected_calls)
2324 def test_delete_cifs_server(self):
2325 self.hook.append(self.mover.resp_get_ref_succeed())
2326 self.hook.append(self.cifs_server.resp_get_succeed(
2327 mover_id=self.mover.mover_id, is_vdm=False, join_domain=True))
2328 self.hook.append(self.cifs_server.resp_task_succeed())
2329 self.hook.append(self.vdm.resp_get_succeed())
2330 self.hook.append(self.cifs_server.resp_get_succeed(
2331 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False))
2332 self.hook.append(self.cifs_server.resp_task_succeed())
2334 context = self.manager.getStorageContext('CIFSServer')
2335 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2337 context.delete(computer_name=self.cifs_server.cifs_server_name,
2338 mover_name=self.mover.mover_name,
2339 is_vdm=False)
2341 context.delete(computer_name=self.cifs_server.cifs_server_name,
2342 mover_name=self.vdm.vdm_name)
2344 expected_calls = [
2345 mock.call(self.mover.req_get_ref()),
2346 mock.call(self.cifs_server.req_get(self.mover.mover_id, False)),
2347 mock.call(self.cifs_server.req_delete(self.mover.mover_id, False)),
2348 mock.call(self.vdm.req_get()),
2349 mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
2350 mock.call(self.cifs_server.req_delete(self.vdm.vdm_id)),
2351 ]
2352 context.conn['XML'].request.assert_has_calls(expected_calls)
2354 def test_delete_cifs_server_but_not_found(self):
2355 self.hook.append(self.mover.resp_get_without_value())
2356 self.hook.append(self.mover.resp_get_ref_succeed())
2357 self.hook.append(self.cifs_server.resp_get_without_value())
2359 context = self.manager.getStorageContext('CIFSServer')
2360 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2362 context.delete(computer_name=self.cifs_server.cifs_server_name,
2363 mover_name=self.mover.mover_name,
2364 is_vdm=False)
2366 context.delete(computer_name=self.cifs_server.cifs_server_name,
2367 mover_name=self.mover.mover_name,
2368 is_vdm=False)
2370 expected_calls = [
2371 mock.call(self.mover.req_get_ref()),
2372 mock.call(self.mover.req_get_ref()),
2373 mock.call(self.cifs_server.req_get(self.mover.mover_id, False)),
2374 ]
2375 context.conn['XML'].request.assert_has_calls(expected_calls)
2377 def test_delete_cifs_server_with_error(self):
2378 self.hook.append(self.mover.resp_get_ref_succeed())
2379 self.hook.append(self.cifs_server.resp_get_succeed(
2380 mover_id=self.mover.mover_id, is_vdm=False, join_domain=True))
2381 self.hook.append(self.cifs_server.resp_task_error())
2383 context = self.manager.getStorageContext('CIFSServer')
2384 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2386 self.assertRaises(exception.EMCVnxXMLAPIError,
2387 context.delete,
2388 computer_name=self.cifs_server.cifs_server_name,
2389 mover_name=self.mover.mover_name,
2390 is_vdm=False)
2392 expected_calls = [
2393 mock.call(self.mover.req_get_ref()),
2394 mock.call(self.cifs_server.req_get(self.mover.mover_id, False)),
2395 mock.call(self.cifs_server.req_delete(self.mover.mover_id, False)),
2396 ]
2397 context.conn['XML'].request.assert_has_calls(expected_calls)
2400class CIFSShareTestCase(StorageObjectTestCaseBase):
2401 def setUp(self):
2402 super(CIFSShareTestCase, self).setUp()
2403 self.hook = utils.RequestSideEffect()
2404 self.ssh_hook = utils.SSHSideEffect()
2406 def test_create_cifs_share(self):
2407 self.hook.append(self.vdm.resp_get_succeed())
2408 self.hook.append(self.cifs_share.resp_task_succeed())
2409 self.hook.append(self.mover.resp_get_ref_succeed())
2410 self.hook.append(self.cifs_share.resp_task_succeed())
2412 context = self.manager.getStorageContext('CIFSShare')
2413 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2415 context.create(name=self.cifs_share.share_name,
2416 server_name=self.cifs_share.cifs_server_name[-14:],
2417 mover_name=self.vdm.vdm_name,
2418 is_vdm=True)
2420 context.create(name=self.cifs_share.share_name,
2421 server_name=self.cifs_share.cifs_server_name[-14:],
2422 mover_name=self.mover.mover_name,
2423 is_vdm=False)
2425 expected_calls = [
2426 mock.call(self.vdm.req_get()),
2427 mock.call(self.cifs_share.req_create(self.vdm.vdm_id)),
2428 mock.call(self.mover.req_get_ref()),
2429 mock.call(self.cifs_share.req_create(self.mover.mover_id, False)),
2430 ]
2431 context.conn['XML'].request.assert_has_calls(expected_calls)
2433 @mock.patch('time.sleep')
2434 def test_create_cifs_share_invalid_mover_id(self, sleep_mock):
2435 self.hook.append(self.mover.resp_get_ref_succeed())
2436 self.hook.append(self.cifs_share.resp_invalid_mover_id())
2437 self.hook.append(self.mover.resp_get_ref_succeed())
2438 self.hook.append(self.cifs_share.resp_task_succeed())
2440 context = self.manager.getStorageContext('CIFSShare')
2441 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2443 context.create(name=self.cifs_share.share_name,
2444 server_name=self.cifs_share.cifs_server_name[-14:],
2445 mover_name=self.mover.mover_name,
2446 is_vdm=False)
2448 expected_calls = [
2449 mock.call(self.mover.req_get_ref()),
2450 mock.call(self.cifs_share.req_create(self.mover.mover_id, False)),
2451 mock.call(self.mover.req_get_ref()),
2452 mock.call(self.cifs_share.req_create(self.mover.mover_id, False)),
2453 ]
2454 context.conn['XML'].request.assert_has_calls(expected_calls)
2456 self.assertTrue(sleep_mock.called)
2458 def test_create_cifs_share_with_error(self):
2459 self.hook.append(self.vdm.resp_get_succeed())
2460 self.hook.append(self.cifs_share.resp_task_error())
2462 context = self.manager.getStorageContext('CIFSShare')
2463 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2465 self.assertRaises(exception.EMCVnxXMLAPIError,
2466 context.create,
2467 name=self.cifs_share.share_name,
2468 server_name=self.cifs_share.cifs_server_name[-14:],
2469 mover_name=self.vdm.vdm_name,
2470 is_vdm=True)
2472 expected_calls = [
2473 mock.call(self.vdm.req_get()),
2474 mock.call(self.cifs_share.req_create(self.vdm.vdm_id)),
2475 ]
2476 context.conn['XML'].request.assert_has_calls(expected_calls)
2478 def test_delete_cifs_share(self):
2479 self.hook.append(self.cifs_share.resp_get_succeed(self.vdm.vdm_id))
2480 self.hook.append(self.vdm.resp_get_succeed())
2481 self.hook.append(self.cifs_share.resp_task_succeed())
2482 self.hook.append(self.cifs_share.resp_get_succeed(self.mover.mover_id,
2483 False))
2484 self.hook.append(self.mover.resp_get_ref_succeed())
2485 self.hook.append(self.cifs_share.resp_task_succeed())
2487 context = self.manager.getStorageContext('CIFSShare')
2488 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2490 context.delete(name=self.cifs_share.share_name,
2491 mover_name=self.vdm.vdm_name,
2492 is_vdm=True)
2494 context.delete(name=self.cifs_share.share_name,
2495 mover_name=self.mover.mover_name,
2496 is_vdm=False)
2498 expected_calls = [
2499 mock.call(self.cifs_share.req_get()),
2500 mock.call(self.vdm.req_get()),
2501 mock.call(self.cifs_share.req_delete(self.vdm.vdm_id)),
2502 mock.call(self.cifs_share.req_get()),
2503 mock.call(self.mover.req_get_ref()),
2504 mock.call(self.cifs_share.req_delete(self.mover.mover_id, False)),
2505 ]
2506 context.conn['XML'].request.assert_has_calls(expected_calls)
2508 def test_delete_cifs_share_not_found(self):
2509 self.hook.append(self.cifs_share.resp_get_error())
2510 self.hook.append(self.cifs_share.resp_get_without_value())
2512 context = self.manager.getStorageContext('CIFSShare')
2513 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2515 self.assertRaises(exception.EMCVnxXMLAPIError,
2516 context.delete,
2517 name=self.cifs_share.share_name,
2518 mover_name=self.vdm.vdm_name,
2519 is_vdm=True)
2521 context.delete(name=self.cifs_share.share_name,
2522 mover_name=self.vdm.vdm_name,
2523 is_vdm=True)
2525 expected_calls = [
2526 mock.call(self.cifs_share.req_get()),
2527 mock.call(self.cifs_share.req_get()),
2528 ]
2529 context.conn['XML'].request.assert_has_calls(expected_calls)
2531 @mock.patch('time.sleep')
2532 def test_delete_cifs_share_invalid_mover_id(self, sleep_mock):
2533 self.hook.append(self.cifs_share.resp_get_succeed(self.mover.mover_id,
2534 False))
2535 self.hook.append(self.mover.resp_get_ref_succeed())
2536 self.hook.append(self.cifs_share.resp_invalid_mover_id())
2537 self.hook.append(self.mover.resp_get_ref_succeed())
2538 self.hook.append(self.cifs_share.resp_task_succeed())
2540 context = self.manager.getStorageContext('CIFSShare')
2541 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2543 context.delete(name=self.cifs_share.share_name,
2544 mover_name=self.mover.mover_name,
2545 is_vdm=False)
2547 expected_calls = [
2548 mock.call(self.cifs_share.req_get()),
2549 mock.call(self.mover.req_get_ref()),
2550 mock.call(self.cifs_share.req_delete(self.mover.mover_id, False)),
2551 mock.call(self.mover.req_get_ref()),
2552 mock.call(self.cifs_share.req_delete(self.mover.mover_id, False)),
2553 ]
2554 context.conn['XML'].request.assert_has_calls(expected_calls)
2556 self.assertTrue(sleep_mock.called)
2558 def test_delete_cifs_share_with_error(self):
2559 self.hook.append(self.cifs_share.resp_get_succeed(self.vdm.vdm_id))
2560 self.hook.append(self.vdm.resp_get_succeed())
2561 self.hook.append(self.cifs_share.resp_task_error())
2563 context = self.manager.getStorageContext('CIFSShare')
2564 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2566 self.assertRaises(exception.EMCVnxXMLAPIError,
2567 context.delete,
2568 name=self.cifs_share.share_name,
2569 mover_name=self.vdm.vdm_name,
2570 is_vdm=True)
2572 expected_calls = [
2573 mock.call(self.cifs_share.req_get()),
2574 mock.call(self.vdm.req_get()),
2575 mock.call(self.cifs_share.req_delete(self.vdm.vdm_id)),
2576 ]
2577 context.conn['XML'].request.assert_has_calls(expected_calls)
2579 def test_get_cifs_share(self):
2580 self.hook.append(self.cifs_share.resp_get_succeed(self.vdm.vdm_id))
2582 context = self.manager.getStorageContext('CIFSShare')
2583 context.conn['XML'].request = utils.EMCMock(side_effect=self.hook)
2585 context.get(self.cifs_share.share_name)
2587 expected_calls = [mock.call(self.cifs_share.req_get())]
2588 context.conn['XML'].request.assert_has_calls(expected_calls)
2590 def test_disable_share_access(self):
2591 self.ssh_hook.append('Command succeeded')
2593 context = self.manager.getStorageContext('CIFSShare')
2594 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2596 context.disable_share_access(share_name=self.cifs_share.share_name,
2597 mover_name=self.vdm.vdm_name)
2599 ssh_calls = [mock.call(self.cifs_share.cmd_disable_access(), True)]
2600 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2602 def test_disable_share_access_with_error(self):
2603 self.ssh_hook.append(ex=processutils.ProcessExecutionError(
2604 stdout=self.cifs_share.fake_output))
2606 context = self.manager.getStorageContext('CIFSShare')
2607 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2609 self.assertRaises(exception.EMCVnxXMLAPIError,
2610 context.disable_share_access,
2611 share_name=self.cifs_share.share_name,
2612 mover_name=self.vdm.vdm_name)
2614 ssh_calls = [mock.call(self.cifs_share.cmd_disable_access(), True)]
2615 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2617 def test_allow_share_access(self):
2618 self.ssh_hook.append(self.cifs_share.output_allow_access())
2620 context = self.manager.getStorageContext('CIFSShare')
2621 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2623 context.allow_share_access(mover_name=self.vdm.vdm_name,
2624 share_name=self.cifs_share.share_name,
2625 user_name=self.cifs_server.domain_user,
2626 domain=self.cifs_server.domain_name,
2627 access=constants.CIFS_ACL_FULLCONTROL)
2629 ssh_calls = [mock.call(self.cifs_share.cmd_change_access(), True)]
2630 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2632 def test_allow_share_access_duplicate_ACE(self):
2633 expt_dup_ace = processutils.ProcessExecutionError(
2634 stdout=self.cifs_share.output_allow_access_but_duplicate_ace())
2635 self.ssh_hook.append(ex=expt_dup_ace)
2637 context = self.manager.getStorageContext('CIFSShare')
2638 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2640 context.allow_share_access(mover_name=self.vdm.vdm_name,
2641 share_name=self.cifs_share.share_name,
2642 user_name=self.cifs_server.domain_user,
2643 domain=self.cifs_server.domain_name,
2644 access=constants.CIFS_ACL_FULLCONTROL)
2646 ssh_calls = [mock.call(self.cifs_share.cmd_change_access(), True)]
2647 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2649 def test_allow_share_access_with_error(self):
2650 expt_err = processutils.ProcessExecutionError(
2651 self.cifs_share.fake_output)
2652 self.ssh_hook.append(ex=expt_err)
2654 context = self.manager.getStorageContext('CIFSShare')
2655 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2657 self.assertRaises(exception.EMCVnxXMLAPIError,
2658 context.allow_share_access,
2659 mover_name=self.vdm.vdm_name,
2660 share_name=self.cifs_share.share_name,
2661 user_name=self.cifs_server.domain_user,
2662 domain=self.cifs_server.domain_name,
2663 access=constants.CIFS_ACL_FULLCONTROL)
2665 ssh_calls = [mock.call(self.cifs_share.cmd_change_access(), True)]
2666 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2668 def test_deny_share_access(self):
2669 self.ssh_hook.append('Command succeeded')
2671 context = self.manager.getStorageContext('CIFSShare')
2672 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2674 context.deny_share_access(mover_name=self.vdm.vdm_name,
2675 share_name=self.cifs_share.share_name,
2676 user_name=self.cifs_server.domain_user,
2677 domain=self.cifs_server.domain_name,
2678 access=constants.CIFS_ACL_FULLCONTROL)
2680 ssh_calls = [
2681 mock.call(self.cifs_share.cmd_change_access(action='revoke'),
2682 True),
2683 ]
2684 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2686 def test_deny_share_access_no_ace(self):
2687 expt_no_ace = processutils.ProcessExecutionError(
2688 stdout=self.cifs_share.output_deny_access_but_no_ace())
2689 self.ssh_hook.append(ex=expt_no_ace)
2691 context = self.manager.getStorageContext('CIFSShare')
2692 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2694 context.deny_share_access(mover_name=self.vdm.vdm_name,
2695 share_name=self.cifs_share.share_name,
2696 user_name=self.cifs_server.domain_user,
2697 domain=self.cifs_server.domain_name,
2698 access=constants.CIFS_ACL_FULLCONTROL)
2700 ssh_calls = [
2701 mock.call(self.cifs_share.cmd_change_access(action='revoke'),
2702 True),
2703 ]
2704 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2706 def test_deny_share_access_but_no_user_found(self):
2707 expt_no_user = processutils.ProcessExecutionError(
2708 stdout=self.cifs_share.output_deny_access_but_no_user_found())
2709 self.ssh_hook.append(ex=expt_no_user)
2711 context = self.manager.getStorageContext('CIFSShare')
2712 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2714 context.deny_share_access(mover_name=self.vdm.vdm_name,
2715 share_name=self.cifs_share.share_name,
2716 user_name=self.cifs_server.domain_user,
2717 domain=self.cifs_server.domain_name,
2718 access=constants.CIFS_ACL_FULLCONTROL)
2720 ssh_calls = [
2721 mock.call(self.cifs_share.cmd_change_access(action='revoke'),
2722 True),
2723 ]
2724 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2726 def test_deny_share_access_with_error(self):
2727 expt_err = processutils.ProcessExecutionError(
2728 self.cifs_share.fake_output)
2729 self.ssh_hook.append(ex=expt_err)
2731 context = self.manager.getStorageContext('CIFSShare')
2732 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2734 self.assertRaises(exception.EMCVnxXMLAPIError,
2735 context.deny_share_access,
2736 mover_name=self.vdm.vdm_name,
2737 share_name=self.cifs_share.share_name,
2738 user_name=self.cifs_server.domain_user,
2739 domain=self.cifs_server.domain_name,
2740 access=constants.CIFS_ACL_FULLCONTROL)
2742 ssh_calls = [
2743 mock.call(self.cifs_share.cmd_change_access(action='revoke'),
2744 True),
2745 ]
2746 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2748 def test_get_share_access(self):
2749 self.ssh_hook.append(fakes.FakeData.cifs_access)
2751 context = self.manager.getStorageContext('CIFSShare')
2752 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2754 ret = context.get_share_access(
2755 mover_name=self.vdm.vdm_name,
2756 share_name=self.cifs_share.share_name)
2758 ssh_calls = [
2759 mock.call(self.cifs_share.cmd_get_access(), True),
2760 ]
2761 self.assertEqual(2, len(ret))
2762 self.assertEqual(constants.CIFS_ACL_FULLCONTROL, ret['administrator'])
2763 self.assertEqual(constants.CIFS_ACL_FULLCONTROL, ret['guest'])
2764 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2766 def test_get_share_access_failed(self):
2767 expt_err = processutils.ProcessExecutionError(
2768 stdout=self.nfs_share.fake_output)
2769 self.ssh_hook.append(ex=expt_err)
2771 context = self.manager.getStorageContext('CIFSShare')
2772 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2774 self.assertRaises(exception.EMCVnxXMLAPIError,
2775 context.get_share_access,
2776 mover_name=self.vdm.vdm_name,
2777 share_name=self.cifs_share.share_name)
2779 ssh_calls = [
2780 mock.call(self.cifs_share.cmd_get_access(), True),
2781 ]
2782 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2784 def test_clear_share_access_has_white_list(self):
2785 self.ssh_hook.append(fakes.FakeData.cifs_access)
2786 self.ssh_hook.append('Command succeeded')
2788 context = self.manager.getStorageContext('CIFSShare')
2789 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2791 to_remove = context.clear_share_access(
2792 mover_name=self.vdm.vdm_name,
2793 share_name=self.cifs_share.share_name,
2794 domain=self.cifs_server.domain_name,
2795 white_list_users=['guest'])
2797 ssh_calls = [
2798 mock.call(self.cifs_share.cmd_get_access(), True),
2799 mock.call(self.cifs_share.cmd_change_access(action='revoke'),
2800 True),
2801 ]
2802 self.assertEqual({'administrator'}, to_remove)
2803 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2806class NFSShareTestCase(StorageObjectTestCaseBase):
2807 def setUp(self):
2808 super(NFSShareTestCase, self).setUp()
2809 self.ssh_hook = utils.SSHSideEffect()
2811 def test_create_nfs_share(self):
2812 self.ssh_hook.append(self.nfs_share.output_create())
2814 context = self.manager.getStorageContext('NFSShare')
2815 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2817 context.create(name=self.nfs_share.share_name,
2818 mover_name=self.vdm.vdm_name)
2820 ssh_calls = [mock.call(self.nfs_share.cmd_create(), True)]
2821 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2823 def test_create_nfs_share_with_error(self):
2824 expt_err = processutils.ProcessExecutionError(
2825 stdout=self.nfs_share.fake_output)
2826 self.ssh_hook.append(ex=expt_err)
2828 context = self.manager.getStorageContext('NFSShare')
2829 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2831 self.assertRaises(exception.EMCVnxXMLAPIError,
2832 context.create,
2833 name=self.nfs_share.share_name,
2834 mover_name=self.vdm.vdm_name)
2836 ssh_calls = [mock.call(self.nfs_share.cmd_create(), True)]
2837 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2839 def test_delete_nfs_share(self):
2840 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2841 rw_hosts=self.nfs_share.rw_hosts,
2842 ro_hosts=self.nfs_share.ro_hosts))
2843 self.ssh_hook.append(self.nfs_share.output_delete_succeed())
2845 context = self.manager.getStorageContext('NFSShare')
2846 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2848 context.delete(name=self.nfs_share.share_name,
2849 mover_name=self.vdm.vdm_name)
2851 ssh_calls = [
2852 mock.call(self.nfs_share.cmd_get(), False),
2853 mock.call(self.nfs_share.cmd_delete(), True),
2854 ]
2855 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2857 def test_delete_nfs_share_not_found(self):
2858 expt_not_found = processutils.ProcessExecutionError(
2859 stdout=self.nfs_share.output_get_but_not_found())
2860 self.ssh_hook.append(ex=expt_not_found)
2862 context = self.manager.getStorageContext('NFSShare')
2863 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2865 context.delete(name=self.nfs_share.share_name,
2866 mover_name=self.vdm.vdm_name)
2868 ssh_calls = [mock.call(self.nfs_share.cmd_get(), False)]
2869 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2871 @mock.patch('time.sleep')
2872 def test_delete_nfs_share_locked(self, sleep_mock):
2873 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2874 rw_hosts=self.nfs_share.rw_hosts,
2875 ro_hosts=self.nfs_share.ro_hosts))
2876 expt_locked = processutils.ProcessExecutionError(
2877 stdout=self.nfs_share.output_delete_but_locked())
2878 self.ssh_hook.append(ex=expt_locked)
2879 self.ssh_hook.append(self.nfs_share.output_delete_succeed())
2881 context = self.manager.getStorageContext('NFSShare')
2882 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2884 context.delete(name=self.nfs_share.share_name,
2885 mover_name=self.vdm.vdm_name)
2887 ssh_calls = [
2888 mock.call(self.nfs_share.cmd_get(), False),
2889 mock.call(self.nfs_share.cmd_delete(), True),
2890 mock.call(self.nfs_share.cmd_delete(), True),
2891 ]
2892 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2894 self.assertTrue(sleep_mock.called)
2896 def test_delete_nfs_share_with_error(self):
2897 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2898 rw_hosts=self.nfs_share.rw_hosts,
2899 ro_hosts=self.nfs_share.ro_hosts))
2900 expt_err = processutils.ProcessExecutionError(
2901 stdout=self.nfs_share.fake_output)
2902 self.ssh_hook.append(ex=expt_err)
2904 context = self.manager.getStorageContext('NFSShare')
2905 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2907 self.assertRaises(exception.EMCVnxXMLAPIError,
2908 context.delete,
2909 name=self.nfs_share.share_name,
2910 mover_name=self.vdm.vdm_name)
2912 ssh_calls = [
2913 mock.call(self.nfs_share.cmd_get(), False),
2914 mock.call(self.nfs_share.cmd_delete(), True),
2915 ]
2916 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2918 def test_get_nfs_share(self):
2919 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2920 rw_hosts=self.nfs_share.rw_hosts,
2921 ro_hosts=self.nfs_share.ro_hosts))
2923 context = self.manager.getStorageContext('NFSShare')
2924 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2926 context.get(name=self.nfs_share.share_name,
2927 mover_name=self.vdm.vdm_name)
2929 # Get NFS share from cache
2930 context.get(name=self.nfs_share.share_name,
2931 mover_name=self.vdm.vdm_name)
2933 ssh_calls = [mock.call(self.nfs_share.cmd_get(), False)]
2934 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2936 def test_get_nfs_share_not_found(self):
2937 expt_not_found = processutils.ProcessExecutionError(
2938 stdout=self.nfs_share.output_get_but_not_found())
2939 self.ssh_hook.append(ex=expt_not_found)
2940 self.ssh_hook.append(self.nfs_share.output_get_but_not_found())
2942 context = self.manager.getStorageContext('NFSShare')
2943 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2945 context.get(name=self.nfs_share.share_name,
2946 mover_name=self.vdm.vdm_name)
2948 context.get(name=self.nfs_share.share_name,
2949 mover_name=self.vdm.vdm_name)
2951 ssh_calls = [
2952 mock.call(self.nfs_share.cmd_get(), False),
2953 mock.call(self.nfs_share.cmd_get(), False),
2954 ]
2955 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2957 def test_get_nfs_share_with_error(self):
2958 expt_err = processutils.ProcessExecutionError(
2959 stdout=self.nfs_share.fake_output)
2960 self.ssh_hook.append(ex=expt_err)
2962 context = self.manager.getStorageContext('NFSShare')
2963 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
2965 self.assertRaises(exception.EMCVnxXMLAPIError,
2966 context.get,
2967 name=self.nfs_share.share_name,
2968 mover_name=self.vdm.vdm_name)
2970 ssh_calls = [mock.call(self.nfs_share.cmd_get(), False)]
2971 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
2973 def test_allow_share_access(self):
2974 rw_hosts = copy.deepcopy(self.nfs_share.rw_hosts)
2975 rw_hosts.append(self.nfs_share.nfs_host_ip)
2977 ro_hosts = copy.deepcopy(self.nfs_share.ro_hosts)
2978 ro_hosts.append(self.nfs_share.nfs_host_ip)
2980 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2981 rw_hosts=self.nfs_share.rw_hosts,
2982 ro_hosts=self.nfs_share.ro_hosts))
2983 self.ssh_hook.append(self.nfs_share.output_set_access_success())
2984 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2985 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts))
2986 self.ssh_hook.append(self.nfs_share.output_set_access_success())
2987 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2988 rw_hosts=self.nfs_share.rw_hosts, ro_hosts=ro_hosts))
2989 self.ssh_hook.append(self.nfs_share.output_set_access_success())
2990 self.ssh_hook.append(self.nfs_share.output_get_succeed(
2991 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts))
2993 context = self.manager.getStorageContext('NFSShare')
2994 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
2995 side_effect=self.ssh_hook)
2997 context.allow_share_access(share_name=self.nfs_share.share_name,
2998 host_ip=self.nfs_share.nfs_host_ip,
2999 mover_name=self.vdm.vdm_name,
3000 access_level=const.ACCESS_LEVEL_RW)
3002 context.allow_share_access(share_name=self.nfs_share.share_name,
3003 host_ip=self.nfs_share.nfs_host_ip,
3004 mover_name=self.vdm.vdm_name,
3005 access_level=const.ACCESS_LEVEL_RO)
3007 context.allow_share_access(share_name=self.nfs_share.share_name,
3008 host_ip=self.nfs_share.nfs_host_ip,
3009 mover_name=self.vdm.vdm_name,
3010 access_level=const.ACCESS_LEVEL_RW)
3012 context.allow_share_access(share_name=self.nfs_share.share_name,
3013 host_ip=self.nfs_share.nfs_host_ip,
3014 mover_name=self.vdm.vdm_name,
3015 access_level=const.ACCESS_LEVEL_RW)
3017 ssh_calls = [
3018 mock.call(self.nfs_share.cmd_get()),
3019 mock.call(self.nfs_share.cmd_set_access(
3020 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts)),
3021 mock.call(self.nfs_share.cmd_get()),
3022 mock.call(self.nfs_share.cmd_set_access(
3023 rw_hosts=self.nfs_share.rw_hosts, ro_hosts=ro_hosts)),
3024 mock.call(self.nfs_share.cmd_get()),
3025 mock.call(self.nfs_share.cmd_set_access(
3026 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts)),
3027 mock.call(self.nfs_share.cmd_get()),
3028 ]
3029 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3031 def test_allow_share_access_not_found(self):
3032 expt_not_found = processutils.ProcessExecutionError(
3033 stdout=self.nfs_share.output_get_but_not_found())
3034 self.ssh_hook.append(ex=expt_not_found)
3036 context = self.manager.getStorageContext('NFSShare')
3037 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
3038 side_effect=self.ssh_hook)
3040 self.assertRaises(exception.EMCVnxXMLAPIError,
3041 context.allow_share_access,
3042 share_name=self.nfs_share.share_name,
3043 host_ip=self.nfs_share.nfs_host_ip,
3044 mover_name=self.vdm.vdm_name,
3045 access_level=const.ACCESS_LEVEL_RW)
3047 ssh_calls = [mock.call(self.nfs_share.cmd_get())]
3048 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3050 def test_deny_rw_share_access(self):
3051 rw_hosts = copy.deepcopy(self.nfs_share.rw_hosts)
3052 rw_hosts.append(self.nfs_share.nfs_host_ip)
3054 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3055 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts))
3056 self.ssh_hook.append(self.nfs_share.output_set_access_success())
3057 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3058 rw_hosts=self.nfs_share.rw_hosts,
3059 ro_hosts=self.nfs_share.ro_hosts))
3061 context = self.manager.getStorageContext('NFSShare')
3062 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
3063 side_effect=self.ssh_hook)
3065 context.deny_share_access(share_name=self.nfs_share.share_name,
3066 host_ip=self.nfs_share.nfs_host_ip,
3067 mover_name=self.vdm.vdm_name)
3069 ssh_calls = [
3070 mock.call(self.nfs_share.cmd_get()),
3071 mock.call(self.nfs_share.cmd_set_access(self.nfs_share.rw_hosts,
3072 self.nfs_share.ro_hosts)),
3073 mock.call(self.nfs_share.cmd_get()),
3074 ]
3075 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3077 def test_clear_share_access(self):
3078 hosts = ['192.168.1.1', '192.168.1.3']
3080 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3081 rw_hosts=self.nfs_share.rw_hosts,
3082 ro_hosts=self.nfs_share.ro_hosts))
3083 self.ssh_hook.append(self.nfs_share.output_set_access_success())
3084 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3085 rw_hosts=[hosts[0]], ro_hosts=[hosts[1]]))
3087 context = self.manager.getStorageContext('NFSShare')
3088 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
3089 side_effect=self.ssh_hook)
3091 context.clear_share_access(share_name=self.nfs_share.share_name,
3092 mover_name=self.vdm.vdm_name,
3093 white_list_hosts=hosts)
3095 ssh_calls = [
3096 mock.call(self.nfs_share.cmd_get()),
3097 mock.call(self.nfs_share.cmd_set_access(
3098 rw_hosts=[hosts[0]], ro_hosts=[hosts[1]])),
3099 mock.call(self.nfs_share.cmd_get()),
3100 ]
3101 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3103 def test_deny_ro_share_access(self):
3104 ro_hosts = copy.deepcopy(self.nfs_share.ro_hosts)
3105 ro_hosts.append(self.nfs_share.nfs_host_ip)
3107 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3108 rw_hosts=self.nfs_share.rw_hosts, ro_hosts=ro_hosts))
3109 self.ssh_hook.append(self.nfs_share.output_set_access_success())
3110 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3111 rw_hosts=self.nfs_share.rw_hosts,
3112 ro_hosts=self.nfs_share.ro_hosts))
3114 context = self.manager.getStorageContext('NFSShare')
3115 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
3116 side_effect=self.ssh_hook)
3118 context.deny_share_access(share_name=self.nfs_share.share_name,
3119 host_ip=self.nfs_share.nfs_host_ip,
3120 mover_name=self.vdm.vdm_name)
3122 context.deny_share_access(share_name=self.nfs_share.share_name,
3123 host_ip=self.nfs_share.nfs_host_ip,
3124 mover_name=self.vdm.vdm_name)
3126 ssh_calls = [
3127 mock.call(self.nfs_share.cmd_get()),
3128 mock.call(self.nfs_share.cmd_set_access(self.nfs_share.rw_hosts,
3129 self.nfs_share.ro_hosts)),
3130 mock.call(self.nfs_share.cmd_get()),
3131 ]
3132 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3134 def test_deny_share_not_found(self):
3135 expt_not_found = processutils.ProcessExecutionError(
3136 stdout=self.nfs_share.output_get_but_not_found())
3137 self.ssh_hook.append(ex=expt_not_found)
3139 context = self.manager.getStorageContext('NFSShare')
3140 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
3141 side_effect=self.ssh_hook)
3143 self.assertRaises(exception.EMCVnxXMLAPIError,
3144 context.deny_share_access,
3145 share_name=self.nfs_share.share_name,
3146 host_ip=self.nfs_share.nfs_host_ip,
3147 mover_name=self.vdm.vdm_name)
3149 ssh_calls = [mock.call(self.nfs_share.cmd_get())]
3150 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3152 def test_deny_rw_share_with_error(self):
3153 rw_hosts = copy.deepcopy(self.nfs_share.rw_hosts)
3154 rw_hosts.append(self.nfs_share.nfs_host_ip)
3156 self.ssh_hook.append(self.nfs_share.output_get_succeed(
3157 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts))
3158 expt_not_found = processutils.ProcessExecutionError(
3159 stdout=self.nfs_share.output_get_but_not_found())
3160 self.ssh_hook.append(ex=expt_not_found)
3162 context = self.manager.getStorageContext('NFSShare')
3163 context.conn['SSH'].run_ssh = utils.EMCNFSShareMock(
3164 side_effect=self.ssh_hook)
3166 self.assertRaises(exception.EMCVnxXMLAPIError,
3167 context.deny_share_access,
3168 share_name=self.nfs_share.share_name,
3169 host_ip=self.nfs_share.nfs_host_ip,
3170 mover_name=self.vdm.vdm_name)
3172 ssh_calls = [
3173 mock.call(self.nfs_share.cmd_get()),
3174 mock.call(self.nfs_share.cmd_set_access(self.nfs_share.rw_hosts,
3175 self.nfs_share.ro_hosts)),
3176 ]
3177 context.conn['SSH'].run_ssh.assert_has_calls(ssh_calls)
3179 def test_clear_share_access_failed_to_get_share(self):
3180 self.ssh_hook.append("no output.")
3182 context = self.manager.getStorageContext('NFSShare')
3183 context.conn['SSH'].run_ssh = mock.Mock(side_effect=self.ssh_hook)
3185 self.assertRaises(exception.EMCVnxXMLAPIError,
3186 context.clear_share_access,
3187 share_name=self.nfs_share.share_name,
3188 mover_name=self.vdm.vdm_name,
3189 white_list_hosts=None)
3191 context.conn['SSH'].run_ssh.assert_called_once_with(
3192 self.nfs_share.cmd_get(), False)