"Fossies" - the Fresh Open Source Software Archive

Member "cinder-17.1.0/cinder/tests/unit/volume/drivers/dell_emc/powerstore/test_volume_create_delete_extend.py" (8 Mar 2021, 7299 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_delete_extend.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_volume
   20 from cinder.tests.unit.volume.drivers.dell_emc import powerstore
   21 from cinder.volume.drivers.dell_emc.powerstore import client
   22 
   23 
   24 class TestVolumeCreateDeleteExtend(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(TestVolumeCreateDeleteExtend, 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 
   40     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   41                 "PowerStoreClient.create_volume")
   42     def test_create_volume(self, mock_create):
   43         mock_create.return_value = "fake_id"
   44         self.driver.create_volume(self.volume)
   45 
   46     @mock.patch("requests.request")
   47     def test_create_volume_bad_status(self, mock_create_request):
   48         mock_create_request.return_value = powerstore.MockResponse(rc=400)
   49         error = self.assertRaises(exception.VolumeBackendAPIException,
   50                                   self.driver.create_volume,
   51                                   self.volume)
   52         self.assertIn("Failed to create PowerStore volume", error.msg)
   53 
   54     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.adapter."
   55                 "CommonAdapter._detach_volume_from_hosts")
   56     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   57                 "PowerStoreClient.delete_volume_or_snapshot")
   58     def test_delete_volume(self, mock_delete, mock_detach):
   59         self.driver.delete_volume(self.volume)
   60 
   61     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.adapter."
   62                 "CommonAdapter._detach_volume_from_hosts")
   63     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   64                 "PowerStoreClient.delete_volume_or_snapshot")
   65     def test_delete_volume_no_provider_id(self, mock_delete, mock_detach):
   66         self.volume.provider_id = None
   67         self.driver.delete_volume(self.volume)
   68         mock_detach.assert_not_called()
   69         mock_delete.assert_not_called()
   70 
   71     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.adapter."
   72                 "CommonAdapter._detach_volume_from_hosts")
   73     @mock.patch("requests.request")
   74     def test_delete_volume_not_found(self, mock_delete_request, mock_detach):
   75         mock_delete_request.return_value = powerstore.MockResponse(rc=404)
   76         self.driver.delete_volume(self.volume)
   77 
   78     @mock.patch("requests.request")
   79     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   80                 "PowerStoreClient.get_volume_mapped_hosts")
   81     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   82                 "PowerStoreClient.delete_volume_or_snapshot")
   83     def test_delete_volume_detach_not_found(self,
   84                                             mock_delete,
   85                                             mock_mapped_hosts,
   86                                             mock_detach_request):
   87         mock_mapped_hosts.return_value = ["fake_host_id"]
   88         mock_detach_request.return_value = powerstore.MockResponse(
   89             content={},
   90             rc=404
   91         )
   92         self.driver.delete_volume(self.volume)
   93 
   94     @mock.patch("requests.request")
   95     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   96                 "PowerStoreClient.get_volume_mapped_hosts")
   97     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   98                 "PowerStoreClient.delete_volume_or_snapshot")
   99     def test_delete_volume_detach_not_mapped(self,
  100                                              mock_delete,
  101                                              mock_mapped_hosts,
  102                                              mock_detach_request):
  103         mock_mapped_hosts.return_value = ["fake_host_id"]
  104         mock_detach_request.return_value = powerstore.MockResponse(
  105             content={
  106                 "messages": [
  107                     {
  108                         "code": client.VOLUME_NOT_MAPPED_ERROR,
  109                     },
  110                 ],
  111             },
  112             rc=422
  113         )
  114         self.driver.delete_volume(self.volume)
  115 
  116     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.adapter."
  117                 "CommonAdapter._detach_volume_from_hosts")
  118     @mock.patch("requests.request")
  119     def test_delete_volume_bad_status(self, mock_delete, mock_detach):
  120         mock_delete.return_value = powerstore.MockResponse(rc=400)
  121         error = self.assertRaises(exception.VolumeBackendAPIException,
  122                                   self.driver.delete_volume,
  123                                   self.volume)
  124         self.assertIn("Failed to delete PowerStore volume", error.msg)
  125 
  126     @mock.patch("requests.request")
  127     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
  128                 "PowerStoreClient.get_volume_mapped_hosts")
  129     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
  130                 "PowerStoreClient.delete_volume_or_snapshot")
  131     def test_delete_volume_detach_bad_status(self,
  132                                              mock_delete,
  133                                              mock_mapped_hosts,
  134                                              mock_detach_request):
  135         mock_mapped_hosts.return_value = ["fake_host_id"]
  136         mock_detach_request.return_value = powerstore.MockResponse(rc=400)
  137         error = self.assertRaises(exception.VolumeBackendAPIException,
  138                                   self.driver.delete_volume,
  139                                   self.volume)
  140         self.assertIn("Failed to detach PowerStore volume", error.msg)
  141 
  142     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
  143                 "PowerStoreClient.extend_volume")
  144     def test_extend_volume(self, mock_extend):
  145         self.driver.extend_volume(self.volume, 16)
  146 
  147     @mock.patch("requests.request")
  148     def test_extend_volume_bad_status(self, mock_extend_request):
  149         mock_extend_request.return_value = powerstore.MockResponse(rc=400)
  150         error = self.assertRaises(exception.VolumeBackendAPIException,
  151                                   self.driver.extend_volume,
  152                                   self.volume,
  153                                   16)
  154         self.assertIn("Failed to extend PowerStore volume", error.msg)