"Fossies" - the Fresh Open Source Software Archive

Member "cinder-14.0.2/cinder/tests/unit/volume/drivers/datacore/test_datacore_driver.py" (4 Oct 2019, 29063 Bytes) of package /linux/misc/openstack/cinder-14.0.2.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.

    1 # Copyright (c) 2017 DataCore Software Corp. All Rights Reserved.
    2 #
    3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    4 #    not use this file except in compliance with the License. You may obtain
    5 #    a copy of the License at
    6 #
    7 #         http://www.apache.org/licenses/LICENSE-2.0
    8 #
    9 #    Unless required by applicable law or agreed to in writing, software
   10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   12 #    License for the specific language governing permissions and limitations
   13 #    under the License.
   14 
   15 """Unit tests for the base Driver for DataCore SANsymphony storage array."""
   16 
   17 from __future__ import division
   18 
   19 import abc
   20 import mock
   21 
   22 from oslo_utils import units
   23 
   24 from cinder import exception as cinder_exception
   25 from cinder.tests.unit import fake_constants
   26 from cinder.tests.unit import utils as testutils
   27 from cinder.volume import configuration as conf
   28 from cinder.volume.drivers.datacore import driver as datacore_driver
   29 from cinder.volume.drivers.datacore import exception as datacore_exception
   30 from cinder.volume.drivers.san import san
   31 
   32 
   33 SERVER_GROUPS = [
   34     mock.Mock(Id='server_group_id1',
   35               OurGroup=True),
   36     mock.Mock(Id='server_group_id2',
   37               OurGroup=False),
   38 ]
   39 
   40 SERVERS = [
   41     mock.Mock(Id='server_id1',
   42               State='Online'),
   43     mock.Mock(Id='server_id2',
   44               State='Online'),
   45 ]
   46 
   47 DISK_POOLS = [
   48     mock.Mock(Id='disk_pool_id1',
   49               Caption='disk_pool1',
   50               ServerId='server_id1',
   51               PoolStatus='Running'),
   52     mock.Mock(Id='disk_pool_id2',
   53               Caption='disk_pool2',
   54               ServerId='server_id2',
   55               PoolStatus='Running'),
   56     mock.Mock(Id='disk_pool_id3',
   57               Caption='disk_pool3',
   58               ServerId='server_id1',
   59               PoolStatus='Offline'),
   60     mock.Mock(Id='disk_pool_id4',
   61               Caption='disk_pool4',
   62               ServerId='server_id2',
   63               PoolStatus='Unknown'),
   64 ]
   65 
   66 DISK_POOL_PERFORMANCE = [
   67     mock.Mock(ObjectId='disk_pool_id1',
   68               PerformanceData=mock.Mock(BytesTotal=5 * units.Gi,
   69                                         BytesAllocated=2 * units.Gi,
   70                                         BytesAvailable=3 * units.Gi,
   71                                         BytesReserved=0)),
   72     mock.Mock(ObjectId='disk_pool_id2',
   73               PerformanceData=mock.Mock(BytesTotal=5 * units.Gi,
   74                                         BytesAllocated=3 * units.Gi,
   75                                         BytesAvailable=1 * units.Gi,
   76                                         BytesReserved=1 * units.Gi)),
   77     mock.Mock(ObjectId='disk_pool_id3',
   78               PerformanceData=None),
   79     mock.Mock(ObjectId='disk_pool_id4',
   80               PerformanceData=None),
   81 ]
   82 
   83 STORAGE_PROFILES = [
   84     mock.Mock(Id='storage_profile_id1',
   85               Caption='storage_profile1'),
   86     mock.Mock(Id='storage_profile_id2',
   87               Caption='storage_profile2'),
   88     mock.Mock(Id='storage_profile_id3',
   89               Caption='storage_profile3'),
   90 ]
   91 
   92 VIRTUAL_DISKS = [
   93     mock.Mock(Id='virtual_disk_id1',
   94               DiskStatus='Online',
   95               IsServed=False,
   96               FirstHostId='server_id1'),
   97     mock.Mock(Id='virtual_disk_id2',
   98               DiskStatus='Failed',
   99               IsServed=False,
  100               FirstHostId='server_id2'),
  101     mock.Mock(Id='virtual_disk_id3',
  102               DiskStatus='Online',
  103               IsServed=True,
  104               FirstHostId='server_id1',
  105               SecondHostId='server_id2'),
  106     mock.Mock(Id='virtual_disk_id4',
  107               DiskStatus='Failed',
  108               IsServed=False,
  109               FirstHostId='server_id1',
  110               SecondHostId='server_id2'),
  111 ]
  112 
  113 VIRTUAL_DISK_SNAPSHOTS = [
  114     mock.Mock(Id='snapshot_id1',
  115               State='Migrated',
  116               Failure='NoFailure',
  117               DestinationLogicalDiskId='logical_disk_id1'),
  118     mock.Mock(Id='snapshot_id2',
  119               State='Failed',
  120               Failure='NotAccessible',
  121               DestinationLogicalDiskId='logical_disk_id2'),
  122     mock.Mock(Id='snapshot_id3',
  123               State='Migrated',
  124               Failure='NoFailure',
  125               DestinationLogicalDiskId='logical_disk_id2'),
  126 ]
  127 
  128 LOGICAL_DISKS = [
  129     mock.Mock(Id='logical_disk_id1',
  130               VirtualDiskId='virtual_disk_id1',
  131               ServerHostId='server_id1',
  132               PoolId='disk_pool_id1',
  133               Size=mock.Mock(Value=1 * units.Gi)),
  134     mock.Mock(Id='logical_disk_id2',
  135               VirtualDiskId='virtual_disk_id2',
  136               ServerHostId='server_id1',
  137               PoolId='disk_pool_id3',
  138               Size=mock.Mock(Value=1 * units.Gi)),
  139     mock.Mock(Id='logical_disk_id3',
  140               VirtualDiskId='virtual_disk_id3',
  141               ServerHostId='server_id1',
  142               PoolId='disk_pool_id1',
  143               Size=mock.Mock(Value=1 * units.Gi)),
  144     mock.Mock(Id='logical_disk_id4',
  145               VirtualDiskId='virtual_disk_id3',
  146               ServerHostId='server_id2',
  147               PoolId='disk_pool_id2',
  148               Size=mock.Mock(Value=1 * units.Gi)),
  149     mock.Mock(Id='logical_disk_id5',
  150               VirtualDiskId='virtual_disk_id4',
  151               ServerHostId='server_id1',
  152               PoolId='disk_pool_id3',
  153               Size=mock.Mock(Value=1 * units.Gi)),
  154     mock.Mock(Id='logical_disk_id6',
  155               VirtualDiskId='virtual_disk_id4',
  156               ServerHostId='server_id2',
  157               PoolId='disk_pool_id4',
  158               Size=mock.Mock(Value=1 * units.Gi)),
  159 ]
  160 
  161 LOGICAL_UNITS = [
  162     mock.Mock(VirtualTargetDeviceId='target_device_id1',
  163               LogicalDiskId='logical_disk_id3'),
  164     mock.Mock(VirtualTargetDeviceId='target_device_id2',
  165               LogicalDiskId='logical_disk_id4'),
  166 ]
  167 
  168 TARGET_DEVICES = [
  169     mock.Mock(Id='target_device_id1',
  170               InitiatorPortId='initiator_port_id1'),
  171     mock.Mock(Id='target_device_id2',
  172               InitiatorPortId='initiator_port_id1'),
  173 ]
  174 
  175 CLIENTS = [
  176     mock.Mock(Id='client_id1',
  177               HostName='client_host_name1'),
  178     mock.Mock(Id='client_id2',
  179               HostName='client_host_name2'),
  180 ]
  181 
  182 VOLUME = {
  183     'id': fake_constants.VOLUME_ID,
  184     'display_name': 'volume_1',
  185     'volume_type_id': None,
  186     'size': 1,
  187 }
  188 
  189 SNAPSHOT = {
  190     'id': fake_constants.SNAPSHOT_ID,
  191     'display_name': 'snapshot_1',
  192 }
  193 
  194 
  195 class DataCoreVolumeDriverTestCase(object):
  196     """Tests for the base Driver for DataCore SANsymphony storage array."""
  197 
  198     def setUp(self):
  199         super(DataCoreVolumeDriverTestCase, self).setUp()
  200         self.override_config('datacore_disk_failed_delay', 0)
  201         self.mock_client = mock.Mock()
  202         self.mock_client.get_servers.return_value = SERVERS
  203         self.mock_client.get_disk_pools.return_value = DISK_POOLS
  204         (self.mock_client.get_performance_by_type
  205          .return_value) = DISK_POOL_PERFORMANCE
  206         self.mock_client.get_virtual_disks.return_value = VIRTUAL_DISKS
  207         self.mock_client.get_storage_profiles.return_value = STORAGE_PROFILES
  208         self.mock_client.get_snapshots.return_value = VIRTUAL_DISK_SNAPSHOTS
  209         self.mock_client.get_logical_disks.return_value = LOGICAL_DISKS
  210         self.mock_client.get_clients.return_value = CLIENTS
  211         self.mock_client.get_server_groups.return_value = SERVER_GROUPS
  212         self.mock_object(datacore_driver.api,
  213                          'DataCoreClient',
  214                          return_value=self.mock_client)
  215 
  216     @staticmethod
  217     @abc.abstractmethod
  218     def init_driver(config):
  219         raise NotImplementedError()
  220 
  221     @staticmethod
  222     def create_configuration():
  223         config = conf.Configuration(None)
  224         config.append_config_values(san.san_opts)
  225         config.append_config_values(datacore_driver.datacore_opts)
  226         return config
  227 
  228     def setup_default_configuration(self):
  229         config = self.create_configuration()
  230         config.volume_backend_name = 'DataCore'
  231         config.san_ip = '127.0.0.1'
  232         config.san_login = 'dcsadmin'
  233         config.san_password = 'password'
  234         config.datacore_api_timeout = 0
  235         return config
  236 
  237     def test_do_setup(self):
  238         config = self.setup_default_configuration()
  239         self.init_driver(config)
  240 
  241     def test_do_setup_failed(self):
  242         config = self.setup_default_configuration()
  243         config.san_ip = None
  244         self.assertRaises(cinder_exception.InvalidInput,
  245                           self.init_driver,
  246                           config)
  247 
  248         config = self.setup_default_configuration()
  249         config.san_login = None
  250         self.assertRaises(cinder_exception.InvalidInput,
  251                           self.init_driver,
  252                           config)
  253 
  254         config = self.setup_default_configuration()
  255         config.san_password = None
  256         self.assertRaises(cinder_exception.InvalidInput,
  257                           self.init_driver,
  258                           config)
  259 
  260     def test_get_volume_stats(self):
  261         aggregation = [(getattr(perf.PerformanceData, 'BytesTotal', 0),
  262                         getattr(perf.PerformanceData, 'BytesAvailable', 0),
  263                         getattr(perf.PerformanceData, 'BytesReserved', 0),)
  264                        for perf in DISK_POOL_PERFORMANCE]
  265 
  266         total, available, reserved = map(sum, zip(*aggregation))
  267         free = (available + reserved) / units.Gi
  268         reserved = 100.0 * reserved / total
  269         total /= units.Gi
  270         provisioned = sum(disk.Size.Value for disk in LOGICAL_DISKS)
  271         provisioned /= units.Gi
  272         ratio = 2.0
  273 
  274         config = self.setup_default_configuration()
  275         config.max_over_subscription_ratio = ratio
  276         driver = self.init_driver(config)
  277         expected_volume_stats = {
  278             'vendor_name': 'DataCore',
  279             'QoS_support': False,
  280             'total_capacity_gb': total,
  281             'free_capacity_gb': free,
  282             'provisioned_capacity_gb': provisioned,
  283             'reserved_percentage': reserved,
  284             'max_over_subscription_ratio': ratio,
  285             'thin_provisioning_support': True,
  286             'thick_provisioning_support': False,
  287             'volume_backend_name': driver.get_volume_backend_name(),
  288             'driver_version': driver.get_version(),
  289             'storage_protocol': driver.get_storage_protocol(),
  290         }
  291         volume_stats = driver.get_volume_stats(refresh=True)
  292         self.assertDictEqual(expected_volume_stats, volume_stats)
  293         volume_stats_cached = driver.get_volume_stats(refresh=False)
  294         self.assertEqual(volume_stats, volume_stats_cached)
  295 
  296     def test_create_volume(self):
  297         virtual_disk = VIRTUAL_DISKS[0]
  298         self.mock_client.create_virtual_disk_ex2.return_value = virtual_disk
  299 
  300         driver = self.init_driver(self.setup_default_configuration())
  301         volume = VOLUME.copy()
  302         result = driver.create_volume(volume)
  303         self.assertIn('provider_location', result)
  304         self.assertEqual(virtual_disk.Id, result['provider_location'])
  305 
  306     def test_create_volume_mirrored_disk_type_specified(self):
  307         virtual_disk = VIRTUAL_DISKS[2]
  308         self.mock_client.create_virtual_disk_ex2.return_value = virtual_disk
  309 
  310         config = self.setup_default_configuration()
  311         config.datacore_disk_type = 'mirrored'
  312         driver = self.init_driver(config)
  313         volume = VOLUME.copy()
  314         result = driver.create_volume(volume)
  315         self.assertIn('provider_location', result)
  316         self.assertEqual(virtual_disk.Id, result['provider_location'])
  317 
  318         driver = self.init_driver(self.setup_default_configuration())
  319         volume_type = {
  320             'extra_specs': {driver.DATACORE_DISK_TYPE_KEY: 'mirrored'}
  321         }
  322         get_volume_type = self.mock_object(datacore_driver.volume_types,
  323                                            'get_volume_type')
  324         get_volume_type.return_value = volume_type
  325         volume = VOLUME.copy()
  326         volume['volume_type_id'] = 'volume_type_id'
  327         result = driver.create_volume(volume)
  328         self.assertIn('provider_location', result)
  329         self.assertEqual(virtual_disk.Id, result['provider_location'])
  330 
  331     def test_create_volume_profile_specified(self):
  332         virtual_disk = VIRTUAL_DISKS[0]
  333         self.mock_client.create_virtual_disk_ex2.return_value = virtual_disk
  334 
  335         config = self.setup_default_configuration()
  336         config.datacore_storage_profile = 'storage_profile1'
  337         driver = self.init_driver(config)
  338         volume = VOLUME.copy()
  339         result = driver.create_volume(volume)
  340         self.assertIn('provider_location', result)
  341         self.assertEqual(virtual_disk.Id, result['provider_location'])
  342 
  343         volume_type = {
  344             'extra_specs': {
  345                 driver.DATACORE_STORAGE_PROFILE_KEY: 'storage_profile2'
  346             }
  347         }
  348         get_volume_type = self.mock_object(datacore_driver.volume_types,
  349                                            'get_volume_type')
  350         get_volume_type.return_value = volume_type
  351         volume = VOLUME.copy()
  352         volume['volume_type_id'] = 'volume_type_id'
  353         result = driver.create_volume(volume)
  354         self.assertIn('provider_location', result)
  355         self.assertEqual(virtual_disk.Id, result['provider_location'])
  356 
  357     def test_create_volume_pool_specified(self):
  358         virtual_disk = VIRTUAL_DISKS[0]
  359         self.mock_client.create_virtual_disk_ex2.return_value = virtual_disk
  360 
  361         config = self.setup_default_configuration()
  362         config.datacore_disk_pools = ['disk_pool1']
  363         driver = self.init_driver(config)
  364         volume = VOLUME.copy()
  365         result = driver.create_volume(volume)
  366         self.assertIn('provider_location', result)
  367         self.assertEqual(virtual_disk.Id, result['provider_location'])
  368 
  369         volume_type = {
  370             'extra_specs': {driver.DATACORE_DISK_POOLS_KEY: 'disk_pool2'}
  371         }
  372         get_volume_type = self.mock_object(datacore_driver.volume_types,
  373                                            'get_volume_type')
  374         get_volume_type.return_value = volume_type
  375         volume = VOLUME.copy()
  376         volume['volume_type_id'] = 'volume_type_id'
  377         result = driver.create_volume(volume)
  378         self.assertIn('provider_location', result)
  379         self.assertEqual(virtual_disk.Id, result['provider_location'])
  380 
  381     def test_create_volume_failed(self):
  382         def fail_with_datacore_fault(*args):
  383             raise datacore_exception.DataCoreFaultException(
  384                 reason="General error.")
  385 
  386         (self.mock_client.create_virtual_disk_ex2
  387          .side_effect) = fail_with_datacore_fault
  388 
  389         driver = self.init_driver(self.setup_default_configuration())
  390         volume = VOLUME.copy()
  391         self.assertRaises(datacore_exception.DataCoreFaultException,
  392                           driver.create_volume,
  393                           volume)
  394 
  395     def test_create_volume_unknown_disk_type_specified(self):
  396         config = self.setup_default_configuration()
  397         config.datacore_disk_type = 'unknown'
  398         driver = self.init_driver(config)
  399         volume = VOLUME.copy()
  400         self.assertRaises(cinder_exception.VolumeDriverException,
  401                           driver.create_volume,
  402                           volume)
  403 
  404         driver = self.init_driver(self.setup_default_configuration())
  405         volume_type = {
  406             'extra_specs': {driver.DATACORE_DISK_TYPE_KEY: 'unknown'}
  407         }
  408         get_volume_type = self.mock_object(datacore_driver.volume_types,
  409                                            'get_volume_type')
  410         get_volume_type.return_value = volume_type
  411         volume = VOLUME.copy()
  412         volume['volume_type_id'] = 'volume_type_id'
  413         self.assertRaises(cinder_exception.VolumeDriverException,
  414                           driver.create_volume,
  415                           volume)
  416 
  417     def test_create_volume_unknown_profile_specified(self):
  418         config = self.setup_default_configuration()
  419         config.datacore_storage_profile = 'unknown'
  420         driver = self.init_driver(config)
  421         volume = VOLUME.copy()
  422         self.assertRaises(cinder_exception.VolumeDriverException,
  423                           driver.create_volume,
  424                           volume)
  425 
  426         driver = self.init_driver(self.setup_default_configuration())
  427         volume_type = {
  428             'extra_specs': {driver.DATACORE_STORAGE_PROFILE_KEY: 'unknown'}
  429         }
  430         get_volume_type = self.mock_object(datacore_driver.volume_types,
  431                                            'get_volume_type')
  432         get_volume_type.return_value = volume_type
  433         volume = VOLUME.copy()
  434         volume['volume_type_id'] = 'volume_type_id'
  435         self.assertRaises(cinder_exception.VolumeDriverException,
  436                           driver.create_volume,
  437                           volume)
  438 
  439     def test_create_volume_on_failed_pool(self):
  440         config = self.setup_default_configuration()
  441         config.datacore_disk_pools = ['disk_pool3', 'disk_pool4']
  442         driver = self.init_driver(config)
  443         volume = VOLUME.copy()
  444         self.assertRaises(cinder_exception.VolumeDriverException,
  445                           driver.create_volume,
  446                           volume)
  447 
  448     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  449                 new=testutils.ZeroIntervalLoopingCall)
  450     def test_create_volume_await_online_timed_out(self):
  451         virtual_disk = VIRTUAL_DISKS[1]
  452         self.mock_client.create_virtual_disk_ex2.return_value = virtual_disk
  453 
  454         config = self.setup_default_configuration()
  455         driver = self.init_driver(config)
  456         volume = VOLUME.copy()
  457         self.assertRaises(cinder_exception.VolumeDriverException,
  458                           driver.create_volume,
  459                           volume)
  460 
  461     def test_extend_volume(self):
  462         virtual_disk = VIRTUAL_DISKS[0]
  463         driver = self.init_driver(self.setup_default_configuration())
  464         volume = VOLUME.copy()
  465         volume['provider_location'] = virtual_disk.Id
  466         driver.extend_volume(volume, 2147483648)
  467 
  468     def test_extend_volume_failed_not_found(self):
  469         driver = self.init_driver(self.setup_default_configuration())
  470         volume = VOLUME.copy()
  471         volume['provider_location'] = 'wrong_virtual_disk_id'
  472         self.assertRaises(cinder_exception.VolumeDriverException,
  473                           driver.extend_volume,
  474                           volume,
  475                           2147483648)
  476 
  477     def test_delete_volume(self):
  478         virtual_disk = VIRTUAL_DISKS[0]
  479         driver = self.init_driver(self.setup_default_configuration())
  480         volume = VOLUME.copy()
  481         volume['provider_location'] = virtual_disk.Id
  482         driver.delete_volume(volume)
  483 
  484     def test_delete_volume_assigned(self):
  485         self.mock_client.get_logical_disks.return_value = LOGICAL_DISKS
  486         self.mock_client.get_logical_units.return_value = LOGICAL_UNITS
  487         self.mock_client.get_target_devices.return_value = TARGET_DEVICES
  488 
  489         driver = self.init_driver(self.setup_default_configuration())
  490         volume = VOLUME.copy()
  491         virtual_disk = VIRTUAL_DISKS[2]
  492         volume['provider_location'] = virtual_disk.Id
  493         driver.delete_volume(volume)
  494 
  495     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  496                 new=testutils.ZeroIntervalLoopingCall)
  497     def test_create_snapshot(self):
  498         virtual_disk = VIRTUAL_DISKS[0]
  499         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  500         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  501 
  502         driver = self.init_driver(self.setup_default_configuration())
  503         volume = VOLUME.copy()
  504         volume['provider_location'] = virtual_disk.Id
  505         snapshot = SNAPSHOT.copy()
  506         snapshot['volume'] = volume
  507         result = driver.create_snapshot(snapshot)
  508         self.assertIn('provider_location', result)
  509 
  510     def test_create_snapshot_on_failed_pool(self):
  511         virtual_disk = VIRTUAL_DISKS[0]
  512         config = self.setup_default_configuration()
  513         config.datacore_disk_pools = ['disk_pool3', 'disk_pool4']
  514         driver = self.init_driver(config)
  515         volume = VOLUME.copy()
  516         volume['provider_location'] = virtual_disk.Id
  517         snapshot = SNAPSHOT.copy()
  518         snapshot['volume'] = volume
  519         self.assertRaises(cinder_exception.VolumeDriverException,
  520                           driver.create_snapshot,
  521                           snapshot)
  522 
  523     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  524                 new=testutils.ZeroIntervalLoopingCall)
  525     def test_create_snapshot_await_migrated_timed_out(self):
  526         virtual_disk = VIRTUAL_DISKS[0]
  527         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[1]
  528         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  529 
  530         driver = self.init_driver(self.setup_default_configuration())
  531         volume = VOLUME.copy()
  532         volume['provider_location'] = virtual_disk.Id
  533         snapshot = SNAPSHOT.copy()
  534         snapshot['volume'] = volume
  535         self.assertRaises(cinder_exception.VolumeDriverException,
  536                           driver.create_snapshot,
  537                           snapshot)
  538 
  539     def test_delete_snapshot(self):
  540         virtual_disk = VIRTUAL_DISKS[0]
  541         driver = self.init_driver(self.setup_default_configuration())
  542         snapshot = SNAPSHOT.copy()
  543         snapshot['provider_location'] = virtual_disk.Id
  544         driver.delete_snapshot(snapshot)
  545 
  546     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  547                 new=testutils.ZeroIntervalLoopingCall)
  548     def test_create_volume_from_snapshot(self):
  549         virtual_disk = VIRTUAL_DISKS[0]
  550         self.mock_client.set_virtual_disk_size.return_value = virtual_disk
  551         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  552         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  553 
  554         driver = self.init_driver(self.setup_default_configuration())
  555         volume = VOLUME.copy()
  556         snapshot = SNAPSHOT.copy()
  557         snapshot['provider_location'] = virtual_disk.Id
  558         result = driver.create_volume_from_snapshot(volume, snapshot)
  559         self.assertIn('provider_location', result)
  560 
  561     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  562                 new=testutils.ZeroIntervalLoopingCall)
  563     def test_create_volume_from_snapshot_mirrored_disk_type_specified(self):
  564         virtual_disk = VIRTUAL_DISKS[0]
  565         self.mock_client.set_virtual_disk_size.return_value = virtual_disk
  566         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  567         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  568 
  569         config = self.setup_default_configuration()
  570         config.datacore_disk_type = 'mirrored'
  571         driver = self.init_driver(config)
  572         volume = VOLUME.copy()
  573         snapshot = SNAPSHOT.copy()
  574         snapshot['provider_location'] = virtual_disk.Id
  575         result = driver.create_volume_from_snapshot(volume, snapshot)
  576         self.assertIn('provider_location', result)
  577 
  578     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  579                 new=testutils.ZeroIntervalLoopingCall)
  580     def test_create_volume_from_snapshot_on_failed_pool(self):
  581         virtual_disk = VIRTUAL_DISKS[0]
  582         self.mock_client.set_virtual_disk_size.return_value = virtual_disk
  583         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  584         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  585 
  586         config = self.setup_default_configuration()
  587         config.datacore_disk_type = 'mirrored'
  588         config.datacore_disk_pools = ['disk_pool1', 'disk_pool4']
  589         driver = self.init_driver(config)
  590         volume = VOLUME.copy()
  591         snapshot = SNAPSHOT.copy()
  592         snapshot['provider_location'] = virtual_disk.Id
  593         self.assertRaises(cinder_exception.VolumeDriverException,
  594                           driver.create_volume_from_snapshot,
  595                           volume,
  596                           snapshot)
  597 
  598     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  599                 new=testutils.ZeroIntervalLoopingCall)
  600     def test_create_volume_from_snapshot_await_online_timed_out(self):
  601         virtual_disk = VIRTUAL_DISKS[0]
  602         snapshot_virtual_disk = VIRTUAL_DISKS[1]
  603         (self.mock_client.set_virtual_disk_size
  604          .return_value) = snapshot_virtual_disk
  605         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[2]
  606         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  607 
  608         driver = self.init_driver(self.setup_default_configuration())
  609         volume = VOLUME.copy()
  610         snapshot = SNAPSHOT.copy()
  611         snapshot['provider_location'] = virtual_disk.Id
  612         self.assertRaises(cinder_exception.VolumeDriverException,
  613                           driver.create_volume_from_snapshot,
  614                           volume,
  615                           snapshot)
  616 
  617     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  618                 new=testutils.ZeroIntervalLoopingCall)
  619     def test_create_cloned_volume(self):
  620         virtual_disk = VIRTUAL_DISKS[0]
  621         self.mock_client.set_virtual_disk_size.return_value = virtual_disk
  622         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  623         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  624 
  625         driver = self.init_driver(self.setup_default_configuration())
  626         volume = VOLUME.copy()
  627         src_vref = VOLUME.copy()
  628         src_vref['provider_location'] = virtual_disk.Id
  629         result = driver.create_cloned_volume(volume, src_vref)
  630         self.assertIn('provider_location', result)
  631 
  632     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  633                 new=testutils.ZeroIntervalLoopingCall)
  634     def test_create_cloned_volume_mirrored_disk_type_specified(self):
  635         virtual_disk = VIRTUAL_DISKS[0]
  636         self.mock_client.set_virtual_disk_size.return_value = virtual_disk
  637         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  638         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  639 
  640         config = self.setup_default_configuration()
  641         config.datacore_disk_type = 'mirrored'
  642         driver = self.init_driver(config)
  643         volume = VOLUME.copy()
  644         src_vref = VOLUME.copy()
  645         src_vref['provider_location'] = virtual_disk.Id
  646         result = driver.create_cloned_volume(volume, src_vref)
  647         self.assertIn('provider_location', result)
  648 
  649     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  650                 new=testutils.ZeroIntervalLoopingCall)
  651     def test_create_cloned_volume_on_failed_pool(self):
  652         virtual_disk = VIRTUAL_DISKS[0]
  653         self.mock_client.set_virtual_disk_size.return_value = virtual_disk
  654         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[0]
  655         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  656 
  657         config = self.setup_default_configuration()
  658         config.datacore_disk_type = 'mirrored'
  659         config.datacore_disk_pools = ['disk_pool1', 'disk_pool4']
  660         driver = self.init_driver(config)
  661         volume = VOLUME.copy()
  662         src_vref = VOLUME.copy()
  663         src_vref['provider_location'] = virtual_disk.Id
  664         self.assertRaises(cinder_exception.VolumeDriverException,
  665                           driver.create_cloned_volume,
  666                           volume,
  667                           src_vref)
  668 
  669     @mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall',
  670                 new=testutils.ZeroIntervalLoopingCall)
  671     def test_create_cloned_volume_await_online_timed_out(self):
  672         virtual_disk = VIRTUAL_DISKS[0]
  673         snapshot_virtual_disk = VIRTUAL_DISKS[1]
  674         (self.mock_client.set_virtual_disk_size
  675          .return_value) = snapshot_virtual_disk
  676         virtual_disk_snapshot = VIRTUAL_DISK_SNAPSHOTS[2]
  677         self.mock_client.create_snapshot.return_value = virtual_disk_snapshot
  678 
  679         driver = self.init_driver(self.setup_default_configuration())
  680         volume = VOLUME.copy()
  681         src_vref = VOLUME.copy()
  682         src_vref['provider_location'] = virtual_disk.Id
  683         self.assertRaises(cinder_exception.VolumeDriverException,
  684                           driver.create_cloned_volume,
  685                           volume,
  686                           src_vref)
  687 
  688     def test_terminate_connection(self):
  689         virtual_disk = VIRTUAL_DISKS[0]
  690         client = CLIENTS[0]
  691         driver = self.init_driver(self.setup_default_configuration())
  692         volume = VOLUME.copy()
  693         volume['provider_location'] = virtual_disk.Id
  694         connector = {'host': client.HostName}
  695         driver.terminate_connection(volume, connector)
  696 
  697     def test_terminate_connection_connector_is_none(self):
  698         virtual_disk = VIRTUAL_DISKS[0]
  699         driver = self.init_driver(self.setup_default_configuration())
  700         volume = VOLUME.copy()
  701         volume['provider_location'] = virtual_disk.Id
  702         driver.terminate_connection(volume, None)