|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 | +# not use this file except in compliance with the License. You may obtain |
| 4 | +# a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +# License for the specific language governing permissions and limitations |
| 12 | +# under the License. |
| 13 | +# |
| 14 | + |
| 15 | +from osc_lib.cli import format_columns |
| 16 | + |
| 17 | +from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes |
| 18 | +from openstackclient.volume.v3 import volume_backend |
| 19 | + |
| 20 | + |
| 21 | +class TestShowVolumeCapability(volume_fakes.TestVolume): |
| 22 | + """Test backend capability functionality.""" |
| 23 | + |
| 24 | + # The capability to be listed |
| 25 | + capability = volume_fakes.create_one_capability() |
| 26 | + |
| 27 | + def setUp(self): |
| 28 | + super().setUp() |
| 29 | + |
| 30 | + # Assign return value to capabilities mock |
| 31 | + self.volume_sdk_client.get_capabilities.return_value = self.capability |
| 32 | + |
| 33 | + # Get the command object to test |
| 34 | + self.cmd = volume_backend.ShowCapability(self.app, None) |
| 35 | + |
| 36 | + def test_capability_show(self): |
| 37 | + self.set_volume_api_version('3.0') |
| 38 | + |
| 39 | + arglist = [ |
| 40 | + 'fake', |
| 41 | + ] |
| 42 | + verifylist = [ |
| 43 | + ('host', 'fake'), |
| 44 | + ] |
| 45 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 46 | + |
| 47 | + # In base command class Lister in cliff, abstract method take_action() |
| 48 | + # returns a tuple containing the column names and an iterable |
| 49 | + # containing the data to be listed. |
| 50 | + columns, data = self.cmd.take_action(parsed_args) |
| 51 | + |
| 52 | + expected_columns = [ |
| 53 | + 'Title', |
| 54 | + 'Key', |
| 55 | + 'Type', |
| 56 | + 'Description', |
| 57 | + ] |
| 58 | + |
| 59 | + # confirming if all expected columns are present in the result. |
| 60 | + self.assertEqual(expected_columns, columns) |
| 61 | + |
| 62 | + capabilities = [ |
| 63 | + 'Compression', |
| 64 | + 'Replication', |
| 65 | + 'QoS', |
| 66 | + 'Thin Provisioning', |
| 67 | + ] |
| 68 | + |
| 69 | + # confirming if all expected values are present in the result. |
| 70 | + for cap in data: |
| 71 | + self.assertIn(cap[0], capabilities) |
| 72 | + |
| 73 | + # checking if proper call was made to get capabilities |
| 74 | + self.volume_sdk_client.get_capabilities.assert_called_with( |
| 75 | + 'fake', |
| 76 | + ) |
| 77 | + |
| 78 | + |
| 79 | +class TestListVolumePool(volume_fakes.TestVolume): |
| 80 | + """Tests for volume backend pool listing.""" |
| 81 | + |
| 82 | + # The pool to be listed |
| 83 | + pools = volume_fakes.create_one_pool() |
| 84 | + |
| 85 | + def setUp(self): |
| 86 | + super().setUp() |
| 87 | + |
| 88 | + self.volume_sdk_client.backend_pools.return_value = [self.pools] |
| 89 | + |
| 90 | + # Get the command object to test |
| 91 | + self.cmd = volume_backend.ListPool(self.app, None) |
| 92 | + |
| 93 | + def test_pool_list(self): |
| 94 | + self.set_volume_api_version('3.0') |
| 95 | + |
| 96 | + arglist = [] |
| 97 | + verifylist = [] |
| 98 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 99 | + |
| 100 | + # In base command class Lister in cliff, abstract method take_action() |
| 101 | + # returns a tuple containing the column names and an iterable |
| 102 | + # containing the data to be listed. |
| 103 | + columns, data = self.cmd.take_action(parsed_args) |
| 104 | + |
| 105 | + expected_columns = [ |
| 106 | + 'Name', |
| 107 | + ] |
| 108 | + |
| 109 | + # confirming if all expected columns are present in the result. |
| 110 | + self.assertEqual(expected_columns, columns) |
| 111 | + |
| 112 | + datalist = ((self.pools.name,),) |
| 113 | + |
| 114 | + # confirming if all expected values are present in the result. |
| 115 | + self.assertEqual(datalist, tuple(data)) |
| 116 | + |
| 117 | + # checking if proper call was made to list pools |
| 118 | + self.volume_sdk_client.backend_pools.assert_called_with( |
| 119 | + detailed=False, |
| 120 | + ) |
| 121 | + |
| 122 | + # checking if long columns are present in output |
| 123 | + self.assertNotIn("total_volumes", columns) |
| 124 | + self.assertNotIn("storage_protocol", columns) |
| 125 | + |
| 126 | + def test_service_list_with_long_option(self): |
| 127 | + self.set_volume_api_version('3.0') |
| 128 | + |
| 129 | + arglist = ['--long'] |
| 130 | + verifylist = [('long', True)] |
| 131 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 132 | + |
| 133 | + # In base command class Lister in cliff, abstract method take_action() |
| 134 | + # returns a tuple containing the column names and an iterable |
| 135 | + # containing the data to be listed. |
| 136 | + columns, data = self.cmd.take_action(parsed_args) |
| 137 | + |
| 138 | + expected_columns = [ |
| 139 | + 'Name', |
| 140 | + 'Capabilities', |
| 141 | + ] |
| 142 | + |
| 143 | + # confirming if all expected columns are present in the result. |
| 144 | + self.assertEqual(expected_columns, columns) |
| 145 | + |
| 146 | + datalist = ( |
| 147 | + ( |
| 148 | + self.pools.name, |
| 149 | + format_columns.DictColumn(self.pools.capabilities), |
| 150 | + ), |
| 151 | + ) |
| 152 | + |
| 153 | + # confirming if all expected values are present in the result. |
| 154 | + self.assertEqual(datalist, tuple(data)) |
| 155 | + |
| 156 | + self.volume_sdk_client.backend_pools.assert_called_with( |
| 157 | + detailed=True, |
| 158 | + ) |
0 commit comments