From f9fe6659dbea065bc522491a0540e1aea7c20ea4 Mon Sep 17 00:00:00 2001 From: licanwei Date: Thu, 25 Oct 2018 19:02:26 +0800 Subject: [PATCH] remove set_host_offline change_node_power_state action can be used to make a host offline. set_host_offline never be used and the Nova os-hosts API is deprecated. So remove it https://developer.openstack.org/api-ref/compute/?expanded=update-host-status-detail#hosts-os-hosts-deprecated Change-Id: I5f81fc9e2189db39b143d2935540d637bd2d88cc --- watcher/common/nova_helper.py | 32 ------------------------ watcher/tests/common/test_nova_helper.py | 13 ---------- 2 files changed, 45 deletions(-) diff --git a/watcher/common/nova_helper.py b/watcher/common/nova_helper.py index ca6408b92..d321b8d6f 100644 --- a/watcher/common/nova_helper.py +++ b/watcher/common/nova_helper.py @@ -406,38 +406,6 @@ class NovaHelper(object): return status - def set_host_offline(self, hostname): - # See API on https://developer.openstack.org/api-ref/compute/ - # especially the PUT request - # regarding this resource : /v2.1/os-hosts/​{host_name}​ - # - # The following body should be sent : - # { - # "host": { - # "host": "65c5d5b7e3bd44308e67fc50f362aee6", - # "maintenance_mode": "off_maintenance", - # "status": "enabled" - # } - # } - - # Voir ici - # https://github.com/openstack/nova/ - # blob/master/nova/virt/xenapi/host.py - # set_host_enabled(self, enabled): - # Sets the compute host's ability to accept new instances. - # host_maintenance_mode(self, host, mode): - # Start/Stop host maintenance window. - # On start, it triggers guest instances evacuation. - host = self.nova.hosts.get(hostname) - - if not host: - LOG.debug("host not found: %s", hostname) - return False - else: - host[0].update( - {"maintenance_mode": "disable", "status": "disable"}) - return True - def create_image_from_instance(self, instance_id, image_name, metadata={"reason": "instance_migrate"}): """This method creates a new image from a given instance. diff --git a/watcher/tests/common/test_nova_helper.py b/watcher/tests/common/test_nova_helper.py index 1d222d129..72222a7e9 100644 --- a/watcher/tests/common/test_nova_helper.py +++ b/watcher/tests/common/test_nova_helper.py @@ -115,19 +115,6 @@ class TestNovaHelper(base.TestCase): result = nova_util.stop_instance(instance_id) self.assertFalse(result) - def test_set_host_offline(self, mock_glance, mock_cinder, mock_neutron, - mock_nova): - host = mock.MagicMock() - nova_util = nova_helper.NovaHelper() - nova_util.nova.hosts = mock.MagicMock() - nova_util.nova.hosts.get.return_value = host - result = nova_util.set_host_offline("rennes") - self.assertTrue(result) - - nova_util.nova.hosts.get.return_value = None - result = nova_util.set_host_offline("rennes") - self.assertFalse(result) - @mock.patch.object(time, 'sleep', mock.Mock()) def test_resize_instance(self, mock_glance, mock_cinder, mock_neutron, mock_nova):