From c53817c33d9bdc5734d26aa2f2051c044d6720d5 Mon Sep 17 00:00:00 2001 From: Alexander Chadin Date: Fri, 2 Mar 2018 20:02:02 +0000 Subject: [PATCH] Fix change_nova_service_state action The function signature has been changed in 2.53 version[1] and this patch is required to fix watcher-tempest-plugin. If all tests are ok, I'll merge it ASAP. [1]: https://developer.openstack.org/api-ref/compute/#enable-scheduling-for-a-compute-service Change-Id: Ie03519dac2a55263e278344fd00f103067f90f27 --- doc/ext/versioned_notifications.py | 2 +- doc/source/conf.py | 1 + watcher/common/nova_helper.py | 35 ++++++++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/doc/ext/versioned_notifications.py b/doc/ext/versioned_notifications.py index 1a8107961..3149f0c47 100644 --- a/doc/ext/versioned_notifications.py +++ b/doc/ext/versioned_notifications.py @@ -20,7 +20,7 @@ It is used via a single directive in the .rst file """ -from sphinx.util.compat import Directive +from docutils.parsers.rst import Directive from docutils import nodes from watcher.notifications import base as notification diff --git a/doc/source/conf.py b/doc/source/conf.py index d975c316c..b0a7c62a8 100755 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -42,6 +42,7 @@ extensions = [ 'ext.versioned_notifications', 'oslo_config.sphinxconfiggen', 'openstackdocstheme', + 'sphinx.ext.napoleon', ] wsme_protocols = ['restjson'] diff --git a/watcher/common/nova_helper.py b/watcher/common/nova_helper.py index f99ac09cf..a1853fca8 100644 --- a/watcher/common/nova_helper.py +++ b/watcher/common/nova_helper.py @@ -29,9 +29,12 @@ import novaclient.exceptions as nvexceptions from watcher.common import clients from watcher.common import exception from watcher.common import utils +from watcher import conf LOG = log.getLogger(__name__) +CONF = conf.CONF + class NovaHelper(object): @@ -556,21 +559,31 @@ class NovaHelper(object): "for the instance %s" % instance_id) def enable_service_nova_compute(self, hostname): - if self.nova.services.enable(host=hostname, - binary='nova-compute'). \ - status == 'enabled': - return True + if float(CONF.nova_client.api_version) < 2.53: + status = self.nova.services.enable( + host=hostname, binary='nova-compute').status == 'enabled' else: - return False + service_uuid = self.nova.services.list(host=hostname, + binary='nova-compute')[0].id + status = self.nova.services.enable( + service_uuid=service_uuid).status == 'enabled' + + return status def disable_service_nova_compute(self, hostname, reason=None): - if self.nova.services.disable_log_reason(host=hostname, - binary='nova-compute', - reason=reason). \ - status == 'disabled': - return True + if float(CONF.nova_client.api_version) < 2.53: + status = self.nova.services.disable_log_reason( + host=hostname, + binary='nova-compute', + reason=reason).status == 'disabled' else: - return False + service_uuid = self.nova.services.list(host=hostname, + binary='nova-compute')[0].id + status = self.nova.services.disable_log_reason( + service_uuid=service_uuid, + reason=reason).status == 'disabled' + + return status def set_host_offline(self, hostname): # See API on https://developer.openstack.org/api-ref/compute/