diff options
| author | jichenjc <jichenjc@cn.ibm.com> | 2016-02-19 22:52:38 +0800 |
|---|---|---|
| committer | jichenjc <jichenjc@cn.ibm.com> | 2016-02-26 05:05:46 +0800 |
| commit | ff3a1d3780486d98bd3205c8329576b396e8161f (patch) | |
| tree | 69a9371806db5e347c1112c033dd66dd2707c360 /openstackclient/tests/compute | |
| parent | 8787ad2b49cdb1043a6c5c5b6bad10e54068aeaf (diff) | |
| download | python-openstackclient-ff3a1d3780486d98bd3205c8329576b396e8161f.tar.gz | |
[compute] Add set host command
set host command is missing, add it as SetHost class.
Change-Id: I7acb94150718b7150598632cbebc3d85018a0d59
Diffstat (limited to 'openstackclient/tests/compute')
| -rw-r--r-- | openstackclient/tests/compute/v2/fakes.py | 56 | ||||
| -rw-r--r-- | openstackclient/tests/compute/v2/test_host.py | 75 |
2 files changed, 131 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 32d257f1..4531f3bf 100644 --- a/openstackclient/tests/compute/v2/fakes.py +++ b/openstackclient/tests/compute/v2/fakes.py @@ -140,6 +140,9 @@ class FakeComputev2Client(object): self.keypairs = mock.Mock() self.keypairs.resource_class = fakes.FakeResource(None, {}) + self.hosts = mock.Mock() + self.hosts.resource_class = fakes.FakeResource(None, {}) + self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] @@ -878,3 +881,56 @@ class FakeNetwork(object): networks.append(FakeNetwork.create_one_network(attrs, methods)) return networks + + +class FakeHost(object): + """Fake one host.""" + + @staticmethod + def create_one_host(attrs=None): + """Create a fake host. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object, with id and other attributes + """ + if attrs is None: + attrs = {} + + # Set default attributes. + host_info = { + "id": 1, + "service_id": 1, + "host": "host1", + "uuid": 'host-id-' + uuid.uuid4().hex, + "vcpus": 10, + "memory_mb": 100, + "local_gb": 100, + "vcpus_used": 5, + "memory_mb_used": 50, + "local_gb_used": 10, + "hypervisor_type": "xen", + "hypervisor_version": 1, + "hypervisor_hostname": "devstack1", + "free_ram_mb": 50, + "free_disk_gb": 50, + "current_workload": 10, + "running_vms": 1, + "cpu_info": "", + "disk_available_least": 1, + "host_ip": "10.10.10.10", + "supported_instances": "", + "metrics": "", + "pci_stats": "", + "extra_resources": "", + "stats": "", + "numa_topology": "", + "ram_allocation_ratio": 1.0, + "cpu_allocation_ratio": 1.0 + } + host_info.update(attrs) + host = fakes.FakeResource( + info=copy.deepcopy(host_info), + loaded=True) + return host diff --git a/openstackclient/tests/compute/v2/test_host.py b/openstackclient/tests/compute/v2/test_host.py new file mode 100644 index 00000000..de537577 --- /dev/null +++ b/openstackclient/tests/compute/v2/test_host.py @@ -0,0 +1,75 @@ +# Copyright 2016 IBM Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# + +from openstackclient.compute.v2 import host +from openstackclient.tests.compute.v2 import fakes as compute_fakes + + +class TestHost(compute_fakes.TestComputev2): + + def setUp(self): + super(TestHost, self).setUp() + + # Get a shortcut to the FlavorManager Mock + self.host_mock = self.app.client_manager.compute.hosts + self.host_mock.reset_mock() + + +class TestHostSet(TestHost): + + def setUp(self): + super(TestHostSet, self).setUp() + + self.host = compute_fakes.FakeHost.create_one_host() + self.host_mock.get.return_value = self.host + self.host_mock.update.return_value = None + + self.cmd = host.SetHost(self.app, None) + + def test_host_set_no_option(self): + arglist = [ + str(self.host.id) + ] + verifylist = [ + ('host', str(self.host.id)) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.assertIsNone(result) + + body = {} + self.host_mock.update.assert_called_with(self.host.id, body) + + def test_host_set(self): + arglist = [ + '--enable', + '--disable-maintenance', + str(self.host.id) + ] + verifylist = [ + ('enable', True), + ('enable_maintenance', False), + ('host', str(self.host.id)) + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + self.assertIsNone(result) + + body = {'status': True, 'maintenance_mode': False} + self.host_mock.update.assert_called_with(self.host.id, body) |
