"Fossies" - the Fresh Open Source Software Archive

Member "cinder-17.1.0/cinder/tests/unit/volume/drivers/dell_emc/powerstore/test_snapshot_create_delete_revert.py" (8 Mar 2021, 3673 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_snapshot_create_delete_revert.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 TestSnapshotCreateDelete(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(TestSnapshotCreateDelete, 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.snapshot = fake_snapshot.fake_snapshot_obj(
   40             {},
   41             provider_id="fake_id_1",
   42             volume=self.volume
   43         )
   44 
   45     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   46                 "PowerStoreClient.create_snapshot")
   47     def test_create_snapshot(self, mock_create):
   48         mock_create.return_value = self.snapshot.provider_id
   49         self.driver.create_snapshot(self.snapshot)
   50 
   51     @mock.patch("requests.request")
   52     def test_create_snapshot_bad_status(self, mock_create_request):
   53         mock_create_request.return_value = powerstore.MockResponse(rc=400)
   54         error = self.assertRaises(
   55             exception.VolumeBackendAPIException,
   56             self.driver.create_snapshot,
   57             self.snapshot
   58         )
   59         self.assertIn("Failed to create snapshot", error.msg)
   60 
   61     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   62                 "PowerStoreClient.delete_volume_or_snapshot")
   63     def test_delete_snapshot(self, mock_delete):
   64         self.driver.delete_snapshot(self.snapshot)
   65 
   66     @mock.patch("requests.request")
   67     def test_delete_snapshot_bad_status(self, mock_delete):
   68         mock_delete.return_value = powerstore.MockResponse(rc=400)
   69         error = self.assertRaises(
   70             exception.VolumeBackendAPIException,
   71             self.driver.delete_snapshot,
   72             self.snapshot
   73         )
   74         self.assertIn("Failed to delete PowerStore snapshot", error.msg)
   75 
   76     @mock.patch("cinder.volume.drivers.dell_emc.powerstore.client."
   77                 "PowerStoreClient.restore_from_snapshot")
   78     def test_revert_to_snapshot(self, mock_revert):
   79         self.driver.revert_to_snapshot({}, self.volume, self.snapshot)
   80 
   81     @mock.patch("requests.request")
   82     def test_revert_to_snapshot_bad_status(self, mock_revert):
   83         mock_revert.return_value = powerstore.MockResponse(rc=400)
   84         error = self.assertRaises(
   85             exception.VolumeBackendAPIException,
   86             self.driver.revert_to_snapshot,
   87             {},
   88             self.volume,
   89             self.snapshot
   90         )
   91         self.assertIn("Failed to restore PowerStore volume", error.msg)