Add support for notify_on_state_change in Nova Cloud Controller charm

This change introduces two new configuration options to the Nova Cloud Controller charm:

- `enable-notify`: Allows users to enable the `notify_on_state_change` setting in the Nova Cloud Controller. This controls whether notifications should be sent for changes in instance states. If `enable-notify` is set to `True`, users can configure the `notify-on-state-change` option to specify the types of state changes to notify on.

- `notify-on-state-change`: Specifies when to send `compute.instance.update` notifications on instance state changes. The possible values are:
  - `None`: Disables notifications.
  - `vm_state`: Sends notifications on changes to the VM state.
  - `vm_and_task_state`: Sends notifications on changes to both VM and task states.

If `enable-notify` is set to `True`, the following configuration is added to `nova.conf`:

    [DEFAULT]
    notify_on_state_change = {{ notify_on_state_change }}

By default, `enable-notify` is set to `False`, keeping the existing behavior unchanged unless explicitly configured. This ensures that no notifications are sent unless the user opts in, providing backward compatibility while offering the flexibility to enable state change notifications when needed.

Closes-Bug: #2085354
Change-Id: I2f8926a89c89b03e81d05d36dd65579eb8bec16c
This commit is contained in:
Fabian Fulga 2024-10-22 15:47:22 +03:00
parent 499cfbab95
commit e1b1da0515
4 changed files with 37 additions and 0 deletions

View File

@ -667,6 +667,25 @@ options:
default notification format unversioned until this is implemented.
.
Possible Values are both, versioned, unversioned.
enable-notify:
type: boolean
default: False
description: |
Enable or disable the addition of the `notify_on_state_change` setting
in `nova.conf`. When set to `True`, the `notify_on_state_change` option
will be configured based on the value of `notify-on-state-change`.
If set to `False`, no state change notifications will be configured.
notify-on-state-change:
type: string
default:
description: |
If set, send `compute.instance.update` notifications on instance state changes.
Possible values:
- `None`: No notifications are sent.
- `vm_state`: Notify on changes to the VM state.
- `vm_and_task_state`: Notify on changes to both the VM and task states.
For more details on the available notifications, refer to:
https://wiki.openstack.org/wiki/SystemUsageData.
cross-az-attach: # LP: 1856776
type: boolean
default: True # OpenStack default value

View File

@ -480,6 +480,14 @@ class NovaConfigContext(ch_context.WorkerConfigContext):
'enable-isolated-aggregate-filtering')
ctxt['max_local_block_devices'] = hookenv.config(
'max-local-block-devices')
enable_notify = hookenv.config('enable-notify')
notify_on_state_change = hookenv.config('notify-on-state-change')
if enable_notify and notify_on_state_change:
ctxt['enable_notify'] = True
ctxt['notify_on_state_change'] = notify_on_state_change
else:
ctxt['enable_notify'] = False
return ctxt

View File

@ -116,6 +116,10 @@ default_floating_pool = {{ default_floating_pool }}
volume_api_class=nova.volume.cinder.API
{% endif -%}
{% if enable_notify -%}
notify_on_state_change = {{ notify_on_state_change }}
{% endif -%}
{% if allow_resize_to_same_host -%}
allow_resize_to_same_host = True
{% endif -%}

View File

@ -346,6 +346,8 @@ class NovaComputeContextTests(CharmTestCase):
self.test_config.set('scheduler-default-filters', 'TestFilter')
self.test_config.set('scheduler-max-attempts', 10)
self.test_config.set('unique-server-names', 'project')
self.test_config.set('enable-notify', True)
self.test_config.set('notify-on-state-change', 'vm_and_task_state')
ctxt = context.NovaConfigContext()()
self.assertEqual(ctxt['scheduler_default_filters'],
self.config('scheduler-default-filters'))
@ -409,6 +411,10 @@ class NovaComputeContextTests(CharmTestCase):
self.config('enable-isolated-aggregate-filtering'))
self.assertEqual(ctxt['max_local_block_devices'],
self.config('max-local-block-devices'))
self.assertEqual(ctxt['enable_notify'],
self.config('enable-notify'))
self.assertEqual(ctxt['notify_on_state_change'],
self.config('notify-on-state-change'))
_pci_alias1 = {
"name": "IntelNIC",