From 5f4dcdce16837e28af18964f533a1eba738b9f34 Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Sat, 7 Nov 2015 11:54:14 +0800 Subject: [PATCH] Enhance value check for option notify_on_state_change oslo.config provides parameter choices for class cfg.StrOpt to make sure user's input must be in the choices. Option notify_on_state_change only allow three values, so let's use parameter choices. UpgradeImpact: option notify_on_state_change allows three values: 'vm_state', 'vm_and_task_state', None, default value is None. Change-Id: I94b2a8ab2584a4a31ef9644ad4f614a15636de8d --- nova/notifications.py | 16 +++++++++------- ...ify_on_state_change_opt-e3c6f6664e143993.yaml | 7 +++++++ 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/notify_on_state_change_opt-e3c6f6664e143993.yaml diff --git a/nova/notifications.py b/nova/notifications.py index a7b4950dcb..116f5d986b 100644 --- a/nova/notifications.py +++ b/nova/notifications.py @@ -42,11 +42,13 @@ LOG = log.getLogger(__name__) notify_opts = [ cfg.StrOpt('notify_on_state_change', - help='If set, send compute.instance.update notifications on instance ' - 'state changes. Valid values are None for no notifications, ' - '"vm_state" for notifications on VM state changes, or ' - '"vm_and_task_state" for notifications on VM and task state ' - 'changes.'), + default=None, + choices=(None, 'vm_state', 'vm_and_task_state'), + help='If set, send compute.instance.update notifications on ' + 'instance state changes. Valid values are None for no ' + 'notifications, "vm_state" for notifications on VM state ' + 'changes, or "vm_and_task_state" for notifications on VM ' + 'and task state changes.'), cfg.BoolOpt('notify_api_faults', default=False, help='If set, send api.fault notifications on caught exceptions ' 'in the API service.'), @@ -133,7 +135,7 @@ def send_update(context, old_instance, new_instance, service="compute", if old_vm_state != new_vm_state: # yes, the vm state is changing: update_with_state_change = True - elif (CONF.notify_on_state_change.lower() == "vm_and_task_state" and + elif (CONF.notify_on_state_change == "vm_and_task_state" and old_task_state != new_task_state): # yes, the task state is changing: update_with_state_change = True @@ -184,7 +186,7 @@ def send_update_with_states(context, instance, old_vm_state, new_vm_state, if old_vm_state != new_vm_state: # yes, the vm state is changing: fire_update = True - elif (CONF.notify_on_state_change.lower() == "vm_and_task_state" and + elif (CONF.notify_on_state_change == "vm_and_task_state" and old_task_state != new_task_state): # yes, the task state is changing: fire_update = True diff --git a/releasenotes/notes/notify_on_state_change_opt-e3c6f6664e143993.yaml b/releasenotes/notes/notify_on_state_change_opt-e3c6f6664e143993.yaml new file mode 100644 index 0000000000..156228e16a --- /dev/null +++ b/releasenotes/notes/notify_on_state_change_opt-e3c6f6664e143993.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + The ``notify_on_state_change`` configuration option was StrOpt, which would accept + any string or None in the previous release. Starting in the Newton release, + it allows only three values: None, ``vm_state``, ``vm_and_task_state``. The default + value is None.