"Fossies" - the Fresh Open Source Software Archive

Member "cinder-17.1.0/cinder/tests/unit/volume/drivers/dell_emc/powerstore/test_volume_create_from_source.py" (8 Mar 2021, 5095 Bytes) of package /linux/misc/openstack/cinder-17.1.0.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_volume_create_from_source.py": 17.0.1_vs_17.1.0.

    1 # Copyright (c) 2020 Dell Inc. or its subsidiaries.
    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 from unittest import mock
   17 
   18 from cinder import exception
   19 from cinder.tests.unit import fake_snapshot
   20 from cinder.tests.unit import fake_volume
   21 from cinder.tests.unit.volume.drivers.dell_emc import powerstore
   22 
   23 
   24 class TestVolumeCreateFromSource(powerstore.TestPowerStoreDriver):
   25     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   26                 "PowerStoreClient.get_chap_config")
   27     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   28                 "PowerStoreClient.get_appliance_id_by_name")
   29     def setUp(self, mock_appliance, mock_chap):
   30         super(TestVolumeCreateFromSource, self).setUp()
   31         mock_appliance.return_value = "A1"
   32         self.driver.check_for_setup_error()
   33         self.volume = fake_volume.fake_volume_obj(
   34             {},
   35             host="host@backend#test-appliance",
   36             provider_id="fake_id",
   37             size=8
   38         )
   39         self.source_volume = fake_volume.fake_volume_obj(
   40             {},
   41             host="host@backend#test-appliance",
   42             provider_id="fake_id_1",
   43             size=8
   44         )
   45         self.source_snapshot = fake_snapshot.fake_snapshot_obj(
   46             {},
   47             provider_id="fake_id_2",
   48             volume_size=8
   49         )
   50 
   51     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   52                 "PowerStoreClient.clone_volume_or_snapshot")
   53     def test_create_cloned_volume(self, mock_create_cloned):
   54         mock_create_cloned.return_value = self.volume.provider_id
   55         self.driver.create_cloned_volume(self.volume, self.source_volume)
   56 
   57     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   58                 "PowerStoreClient.extend_volume")
   59     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   60                 "PowerStoreClient.clone_volume_or_snapshot")
   61     def test_create_cloned_volume_extended(self,
   62                                            mock_create_cloned,
   63                                            mock_extend):
   64         mock_create_cloned.return_value = self.volume.provider_id
   65         self.volume.size = 16
   66         self.driver.create_cloned_volume(self.volume, self.source_volume)
   67         mock_extend.assert_called_once()
   68 
   69     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   70                 "PowerStoreClient.clone_volume_or_snapshot")
   71     def test_create_volume_from_snapshot(self, mock_create_from_snap):
   72         mock_create_from_snap.return_value = self.volume.provider_id
   73         self.driver.create_volume_from_snapshot(self.volume,
   74                                                 self.source_snapshot)
   75 
   76     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   77                 "PowerStoreClient.extend_volume")
   78     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   79                 "PowerStoreClient.clone_volume_or_snapshot")
   80     def test_create_volume_from_snapshot_extended(self,
   81                                                   mock_create_from_snap,
   82                                                   mock_extend):
   83         mock_create_from_snap.return_value = self.volume.provider_id
   84         self.volume.size = 16
   85         self.driver.create_volume_from_snapshot(self.volume,
   86                                                 self.source_snapshot)
   87         mock_extend.assert_called_once()
   88 
   89     @mock.patch("requests.request")
   90     def test_create_volume_from_source_bad_status(self, mock_create_request):
   91         mock_create_request.return_value = powerstore.MockResponse(rc=400)
   92         error = self.assertRaises(
   93             exception.VolumeBackendAPIException,
   94             self.driver.adapter._create_volume_from_source,
   95             self.volume,
   96             self.source_volume
   97         )
   98         self.assertIn("Failed to create clone", error.msg)
   99 
  100     @mock.patch("requests.request")
  101     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
  102                 "PowerStoreClient.clone_volume_or_snapshot")
  103     def test_create_volume_from_source_extende_bad_status(
  104             self,
  105             mock_create_from_source,
  106             mock_extend_request
  107     ):
  108         mock_extend_request.return_value = powerstore.MockResponse(rc=400)
  109         self.volume.size = 16
  110         error = self.assertRaises(
  111             exception.VolumeBackendAPIException,
  112             self.driver.adapter._create_volume_from_source,
  113             self.volume,
  114             self.source_volume
  115         )
  116         self.assertIn("Failed to extend PowerStore volume", error.msg)