|
| 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 | +from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes |
| 15 | +from openstackclient.volume.v3 import volume_host |
| 16 | + |
| 17 | + |
| 18 | +class TestVolumeHost(volume_fakes.TestVolume): |
| 19 | + def setUp(self): |
| 20 | + super().setUp() |
| 21 | + |
| 22 | + self.host_mock = self.volume_client.services |
| 23 | + self.host_mock.reset_mock() |
| 24 | + |
| 25 | + |
| 26 | +class TestVolumeHostSet(TestVolumeHost): |
| 27 | + service = volume_fakes.create_one_service() |
| 28 | + |
| 29 | + def setUp(self): |
| 30 | + super().setUp() |
| 31 | + |
| 32 | + self.host_mock.freeze_host.return_value = None |
| 33 | + self.host_mock.thaw_host.return_value = None |
| 34 | + |
| 35 | + # Get the command object to mock |
| 36 | + self.cmd = volume_host.SetVolumeHost(self.app, None) |
| 37 | + |
| 38 | + def test_volume_host_set_nothing(self): |
| 39 | + arglist = [ |
| 40 | + self.service.host, |
| 41 | + ] |
| 42 | + verifylist = [ |
| 43 | + ('host', self.service.host), |
| 44 | + ] |
| 45 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 46 | + result = self.cmd.take_action(parsed_args) |
| 47 | + |
| 48 | + self.host_mock.freeze_host.assert_not_called() |
| 49 | + self.host_mock.thaw_host.assert_not_called() |
| 50 | + self.assertIsNone(result) |
| 51 | + |
| 52 | + def test_volume_host_set_enable(self): |
| 53 | + arglist = [ |
| 54 | + '--enable', |
| 55 | + self.service.host, |
| 56 | + ] |
| 57 | + verifylist = [ |
| 58 | + ('enable', True), |
| 59 | + ('host', self.service.host), |
| 60 | + ] |
| 61 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 62 | + |
| 63 | + result = self.cmd.take_action(parsed_args) |
| 64 | + |
| 65 | + self.host_mock.thaw_host.assert_called_with(self.service.host) |
| 66 | + self.host_mock.freeze_host.assert_not_called() |
| 67 | + self.assertIsNone(result) |
| 68 | + |
| 69 | + def test_volume_host_set_disable(self): |
| 70 | + arglist = [ |
| 71 | + '--disable', |
| 72 | + self.service.host, |
| 73 | + ] |
| 74 | + verifylist = [ |
| 75 | + ('disable', True), |
| 76 | + ('host', self.service.host), |
| 77 | + ] |
| 78 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 79 | + |
| 80 | + result = self.cmd.take_action(parsed_args) |
| 81 | + |
| 82 | + self.host_mock.freeze_host.assert_called_with(self.service.host) |
| 83 | + self.host_mock.thaw_host.assert_not_called() |
| 84 | + self.assertIsNone(result) |
| 85 | + |
| 86 | + |
| 87 | +class TestVolumeHostFailover(TestVolumeHost): |
| 88 | + service = volume_fakes.create_one_service() |
| 89 | + |
| 90 | + def setUp(self): |
| 91 | + super().setUp() |
| 92 | + |
| 93 | + self.host_mock.failover_host.return_value = None |
| 94 | + |
| 95 | + # Get the command object to mock |
| 96 | + self.cmd = volume_host.FailoverVolumeHost(self.app, None) |
| 97 | + |
| 98 | + def test_volume_host_failover(self): |
| 99 | + arglist = [ |
| 100 | + '--volume-backend', |
| 101 | + 'backend_test', |
| 102 | + self.service.host, |
| 103 | + ] |
| 104 | + verifylist = [ |
| 105 | + ('volume_backend', 'backend_test'), |
| 106 | + ('host', self.service.host), |
| 107 | + ] |
| 108 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 109 | + |
| 110 | + result = self.cmd.take_action(parsed_args) |
| 111 | + |
| 112 | + self.host_mock.failover_host.assert_called_with( |
| 113 | + self.service.host, 'backend_test' |
| 114 | + ) |
| 115 | + self.assertIsNone(result) |
0 commit comments