From b7fac8514bfccea581df4389fe273b0b759a7d4c Mon Sep 17 00:00:00 2001 From: Tytus Kurek Date: Wed, 7 Dec 2016 12:06:11 +0100 Subject: [PATCH] Add support for 'default_availability_zone' parameter. I've added support for 'default_availability_zone' parameter. I've added charm parameter, modified 'nova.conf' templates and implemented it to be exposed via 'neutron-plugin' relation settings. Change-Id: I85008ac0f3540a2b5c817893d63e497b63f43043 Closes-Bug: 1595937 --- config.yaml | 13 +++++++++++++ hooks/nova_compute_context.py | 10 ++++++++++ hooks/nova_compute_hooks.py | 3 ++- hooks/nova_compute_utils.py | 4 +++- templates/icehouse/nova.conf | 4 ++++ templates/juno/nova.conf | 4 ++++ templates/kilo/nova.conf | 4 ++++ templates/liberty/nova.conf | 4 ++++ templates/mitaka/nova.conf | 6 +++++- unit_tests/test_nova_compute_hooks.py | 13 +++++++++++-- 10 files changed, 60 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 2aa20fd9..11efe63b 100644 --- a/config.yaml +++ b/config.yaml @@ -331,3 +331,16 @@ options: description: | Experimental enable apparmor profile. Valid settings: 'complain', 'enforce' or 'disable'. AA disabled by default. + default-availability-zone: + type: string + default: 'nova' + description: | + Default compute node availability zone. + . + This option determines the availability zone to be used when it is not + specified in the VM creation request. If this option is not set, the + default availability zone 'nova' is used. + . + NOTE: Availability zones must be created manually using the + 'openstack aggregate create' command. + . diff --git a/hooks/nova_compute_context.py b/hooks/nova_compute_context.py index b5a21167..2fde9e3d 100644 --- a/hooks/nova_compute_context.py +++ b/hooks/nova_compute_context.py @@ -645,3 +645,13 @@ class NovaNetworkAppArmorContext(context.AppArmorContext): return self.ctxt self._ctxt.update({'aa_profile': self.aa_profile}) return self.ctxt + + +class NovaComputeAvailabilityZoneContext(context.OSContextGenerator): + + def __call__(self): + ctxt = {} + if config('default-availability-zone'): + ctxt['default_availability_zone'] = config( + 'default-availability-zone') + return ctxt diff --git a/hooks/nova_compute_hooks.py b/hooks/nova_compute_hooks.py index 78df7e3c..9b917650 100755 --- a/hooks/nova_compute_hooks.py +++ b/hooks/nova_compute_hooks.py @@ -445,7 +445,8 @@ def update_nrpe_config(): @hooks.hook('neutron-plugin-relation-joined') def neutron_plugin_joined(relid=None, remote_restart=False): rel_settings = { - 'hugepage_number': get_hugepage_number() + 'hugepage_number': get_hugepage_number(), + 'default_availability_zone': config('default-availability-zone') } if remote_restart: rel_settings['restart-trigger'] = str(uuid.uuid4()) diff --git a/hooks/nova_compute_utils.py b/hooks/nova_compute_utils.py index e65dcc14..974b0c21 100644 --- a/hooks/nova_compute_utils.py +++ b/hooks/nova_compute_utils.py @@ -111,6 +111,7 @@ from nova_compute_context import ( NovaComputeAppArmorContext, NovaNetworkAppArmorContext, SerialConsoleContext, + NovaComputeAvailabilityZoneContext, ) CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' @@ -226,7 +227,8 @@ BASE_RESOURCE_MAP = { NovaComputeVirtContext(), context.LogLevelContext(), context.InternalEndpointContext(), - SerialConsoleContext()], + SerialConsoleContext(), + NovaComputeAvailabilityZoneContext()], }, NOVA_API_AA_PROFILE_PATH: { 'services': ['nova-api'], diff --git a/templates/icehouse/nova.conf b/templates/icehouse/nova.conf index 2f0b8346..a0199571 100644 --- a/templates/icehouse/nova.conf +++ b/templates/icehouse/nova.conf @@ -138,6 +138,10 @@ instances_path = {{ instances_path }} {% endfor -%} {% endif -%} +{% if default_availability_zone -%} +default_availability_zone = {{ default_availability_zone }} +{% endif -%} + {% if console_access_protocol == 'spice' -%} [spice] agent_enabled = True diff --git a/templates/juno/nova.conf b/templates/juno/nova.conf index 3f0c3280..ffae4223 100644 --- a/templates/juno/nova.conf +++ b/templates/juno/nova.conf @@ -131,6 +131,10 @@ instances_path = {{ instances_path }} {% endfor -%} {% endif -%} +{% if default_availability_zone -%} +default_availability_zone = {{ default_availability_zone }} +{% endif -%} + {% if console_access_protocol == 'spice' -%} [spice] agent_enabled = True diff --git a/templates/kilo/nova.conf b/templates/kilo/nova.conf index 2ca4b089..6a2d9343 100644 --- a/templates/kilo/nova.conf +++ b/templates/kilo/nova.conf @@ -124,6 +124,10 @@ pci_passthrough_whitelist = {{ pci_passthrough_whitelist }} {% include "section-zeromq" %} +{% if default_availability_zone -%} +default_availability_zone = {{ default_availability_zone }} +{% endif -%} + {% if network_manager == 'neutron' and network_manager_config -%} [neutron] url = {{ network_manager_config.neutron_url }} diff --git a/templates/liberty/nova.conf b/templates/liberty/nova.conf index 4816ee0f..9422ede4 100644 --- a/templates/liberty/nova.conf +++ b/templates/liberty/nova.conf @@ -130,6 +130,10 @@ pci_passthrough_whitelist = {{ pci_passthrough_whitelist }} {% include "section-zeromq" %} +{% if default_availability_zone -%} +default_availability_zone = {{ default_availability_zone }} +{% endif -%} + {% if network_manager == 'neutron' and network_manager_config -%} [neutron] url = {{ network_manager_config.neutron_url }} diff --git a/templates/mitaka/nova.conf b/templates/mitaka/nova.conf index fe14c136..e4b72b12 100644 --- a/templates/mitaka/nova.conf +++ b/templates/mitaka/nova.conf @@ -131,6 +131,10 @@ pci_passthrough_whitelist = {{ pci_passthrough_whitelist }} {% include "section-zeromq" %} +{% if default_availability_zone -%} +default_availability_zone = {{ default_availability_zone }} +{% endif -%} + {% if network_manager == 'neutron' and network_manager_config -%} [neutron] url = {{ network_manager_config.neutron_url }} @@ -220,4 +224,4 @@ disable_libvirt_livesnapshot = False {% include "parts/section-ephemeral" %} -{% include "parts/section-serial-console" %} \ No newline at end of file +{% include "parts/section-serial-console" %} diff --git a/unit_tests/test_nova_compute_hooks.py b/unit_tests/test_nova_compute_hooks.py index e754914f..f48114a1 100644 --- a/unit_tests/test_nova_compute_hooks.py +++ b/unit_tests/test_nova_compute_hooks.py @@ -557,18 +557,26 @@ class NovaComputeRelationsTests(CharmTestCase): def test_neutron_plugin_joined_relid(self, get_hugepage_number): get_hugepage_number.return_value = None hooks.neutron_plugin_joined(relid='relid23') + expect_rel_settings = { + 'hugepage_number': None, + 'default_availability_zone': 'nova', + } self.relation_set.assert_called_with( relation_id='relid23', - **{'hugepage_number': None} + **expect_rel_settings ) @patch.object(hooks, 'get_hugepage_number') def test_neutron_plugin_joined_huge(self, get_hugepage_number): get_hugepage_number.return_value = 12 hooks.neutron_plugin_joined() + expect_rel_settings = { + 'hugepage_number': 12, + 'default_availability_zone': 'nova', + } self.relation_set.assert_called_with( relation_id=None, - **{'hugepage_number': 12} + **expect_rel_settings ) @patch.object(hooks, 'get_hugepage_number') @@ -579,6 +587,7 @@ class NovaComputeRelationsTests(CharmTestCase): expect_rel_settings = { 'hugepage_number': None, 'restart-trigger': 'e030b959-7207', + 'default_availability_zone': 'nova', } self.relation_set.assert_called_with( relation_id=None,