|
| 1 | +# Copyright 2016 IBM Corporation |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | + |
| 16 | +from openstackclient.compute.v2 import host |
| 17 | +from openstackclient.tests.compute.v2 import fakes as compute_fakes |
| 18 | + |
| 19 | + |
| 20 | +class TestHost(compute_fakes.TestComputev2): |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + super(TestHost, self).setUp() |
| 24 | + |
| 25 | + # Get a shortcut to the FlavorManager Mock |
| 26 | + self.host_mock = self.app.client_manager.compute.hosts |
| 27 | + self.host_mock.reset_mock() |
| 28 | + |
| 29 | + |
| 30 | +class TestHostSet(TestHost): |
| 31 | + |
| 32 | + def setUp(self): |
| 33 | + super(TestHostSet, self).setUp() |
| 34 | + |
| 35 | + self.host = compute_fakes.FakeHost.create_one_host() |
| 36 | + self.host_mock.get.return_value = self.host |
| 37 | + self.host_mock.update.return_value = None |
| 38 | + |
| 39 | + self.cmd = host.SetHost(self.app, None) |
| 40 | + |
| 41 | + def test_host_set_no_option(self): |
| 42 | + arglist = [ |
| 43 | + str(self.host.id) |
| 44 | + ] |
| 45 | + verifylist = [ |
| 46 | + ('host', str(self.host.id)) |
| 47 | + ] |
| 48 | + |
| 49 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 50 | + |
| 51 | + result = self.cmd.take_action(parsed_args) |
| 52 | + self.assertIsNone(result) |
| 53 | + |
| 54 | + body = {} |
| 55 | + self.host_mock.update.assert_called_with(self.host.id, body) |
| 56 | + |
| 57 | + def test_host_set(self): |
| 58 | + arglist = [ |
| 59 | + '--enable', |
| 60 | + '--disable-maintenance', |
| 61 | + str(self.host.id) |
| 62 | + ] |
| 63 | + verifylist = [ |
| 64 | + ('enable', True), |
| 65 | + ('enable_maintenance', False), |
| 66 | + ('host', str(self.host.id)) |
| 67 | + ] |
| 68 | + |
| 69 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 70 | + |
| 71 | + result = self.cmd.take_action(parsed_args) |
| 72 | + self.assertIsNone(result) |
| 73 | + |
| 74 | + body = {'status': True, 'maintenance_mode': False} |
| 75 | + self.host_mock.update.assert_called_with(self.host.id, body) |
0 commit comments