"Fossies" - the Fresh Open Source Software Archive

Member "manila-8.1.4/manila/tests/share/drivers/dell_emc/plugins/vnx/test_connection.py" (19 Nov 2020, 97975 Bytes) of package /linux/misc/openstack/manila-8.1.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_connection.py": 8.1.3_vs_8.1.4.

    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.
   15 
   16 import copy
   17 
   18 import ddt
   19 import mock
   20 from oslo_log import log
   21 
   22 from manila import exception
   23 from manila.share.drivers.dell_emc.common.enas import connector
   24 from manila.share.drivers.dell_emc.common.enas import utils as enas_utils
   25 from manila.share.drivers.dell_emc.plugins.vnx import connection
   26 from manila.share.drivers.dell_emc.plugins.vnx import object_manager
   27 from manila import test
   28 from manila.tests import fake_share
   29 from manila.tests.share.drivers.dell_emc.common.enas import fakes
   30 from manila.tests.share.drivers.dell_emc.common.enas import utils
   31 
   32 LOG = log.getLogger(__name__)
   33 
   34 
   35 @ddt.ddt
   36 class StorageConnectionTestCase(test.TestCase):
   37     @mock.patch.object(connector.XMLAPIConnector, "_do_setup", mock.Mock())
   38     def setUp(self):
   39         super(StorageConnectionTestCase, self).setUp()
   40         self.emc_share_driver = fakes.FakeEMCShareDriver()
   41 
   42         self.connection = connection.VNXStorageConnection(LOG)
   43 
   44         self.pool = fakes.PoolTestData()
   45         self.vdm = fakes.VDMTestData()
   46         self.mover = fakes.MoverTestData()
   47         self.fs = fakes.FileSystemTestData()
   48         self.mount = fakes.MountPointTestData()
   49         self.snap = fakes.SnapshotTestData()
   50         self.cifs_share = fakes.CIFSShareTestData()
   51         self.nfs_share = fakes.NFSShareTestData()
   52         self.cifs_server = fakes.CIFSServerTestData()
   53         self.dns = fakes.DNSDomainTestData()
   54 
   55         with mock.patch.object(connector.XMLAPIConnector, 'request',
   56                                mock.Mock()):
   57             self.connection.connect(self.emc_share_driver, None)
   58 
   59     def test_check_for_setup_error(self):
   60         hook = utils.RequestSideEffect()
   61         hook.append(self.mover.resp_get_ref_succeed())
   62         xml_req_mock = utils.EMCMock(side_effect=hook)
   63         self.connection.manager.connectors['XML'].request = xml_req_mock
   64 
   65         with mock.patch.object(connection.VNXStorageConnection,
   66                                '_get_managed_storage_pools',
   67                                mock.Mock()):
   68             self.connection.check_for_setup_error()
   69 
   70         expected_calls = [mock.call(self.mover.req_get_ref())]
   71         xml_req_mock.assert_has_calls(expected_calls)
   72 
   73     def test_check_for_setup_error_with_invalid_mover_name(self):
   74         hook = utils.RequestSideEffect()
   75         hook.append(self.mover.resp_get_error())
   76         xml_req_mock = utils.EMCMock(side_effect=hook)
   77         self.connection.manager.connectors['XML'].request = xml_req_mock
   78 
   79         self.assertRaises(exception.InvalidParameterValue,
   80                           self.connection.check_for_setup_error)
   81 
   82         expected_calls = [mock.call(self.mover.req_get_ref())]
   83         xml_req_mock.assert_has_calls(expected_calls)
   84 
   85     @ddt.data({'pool_conf': None,
   86                'real_pools': ['fake_pool', 'nas_pool'],
   87                'matched_pool': set()},
   88               {'pool_conf': [],
   89                'real_pools': ['fake_pool', 'nas_pool'],
   90                'matched_pool': set()},
   91               {'pool_conf': ['*'],
   92                'real_pools': ['fake_pool', 'nas_pool'],
   93                'matched_pool': {'fake_pool', 'nas_pool'}},
   94               {'pool_conf': ['fake_*'],
   95                'real_pools': ['fake_pool', 'nas_pool', 'Perf_Pool'],
   96                'matched_pool': {'fake_pool'}},
   97               {'pool_conf': ['*pool'],
   98                'real_pools': ['fake_pool', 'NAS_Pool', 'Perf_POOL'],
   99                'matched_pool': {'fake_pool'}},
  100               {'pool_conf': ['nas_pool'],
  101                'real_pools': ['fake_pool', 'nas_pool', 'perf_pool'],
  102                'matched_pool': {'nas_pool'}})
  103     @ddt.unpack
  104     def test__get_managed_storage_pools(self, pool_conf, real_pools,
  105                                         matched_pool):
  106         with mock.patch.object(object_manager.StoragePool,
  107                                'get_all',
  108                                mock.Mock(return_value=('ok', real_pools))):
  109             pool = self.connection._get_managed_storage_pools(pool_conf)
  110             self.assertEqual(matched_pool, pool)
  111 
  112     def test__get_managed_storage_pools_failed_to_get_pool_info(self):
  113         hook = utils.RequestSideEffect()
  114         hook.append(self.pool.resp_get_error())
  115         xml_req_mock = utils.EMCMock(side_effect=hook)
  116         self.connection.manager.connectors['XML'].request = xml_req_mock
  117 
  118         pool_conf = fakes.FakeData.pool_name
  119         self.assertRaises(exception.EMCVnxXMLAPIError,
  120                           self.connection._get_managed_storage_pools,
  121                           pool_conf)
  122 
  123         expected_calls = [mock.call(self.pool.req_get())]
  124         xml_req_mock.assert_has_calls(expected_calls)
  125 
  126     @ddt.data(
  127         {'pool_conf': ['fake_*'],
  128          'real_pools': ['nas_pool', 'Perf_Pool']},
  129         {'pool_conf': ['*pool'],
  130          'real_pools': ['NAS_Pool', 'Perf_POOL']},
  131         {'pool_conf': ['nas_pool'],
  132          'real_pools': ['fake_pool', 'perf_pool']},
  133     )
  134     @ddt.unpack
  135     def test__get_managed_storage_pools_without_matched_pool(self, pool_conf,
  136                                                              real_pools):
  137         with mock.patch.object(object_manager.StoragePool,
  138                                'get_all',
  139                                mock.Mock(return_value=('ok', real_pools))):
  140             self.assertRaises(exception.InvalidParameterValue,
  141                               self.connection._get_managed_storage_pools,
  142                               pool_conf)
  143 
  144     def test_create_cifs_share(self):
  145         share_server = fakes.SHARE_SERVER
  146         share = fakes.CIFS_SHARE
  147 
  148         hook = utils.RequestSideEffect()
  149         hook.append(self.vdm.resp_get_succeed())
  150         hook.append(self.cifs_server.resp_get_succeed(
  151             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
  152         hook.append(self.pool.resp_get_succeed())
  153         hook.append(self.fs.resp_task_succeed())
  154         hook.append(self.cifs_share.resp_task_succeed())
  155         xml_req_mock = utils.EMCMock(side_effect=hook)
  156         self.connection.manager.connectors['XML'].request = xml_req_mock
  157 
  158         ssh_hook = utils.SSHSideEffect()
  159         ssh_hook.append()
  160         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  161         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  162 
  163         location = self.connection.create_share(None, share, share_server)
  164 
  165         expected_calls = [
  166             mock.call(self.vdm.req_get()),
  167             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
  168             mock.call(self.pool.req_get()),
  169             mock.call(self.fs.req_create_on_vdm()),
  170             mock.call(self.cifs_share.req_create(self.vdm.vdm_id)),
  171         ]
  172         xml_req_mock.assert_has_calls(expected_calls)
  173 
  174         ssh_calls = [mock.call(self.cifs_share.cmd_disable_access(), True)]
  175         ssh_cmd_mock.assert_has_calls(ssh_calls)
  176 
  177         self.assertEqual(location, r'\\%s\%s' %
  178                          (fakes.FakeData.network_allocations_ip1,
  179                           share['name']),
  180                          'CIFS export path is incorrect')
  181 
  182     def test_create_cifs_share_with_ipv6(self):
  183         share_server = fakes.SHARE_SERVER_IPV6
  184         share = fakes.CIFS_SHARE
  185 
  186         hook = utils.RequestSideEffect()
  187         hook.append(self.vdm.resp_get_succeed(
  188             interface1=fakes.FakeData.interface_name3,
  189             interface2=fakes.FakeData.interface_name4))
  190         hook.append(self.cifs_server.resp_get_succeed(
  191             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
  192             ip_addr=fakes.FakeData.network_allocations_ip3))
  193         hook.append(self.pool.resp_get_succeed())
  194         hook.append(self.fs.resp_task_succeed())
  195         hook.append(self.cifs_share.resp_task_succeed())
  196         xml_req_mock = utils.EMCMock(side_effect=hook)
  197         self.connection.manager.connectors['XML'].request = xml_req_mock
  198 
  199         ssh_hook = utils.SSHSideEffect()
  200         ssh_hook.append()
  201         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  202         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  203 
  204         location = self.connection.create_share(None, share, share_server)
  205 
  206         expected_calls = [
  207             mock.call(self.vdm.req_get()),
  208             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
  209             mock.call(self.pool.req_get()),
  210             mock.call(self.fs.req_create_on_vdm()),
  211             mock.call(self.cifs_share.req_create(self.vdm.vdm_id)),
  212         ]
  213         xml_req_mock.assert_has_calls(expected_calls)
  214 
  215         ssh_calls = [mock.call(self.cifs_share.cmd_disable_access(), True)]
  216         ssh_cmd_mock.assert_has_calls(ssh_calls)
  217 
  218         self.assertEqual(location, r'\\%s.ipv6-literal.net\%s' %
  219                          (fakes.FakeData.network_allocations_ip3.replace(':',
  220                                                                          '-'),
  221                           share['name']),
  222                          'CIFS export path is incorrect')
  223 
  224     def test_create_nfs_share(self):
  225         share_server = fakes.SHARE_SERVER
  226         share = fakes.NFS_SHARE
  227 
  228         hook = utils.RequestSideEffect()
  229         hook.append(self.pool.resp_get_succeed())
  230         hook.append(self.vdm.resp_get_succeed())
  231         hook.append(self.fs.resp_task_succeed())
  232         xml_req_mock = utils.EMCMock(side_effect=hook)
  233         self.connection.manager.connectors['XML'].request = xml_req_mock
  234 
  235         ssh_hook = utils.SSHSideEffect()
  236         ssh_hook.append(self.nfs_share.output_create())
  237         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  238         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  239 
  240         location = self.connection.create_share(None, share, share_server)
  241 
  242         expected_calls = [
  243             mock.call(self.pool.req_get()),
  244             mock.call(self.vdm.req_get()),
  245             mock.call(self.fs.req_create_on_vdm()),
  246         ]
  247         xml_req_mock.assert_has_calls(expected_calls)
  248 
  249         ssh_calls = [mock.call(self.nfs_share.cmd_create(), True)]
  250         ssh_cmd_mock.assert_has_calls(ssh_calls)
  251 
  252         self.assertEqual(location, '192.168.1.2:/%s' % share['name'],
  253                          'NFS export path is incorrect')
  254 
  255     def test_create_nfs_share_with_ipv6(self):
  256         share_server = fakes.SHARE_SERVER_IPV6
  257         share = fakes.NFS_SHARE
  258 
  259         hook = utils.RequestSideEffect()
  260         hook.append(self.pool.resp_get_succeed())
  261         hook.append(self.vdm.resp_get_succeed(
  262             interface1=fakes.FakeData.interface_name3,
  263             interface2=fakes.FakeData.interface_name4))
  264         hook.append(self.fs.resp_task_succeed())
  265         xml_req_mock = utils.EMCMock(side_effect=hook)
  266         self.connection.manager.connectors['XML'].request = xml_req_mock
  267 
  268         ssh_hook = utils.SSHSideEffect()
  269         ssh_hook.append(self.nfs_share.output_create())
  270         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  271         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  272 
  273         location = self.connection.create_share(None, share, share_server)
  274 
  275         expected_calls = [
  276             mock.call(self.pool.req_get()),
  277             mock.call(self.vdm.req_get()),
  278             mock.call(self.fs.req_create_on_vdm()),
  279         ]
  280         xml_req_mock.assert_has_calls(expected_calls)
  281 
  282         ssh_calls = [mock.call(self.nfs_share.cmd_create(), True)]
  283         ssh_cmd_mock.assert_has_calls(ssh_calls)
  284 
  285         self.assertEqual(location, '[%s]:/%s' %
  286                          (fakes.FakeData.network_allocations_ip4,
  287                           share['name']),
  288                          'NFS export path is incorrect')
  289 
  290     def test_create_cifs_share_without_share_server(self):
  291         share = fakes.CIFS_SHARE
  292 
  293         self.assertRaises(exception.InvalidInput,
  294                           self.connection.create_share,
  295                           None, share, None)
  296 
  297     def test_create_cifs_share_without_share_server_name(self):
  298         share = fakes.CIFS_SHARE
  299         share_server = copy.deepcopy(fakes.SHARE_SERVER)
  300         share_server['backend_details']['share_server_name'] = None
  301 
  302         self.assertRaises(exception.EMCVnxXMLAPIError,
  303                           self.connection.create_share,
  304                           None, share, share_server)
  305 
  306     def test_create_cifs_share_with_invalide_cifs_server_name(self):
  307         share_server = fakes.SHARE_SERVER
  308         share = fakes.CIFS_SHARE
  309 
  310         hook = utils.RequestSideEffect()
  311         hook.append(self.vdm.resp_get_succeed())
  312         hook.append(self.cifs_server.resp_get_error())
  313         xml_req_mock = utils.EMCMock(side_effect=hook)
  314         self.connection.manager.connectors['XML'].request = xml_req_mock
  315 
  316         self.assertRaises(exception.EMCVnxXMLAPIError,
  317                           self.connection.create_share,
  318                           None, share, share_server)
  319 
  320         expected_calls = [
  321             mock.call(self.vdm.req_get()),
  322             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
  323         ]
  324         xml_req_mock.assert_has_calls(expected_calls)
  325 
  326     def test_create_cifs_share_without_interface_in_cifs_server(self):
  327         share_server = fakes.SHARE_SERVER
  328         share = fakes.CIFS_SHARE
  329 
  330         hook = utils.RequestSideEffect()
  331         hook.append(self.vdm.resp_get_succeed())
  332         hook.append(self.cifs_server.resp_get_without_interface(
  333             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
  334         hook.append(self.pool.resp_get_succeed())
  335         hook.append(self.fs.resp_task_succeed())
  336         xml_req_mock = utils.EMCMock(side_effect=hook)
  337         self.connection.manager.connectors['XML'].request = xml_req_mock
  338 
  339         self.assertRaises(exception.EMCVnxXMLAPIError,
  340                           self.connection.create_share,
  341                           None, share, share_server)
  342 
  343         expected_calls = [
  344             mock.call(self.vdm.req_get()),
  345             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
  346             mock.call(self.pool.req_get()),
  347             mock.call(self.fs.req_create_on_vdm()),
  348 
  349         ]
  350         xml_req_mock.assert_has_calls(expected_calls)
  351 
  352     def test_create_cifs_share_without_pool_name(self):
  353         share_server = fakes.SHARE_SERVER
  354         share = fake_share.fake_share(host='HostA@BackendB',
  355                                       share_proto='CIFS')
  356 
  357         self.assertRaises(exception.InvalidHost,
  358                           self.connection.create_share,
  359                           None, share, share_server)
  360 
  361     def test_create_cifs_share_from_snapshot(self):
  362         share_server = fakes.SHARE_SERVER
  363         share = fakes.CIFS_SHARE
  364         snapshot = fake_share.fake_snapshot(
  365             name=fakes.FakeData.src_snap_name,
  366             share_name=fakes.FakeData.src_share_name,
  367             share_id=fakes.FakeData.src_share_name,
  368             id=fakes.FakeData.src_snap_name)
  369 
  370         hook = utils.RequestSideEffect()
  371         hook.append(self.fs.resp_get_succeed())
  372         hook.append(self.vdm.resp_get_succeed())
  373         hook.append(self.cifs_server.resp_get_succeed(
  374             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
  375         hook.append(self.cifs_share.resp_task_succeed())
  376         xml_req_mock = utils.EMCMock(side_effect=hook)
  377         self.connection.manager.connectors['XML'].request = xml_req_mock
  378 
  379         ssh_hook = utils.SSHSideEffect()
  380         ssh_hook.append(self.mover.output_get_interconnect_id())
  381         ssh_hook.append()
  382         ssh_hook.append()
  383         ssh_hook.append(self.fs.output_copy_ckpt)
  384         ssh_hook.append(self.fs.output_info())
  385         ssh_hook.append()
  386         ssh_hook.append()
  387         ssh_hook.append()
  388         ssh_hook.append()
  389         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  390         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  391 
  392         location = self.connection.create_share_from_snapshot(
  393             None, share, snapshot, share_server)
  394 
  395         expected_calls = [
  396             mock.call(self.fs.req_get()),
  397             mock.call(self.vdm.req_get()),
  398             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
  399             mock.call(self.cifs_share.req_create(self.vdm.vdm_id)),
  400         ]
  401         xml_req_mock.assert_has_calls(expected_calls)
  402 
  403         ssh_calls = [
  404             mock.call(self.mover.cmd_get_interconnect_id(), False),
  405             mock.call(self.fs.cmd_create_from_ckpt(), False),
  406             mock.call(self.mount.cmd_server_mount('ro'), False),
  407             mock.call(self.fs.cmd_copy_ckpt(), True),
  408             mock.call(self.fs.cmd_nas_fs_info(), False),
  409             mock.call(self.mount.cmd_server_umount(), False),
  410             mock.call(self.fs.cmd_delete(), False),
  411             mock.call(self.mount.cmd_server_mount('rw'), False),
  412             mock.call(self.cifs_share.cmd_disable_access(), True),
  413         ]
  414         ssh_cmd_mock.assert_has_calls(ssh_calls)
  415 
  416         self.assertEqual(location, r'\\192.168.1.1\%s' % share['name'],
  417                          'CIFS export path is incorrect')
  418 
  419     def test_create_cifs_share_from_snapshot_with_ipv6(self):
  420         share_server = fakes.SHARE_SERVER_IPV6
  421         share = fakes.CIFS_SHARE
  422         snapshot = fake_share.fake_snapshot(
  423             name=fakes.FakeData.src_snap_name,
  424             share_name=fakes.FakeData.src_share_name,
  425             share_id=fakes.FakeData.src_share_name,
  426             id=fakes.FakeData.src_snap_name)
  427 
  428         hook = utils.RequestSideEffect()
  429         hook.append(self.fs.resp_get_succeed())
  430         hook.append(self.vdm.resp_get_succeed(
  431             interface1=fakes.FakeData.interface_name3,
  432             interface2=fakes.FakeData.interface_name4))
  433         hook.append(self.cifs_server.resp_get_succeed(
  434             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
  435             ip_addr=fakes.FakeData.network_allocations_ip3))
  436         hook.append(self.cifs_share.resp_task_succeed())
  437         xml_req_mock = utils.EMCMock(side_effect=hook)
  438         self.connection.manager.connectors['XML'].request = xml_req_mock
  439 
  440         ssh_hook = utils.SSHSideEffect()
  441         ssh_hook.append(self.mover.output_get_interconnect_id())
  442         ssh_hook.append()
  443         ssh_hook.append()
  444         ssh_hook.append(self.fs.output_copy_ckpt)
  445         ssh_hook.append(self.fs.output_info())
  446         ssh_hook.append()
  447         ssh_hook.append()
  448         ssh_hook.append()
  449         ssh_hook.append()
  450         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  451         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  452 
  453         location = self.connection.create_share_from_snapshot(
  454             None, share, snapshot, share_server)
  455 
  456         expected_calls = [
  457             mock.call(self.fs.req_get()),
  458             mock.call(self.vdm.req_get()),
  459             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
  460             mock.call(self.cifs_share.req_create(self.vdm.vdm_id)),
  461         ]
  462         xml_req_mock.assert_has_calls(expected_calls)
  463 
  464         ssh_calls = [
  465             mock.call(self.mover.cmd_get_interconnect_id(), False),
  466             mock.call(self.fs.cmd_create_from_ckpt(), False),
  467             mock.call(self.mount.cmd_server_mount('ro'), False),
  468             mock.call(self.fs.cmd_copy_ckpt(), True),
  469             mock.call(self.fs.cmd_nas_fs_info(), False),
  470             mock.call(self.mount.cmd_server_umount(), False),
  471             mock.call(self.fs.cmd_delete(), False),
  472             mock.call(self.mount.cmd_server_mount('rw'), False),
  473             mock.call(self.cifs_share.cmd_disable_access(), True),
  474         ]
  475         ssh_cmd_mock.assert_has_calls(ssh_calls)
  476 
  477         self.assertEqual(location, r'\\%s.ipv6-literal.net\%s' %
  478                          (fakes.FakeData.network_allocations_ip3.replace(':',
  479                                                                          '-'),
  480                           share['name']),
  481                          'CIFS export path is incorrect')
  482 
  483     def test_create_nfs_share_from_snapshot(self):
  484         share_server = fakes.SHARE_SERVER
  485         share = fakes.NFS_SHARE
  486         snapshot = fake_share.fake_snapshot(
  487             name=fakes.FakeData.src_snap_name,
  488             share_name=fakes.FakeData.src_share_name,
  489             share_id=fakes.FakeData.src_share_name,
  490             id=fakes.FakeData.src_snap_name)
  491 
  492         hook = utils.RequestSideEffect()
  493         hook.append(self.fs.resp_get_succeed())
  494         xml_req_mock = utils.EMCMock(side_effect=hook)
  495         self.connection.manager.connectors['XML'].request = xml_req_mock
  496 
  497         ssh_hook = utils.SSHSideEffect()
  498         ssh_hook.append(self.mover.output_get_interconnect_id())
  499         ssh_hook.append()
  500         ssh_hook.append()
  501         ssh_hook.append(self.fs.output_copy_ckpt)
  502         ssh_hook.append(self.fs.output_info())
  503         ssh_hook.append()
  504         ssh_hook.append()
  505         ssh_hook.append()
  506         ssh_hook.append(self.nfs_share.output_create())
  507         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  508         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  509 
  510         location = self.connection.create_share_from_snapshot(
  511             None, share, snapshot, share_server)
  512 
  513         expected_calls = [mock.call(self.fs.req_get())]
  514         xml_req_mock.assert_has_calls(expected_calls)
  515 
  516         ssh_calls = [
  517             mock.call(self.mover.cmd_get_interconnect_id(), False),
  518             mock.call(self.fs.cmd_create_from_ckpt(), False),
  519             mock.call(self.mount.cmd_server_mount('ro'), False),
  520             mock.call(self.fs.cmd_copy_ckpt(), True),
  521             mock.call(self.fs.cmd_nas_fs_info(), False),
  522             mock.call(self.mount.cmd_server_umount(), False),
  523             mock.call(self.fs.cmd_delete(), False),
  524             mock.call(self.mount.cmd_server_mount('rw'), False),
  525             mock.call(self.nfs_share.cmd_create(), True)
  526         ]
  527         ssh_cmd_mock.assert_has_calls(ssh_calls)
  528 
  529         self.assertEqual(location, '192.168.1.2:/%s' % share['name'],
  530                          'NFS export path is incorrect')
  531 
  532     def test_create_nfs_share_from_snapshot_with_ipv6(self):
  533         share_server = fakes.SHARE_SERVER_IPV6
  534         share = fakes.NFS_SHARE
  535         snapshot = fake_share.fake_snapshot(
  536             name=fakes.FakeData.src_snap_name,
  537             share_name=fakes.FakeData.src_share_name,
  538             share_id=fakes.FakeData.src_share_name,
  539             id=fakes.FakeData.src_snap_name)
  540 
  541         hook = utils.RequestSideEffect()
  542         hook.append(self.fs.resp_get_succeed())
  543         xml_req_mock = utils.EMCMock(side_effect=hook)
  544         self.connection.manager.connectors['XML'].request = xml_req_mock
  545 
  546         ssh_hook = utils.SSHSideEffect()
  547         ssh_hook.append(self.mover.output_get_interconnect_id())
  548         ssh_hook.append()
  549         ssh_hook.append()
  550         ssh_hook.append(self.fs.output_copy_ckpt)
  551         ssh_hook.append(self.fs.output_info())
  552         ssh_hook.append()
  553         ssh_hook.append()
  554         ssh_hook.append()
  555         ssh_hook.append(self.nfs_share.output_create())
  556         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  557         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  558 
  559         location = self.connection.create_share_from_snapshot(
  560             None, share, snapshot, share_server)
  561 
  562         expected_calls = [mock.call(self.fs.req_get())]
  563         xml_req_mock.assert_has_calls(expected_calls)
  564 
  565         ssh_calls = [
  566             mock.call(self.mover.cmd_get_interconnect_id(), False),
  567             mock.call(self.fs.cmd_create_from_ckpt(), False),
  568             mock.call(self.mount.cmd_server_mount('ro'), False),
  569             mock.call(self.fs.cmd_copy_ckpt(), True),
  570             mock.call(self.fs.cmd_nas_fs_info(), False),
  571             mock.call(self.mount.cmd_server_umount(), False),
  572             mock.call(self.fs.cmd_delete(), False),
  573             mock.call(self.mount.cmd_server_mount('rw'), False),
  574             mock.call(self.nfs_share.cmd_create(), True)
  575         ]
  576         ssh_cmd_mock.assert_has_calls(ssh_calls)
  577 
  578         self.assertEqual(location, '[%s]:/%s' %
  579                          (fakes.FakeData.network_allocations_ip4,
  580                           share['name']),
  581                          'NFS export path is incorrect')
  582 
  583     def test_create_share_with_incorrect_proto(self):
  584         share_server = fakes.SHARE_SERVER
  585         share = fake_share.fake_share(share_proto='FAKE_PROTO')
  586 
  587         self.assertRaises(exception.InvalidShare,
  588                           self.connection.create_share,
  589                           context=None,
  590                           share=share,
  591                           share_server=share_server)
  592 
  593     def test_create_share_from_snapshot_with_incorrect_proto(self):
  594         share_server = fakes.SHARE_SERVER
  595         share = fake_share.fake_share(share_proto='FAKE_PROTO')
  596         snapshot = fake_share.fake_snapshot()
  597 
  598         self.assertRaises(exception.InvalidShare,
  599                           self.connection.create_share_from_snapshot,
  600                           None, share, snapshot, share_server)
  601 
  602     def test_create_share_from_snapshot_without_pool_name(self):
  603         share_server = fakes.SHARE_SERVER
  604         share = fake_share.fake_share(host='HostA@BackendB',
  605                                       share_proto='CIFS')
  606         snapshot = fake_share.fake_snapshot()
  607 
  608         self.assertRaises(exception.InvalidHost,
  609                           self.connection.create_share_from_snapshot,
  610                           None, share, snapshot, share_server)
  611 
  612     def test_delete_cifs_share(self):
  613         share_server = fakes.SHARE_SERVER
  614         share = fakes.CIFS_SHARE
  615 
  616         hook = utils.RequestSideEffect()
  617         hook.append(self.cifs_share.resp_get_succeed(self.vdm.vdm_id))
  618         hook.append(self.vdm.resp_get_succeed())
  619         hook.append(self.cifs_share.resp_task_succeed())
  620         hook.append(self.mount.resp_task_succeed())
  621         hook.append(self.fs.resp_get_succeed())
  622         hook.append(self.fs.resp_task_succeed())
  623         xml_req_mock = utils.EMCMock(side_effect=hook)
  624         self.connection.manager.connectors['XML'].request = xml_req_mock
  625 
  626         self.connection.delete_share(None, share, share_server)
  627 
  628         expected_calls = [
  629             mock.call(self.cifs_share.req_get()),
  630             mock.call(self.vdm.req_get()),
  631             mock.call(self.cifs_share.req_delete(self.vdm.vdm_id)),
  632             mock.call(self.mount.req_delete(self.vdm.vdm_id)),
  633             mock.call(self.fs.req_get()),
  634             mock.call(self.fs.req_delete()),
  635         ]
  636         xml_req_mock.assert_has_calls(expected_calls)
  637 
  638     def test_delete_cifs_share_with_ipv6(self):
  639         share_server = fakes.SHARE_SERVER_IPV6
  640         share = fakes.CIFS_SHARE
  641 
  642         hook = utils.RequestSideEffect()
  643         hook.append(self.cifs_share.resp_get_succeed(self.vdm.vdm_id))
  644         hook.append(self.vdm.resp_get_succeed(
  645             interface1=fakes.FakeData.interface_name3,
  646             interface2=fakes.FakeData.interface_name4))
  647         hook.append(self.cifs_share.resp_task_succeed())
  648         hook.append(self.mount.resp_task_succeed())
  649         hook.append(self.fs.resp_get_succeed())
  650         hook.append(self.fs.resp_task_succeed())
  651         xml_req_mock = utils.EMCMock(side_effect=hook)
  652         self.connection.manager.connectors['XML'].request = xml_req_mock
  653 
  654         self.connection.delete_share(None, share, share_server)
  655 
  656         expected_calls = [
  657             mock.call(self.cifs_share.req_get()),
  658             mock.call(self.vdm.req_get()),
  659             mock.call(self.cifs_share.req_delete(self.vdm.vdm_id)),
  660             mock.call(self.mount.req_delete(self.vdm.vdm_id)),
  661             mock.call(self.fs.req_get()),
  662             mock.call(self.fs.req_delete()),
  663         ]
  664         xml_req_mock.assert_has_calls(expected_calls)
  665 
  666     def test_delete_nfs_share(self):
  667         share_server = fakes.SHARE_SERVER
  668         share = fakes.NFS_SHARE
  669 
  670         hook = utils.RequestSideEffect()
  671         hook.append(self.vdm.resp_get_succeed())
  672         hook.append(self.mount.resp_task_succeed())
  673         hook.append(self.fs.resp_get_succeed())
  674         hook.append(self.fs.resp_task_succeed())
  675         xml_req_mock = utils.EMCMock(side_effect=hook)
  676         self.connection.manager.connectors['XML'].request = xml_req_mock
  677 
  678         ssh_hook = utils.SSHSideEffect()
  679         ssh_hook.append(self.nfs_share.output_get_succeed(
  680             rw_hosts=self.nfs_share.rw_hosts,
  681             ro_hosts=self.nfs_share.ro_hosts))
  682         ssh_hook.append(self.nfs_share.output_delete_succeed())
  683         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  684         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  685 
  686         self.connection.delete_share(None, share, share_server)
  687 
  688         expected_calls = [
  689             mock.call(self.vdm.req_get()),
  690             mock.call(self.mount.req_delete(self.vdm.vdm_id)),
  691             mock.call(self.fs.req_get()),
  692             mock.call(self.fs.req_delete()),
  693         ]
  694         xml_req_mock.assert_has_calls(expected_calls)
  695 
  696         ssh_calls = [
  697             mock.call(self.nfs_share.cmd_get(), False),
  698             mock.call(self.nfs_share.cmd_delete(), True),
  699         ]
  700         ssh_cmd_mock.assert_has_calls(ssh_calls)
  701 
  702     def test_delete_nfs_share_with_ipv6(self):
  703         share_server = fakes.SHARE_SERVER_IPV6
  704         share = fakes.NFS_SHARE
  705 
  706         hook = utils.RequestSideEffect()
  707         hook.append(self.vdm.resp_get_succeed(
  708             interface1=fakes.FakeData.interface_name3,
  709             interface2=fakes.FakeData.interface_name4))
  710         hook.append(self.mount.resp_task_succeed())
  711         hook.append(self.fs.resp_get_succeed())
  712         hook.append(self.fs.resp_task_succeed())
  713         xml_req_mock = utils.EMCMock(side_effect=hook)
  714         self.connection.manager.connectors['XML'].request = xml_req_mock
  715 
  716         ssh_hook = utils.SSHSideEffect()
  717         ssh_hook.append(self.nfs_share.output_get_succeed(
  718             rw_hosts=self.nfs_share.rw_hosts,
  719             ro_hosts=self.nfs_share.ro_hosts))
  720         ssh_hook.append(self.nfs_share.output_delete_succeed())
  721         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  722         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  723 
  724         self.connection.delete_share(None, share, share_server)
  725 
  726         expected_calls = [
  727             mock.call(self.vdm.req_get()),
  728             mock.call(self.mount.req_delete(self.vdm.vdm_id)),
  729             mock.call(self.fs.req_get()),
  730             mock.call(self.fs.req_delete()),
  731         ]
  732         xml_req_mock.assert_has_calls(expected_calls)
  733 
  734         ssh_calls = [
  735             mock.call(self.nfs_share.cmd_get(), False),
  736             mock.call(self.nfs_share.cmd_delete(), True),
  737         ]
  738         ssh_cmd_mock.assert_has_calls(ssh_calls)
  739 
  740     def test_delete_share_without_share_server(self):
  741         share = fakes.CIFS_SHARE
  742 
  743         self.connection.delete_share(None, share)
  744 
  745     def test_delete_share_with_incorrect_proto(self):
  746         share_server = fakes.SHARE_SERVER
  747         share = fake_share.fake_share(share_proto='FAKE_PROTO')
  748 
  749         self.assertRaises(exception.InvalidShare,
  750                           self.connection.delete_share,
  751                           context=None,
  752                           share=share,
  753                           share_server=share_server)
  754 
  755     def test_delete_cifs_share_with_nonexistent_mount_and_filesystem(self):
  756         share_server = fakes.SHARE_SERVER
  757         share = fakes.CIFS_SHARE
  758 
  759         hook = utils.RequestSideEffect()
  760         hook.append(self.cifs_share.resp_get_succeed(self.vdm.vdm_id))
  761         hook.append(self.vdm.resp_get_succeed())
  762         hook.append(self.cifs_share.resp_task_succeed())
  763         hook.append(self.mount.resp_task_error())
  764         hook.append(self.fs.resp_get_succeed())
  765         hook.append(self.fs.resp_task_error())
  766         xml_req_mock = utils.EMCMock(side_effect=hook)
  767         self.connection.manager.connectors['XML'].request = xml_req_mock
  768 
  769         self.connection.delete_share(None, share, share_server)
  770 
  771         expected_calls = [
  772             mock.call(self.cifs_share.req_get()),
  773             mock.call(self.vdm.req_get()),
  774             mock.call(self.cifs_share.req_delete(self.vdm.vdm_id)),
  775             mock.call(self.mount.req_delete(self.vdm.vdm_id)),
  776             mock.call(self.fs.req_get()),
  777             mock.call(self.fs.req_delete()),
  778         ]
  779         xml_req_mock.assert_has_calls(expected_calls)
  780 
  781     def test_extend_share(self):
  782         share_server = fakes.SHARE_SERVER
  783         share = fakes.CIFS_SHARE
  784         new_size = fakes.FakeData.new_size
  785 
  786         hook = utils.RequestSideEffect()
  787         hook.append(self.fs.resp_get_succeed())
  788         hook.append(self.pool.resp_get_succeed())
  789         hook.append(self.fs.resp_task_succeed())
  790         xml_req_mock = utils.EMCMock(side_effect=hook)
  791         self.connection.manager.connectors['XML'].request = xml_req_mock
  792 
  793         self.connection.extend_share(share, new_size, share_server)
  794 
  795         expected_calls = [
  796             mock.call(self.fs.req_get()),
  797             mock.call(self.pool.req_get()),
  798             mock.call(self.fs.req_extend()),
  799         ]
  800         xml_req_mock.assert_has_calls(expected_calls)
  801 
  802     def test_extend_share_with_ipv6(self):
  803         share_server = fakes.SHARE_SERVER_IPV6
  804         share = fakes.CIFS_SHARE
  805         new_size = fakes.FakeData.new_size
  806 
  807         hook = utils.RequestSideEffect()
  808         hook.append(self.fs.resp_get_succeed())
  809         hook.append(self.pool.resp_get_succeed())
  810         hook.append(self.fs.resp_task_succeed())
  811         xml_req_mock = utils.EMCMock(side_effect=hook)
  812         self.connection.manager.connectors['XML'].request = xml_req_mock
  813 
  814         self.connection.extend_share(share, new_size, share_server)
  815 
  816         expected_calls = [
  817             mock.call(self.fs.req_get()),
  818             mock.call(self.pool.req_get()),
  819             mock.call(self.fs.req_extend()),
  820         ]
  821         xml_req_mock.assert_has_calls(expected_calls)
  822 
  823     def test_extend_share_without_pool_name(self):
  824         share_server = fakes.SHARE_SERVER
  825         share = fake_share.fake_share(host='HostA@BackendB',
  826                                       share_proto='CIFS')
  827         new_size = fakes.FakeData.new_size
  828 
  829         self.assertRaises(exception.InvalidHost,
  830                           self.connection.extend_share,
  831                           share, new_size, share_server)
  832 
  833     def test_create_snapshot(self):
  834         share_server = fakes.SHARE_SERVER
  835         snapshot = fake_share.fake_snapshot(
  836             id=fakes.FakeData.snapshot_name,
  837             share_id=fakes.FakeData.filesystem_name,
  838             share_name=fakes.FakeData.share_name)
  839 
  840         hook = utils.RequestSideEffect()
  841         hook.append(self.fs.resp_get_succeed())
  842         hook.append(self.snap.resp_task_succeed())
  843         xml_req_mock = utils.EMCMock(side_effect=hook)
  844         self.connection.manager.connectors['XML'].request = xml_req_mock
  845 
  846         self.connection.create_snapshot(None, snapshot, share_server)
  847 
  848         expected_calls = [
  849             mock.call(self.fs.req_get()),
  850             mock.call(self.snap.req_create()),
  851         ]
  852         xml_req_mock.assert_has_calls(expected_calls)
  853 
  854     def test_create_snapshot_with_ipv6(self):
  855         share_server = fakes.SHARE_SERVER_IPV6
  856         snapshot = fake_share.fake_snapshot(
  857             id=fakes.FakeData.snapshot_name,
  858             share_id=fakes.FakeData.filesystem_name,
  859             share_name=fakes.FakeData.share_name)
  860 
  861         hook = utils.RequestSideEffect()
  862         hook.append(self.fs.resp_get_succeed())
  863         hook.append(self.snap.resp_task_succeed())
  864         xml_req_mock = utils.EMCMock(side_effect=hook)
  865         self.connection.manager.connectors['XML'].request = xml_req_mock
  866 
  867         self.connection.create_snapshot(None, snapshot, share_server)
  868 
  869         expected_calls = [
  870             mock.call(self.fs.req_get()),
  871             mock.call(self.snap.req_create()),
  872         ]
  873         xml_req_mock.assert_has_calls(expected_calls)
  874 
  875     def test_create_snapshot_with_incorrect_share_info(self):
  876         share_server = fakes.SHARE_SERVER
  877         snapshot = fake_share.fake_snapshot(
  878             id=fakes.FakeData.snapshot_name,
  879             share_id=fakes.FakeData.filesystem_name,
  880             share_name=fakes.FakeData.share_name)
  881 
  882         hook = utils.RequestSideEffect()
  883         hook.append(self.fs.resp_get_but_not_found())
  884         xml_req_mock = utils.EMCMock(side_effect=hook)
  885         self.connection.manager.connectors['XML'].request = xml_req_mock
  886 
  887         self.assertRaises(exception.EMCVnxXMLAPIError,
  888                           self.connection.create_snapshot,
  889                           None, snapshot, share_server)
  890 
  891         expected_calls = [mock.call(self.fs.req_get())]
  892         xml_req_mock.assert_has_calls(expected_calls)
  893 
  894     def test_delete_snapshot(self):
  895         share_server = fakes.SHARE_SERVER
  896         snapshot = fake_share.fake_snapshot(
  897             id=fakes.FakeData.snapshot_name,
  898             share_id=fakes.FakeData.filesystem_name,
  899             share_name=fakes.FakeData.share_name)
  900 
  901         hook = utils.RequestSideEffect()
  902         hook.append(self.snap.resp_get_succeed())
  903         hook.append(self.snap.resp_task_succeed())
  904         xml_req_mock = utils.EMCMock(side_effect=hook)
  905         self.connection.manager.connectors['XML'].request = xml_req_mock
  906 
  907         self.connection.delete_snapshot(None, snapshot, share_server)
  908 
  909         expected_calls = [
  910             mock.call(self.snap.req_get()),
  911             mock.call(self.snap.req_delete()),
  912         ]
  913         xml_req_mock.assert_has_calls(expected_calls)
  914 
  915     def test_delete_snapshot_with_ipv6(self):
  916         share_server = fakes.SHARE_SERVER_IPV6
  917         snapshot = fake_share.fake_snapshot(
  918             id=fakes.FakeData.snapshot_name,
  919             share_id=fakes.FakeData.filesystem_name,
  920             share_name=fakes.FakeData.share_name)
  921 
  922         hook = utils.RequestSideEffect()
  923         hook.append(self.snap.resp_get_succeed())
  924         hook.append(self.snap.resp_task_succeed())
  925         xml_req_mock = utils.EMCMock(side_effect=hook)
  926         self.connection.manager.connectors['XML'].request = xml_req_mock
  927 
  928         self.connection.delete_snapshot(None, snapshot, share_server)
  929 
  930         expected_calls = [
  931             mock.call(self.snap.req_get()),
  932             mock.call(self.snap.req_delete()),
  933         ]
  934         xml_req_mock.assert_has_calls(expected_calls)
  935 
  936     @utils.patch_get_managed_ports_vnx(return_value=['cge-1-0'])
  937     def test_setup_server(self):
  938         hook = utils.RequestSideEffect()
  939         hook.append(self.vdm.resp_get_but_not_found())
  940         hook.append(self.mover.resp_get_ref_succeed())
  941         hook.append(self.vdm.resp_task_succeed())
  942         hook.append(self.mover.resp_task_succeed())
  943         hook.append(self.mover.resp_task_succeed())
  944         hook.append(self.dns.resp_task_succeed())
  945         hook.append(self.vdm.resp_get_succeed())
  946         hook.append(self.cifs_server.resp_task_succeed())
  947         xml_req_mock = utils.EMCMock(side_effect=hook)
  948         self.connection.manager.connectors['XML'].request = xml_req_mock
  949 
  950         ssh_hook = utils.SSHSideEffect()
  951         ssh_hook.append()
  952         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  953         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  954 
  955         self.connection.setup_server(fakes.NETWORK_INFO, None)
  956 
  957         if_name_1 = fakes.FakeData.interface_name1
  958         if_name_2 = fakes.FakeData.interface_name2
  959 
  960         expected_calls = [
  961             mock.call(self.vdm.req_get()),
  962             mock.call(self.mover.req_get_ref()),
  963             mock.call(self.vdm.req_create()),
  964             mock.call(self.mover.req_create_interface(
  965                 if_name=if_name_1,
  966                 ip=fakes.FakeData.network_allocations_ip1)),
  967             mock.call(self.mover.req_create_interface(
  968                 if_name=if_name_2,
  969                 ip=fakes.FakeData.network_allocations_ip2)),
  970             mock.call(self.dns.req_create()),
  971             mock.call(self.vdm.req_get()),
  972             mock.call(self.cifs_server.req_create(self.vdm.vdm_id)),
  973         ]
  974         xml_req_mock.assert_has_calls(expected_calls)
  975 
  976         ssh_calls = [
  977             mock.call(self.vdm.cmd_attach_nfs_interface(), False),
  978         ]
  979         ssh_cmd_mock.assert_has_calls(ssh_calls)
  980 
  981     @utils.patch_get_managed_ports_vnx(return_value=['cge-1-0'])
  982     def test_setup_server_with_ipv6(self):
  983         hook = utils.RequestSideEffect()
  984         hook.append(self.vdm.resp_get_but_not_found())
  985         hook.append(self.mover.resp_get_ref_succeed())
  986         hook.append(self.vdm.resp_task_succeed())
  987         hook.append(self.mover.resp_task_succeed())
  988         hook.append(self.mover.resp_task_succeed())
  989         hook.append(self.dns.resp_task_succeed())
  990         hook.append(self.vdm.resp_get_succeed())
  991         hook.append(self.cifs_server.resp_task_succeed())
  992         xml_req_mock = utils.EMCMock(side_effect=hook)
  993         self.connection.manager.connectors['XML'].request = xml_req_mock
  994 
  995         ssh_hook = utils.SSHSideEffect()
  996         ssh_hook.append()
  997         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
  998         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
  999 
 1000         self.connection.setup_server(fakes.NETWORK_INFO_IPV6, None)
 1001 
 1002         if_name_1 = fakes.FakeData.interface_name3
 1003         if_name_2 = fakes.FakeData.interface_name4
 1004 
 1005         expect_ip_1 = fakes.FakeData.network_allocations_ip3
 1006         expect_ip_2 = fakes.FakeData.network_allocations_ip4
 1007 
 1008         expected_calls = [
 1009             mock.call(self.vdm.req_get()),
 1010             mock.call(self.mover.req_get_ref()),
 1011             mock.call(self.vdm.req_create()),
 1012             mock.call(self.mover.req_create_interface_with_ipv6(
 1013                 if_name=if_name_1,
 1014                 ip=expect_ip_1)),
 1015             mock.call(self.mover.req_create_interface_with_ipv6(
 1016                 if_name=if_name_2,
 1017                 ip=expect_ip_2)),
 1018             mock.call(self.dns.req_create(
 1019                 ip_addr=fakes.FakeData.dns_ipv6_address)),
 1020             mock.call(self.vdm.req_get()),
 1021             mock.call(self.cifs_server.req_create(
 1022                 self.vdm.vdm_id,
 1023                 ip_addr=fakes.FakeData.network_allocations_ip3)),
 1024         ]
 1025         xml_req_mock.assert_has_calls(expected_calls)
 1026 
 1027         ssh_calls = [
 1028             mock.call(self.vdm.cmd_attach_nfs_interface(
 1029                 interface=fakes.FakeData.interface_name4), False),
 1030         ]
 1031 
 1032         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1033 
 1034     @utils.patch_get_managed_ports_vnx(return_value=['cge-1-0'])
 1035     def test_setup_server_with_existing_vdm(self):
 1036         hook = utils.RequestSideEffect()
 1037         hook.append(self.vdm.resp_get_succeed())
 1038         hook.append(self.mover.resp_get_ref_succeed())
 1039         hook.append(self.mover.resp_task_succeed())
 1040         hook.append(self.mover.resp_task_succeed())
 1041         hook.append(self.dns.resp_task_succeed())
 1042         hook.append(self.cifs_server.resp_task_succeed())
 1043         xml_req_mock = utils.EMCMock(side_effect=hook)
 1044         self.connection.manager.connectors['XML'].request = xml_req_mock
 1045 
 1046         ssh_hook = utils.SSHSideEffect()
 1047         ssh_hook.append()
 1048         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1049         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1050         self.connection.setup_server(fakes.NETWORK_INFO, None)
 1051 
 1052         if_name_1 = fakes.FakeData.network_allocations_id1[-12:]
 1053         if_name_2 = fakes.FakeData.network_allocations_id2[-12:]
 1054 
 1055         expected_calls = [
 1056             mock.call(self.vdm.req_get()),
 1057             mock.call(self.mover.req_get_ref()),
 1058             mock.call(self.mover.req_create_interface(
 1059                 if_name=if_name_1,
 1060                 ip=fakes.FakeData.network_allocations_ip1)),
 1061             mock.call(self.mover.req_create_interface(
 1062                 if_name=if_name_2,
 1063                 ip=fakes.FakeData.network_allocations_ip2)),
 1064             mock.call(self.dns.req_create()),
 1065             mock.call(self.cifs_server.req_create(self.vdm.vdm_id)),
 1066         ]
 1067         xml_req_mock.assert_has_calls(expected_calls)
 1068 
 1069         ssh_calls = [
 1070             mock.call(self.vdm.cmd_attach_nfs_interface(), False),
 1071         ]
 1072         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1073 
 1074     def test_setup_server_with_invalid_security_service(self):
 1075         network_info = copy.deepcopy(fakes.NETWORK_INFO)
 1076         network_info['security_services'][0]['type'] = 'fake_type'
 1077 
 1078         self.assertRaises(exception.EMCVnxXMLAPIError,
 1079                           self.connection.setup_server,
 1080                           network_info, None)
 1081 
 1082     @utils.patch_get_managed_ports_vnx(
 1083         side_effect=exception.EMCVnxXMLAPIError(
 1084             err="Get managed ports fail."))
 1085     def test_setup_server_without_valid_physical_device(self):
 1086         hook = utils.RequestSideEffect()
 1087         hook.append(self.vdm.resp_get_but_not_found())
 1088         hook.append(self.mover.resp_get_ref_succeed())
 1089         hook.append(self.vdm.resp_task_succeed())
 1090         hook.append(self.vdm.resp_get_succeed())
 1091         hook.append(self.cifs_server.resp_get_without_value())
 1092         hook.append(self.vdm.resp_task_succeed())
 1093         xml_req_mock = utils.EMCMock(side_effect=hook)
 1094         self.connection.manager.connectors['XML'].request = xml_req_mock
 1095         ssh_hook = utils.SSHSideEffect()
 1096         ssh_hook.append(self.vdm.output_get_interfaces_vdm(nfs_interface=''))
 1097         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1098         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1099 
 1100         self.assertRaises(exception.EMCVnxXMLAPIError,
 1101                           self.connection.setup_server,
 1102                           fakes.NETWORK_INFO, None)
 1103 
 1104         expected_calls = [
 1105             mock.call(self.vdm.req_get()),
 1106             mock.call(self.mover.req_get_ref()),
 1107             mock.call(self.vdm.req_create()),
 1108             mock.call(self.vdm.req_get()),
 1109             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1110             mock.call(self.vdm.req_delete()),
 1111         ]
 1112         xml_req_mock.assert_has_calls(expected_calls)
 1113 
 1114         ssh_calls = [
 1115             mock.call(self.vdm.cmd_get_interfaces(), False),
 1116         ]
 1117         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1118 
 1119     @utils.patch_get_managed_ports_vnx(return_value=['cge-1-0'])
 1120     def test_setup_server_with_exception(self):
 1121         hook = utils.RequestSideEffect()
 1122         hook.append(self.vdm.resp_get_but_not_found())
 1123         hook.append(self.mover.resp_get_ref_succeed())
 1124         hook.append(self.vdm.resp_task_succeed())
 1125         hook.append(self.mover.resp_task_succeed())
 1126         hook.append(self.mover.resp_task_error())
 1127         hook.append(self.vdm.resp_get_succeed())
 1128         hook.append(self.cifs_server.resp_get_without_value())
 1129         hook.append(self.mover.resp_task_succeed())
 1130         hook.append(self.vdm.resp_task_succeed())
 1131         xml_req_mock = utils.EMCMock(side_effect=hook)
 1132         self.connection.manager.connectors['XML'].request = xml_req_mock
 1133 
 1134         ssh_hook = utils.SSHSideEffect()
 1135         ssh_hook.append(self.vdm.output_get_interfaces_vdm(nfs_interface=''))
 1136         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1137         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1138 
 1139         self.assertRaises(exception.EMCVnxXMLAPIError,
 1140                           self.connection.setup_server,
 1141                           fakes.NETWORK_INFO, None)
 1142 
 1143         if_name_1 = fakes.FakeData.network_allocations_id1[-12:]
 1144         if_name_2 = fakes.FakeData.network_allocations_id2[-12:]
 1145 
 1146         expected_calls = [
 1147             mock.call(self.vdm.req_get()),
 1148             mock.call(self.mover.req_get_ref()),
 1149             mock.call(self.vdm.req_create()),
 1150             mock.call(self.mover.req_create_interface(
 1151                 if_name=if_name_1,
 1152                 ip=fakes.FakeData.network_allocations_ip1)),
 1153             mock.call(self.mover.req_create_interface(
 1154                 if_name=if_name_2,
 1155                 ip=fakes.FakeData.network_allocations_ip2)),
 1156             mock.call(self.vdm.req_get()),
 1157             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1158             mock.call(self.mover.req_delete_interface(
 1159                 fakes.FakeData.network_allocations_ip1)),
 1160             mock.call(self.vdm.req_delete()),
 1161         ]
 1162         xml_req_mock.assert_has_calls(expected_calls)
 1163 
 1164         ssh_calls = [
 1165             mock.call(self.vdm.cmd_get_interfaces(), False),
 1166         ]
 1167         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1168 
 1169     def test_teardown_server(self):
 1170         hook = utils.RequestSideEffect()
 1171         hook.append(self.vdm.resp_get_succeed())
 1172         hook.append(self.cifs_server.resp_get_succeed(
 1173             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1174         hook.append(self.cifs_server.resp_task_succeed())
 1175         hook.append(self.cifs_server.resp_get_succeed(
 1176             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False))
 1177         hook.append(self.mover.resp_get_ref_succeed())
 1178         hook.append(self.mover.resp_task_succeed())
 1179         hook.append(self.mover.resp_task_succeed())
 1180         hook.append(self.vdm.resp_task_succeed())
 1181         xml_req_mock = utils.EMCMock(side_effect=hook)
 1182         self.connection.manager.connectors['XML'].request = xml_req_mock
 1183 
 1184         ssh_hook = utils.SSHSideEffect()
 1185         ssh_hook.append(self.vdm.output_get_interfaces_vdm())
 1186         ssh_hook.append()
 1187         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1188         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1189 
 1190         self.connection.teardown_server(fakes.SERVER_DETAIL,
 1191                                         fakes.SECURITY_SERVICE)
 1192 
 1193         expected_calls = [
 1194             mock.call(self.vdm.req_get()),
 1195             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1196             mock.call(self.cifs_server.req_modify(
 1197                 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False)),
 1198             mock.call(self.cifs_server.req_delete(self.vdm.vdm_id)),
 1199             mock.call(self.mover.req_get_ref()),
 1200             mock.call(self.mover.req_delete_interface(
 1201                 fakes.FakeData.network_allocations_ip1)),
 1202             mock.call(self.mover.req_delete_interface(
 1203                 fakes.FakeData.network_allocations_ip2)),
 1204             mock.call(self.vdm.req_delete()),
 1205         ]
 1206         xml_req_mock.assert_has_calls(expected_calls)
 1207 
 1208         ssh_calls = [
 1209             mock.call(self.vdm.cmd_get_interfaces(), False),
 1210             mock.call(self.vdm.cmd_detach_nfs_interface(), True),
 1211         ]
 1212         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1213 
 1214     def test_teardown_server_with_ipv6(self):
 1215         hook = utils.RequestSideEffect()
 1216         hook.append(self.vdm.resp_get_succeed())
 1217         hook.append(self.cifs_server.resp_get_succeed(
 1218             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1219         hook.append(self.cifs_server.resp_task_succeed())
 1220         hook.append(self.cifs_server.resp_get_succeed(
 1221             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False))
 1222         hook.append(self.mover.resp_get_ref_succeed())
 1223         hook.append(self.mover.resp_task_succeed())
 1224         hook.append(self.mover.resp_task_succeed())
 1225         hook.append(self.vdm.resp_task_succeed())
 1226         xml_req_mock = utils.EMCMock(side_effect=hook)
 1227         self.connection.manager.connectors['XML'].request = xml_req_mock
 1228 
 1229         ssh_hook = utils.SSHSideEffect()
 1230         ssh_hook.append(self.vdm.output_get_interfaces_vdm())
 1231         ssh_hook.append()
 1232         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1233         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1234 
 1235         self.connection.teardown_server(fakes.SERVER_DETAIL_IPV6,
 1236                                         fakes.SECURITY_SERVICE_IPV6)
 1237 
 1238         expected_calls = [
 1239             mock.call(self.vdm.req_get()),
 1240             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1241             mock.call(self.cifs_server.req_modify(
 1242                 mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False)),
 1243             mock.call(self.cifs_server.req_delete(self.vdm.vdm_id)),
 1244             mock.call(self.mover.req_get_ref()),
 1245             mock.call(self.mover.req_delete_interface(
 1246                 fakes.FakeData.network_allocations_ip3)),
 1247             mock.call(self.mover.req_delete_interface(
 1248                 fakes.FakeData.network_allocations_ip4)),
 1249             mock.call(self.vdm.req_delete()),
 1250         ]
 1251         xml_req_mock.assert_has_calls(expected_calls)
 1252 
 1253         ssh_calls = [
 1254             mock.call(self.vdm.cmd_get_interfaces(), False),
 1255             mock.call(self.vdm.cmd_detach_nfs_interface(), True),
 1256         ]
 1257         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1258 
 1259     def test_teardown_server_without_server_detail(self):
 1260         self.connection.teardown_server(None, fakes.SECURITY_SERVICE)
 1261 
 1262     def test_teardown_server_without_security_services(self):
 1263         hook = utils.RequestSideEffect()
 1264         hook.append(self.vdm.resp_get_succeed())
 1265         hook.append(self.mover.resp_get_ref_succeed())
 1266         hook.append(self.mover.resp_task_succeed())
 1267         hook.append(self.mover.resp_task_succeed())
 1268         hook.append(self.vdm.resp_task_succeed())
 1269         xml_req_mock = utils.EMCMock(side_effect=hook)
 1270         self.connection.manager.connectors['XML'].request = xml_req_mock
 1271 
 1272         ssh_hook = utils.SSHSideEffect()
 1273         ssh_hook.append(self.vdm.output_get_interfaces_vdm())
 1274         ssh_hook.append()
 1275         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1276         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1277 
 1278         self.connection.teardown_server(fakes.SERVER_DETAIL, [])
 1279 
 1280         expected_calls = [
 1281             mock.call(self.vdm.req_get()),
 1282             mock.call(self.mover.req_get_ref()),
 1283             mock.call(self.mover.req_delete_interface(
 1284                 fakes.FakeData.network_allocations_ip1)),
 1285             mock.call(self.mover.req_delete_interface(
 1286                 fakes.FakeData.network_allocations_ip2)),
 1287             mock.call(self.vdm.req_delete()),
 1288         ]
 1289         xml_req_mock.assert_has_calls(expected_calls)
 1290 
 1291         ssh_calls = [
 1292             mock.call(self.vdm.cmd_get_interfaces(), False),
 1293             mock.call(self.vdm.cmd_detach_nfs_interface(), True),
 1294         ]
 1295         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1296 
 1297     def test_teardown_server_without_share_server_name_in_server_detail(self):
 1298         server_detail = {
 1299             'cifs_if': fakes.FakeData.network_allocations_ip1,
 1300             'nfs_if': fakes.FakeData.network_allocations_ip2,
 1301         }
 1302         self.connection.teardown_server(server_detail, fakes.SECURITY_SERVICE)
 1303 
 1304     def test_teardown_server_with_invalid_server_name(self):
 1305         hook = utils.RequestSideEffect()
 1306         hook.append(self.vdm.resp_get_error())
 1307         xml_req_mock = utils.EMCMock(side_effect=hook)
 1308         self.connection.manager.connectors['XML'].request = xml_req_mock
 1309 
 1310         self.connection.teardown_server(fakes.SERVER_DETAIL,
 1311                                         fakes.SECURITY_SERVICE)
 1312 
 1313         expected_calls = [mock.call(self.vdm.req_get())]
 1314         xml_req_mock.assert_has_calls(expected_calls)
 1315 
 1316     def test_teardown_server_without_cifs_server(self):
 1317         hook = utils.RequestSideEffect()
 1318         hook.append(self.vdm.resp_get_succeed())
 1319         hook.append(self.cifs_server.resp_get_error())
 1320         hook.append(self.mover.resp_get_ref_succeed())
 1321         hook.append(self.cifs_server.resp_task_succeed())
 1322         hook.append(self.cifs_server.resp_get_succeed(
 1323             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=False))
 1324         hook.append(self.mover.resp_task_succeed())
 1325         hook.append(self.mover.resp_task_succeed())
 1326         hook.append(self.vdm.resp_task_succeed())
 1327         xml_req_mock = utils.EMCMock(side_effect=hook)
 1328         self.connection.manager.connectors['XML'].request = xml_req_mock
 1329 
 1330         ssh_hook = utils.SSHSideEffect()
 1331         ssh_hook.append(self.vdm.output_get_interfaces_vdm())
 1332         ssh_hook.append()
 1333         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1334         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1335 
 1336         self.connection.teardown_server(fakes.SERVER_DETAIL,
 1337                                         fakes.SECURITY_SERVICE)
 1338 
 1339         expected_calls = [
 1340             mock.call(self.vdm.req_get()),
 1341             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1342             mock.call(self.mover.req_get_ref()),
 1343             mock.call(self.mover.req_delete_interface(
 1344                 fakes.FakeData.network_allocations_ip1)),
 1345             mock.call(self.mover.req_delete_interface(
 1346                 fakes.FakeData.network_allocations_ip2)),
 1347             mock.call(self.vdm.req_delete()),
 1348         ]
 1349         xml_req_mock.assert_has_calls(expected_calls)
 1350 
 1351         ssh_calls = [
 1352             mock.call(self.vdm.cmd_get_interfaces(), False),
 1353             mock.call(self.vdm.cmd_detach_nfs_interface(), True),
 1354         ]
 1355         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1356 
 1357     def test_teardown_server_with_invalid_cifs_server_modification(self):
 1358         hook = utils.RequestSideEffect()
 1359         hook.append(self.vdm.resp_get_succeed())
 1360         hook.append(self.cifs_server.resp_get_succeed(
 1361             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1362         hook.append(self.cifs_server.resp_task_error())
 1363         hook.append(self.cifs_server.resp_task_succeed())
 1364         hook.append(self.mover.resp_get_ref_succeed())
 1365         hook.append(self.mover.resp_task_succeed())
 1366         hook.append(self.mover.resp_task_succeed())
 1367         hook.append(self.vdm.resp_task_succeed())
 1368         xml_req_mock = utils.EMCMock(side_effect=hook)
 1369         self.connection.manager.connectors['XML'].request = xml_req_mock
 1370 
 1371         ssh_hook = utils.SSHSideEffect()
 1372         ssh_hook.append(self.vdm.output_get_interfaces_vdm())
 1373         ssh_hook.append()
 1374         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1375         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1376 
 1377         self.connection.teardown_server(fakes.SERVER_DETAIL,
 1378                                         fakes.SECURITY_SERVICE)
 1379 
 1380         expected_calls = [
 1381             mock.call(self.vdm.req_get()),
 1382             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1383             mock.call(self.cifs_server.req_modify(self.vdm.vdm_id)),
 1384             mock.call(self.cifs_server.req_delete(self.vdm.vdm_id)),
 1385             mock.call(self.mover.req_get_ref()),
 1386             mock.call(self.mover.req_delete_interface(
 1387                 fakes.FakeData.network_allocations_ip1)),
 1388             mock.call(self.mover.req_delete_interface(
 1389                 fakes.FakeData.network_allocations_ip2)),
 1390             mock.call(self.vdm.req_delete()),
 1391         ]
 1392         xml_req_mock.assert_has_calls(expected_calls)
 1393 
 1394         ssh_calls = [
 1395             mock.call(self.vdm.cmd_get_interfaces(), False),
 1396             mock.call(self.vdm.cmd_detach_nfs_interface(), True),
 1397         ]
 1398         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1399 
 1400     def test_update_access_add_cifs_rw(self):
 1401         share_server = fakes.SHARE_SERVER
 1402         share = fakes.CIFS_SHARE
 1403         access = fakes.CIFS_RW_ACCESS
 1404 
 1405         hook = utils.RequestSideEffect()
 1406         hook.append(self.vdm.resp_get_succeed())
 1407         hook.append(self.cifs_server.resp_get_succeed(
 1408             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1409         xml_req_mock = utils.EMCMock(side_effect=hook)
 1410         self.connection.manager.connectors['XML'].request = xml_req_mock
 1411 
 1412         ssh_hook = utils.SSHSideEffect()
 1413         ssh_hook.append(self.cifs_share.output_allow_access())
 1414         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1415         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1416 
 1417         self.connection.update_access(None, share, [], [access], [],
 1418                                       share_server=share_server)
 1419 
 1420         expected_calls = [
 1421             mock.call(self.vdm.req_get()),
 1422             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1423         ]
 1424         xml_req_mock.assert_has_calls(expected_calls)
 1425 
 1426         ssh_calls = [
 1427             mock.call(self.cifs_share.cmd_change_access(), True),
 1428         ]
 1429         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1430 
 1431     def test_update_access_add_cifs_rw_with_ipv6(self):
 1432         share_server = fakes.SHARE_SERVER_IPV6
 1433         share = fakes.CIFS_SHARE
 1434         access = fakes.CIFS_RW_ACCESS
 1435 
 1436         hook = utils.RequestSideEffect()
 1437         hook.append(self.vdm.resp_get_succeed(
 1438             interface1=fakes.FakeData.interface_name3,
 1439             interface2=fakes.FakeData.interface_name4))
 1440         hook.append(self.cifs_server.resp_get_succeed(
 1441             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 1442             ip_addr=fakes.FakeData.network_allocations_ip3))
 1443         xml_req_mock = utils.EMCMock(side_effect=hook)
 1444         self.connection.manager.connectors['XML'].request = xml_req_mock
 1445 
 1446         ssh_hook = utils.SSHSideEffect()
 1447         ssh_hook.append(self.cifs_share.output_allow_access())
 1448         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1449         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1450 
 1451         self.connection.update_access(None, share, [], [access], [],
 1452                                       share_server=share_server)
 1453 
 1454         expected_calls = [
 1455             mock.call(self.vdm.req_get()),
 1456             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1457         ]
 1458         xml_req_mock.assert_has_calls(expected_calls)
 1459 
 1460         ssh_calls = [
 1461             mock.call(self.cifs_share.cmd_change_access(), True),
 1462         ]
 1463         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1464 
 1465     def test_update_access_deny_nfs(self):
 1466         share_server = fakes.SHARE_SERVER
 1467         share = fakes.NFS_SHARE
 1468         access = fakes.NFS_RW_ACCESS
 1469 
 1470         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts)
 1471         rw_hosts.append(access['access_to'])
 1472 
 1473         ssh_hook = utils.SSHSideEffect()
 1474         ssh_hook.append(self.nfs_share.output_get_succeed(
 1475             rw_hosts=rw_hosts,
 1476             ro_hosts=fakes.FakeData.ro_hosts))
 1477         ssh_hook.append(self.nfs_share.output_set_access_success())
 1478         ssh_hook.append(self.nfs_share.output_get_succeed(
 1479             rw_hosts=fakes.FakeData.rw_hosts,
 1480             ro_hosts=fakes.FakeData.ro_hosts))
 1481         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 1482         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1483 
 1484         self.connection.update_access(None, share, [], [], [access],
 1485                                       share_server=share_server)
 1486 
 1487         ssh_calls = [
 1488             mock.call(self.nfs_share.cmd_get(), True),
 1489             mock.call(self.nfs_share.cmd_set_access(
 1490                 rw_hosts=self.nfs_share.rw_hosts,
 1491                 ro_hosts=self.nfs_share.ro_hosts), True),
 1492             mock.call(self.nfs_share.cmd_get(), True),
 1493         ]
 1494         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1495 
 1496     def test_update_access_deny_nfs_with_ipv6(self):
 1497         share_server = fakes.SHARE_SERVER_IPV6
 1498         share = fakes.NFS_SHARE
 1499         access = fakes.NFS_RW_ACCESS
 1500 
 1501         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts_ipv6)
 1502         rw_hosts.append(access['access_to'])
 1503 
 1504         ssh_hook = utils.SSHSideEffect()
 1505         ssh_hook.append(self.nfs_share.output_get_succeed(
 1506             rw_hosts=rw_hosts,
 1507             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 1508         ssh_hook.append(self.nfs_share.output_set_access_success())
 1509         ssh_hook.append(self.nfs_share.output_get_succeed(
 1510             rw_hosts=fakes.FakeData.rw_hosts_ipv6,
 1511             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 1512         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 1513         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1514 
 1515         self.connection.update_access(None, share, [], [], [access],
 1516                                       share_server=share_server)
 1517 
 1518         ssh_calls = [
 1519             mock.call(self.nfs_share.cmd_get(), True),
 1520             mock.call(self.nfs_share.cmd_set_access(
 1521                 rw_hosts=self.nfs_share.rw_hosts_ipv6,
 1522                 ro_hosts=self.nfs_share.ro_hosts_ipv6), True),
 1523             mock.call(self.nfs_share.cmd_get(), True),
 1524         ]
 1525         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1526 
 1527     def test_update_access_recover_nfs_rule(self):
 1528         share_server = fakes.SHARE_SERVER
 1529         share = fakes.NFS_SHARE
 1530         access = fakes.NFS_RW_ACCESS
 1531         hosts = ['192.168.1.5']
 1532 
 1533         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts)
 1534         rw_hosts.append(access['access_to'])
 1535 
 1536         ssh_hook = utils.SSHSideEffect()
 1537         ssh_hook.append(self.nfs_share.output_get_succeed(
 1538             rw_hosts=rw_hosts,
 1539             ro_hosts=fakes.FakeData.ro_hosts))
 1540         ssh_hook.append(self.nfs_share.output_set_access_success())
 1541         ssh_hook.append(self.nfs_share.output_get_succeed(
 1542             rw_hosts=hosts,
 1543             ro_hosts=[]))
 1544         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 1545         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1546 
 1547         self.connection.update_access(None, share, [access], [], [],
 1548                                       share_server=share_server)
 1549 
 1550         ssh_calls = [
 1551             mock.call(self.nfs_share.cmd_get(), True),
 1552             mock.call(self.nfs_share.cmd_set_access(
 1553                 rw_hosts=hosts,
 1554                 ro_hosts=[]), True),
 1555             mock.call(self.nfs_share.cmd_get(), True),
 1556         ]
 1557         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1558 
 1559     def test_update_access_recover_nfs_rule_with_ipv6(self):
 1560         share_server = fakes.SHARE_SERVER_IPV6
 1561         share = fakes.NFS_SHARE
 1562         access = fakes.NFS_RW_ACCESS_IPV6
 1563         hosts = ['fdf8:f53b:82e1::5']
 1564 
 1565         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts_ipv6)
 1566         rw_hosts.append(access['access_to'])
 1567 
 1568         ssh_hook = utils.SSHSideEffect()
 1569         ssh_hook.append(self.nfs_share.output_get_succeed(
 1570             rw_hosts=rw_hosts,
 1571             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 1572         ssh_hook.append(self.nfs_share.output_set_access_success())
 1573         ssh_hook.append(self.nfs_share.output_get_succeed(
 1574             rw_hosts=hosts,
 1575             ro_hosts=[]))
 1576         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 1577         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1578 
 1579         self.connection.update_access(None, share, [access], [], [],
 1580                                       share_server=share_server)
 1581 
 1582         ssh_calls = [
 1583             mock.call(self.nfs_share.cmd_get(), True),
 1584             mock.call(self.nfs_share.cmd_set_access(
 1585                 rw_hosts=hosts,
 1586                 ro_hosts=[]), True),
 1587             mock.call(self.nfs_share.cmd_get(), True),
 1588         ]
 1589         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1590 
 1591     def test_update_access_recover_cifs_rule(self):
 1592         share_server = fakes.SHARE_SERVER
 1593         share = fakes.CIFS_SHARE
 1594         access = fakes.CIFS_RW_ACCESS
 1595 
 1596         hook = utils.RequestSideEffect()
 1597         hook.append(self.vdm.resp_get_succeed())
 1598         hook.append(self.cifs_server.resp_get_succeed(
 1599             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1600         xml_req_mock = utils.EMCMock(side_effect=hook)
 1601         self.connection.manager.connectors['XML'].request = xml_req_mock
 1602 
 1603         ssh_hook = utils.SSHSideEffect()
 1604         ssh_hook.append(self.cifs_share.output_allow_access())
 1605         ssh_hook.append(fakes.FakeData.cifs_access)
 1606         ssh_hook.append('Command succeeded')
 1607 
 1608         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1609         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1610 
 1611         self.connection.update_access(None, share, [access], [], [],
 1612                                       share_server=share_server)
 1613 
 1614         expected_calls = [
 1615             mock.call(self.vdm.req_get()),
 1616             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1617         ]
 1618         xml_req_mock.assert_has_calls(expected_calls)
 1619 
 1620         ssh_calls = [
 1621             mock.call(self.cifs_share.cmd_change_access(), True),
 1622             mock.call(self.cifs_share.cmd_get_access(), True),
 1623             mock.call(self.cifs_share.cmd_change_access(
 1624                 action='revoke', user='guest'), True),
 1625         ]
 1626         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1627 
 1628     def test_update_access_recover_cifs_rule_with_ipv6(self):
 1629         share_server = fakes.SHARE_SERVER_IPV6
 1630         share = fakes.CIFS_SHARE
 1631         access = fakes.CIFS_RW_ACCESS
 1632 
 1633         hook = utils.RequestSideEffect()
 1634         hook.append(self.vdm.resp_get_succeed(
 1635             interface1=fakes.FakeData.interface_name3,
 1636             interface2=fakes.FakeData.interface_name4))
 1637         hook.append(self.cifs_server.resp_get_succeed(
 1638             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 1639             ip_addr=fakes.FakeData.network_allocations_ip3))
 1640         xml_req_mock = utils.EMCMock(side_effect=hook)
 1641         self.connection.manager.connectors['XML'].request = xml_req_mock
 1642 
 1643         ssh_hook = utils.SSHSideEffect()
 1644         ssh_hook.append(self.cifs_share.output_allow_access())
 1645         ssh_hook.append(fakes.FakeData.cifs_access)
 1646         ssh_hook.append('Command succeeded')
 1647 
 1648         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1649         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1650 
 1651         self.connection.update_access(None, share, [access], [], [],
 1652                                       share_server=share_server)
 1653 
 1654         expected_calls = [
 1655             mock.call(self.vdm.req_get()),
 1656             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1657         ]
 1658         xml_req_mock.assert_has_calls(expected_calls)
 1659 
 1660         ssh_calls = [
 1661             mock.call(self.cifs_share.cmd_change_access(), True),
 1662             mock.call(self.cifs_share.cmd_get_access(), True),
 1663             mock.call(self.cifs_share.cmd_change_access(
 1664                 action='revoke', user='guest'), True),
 1665         ]
 1666         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1667 
 1668     def test_cifs_clear_access_server_not_found(self):
 1669         server = fakes.SHARE_SERVER
 1670 
 1671         hook = utils.RequestSideEffect()
 1672         hook.append(self.vdm.resp_get_succeed())
 1673         hook.append(self.cifs_server.resp_get_succeed(
 1674             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 1675             cifs_server_name='cifs_server_name'))
 1676         xml_req_mock = utils.EMCMock(side_effect=hook)
 1677         self.connection.manager.connectors['XML'].request = xml_req_mock
 1678 
 1679         self.assertRaises(exception.EMCVnxXMLAPIError,
 1680                           self.connection._cifs_clear_access,
 1681                           'share_name', server, None)
 1682 
 1683         expected_calls = [
 1684             mock.call(self.vdm.req_get()),
 1685             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1686         ]
 1687         xml_req_mock.assert_has_calls(expected_calls)
 1688 
 1689     def test_allow_cifs_rw_access(self):
 1690         share_server = fakes.SHARE_SERVER
 1691         share = fakes.CIFS_SHARE
 1692         access = fakes.CIFS_RW_ACCESS
 1693 
 1694         hook = utils.RequestSideEffect()
 1695         hook.append(self.vdm.resp_get_succeed())
 1696         hook.append(self.cifs_server.resp_get_succeed(
 1697             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1698         xml_req_mock = utils.EMCMock(side_effect=hook)
 1699         self.connection.manager.connectors['XML'].request = xml_req_mock
 1700 
 1701         ssh_hook = utils.SSHSideEffect()
 1702         ssh_hook.append(self.cifs_share.output_allow_access())
 1703         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1704         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1705 
 1706         self.connection.allow_access(None, share, access, share_server)
 1707 
 1708         expected_calls = [
 1709             mock.call(self.vdm.req_get()),
 1710             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1711         ]
 1712         xml_req_mock.assert_has_calls(expected_calls)
 1713 
 1714         ssh_calls = [
 1715             mock.call(self.cifs_share.cmd_change_access(), True),
 1716         ]
 1717         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1718 
 1719     def test_allow_cifs_rw_access_with_ipv6(self):
 1720         share_server = fakes.SHARE_SERVER_IPV6
 1721         share = fakes.CIFS_SHARE
 1722         access = fakes.CIFS_RW_ACCESS
 1723 
 1724         hook = utils.RequestSideEffect()
 1725         hook.append(self.vdm.resp_get_succeed(
 1726             interface1=fakes.FakeData.interface_name3,
 1727             interface2=fakes.FakeData.interface_name4))
 1728         hook.append(self.cifs_server.resp_get_succeed(
 1729             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 1730             ip_addr=fakes.FakeData.network_allocations_ip3))
 1731         xml_req_mock = utils.EMCMock(side_effect=hook)
 1732         self.connection.manager.connectors['XML'].request = xml_req_mock
 1733 
 1734         ssh_hook = utils.SSHSideEffect()
 1735         ssh_hook.append(self.cifs_share.output_allow_access())
 1736         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1737         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1738 
 1739         self.connection.allow_access(None, share, access, share_server)
 1740 
 1741         expected_calls = [
 1742             mock.call(self.vdm.req_get()),
 1743             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1744         ]
 1745         xml_req_mock.assert_has_calls(expected_calls)
 1746 
 1747         ssh_calls = [
 1748             mock.call(self.cifs_share.cmd_change_access(), True),
 1749         ]
 1750         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1751 
 1752     def test_allow_cifs_ro_access(self):
 1753         share_server = fakes.SHARE_SERVER
 1754         share = fakes.CIFS_SHARE
 1755         access = fakes.CIFS_RO_ACCESS
 1756 
 1757         hook = utils.RequestSideEffect()
 1758         hook.append(self.vdm.resp_get_succeed())
 1759         hook.append(self.cifs_server.resp_get_succeed(
 1760             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1761         xml_req_mock = utils.EMCMock(side_effect=hook)
 1762         self.connection.manager.connectors['XML'].request = xml_req_mock
 1763 
 1764         ssh_hook = utils.SSHSideEffect()
 1765         ssh_hook.append(self.cifs_share.output_allow_access())
 1766         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1767         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1768 
 1769         self.connection.allow_access(None, share, access, share_server)
 1770 
 1771         expected_calls = [
 1772             mock.call(self.vdm.req_get()),
 1773             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1774         ]
 1775         xml_req_mock.assert_has_calls(expected_calls)
 1776 
 1777         ssh_calls = [
 1778             mock.call(self.cifs_share.cmd_change_access('ro'), True),
 1779         ]
 1780         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1781 
 1782     def test_allow_cifs_ro_access_with_ipv6(self):
 1783         share_server = fakes.SHARE_SERVER_IPV6
 1784         share = fakes.CIFS_SHARE
 1785         access = fakes.CIFS_RO_ACCESS
 1786 
 1787         hook = utils.RequestSideEffect()
 1788         hook.append(self.vdm.resp_get_succeed(
 1789             interface1=fakes.FakeData.interface_name3,
 1790             interface2=fakes.FakeData.interface_name4))
 1791         hook.append(self.cifs_server.resp_get_succeed(
 1792             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 1793             ip_addr=fakes.FakeData.network_allocations_ip3))
 1794         xml_req_mock = utils.EMCMock(side_effect=hook)
 1795         self.connection.manager.connectors['XML'].request = xml_req_mock
 1796 
 1797         ssh_hook = utils.SSHSideEffect()
 1798         ssh_hook.append(self.cifs_share.output_allow_access())
 1799         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1800         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1801 
 1802         self.connection.allow_access(None, share, access, share_server)
 1803 
 1804         expected_calls = [
 1805             mock.call(self.vdm.req_get()),
 1806             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1807         ]
 1808         xml_req_mock.assert_has_calls(expected_calls)
 1809 
 1810         ssh_calls = [
 1811             mock.call(self.cifs_share.cmd_change_access('ro'), True),
 1812         ]
 1813         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1814 
 1815     def test_allow_ro_access_without_share_server_name(self):
 1816         share = fakes.CIFS_SHARE
 1817         share_server = copy.deepcopy(fakes.SHARE_SERVER)
 1818         share_server['backend_details'].pop('share_server_name')
 1819         access = fakes.CIFS_RO_ACCESS
 1820 
 1821         hook = utils.RequestSideEffect()
 1822         hook.append(self.vdm.resp_get_succeed())
 1823         hook.append(self.cifs_server.resp_get_succeed(
 1824             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1825         xml_req_mock = utils.EMCMock(side_effect=hook)
 1826         self.connection.manager.connectors['XML'].request = xml_req_mock
 1827 
 1828         ssh_hook = utils.SSHSideEffect()
 1829         ssh_hook.append(self.cifs_share.output_allow_access())
 1830         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1831         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1832 
 1833         self.connection.allow_access(None, share, access, share_server)
 1834 
 1835         expected_calls = [
 1836             mock.call(self.vdm.req_get()),
 1837             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1838         ]
 1839         xml_req_mock.assert_has_calls(expected_calls)
 1840 
 1841         ssh_calls = [
 1842             mock.call(self.cifs_share.cmd_change_access('ro'), True),
 1843         ]
 1844         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1845 
 1846     def test_allow_access_with_invalid_access_level(self):
 1847         share_server = fakes.SHARE_SERVER
 1848         share = fakes.CIFS_SHARE
 1849         access = fake_share.fake_access(access_level='fake_level')
 1850 
 1851         self.assertRaises(exception.InvalidShareAccessLevel,
 1852                           self.connection.allow_access,
 1853                           None, share, access, share_server)
 1854 
 1855     def test_allow_access_with_invalid_share_server_name(self):
 1856         share_server = fakes.SHARE_SERVER
 1857         share = fakes.CIFS_SHARE
 1858         access = fakes.CIFS_RW_ACCESS
 1859 
 1860         hook = utils.RequestSideEffect()
 1861         hook.append(self.vdm.resp_get_succeed())
 1862         hook.append(self.cifs_server.resp_get_error())
 1863         xml_req_mock = utils.EMCMock(side_effect=hook)
 1864         self.connection.manager.connectors['XML'].request = xml_req_mock
 1865 
 1866         self.assertRaises(exception.EMCVnxXMLAPIError,
 1867                           self.connection.allow_access,
 1868                           None, share, access, share_server)
 1869 
 1870         expected_calls = [
 1871             mock.call(self.vdm.req_get()),
 1872             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1873         ]
 1874         xml_req_mock.assert_has_calls(expected_calls)
 1875 
 1876     def test_allow_nfs_access(self):
 1877         share_server = fakes.SHARE_SERVER
 1878         share = fakes.NFS_SHARE
 1879         access = fakes.NFS_RW_ACCESS
 1880 
 1881         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts)
 1882         rw_hosts.append(access['access_to'])
 1883 
 1884         ssh_hook = utils.SSHSideEffect()
 1885         ssh_hook.append(self.nfs_share.output_get_succeed(
 1886             rw_hosts=fakes.FakeData.rw_hosts,
 1887             ro_hosts=fakes.FakeData.ro_hosts))
 1888         ssh_hook.append(self.nfs_share.output_set_access_success())
 1889         ssh_hook.append(self.nfs_share.output_get_succeed(
 1890             rw_hosts=rw_hosts,
 1891             ro_hosts=fakes.FakeData.ro_hosts))
 1892         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 1893         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1894 
 1895         self.connection.allow_access(None, share, access, share_server)
 1896 
 1897         ssh_calls = [
 1898             mock.call(self.nfs_share.cmd_get(), True),
 1899             mock.call(self.nfs_share.cmd_set_access(
 1900                 rw_hosts=rw_hosts, ro_hosts=self.nfs_share.ro_hosts), True),
 1901             mock.call(self.nfs_share.cmd_get(), True),
 1902         ]
 1903         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1904 
 1905     def test_allow_nfs_access_with_ipv6(self):
 1906         share_server = fakes.SHARE_SERVER_IPV6
 1907         share = fakes.NFS_SHARE
 1908         access = fakes.NFS_RW_ACCESS_IPV6
 1909 
 1910         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts_ipv6)
 1911         rw_hosts.append(access['access_to'])
 1912 
 1913         ssh_hook = utils.SSHSideEffect()
 1914         ssh_hook.append(self.nfs_share.output_get_succeed(
 1915             rw_hosts=fakes.FakeData.rw_hosts_ipv6,
 1916             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 1917         ssh_hook.append(self.nfs_share.output_set_access_success())
 1918         ssh_hook.append(self.nfs_share.output_get_succeed(
 1919             rw_hosts=rw_hosts,
 1920             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 1921         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 1922         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1923 
 1924         self.connection.allow_access(None, share, access, share_server)
 1925 
 1926         ssh_calls = [
 1927             mock.call(self.nfs_share.cmd_get(), True),
 1928             mock.call(self.nfs_share.cmd_set_access(
 1929                 rw_hosts=rw_hosts,
 1930                 ro_hosts=self.nfs_share.ro_hosts_ipv6),
 1931                 True),
 1932             mock.call(self.nfs_share.cmd_get(), True),
 1933         ]
 1934         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1935 
 1936     def test_allow_cifs_access_with_incorrect_access_type(self):
 1937         share_server = fakes.SHARE_SERVER
 1938         share = fakes.CIFS_SHARE
 1939         access = fake_share.fake_access(access_type='fake_type')
 1940 
 1941         self.assertRaises(exception.InvalidShareAccess,
 1942                           self.connection.allow_access,
 1943                           None, share, access, share_server)
 1944 
 1945     def test_allow_nfs_access_with_incorrect_access_type(self):
 1946         share_server = fakes.SHARE_SERVER
 1947         share = fakes.NFS_SHARE
 1948         access = fake_share.fake_access(access_type='fake_type')
 1949 
 1950         self.assertRaises(exception.InvalidShareAccess,
 1951                           self.connection.allow_access,
 1952                           None, share, access, share_server)
 1953 
 1954     def test_allow_access_with_incorrect_proto(self):
 1955         share_server = fakes.SHARE_SERVER
 1956         share = fake_share.fake_share(share_proto='FAKE_PROTO')
 1957         access = fake_share.fake_access()
 1958 
 1959         self.assertRaises(exception.InvalidShare,
 1960                           self.connection.allow_access,
 1961                           None, share, access, share_server)
 1962 
 1963     def test_deny_cifs_rw_access(self):
 1964         share_server = fakes.SHARE_SERVER
 1965         share = fakes.CIFS_SHARE
 1966         access = fakes.CIFS_RW_ACCESS
 1967 
 1968         hook = utils.RequestSideEffect()
 1969         hook.append(self.vdm.resp_get_succeed())
 1970         hook.append(self.cifs_server.resp_get_succeed(
 1971             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 1972         xml_req_mock = utils.EMCMock(side_effect=hook)
 1973         self.connection.manager.connectors['XML'].request = xml_req_mock
 1974 
 1975         ssh_hook = utils.SSHSideEffect()
 1976         ssh_hook.append(self.cifs_share.output_allow_access())
 1977         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 1978         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 1979 
 1980         self.connection.deny_access(None, share, access, share_server)
 1981 
 1982         expected_calls = [
 1983             mock.call(self.vdm.req_get()),
 1984             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 1985         ]
 1986         xml_req_mock.assert_has_calls(expected_calls)
 1987 
 1988         ssh_calls = [
 1989             mock.call(self.cifs_share.cmd_change_access(action='revoke'),
 1990                       True),
 1991         ]
 1992         ssh_cmd_mock.assert_has_calls(ssh_calls)
 1993 
 1994     def test_deny_cifs_rw_access_with_ipv6(self):
 1995         share_server = fakes.SHARE_SERVER_IPV6
 1996         share = fakes.CIFS_SHARE
 1997         access = fakes.CIFS_RW_ACCESS
 1998 
 1999         hook = utils.RequestSideEffect()
 2000         hook.append(self.vdm.resp_get_succeed(
 2001             interface1=fakes.FakeData.interface_name3,
 2002             interface2=fakes.FakeData.interface_name4))
 2003         hook.append(self.cifs_server.resp_get_succeed(
 2004             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 2005             ip_addr=fakes.FakeData.network_allocations_ip3))
 2006         xml_req_mock = utils.EMCMock(side_effect=hook)
 2007         self.connection.manager.connectors['XML'].request = xml_req_mock
 2008 
 2009         ssh_hook = utils.SSHSideEffect()
 2010         ssh_hook.append(self.cifs_share.output_allow_access())
 2011         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 2012         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2013 
 2014         self.connection.deny_access(None, share, access, share_server)
 2015 
 2016         expected_calls = [
 2017             mock.call(self.vdm.req_get()),
 2018             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 2019         ]
 2020         xml_req_mock.assert_has_calls(expected_calls)
 2021 
 2022         ssh_calls = [
 2023             mock.call(self.cifs_share.cmd_change_access(action='revoke'),
 2024                       True),
 2025         ]
 2026         ssh_cmd_mock.assert_has_calls(ssh_calls)
 2027 
 2028     def test_deny_cifs_ro_access(self):
 2029         share_server = fakes.SHARE_SERVER
 2030         share = fakes.CIFS_SHARE
 2031         access = fakes.CIFS_RO_ACCESS
 2032 
 2033         hook = utils.RequestSideEffect()
 2034         hook.append(self.vdm.resp_get_succeed())
 2035         hook.append(self.cifs_server.resp_get_succeed(
 2036             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True))
 2037         xml_req_mock = utils.EMCMock(side_effect=hook)
 2038         self.connection.manager.connectors['XML'].request = xml_req_mock
 2039 
 2040         ssh_hook = utils.SSHSideEffect()
 2041         ssh_hook.append(self.cifs_share.output_allow_access())
 2042         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 2043         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2044 
 2045         self.connection.deny_access(None, share, access, share_server)
 2046 
 2047         expected_calls = [
 2048             mock.call(self.vdm.req_get()),
 2049             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 2050         ]
 2051         xml_req_mock.assert_has_calls(expected_calls)
 2052 
 2053         ssh_calls = [
 2054             mock.call(self.cifs_share.cmd_change_access('ro', 'revoke'), True),
 2055         ]
 2056         ssh_cmd_mock.assert_has_calls(ssh_calls)
 2057 
 2058     def test_deny_cifs_ro_access_with_ipv6(self):
 2059         share_server = fakes.SHARE_SERVER_IPV6
 2060         share = fakes.CIFS_SHARE
 2061         access = fakes.CIFS_RO_ACCESS
 2062 
 2063         hook = utils.RequestSideEffect()
 2064         hook.append(self.vdm.resp_get_succeed(
 2065             interface1=fakes.FakeData.interface_name3,
 2066             interface2=fakes.FakeData.interface_name4))
 2067         hook.append(self.cifs_server.resp_get_succeed(
 2068             mover_id=self.vdm.vdm_id, is_vdm=True, join_domain=True,
 2069             ip_addr=fakes.FakeData.network_allocations_ip3))
 2070         xml_req_mock = utils.EMCMock(side_effect=hook)
 2071         self.connection.manager.connectors['XML'].request = xml_req_mock
 2072 
 2073         ssh_hook = utils.SSHSideEffect()
 2074         ssh_hook.append(self.cifs_share.output_allow_access())
 2075         ssh_cmd_mock = mock.Mock(side_effect=ssh_hook)
 2076         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2077 
 2078         self.connection.deny_access(None, share, access, share_server)
 2079 
 2080         expected_calls = [
 2081             mock.call(self.vdm.req_get()),
 2082             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 2083         ]
 2084         xml_req_mock.assert_has_calls(expected_calls)
 2085 
 2086         ssh_calls = [
 2087             mock.call(self.cifs_share.cmd_change_access('ro', 'revoke'), True),
 2088         ]
 2089         ssh_cmd_mock.assert_has_calls(ssh_calls)
 2090 
 2091     def test_deny_cifs_access_with_invliad_share_server_name(self):
 2092         share_server = fakes.SHARE_SERVER
 2093         share = fakes.CIFS_SHARE
 2094         access = fakes.CIFS_RW_ACCESS
 2095 
 2096         hook = utils.RequestSideEffect()
 2097         hook.append(self.vdm.resp_get_succeed())
 2098         hook.append(self.cifs_server.resp_get_error())
 2099         xml_req_mock = utils.EMCMock(side_effect=hook)
 2100         self.connection.manager.connectors['XML'].request = xml_req_mock
 2101 
 2102         self.assertRaises(exception.EMCVnxXMLAPIError,
 2103                           self.connection.deny_access,
 2104                           None, share, access, share_server)
 2105 
 2106         expected_calls = [
 2107             mock.call(self.vdm.req_get()),
 2108             mock.call(self.cifs_server.req_get(self.vdm.vdm_id)),
 2109         ]
 2110         xml_req_mock.assert_has_calls(expected_calls)
 2111 
 2112     def test_deny_nfs_access(self):
 2113         share_server = fakes.SHARE_SERVER
 2114         share = fakes.NFS_SHARE
 2115         access = fakes.NFS_RW_ACCESS
 2116 
 2117         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts)
 2118         rw_hosts.append(access['access_to'])
 2119 
 2120         ssh_hook = utils.SSHSideEffect()
 2121         ssh_hook.append(self.nfs_share.output_get_succeed(
 2122             rw_hosts=rw_hosts,
 2123             ro_hosts=fakes.FakeData.ro_hosts))
 2124         ssh_hook.append(self.nfs_share.output_set_access_success())
 2125         ssh_hook.append(self.nfs_share.output_get_succeed(
 2126             rw_hosts=fakes.FakeData.rw_hosts,
 2127             ro_hosts=fakes.FakeData.ro_hosts))
 2128         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 2129         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2130 
 2131         self.connection.deny_access(None, share, access, share_server)
 2132 
 2133         ssh_calls = [
 2134             mock.call(self.nfs_share.cmd_get(), True),
 2135             mock.call(self.nfs_share.cmd_set_access(
 2136                 rw_hosts=self.nfs_share.rw_hosts,
 2137                 ro_hosts=self.nfs_share.ro_hosts), True),
 2138             mock.call(self.nfs_share.cmd_get(), True),
 2139         ]
 2140         ssh_cmd_mock.assert_has_calls(ssh_calls)
 2141 
 2142     def test_deny_nfs_access_with_ipv6(self):
 2143         share_server = fakes.SHARE_SERVER_IPV6
 2144         share = fakes.NFS_SHARE
 2145         access = fakes.NFS_RW_ACCESS_IPV6
 2146 
 2147         rw_hosts = copy.deepcopy(fakes.FakeData.rw_hosts_ipv6)
 2148         rw_hosts.append(access['access_to'])
 2149 
 2150         ssh_hook = utils.SSHSideEffect()
 2151         ssh_hook.append(self.nfs_share.output_get_succeed(
 2152             rw_hosts=rw_hosts,
 2153             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 2154         ssh_hook.append(self.nfs_share.output_set_access_success())
 2155         ssh_hook.append(self.nfs_share.output_get_succeed(
 2156             rw_hosts=fakes.FakeData.rw_hosts_ipv6,
 2157             ro_hosts=fakes.FakeData.ro_hosts_ipv6))
 2158         ssh_cmd_mock = utils.EMCNFSShareMock(side_effect=ssh_hook)
 2159         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2160 
 2161         self.connection.deny_access(None, share, access, share_server)
 2162 
 2163         ssh_calls = [
 2164             mock.call(self.nfs_share.cmd_get(), True),
 2165             mock.call(self.nfs_share.cmd_set_access(
 2166                 rw_hosts=self.nfs_share.rw_hosts_ipv6,
 2167                 ro_hosts=self.nfs_share.ro_hosts_ipv6), True),
 2168             mock.call(self.nfs_share.cmd_get(), True),
 2169         ]
 2170         ssh_cmd_mock.assert_has_calls(ssh_calls)
 2171 
 2172     def test_deny_access_with_incorrect_proto(self):
 2173         share_server = fakes.SHARE_SERVER
 2174         share = fake_share.fake_share(share_proto='FAKE_PROTO')
 2175         access = fakes.CIFS_RW_ACCESS
 2176 
 2177         self.assertRaises(exception.InvalidShare,
 2178                           self.connection.deny_access,
 2179                           None, share, access, share_server)
 2180 
 2181     def test_deny_cifs_access_with_incorrect_access_type(self):
 2182         share_server = fakes.SHARE_SERVER
 2183         share = fakes.CIFS_SHARE
 2184         access = fake_share.fake_access(access_type='fake_type')
 2185 
 2186         self.assertRaises(exception.InvalidShareAccess,
 2187                           self.connection.deny_access,
 2188                           None, share, access, share_server)
 2189 
 2190     def test_deny_nfs_access_with_incorrect_access_type(self):
 2191         share_server = fakes.SHARE_SERVER
 2192         share = fakes.NFS_SHARE
 2193         access = fake_share.fake_access(access_type='fake_type')
 2194 
 2195         self.assertRaises(exception.InvalidShareAccess,
 2196                           self.connection.deny_access,
 2197                           None, share, access, share_server)
 2198 
 2199     def test_update_share_stats(self):
 2200         hook = utils.RequestSideEffect()
 2201         hook.append(self.mover.resp_get_ref_succeed())
 2202         hook.append(self.pool.resp_get_succeed())
 2203         xml_req_mock = utils.EMCMock(side_effect=hook)
 2204         self.connection.manager.connectors['XML'].request = xml_req_mock
 2205 
 2206         self.connection.update_share_stats(fakes.STATS)
 2207 
 2208         expected_calls = [
 2209             mock.call(self.mover.req_get_ref()),
 2210             mock.call(self.pool.req_get()),
 2211         ]
 2212         xml_req_mock.assert_has_calls(expected_calls)
 2213 
 2214         for pool in fakes.STATS['pools']:
 2215             if pool['pool_name'] == fakes.FakeData.pool_name:
 2216                 self.assertEqual(
 2217                     enas_utils.mb_to_gb(fakes.FakeData.pool_total_size),
 2218                     pool['total_capacity_gb'])
 2219 
 2220                 free_size = (fakes.FakeData.pool_total_size -
 2221                              fakes.FakeData.pool_used_size)
 2222                 self.assertEqual(
 2223                     enas_utils.mb_to_gb(free_size), pool['free_capacity_gb'])
 2224 
 2225     def test_update_share_stats_without_matched_config_pools(self):
 2226         self.connection.pools = set('fake_pool')
 2227 
 2228         hook = utils.RequestSideEffect()
 2229         hook.append(self.mover.resp_get_ref_succeed())
 2230         hook.append(self.pool.resp_get_succeed())
 2231         xml_req_mock = utils.EMCMock(side_effect=hook)
 2232         self.connection.manager.connectors['XML'].request = xml_req_mock
 2233 
 2234         self.assertRaises(exception.EMCVnxXMLAPIError,
 2235                           self.connection.update_share_stats,
 2236                           fakes.STATS)
 2237 
 2238         expected_calls = [
 2239             mock.call(self.mover.req_get_ref()),
 2240             mock.call(self.pool.req_get()),
 2241         ]
 2242         xml_req_mock.assert_has_calls(expected_calls)
 2243 
 2244     def test_get_pool(self):
 2245         share = fakes.CIFS_SHARE
 2246 
 2247         hook = utils.RequestSideEffect()
 2248         hook.append(self.fs.resp_get_succeed())
 2249         hook.append(self.pool.resp_get_succeed())
 2250         xml_req_mock = utils.EMCMock(side_effect=hook)
 2251         self.connection.manager.connectors['XML'].request = xml_req_mock
 2252 
 2253         pool_name = self.connection.get_pool(share)
 2254 
 2255         expected_calls = [
 2256             mock.call(self.fs.req_get()),
 2257             mock.call(self.pool.req_get()),
 2258         ]
 2259         xml_req_mock.assert_has_calls(expected_calls)
 2260 
 2261         self.assertEqual(fakes.FakeData.pool_name, pool_name)
 2262 
 2263     def test_get_pool_failed_to_get_filesystem_info(self):
 2264         share = fakes.CIFS_SHARE
 2265 
 2266         hook = utils.RequestSideEffect()
 2267         hook.append(self.fs.resp_get_error())
 2268         xml_req_mock = utils.EMCMock(side_effect=hook)
 2269         self.connection.manager.connectors['XML'].request = xml_req_mock
 2270 
 2271         self.assertRaises(exception.EMCVnxXMLAPIError,
 2272                           self.connection.get_pool,
 2273                           share)
 2274 
 2275         expected_calls = [mock.call(self.fs.req_get())]
 2276         xml_req_mock.assert_has_calls(expected_calls)
 2277 
 2278     def test_get_pool_failed_to_get_pool_info(self):
 2279         share = fakes.CIFS_SHARE
 2280 
 2281         hook = utils.RequestSideEffect()
 2282         hook.append(self.fs.resp_get_succeed())
 2283         hook.append(self.pool.resp_get_error())
 2284         xml_req_mock = utils.EMCMock(side_effect=hook)
 2285         self.connection.manager.connectors['XML'].request = xml_req_mock
 2286 
 2287         self.assertRaises(exception.EMCVnxXMLAPIError,
 2288                           self.connection.get_pool,
 2289                           share)
 2290 
 2291         expected_calls = [
 2292             mock.call(self.fs.req_get()),
 2293             mock.call(self.pool.req_get()),
 2294         ]
 2295         xml_req_mock.assert_has_calls(expected_calls)
 2296 
 2297     def test_get_pool_failed_to_find_matched_pool_name(self):
 2298         share = fakes.CIFS_SHARE
 2299 
 2300         hook = utils.RequestSideEffect()
 2301         hook.append(self.fs.resp_get_succeed())
 2302         hook.append(self.pool.resp_get_succeed(name='unmatch_pool_name',
 2303                                                id='unmatch_pool_id'))
 2304         xml_req_mock = utils.EMCMock(side_effect=hook)
 2305         self.connection.manager.connectors['XML'].request = xml_req_mock
 2306 
 2307         self.assertRaises(exception.EMCVnxXMLAPIError,
 2308                           self.connection.get_pool,
 2309                           share)
 2310 
 2311         expected_calls = [
 2312             mock.call(self.fs.req_get()),
 2313             mock.call(self.pool.req_get()),
 2314         ]
 2315         xml_req_mock.assert_has_calls(expected_calls)
 2316 
 2317     @ddt.data({'port_conf': None,
 2318                'managed_ports': ['cge-1-0', 'cge-1-3']},
 2319               {'port_conf': '*',
 2320                'managed_ports': ['cge-1-0', 'cge-1-3']},
 2321               {'port_conf': ['cge-1-*'],
 2322                'managed_ports': ['cge-1-0', 'cge-1-3']},
 2323               {'port_conf': ['cge-1-3'],
 2324                'managed_ports': ['cge-1-3']})
 2325     @ddt.unpack
 2326     def test_get_managed_ports_one_port(self, port_conf, managed_ports):
 2327         hook = utils.SSHSideEffect()
 2328         hook.append(self.mover.output_get_physical_devices())
 2329 
 2330         ssh_cmd_mock = mock.Mock(side_effect=hook)
 2331         expected_calls = [
 2332             mock.call(self.mover.cmd_get_physical_devices(), False),
 2333         ]
 2334         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2335         self.connection.port_conf = port_conf
 2336         ports = self.connection.get_managed_ports()
 2337         self.assertIsInstance(ports, list)
 2338         self.assertEqual(sorted(managed_ports), sorted(ports))
 2339         ssh_cmd_mock.assert_has_calls(expected_calls)
 2340 
 2341     def test_get_managed_ports_no_valid_port(self):
 2342         hook = utils.SSHSideEffect()
 2343         hook.append(self.mover.output_get_physical_devices())
 2344 
 2345         ssh_cmd_mock = mock.Mock(side_effect=hook)
 2346         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2347         self.connection.port_conf = ['cge-2-0']
 2348 
 2349         self.assertRaises(exception.BadConfigurationException,
 2350                           self.connection.get_managed_ports)
 2351 
 2352     def test_get_managed_ports_query_devices_failed(self):
 2353         hook = utils.SSHSideEffect()
 2354         hook.append(self.mover.fake_output)
 2355         ssh_cmd_mock = mock.Mock(side_effect=hook)
 2356         self.connection.manager.connectors['SSH'].run_ssh = ssh_cmd_mock
 2357         self.connection.port_conf = ['cge-2-0']
 2358 
 2359         self.assertRaises(exception.EMCVnxXMLAPIError,
 2360                           self.connection.get_managed_ports)