"Fossies" - the Fresh Open Source Software Archive

Member "cinder-17.1.0/cinder/tests/unit/volume/drivers/dell_emc/powerstore/test_base.py" (8 Mar 2021, 4086 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_base.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.volume.drivers.dell_emc import powerstore
   20 
   21 
   22 class TestBase(powerstore.TestPowerStoreDriver):
   23     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   24                 "PowerStoreClient.get_chap_config")
   25     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   26                 "PowerStoreClient.get_appliance_id_by_name")
   27     def test_configuration(self, mock_appliance, mock_chap):
   28         mock_appliance.return_value = "A1"
   29         self.driver.check_for_setup_error()
   30 
   31     def test_configuration_rest_parameters_not_set(self):
   32         self.driver.adapter.client.rest_ip = None
   33         self.assertRaises(exception.VolumeBackendAPIException,
   34                           self.driver.check_for_setup_error)
   35 
   36     def test_configuration_appliances_not_set(self):
   37         self.driver.adapter.appliances = {}
   38         self.assertRaises(exception.VolumeBackendAPIException,
   39                           self.driver.check_for_setup_error)
   40 
   41     @mock.patch("requests.request")
   42     def test_configuration_appliance_not_found(self, mock_get_request):
   43         mock_get_request.return_value = powerstore.MockResponse()
   44         error = self.assertRaises(exception.VolumeBackendAPIException,
   45                                   self.driver.check_for_setup_error)
   46         self.assertIn("not found", error.msg)
   47 
   48     @mock.patch("requests.request")
   49     def test_configuration_appliance_bad_status(self, mock_get_request):
   50         mock_get_request.return_value = powerstore.MockResponse(rc=400)
   51         error = self.assertRaises(exception.VolumeBackendAPIException,
   52                                   self.driver.check_for_setup_error)
   53         self.assertIn("Failed to query PowerStore appliances.", error.msg)
   54 
   55     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   56                 "PowerStoreClient.get_chap_config")
   57     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   58                 "PowerStoreClient.get_appliance_id_by_name")
   59     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   60                 "PowerStoreClient.get_appliance_metrics")
   61     def test_update_volume_stats(self,
   62                                  mock_metrics,
   63                                  mock_appliance,
   64                                  mock_chap):
   65         mock_appliance.return_value = "A1"
   66         mock_metrics.return_value = {
   67             "physical_total": 2147483648,
   68             "physical_used": 1073741824,
   69         }
   70         self.driver.check_for_setup_error()
   71         self.driver._update_volume_stats()
   72 
   73     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   74                 "PowerStoreClient.get_chap_config")
   75     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   76                 "PowerStoreClient.get_appliance_id_by_name")
   77     @mock.patch("requests.request")
   78     def test_update_volume_stats_bad_status(self,
   79                                             mock_metrics,
   80                                             mock_appliance,
   81                                             mock_chap):
   82         mock_appliance.return_value = "A1"
   83         mock_metrics.return_value = powerstore.MockResponse(rc=400)
   84         self.driver.check_for_setup_error()
   85         error = self.assertRaises(exception.VolumeBackendAPIException,
   86                                   self.driver._update_volume_stats)
   87         self.assertIn("Failed to query metrics", error.msg)