|
17 | 17 | from osc_lib import utils |
18 | 18 |
|
19 | 19 | from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes |
| 20 | +from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes_v3 |
20 | 21 | from openstackclient.volume.v3 import volume_snapshot |
21 | 22 |
|
22 | 23 |
|
23 | | -class TestVolumeSnapshot(volume_fakes.TestVolume): |
| 24 | +class TestVolumeSnapshot(volume_fakes_v3.TestVolume): |
24 | 25 | def setUp(self): |
25 | 26 | super().setUp() |
26 | 27 |
|
27 | 28 | self.snapshots_mock = self.volume_client.volume_snapshots |
28 | 29 | self.snapshots_mock.reset_mock() |
29 | 30 |
|
| 31 | + self.volume_sdk_client.unmanage_snapshot.return_value = None |
| 32 | + |
30 | 33 |
|
31 | 34 | class TestVolumeSnapshotDelete(TestVolumeSnapshot): |
32 | 35 | snapshots = volume_fakes.create_snapshots(count=2) |
@@ -111,3 +114,48 @@ def test_delete_multiple_snapshots_with_exception(self): |
111 | 114 | self.snapshots_mock.delete.assert_called_once_with( |
112 | 115 | self.snapshots[0].id, False |
113 | 116 | ) |
| 117 | + |
| 118 | + def test_snapshot_delete_remote(self): |
| 119 | + arglist = ['--remote', self.snapshots[0].id] |
| 120 | + verifylist = [('remote', True), ("snapshots", [self.snapshots[0].id])] |
| 121 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 122 | + |
| 123 | + result = self.cmd.take_action(parsed_args) |
| 124 | + |
| 125 | + self.volume_sdk_client.unmanage_snapshot.assert_called_with( |
| 126 | + self.snapshots[0].id |
| 127 | + ) |
| 128 | + self.assertIsNone(result) |
| 129 | + |
| 130 | + def test_snapshot_delete_with_remote_force(self): |
| 131 | + arglist = ['--remote', '--force', self.snapshots[0].id] |
| 132 | + verifylist = [ |
| 133 | + ('remote', True), |
| 134 | + ('force', True), |
| 135 | + ("snapshots", [self.snapshots[0].id]), |
| 136 | + ] |
| 137 | + |
| 138 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 139 | + exc = self.assertRaises( |
| 140 | + exceptions.CommandError, self.cmd.take_action, parsed_args |
| 141 | + ) |
| 142 | + self.assertIn( |
| 143 | + "The --force option is not supported with the --remote " |
| 144 | + "parameter.", |
| 145 | + str(exc), |
| 146 | + ) |
| 147 | + |
| 148 | + def test_delete_multiple_snapshots_remote(self): |
| 149 | + arglist = ['--remote'] |
| 150 | + for s in self.snapshots: |
| 151 | + arglist.append(s.id) |
| 152 | + verifylist = [('remote', True), ('snapshots', arglist[1:])] |
| 153 | + |
| 154 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 155 | + result = self.cmd.take_action(parsed_args) |
| 156 | + |
| 157 | + calls = [] |
| 158 | + for s in self.snapshots: |
| 159 | + calls.append(mock.call(s.id)) |
| 160 | + self.volume_sdk_client.unmanage_snapshot.assert_has_calls(calls) |
| 161 | + self.assertIsNone(result) |
0 commit comments