|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | +# |
| 13 | + |
| 14 | +from novaclient import api_versions |
| 15 | + |
| 16 | +from openstackclient.compute.v2 import server_volume |
| 17 | +from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes |
| 18 | + |
| 19 | + |
| 20 | +class TestServerVolume(compute_fakes.TestComputev2): |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + super().setUp() |
| 24 | + |
| 25 | + # Get a shortcut to the compute client ServerManager Mock |
| 26 | + self.servers_mock = self.app.client_manager.compute.servers |
| 27 | + self.servers_mock.reset_mock() |
| 28 | + |
| 29 | + # Get a shortcut to the compute client VolumeManager mock |
| 30 | + self.servers_volumes_mock = self.app.client_manager.compute.volumes |
| 31 | + self.servers_volumes_mock.reset_mock() |
| 32 | + |
| 33 | + |
| 34 | +class TestServerVolumeList(TestServerVolume): |
| 35 | + |
| 36 | + def setUp(self): |
| 37 | + super().setUp() |
| 38 | + |
| 39 | + self.server = compute_fakes.FakeServer.create_one_server() |
| 40 | + self.volume_attachments = ( |
| 41 | + compute_fakes.FakeVolumeAttachment.create_volume_attachments()) |
| 42 | + |
| 43 | + self.servers_mock.get.return_value = self.server |
| 44 | + self.servers_volumes_mock.get_server_volumes.return_value = ( |
| 45 | + self.volume_attachments) |
| 46 | + |
| 47 | + # Get the command object to test |
| 48 | + self.cmd = server_volume.ListServerVolume(self.app, None) |
| 49 | + |
| 50 | + def test_server_volume_list(self): |
| 51 | + self.app.client_manager.compute.api_version = \ |
| 52 | + api_versions.APIVersion('2.1') |
| 53 | + |
| 54 | + arglist = [ |
| 55 | + self.server.id, |
| 56 | + ] |
| 57 | + verifylist = [ |
| 58 | + ('server', self.server.id), |
| 59 | + ] |
| 60 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 61 | + |
| 62 | + columns, data = self.cmd.take_action(parsed_args) |
| 63 | + |
| 64 | + self.assertEqual(('ID', 'Device', 'Server ID', 'Volume ID'), columns) |
| 65 | + self.assertEqual( |
| 66 | + ( |
| 67 | + ( |
| 68 | + self.volume_attachments[0].id, |
| 69 | + self.volume_attachments[0].device, |
| 70 | + self.volume_attachments[0].serverId, |
| 71 | + self.volume_attachments[0].volumeId, |
| 72 | + ), |
| 73 | + ( |
| 74 | + self.volume_attachments[1].id, |
| 75 | + self.volume_attachments[1].device, |
| 76 | + self.volume_attachments[1].serverId, |
| 77 | + self.volume_attachments[1].volumeId, |
| 78 | + ), |
| 79 | + ), |
| 80 | + tuple(data), |
| 81 | + ) |
| 82 | + self.servers_volumes_mock.get_server_volumes.assert_called_once_with( |
| 83 | + self.server.id) |
| 84 | + |
| 85 | + def test_server_volume_list_with_tags(self): |
| 86 | + self.app.client_manager.compute.api_version = \ |
| 87 | + api_versions.APIVersion('2.70') |
| 88 | + |
| 89 | + arglist = [ |
| 90 | + self.server.id, |
| 91 | + ] |
| 92 | + verifylist = [ |
| 93 | + ('server', self.server.id), |
| 94 | + ] |
| 95 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 96 | + |
| 97 | + columns, data = self.cmd.take_action(parsed_args) |
| 98 | + |
| 99 | + self.assertEqual( |
| 100 | + ('ID', 'Device', 'Server ID', 'Volume ID', 'Tag',), columns, |
| 101 | + ) |
| 102 | + self.assertEqual( |
| 103 | + ( |
| 104 | + ( |
| 105 | + self.volume_attachments[0].id, |
| 106 | + self.volume_attachments[0].device, |
| 107 | + self.volume_attachments[0].serverId, |
| 108 | + self.volume_attachments[0].volumeId, |
| 109 | + self.volume_attachments[0].tag, |
| 110 | + ), |
| 111 | + ( |
| 112 | + self.volume_attachments[1].id, |
| 113 | + self.volume_attachments[1].device, |
| 114 | + self.volume_attachments[1].serverId, |
| 115 | + self.volume_attachments[1].volumeId, |
| 116 | + self.volume_attachments[1].tag, |
| 117 | + ), |
| 118 | + ), |
| 119 | + tuple(data), |
| 120 | + ) |
| 121 | + self.servers_volumes_mock.get_server_volumes.assert_called_once_with( |
| 122 | + self.server.id) |
| 123 | + |
| 124 | + def test_server_volume_list_with_delete_on_attachment(self): |
| 125 | + self.app.client_manager.compute.api_version = \ |
| 126 | + api_versions.APIVersion('2.79') |
| 127 | + |
| 128 | + arglist = [ |
| 129 | + self.server.id, |
| 130 | + ] |
| 131 | + verifylist = [ |
| 132 | + ('server', self.server.id), |
| 133 | + ] |
| 134 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 135 | + |
| 136 | + columns, data = self.cmd.take_action(parsed_args) |
| 137 | + |
| 138 | + self.assertEqual( |
| 139 | + ( |
| 140 | + 'ID', 'Device', 'Server ID', 'Volume ID', 'Tag', |
| 141 | + 'Delete On Termination?', |
| 142 | + ), |
| 143 | + columns, |
| 144 | + ) |
| 145 | + self.assertEqual( |
| 146 | + ( |
| 147 | + ( |
| 148 | + self.volume_attachments[0].id, |
| 149 | + self.volume_attachments[0].device, |
| 150 | + self.volume_attachments[0].serverId, |
| 151 | + self.volume_attachments[0].volumeId, |
| 152 | + self.volume_attachments[0].tag, |
| 153 | + self.volume_attachments[0].delete_on_termination, |
| 154 | + ), |
| 155 | + ( |
| 156 | + self.volume_attachments[1].id, |
| 157 | + self.volume_attachments[1].device, |
| 158 | + self.volume_attachments[1].serverId, |
| 159 | + self.volume_attachments[1].volumeId, |
| 160 | + self.volume_attachments[1].tag, |
| 161 | + self.volume_attachments[1].delete_on_termination, |
| 162 | + ), |
| 163 | + ), |
| 164 | + tuple(data), |
| 165 | + ) |
| 166 | + self.servers_volumes_mock.get_server_volumes.assert_called_once_with( |
| 167 | + self.server.id) |
0 commit comments