From 7a7051ab4885e8a7aaed50f6e90dfcdedfb57773 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Gagne=CC=81?= Date: Tue, 7 Jul 2015 20:53:02 -0400 Subject: [PATCH] Add ability to override compute_driver This change introduces a new compute_driver parameter for all compute driver manifests. This will allow a user to override the compute_driver config value by its own instead of forking or monkey-patching the manifests. It also changes the compute_driver config value of Ironic for ironic.IronicDriver which also works and better fit the config value style already used in the other manifests. Common use case for this parameter is to allow the use of a local or derivative version of a driver which adds features and/or bug fixes. Closes-bug: #1472445 Change-Id: I4cd211b389303c22f4c2aa6db7592cc9861d4f40 --- manifests/compute/ironic.pp | 8 +++-- manifests/compute/libvirt.pp | 7 +++- manifests/compute/vmware.pp | 18 ++++++---- manifests/compute/xenserver.pp | 9 +++-- spec/classes/nova_compute_ironic_spec.rb | 38 +++++++++++++++++---- spec/classes/nova_compute_libvirt_spec.rb | 4 ++- spec/classes/nova_compute_vmware_spec.rb | 4 ++- spec/classes/nova_compute_xenserver_spec.rb | 10 ++++++ 8 files changed, 77 insertions(+), 21 deletions(-) diff --git a/manifests/compute/ironic.pp b/manifests/compute/ironic.pp index 52bb37596..ae5c8800f 100644 --- a/manifests/compute/ironic.pp +++ b/manifests/compute/ironic.pp @@ -24,13 +24,16 @@ # The url for Ironic api endpoint. # Defaults to 'http://127.0.0.1:6385/v1' # +# [*compute_driver*] +# (optional) Compute driver. +# Defaults to 'ironic.IronicDriver' +# # [*admin_user*] # (optional) DEPRECATED: Use admin_username instead. # # [*admin_passwd*] # (optional) DEPRECATED: Use admin_password instead. # - class nova::compute::ironic ( $admin_username = 'admin', $admin_password = 'ironic', @@ -40,6 +43,7 @@ class nova::compute::ironic ( # DEPRECATED PARAMETERS $admin_user = undef, $admin_passwd = undef, + $compute_driver = 'ironic.IronicDriver' ) { if $admin_user { @@ -59,6 +63,6 @@ class nova::compute::ironic ( 'ironic/admin_url': value => $admin_url; 'ironic/admin_tenant_name': value => $admin_tenant_name; 'ironic/api_endpoint': value => $api_endpoint; - 'DEFAULT/compute_driver': value => 'nova.virt.ironic.IronicDriver'; + 'DEFAULT/compute_driver': value => $compute_driver; } } diff --git a/manifests/compute/libvirt.pp b/manifests/compute/libvirt.pp index 7f7e5df65..f6834ca54 100644 --- a/manifests/compute/libvirt.pp +++ b/manifests/compute/libvirt.pp @@ -78,6 +78,10 @@ # (optional) libvirt service name. # Defaults to $::nova::params::libvirt_service_name # +# [*compute_driver*] +# (optional) Compute driver. +# Defaults to 'libvirt.LibvirtDriver' +# class nova::compute::libvirt ( $libvirt_virt_type = 'kvm', $vncserver_listen = '127.0.0.1', @@ -92,6 +96,7 @@ class nova::compute::libvirt ( $remove_unused_resized_minimum_age_seconds = undef, $remove_unused_original_minimum_age_seconds = undef, $libvirt_service_name = $::nova::params::libvirt_service_name, + $compute_driver = 'libvirt.LibvirtDriver' ) inherits nova::params { include ::nova::params @@ -171,7 +176,7 @@ class nova::compute::libvirt ( } nova_config { - 'DEFAULT/compute_driver': value => 'libvirt.LibvirtDriver'; + 'DEFAULT/compute_driver': value => $compute_driver; 'DEFAULT/vncserver_listen': value => $vncserver_listen; 'libvirt/virt_type': value => $libvirt_virt_type; 'libvirt/cpu_mode': value => $libvirt_cpu_mode_real; diff --git a/manifests/compute/vmware.pp b/manifests/compute/vmware.pp index 5432e5bcf..40b2d460d 100644 --- a/manifests/compute/vmware.pp +++ b/manifests/compute/vmware.pp @@ -43,21 +43,25 @@ # default location for bug work-arounds. # Defaults to None. # - +# [*compute_driver*] +# (optional) Compute driver. +# Defaults to 'vmwareapi.VMwareVCDriver' +# class nova::compute::vmware( $host_ip, $host_username, $host_password, $cluster_name, - $api_retry_count=5, - $maximum_objects=100, - $task_poll_interval=5.0, - $use_linked_clone=true, - $wsdl_location=undef + $api_retry_count = 5, + $maximum_objects = 100, + $task_poll_interval = 5.0, + $use_linked_clone = true, + $wsdl_location = undef, + $compute_driver = 'vmwareapi.VMwareVCDriver' ) { nova_config { - 'DEFAULT/compute_driver': value => 'vmwareapi.VMwareVCDriver'; + 'DEFAULT/compute_driver': value => $compute_driver; 'VMWARE/host_ip': value => $host_ip; 'VMWARE/host_username': value => $host_username; 'VMWARE/host_password': value => $host_password; diff --git a/manifests/compute/xenserver.pp b/manifests/compute/xenserver.pp index f28c0b486..9265e5be2 100644 --- a/manifests/compute/xenserver.pp +++ b/manifests/compute/xenserver.pp @@ -17,15 +17,20 @@ # (optional) This parameter was removed in Diablo and does nothing. # Defaults to false # +# [*compute_driver*] +# (optional) Compute driver. +# Defaults to 'xenapi.XenAPIDriver' +# class nova::compute::xenserver( $xenapi_connection_url, $xenapi_connection_username, $xenapi_connection_password, - $xenapi_inject_image=false + $xenapi_inject_image = false, + $compute_driver = 'xenapi.XenAPIDriver' ) { nova_config { - 'DEFAULT/compute_driver': value => 'xenapi.XenAPIDriver'; + 'DEFAULT/compute_driver': value => $compute_driver; 'DEFAULT/connection_type': value => 'xenapi'; 'DEFAULT/xenapi_connection_url': value => $xenapi_connection_url; 'DEFAULT/xenapi_connection_username': value => $xenapi_connection_username; diff --git a/spec/classes/nova_compute_ironic_spec.rb b/spec/classes/nova_compute_ironic_spec.rb index d5433f753..401839526 100644 --- a/spec/classes/nova_compute_ironic_spec.rb +++ b/spec/classes/nova_compute_ironic_spec.rb @@ -2,13 +2,37 @@ require 'spec_helper' describe 'nova::compute::ironic' do - it 'configures ironic in nova.conf' do - is_expected.to contain_nova_config('ironic/admin_username').with_value('admin') - is_expected.to contain_nova_config('ironic/admin_password').with_value('ironic') - is_expected.to contain_nova_config('ironic/admin_url').with_value('http://127.0.0.1:35357/v2.0') - is_expected.to contain_nova_config('ironic/admin_tenant_name').with_value('services') - is_expected.to contain_nova_config('ironic/api_endpoint').with_value('http://127.0.0.1:6385/v1') - is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('nova.virt.ironic.IronicDriver') + context 'with default parameters' do + it 'configures ironic in nova.conf' do + is_expected.to contain_nova_config('ironic/admin_username').with_value('admin') + is_expected.to contain_nova_config('ironic/admin_password').with_value('ironic') + is_expected.to contain_nova_config('ironic/admin_url').with_value('http://127.0.0.1:35357/v2.0') + is_expected.to contain_nova_config('ironic/admin_tenant_name').with_value('services') + is_expected.to contain_nova_config('ironic/api_endpoint').with_value('http://127.0.0.1:6385/v1') + is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('ironic.IronicDriver') + end + end + + context 'with overridden parameters' do + let :params do + { + :admin_username => 'ironic', + :admin_password => 's3cr3t', + :admin_url => 'http://10.0.0.10:35357/v2.0', + :admin_tenant_name => 'services2', + :api_endpoint => 'http://10.0.0.10:6385/v1', + :compute_driver => 'ironic.FoobarDriver' + } + end + + it 'configures ironic in nova.conf' do + is_expected.to contain_nova_config('ironic/admin_username').with_value('ironic') + is_expected.to contain_nova_config('ironic/admin_password').with_value('s3cr3t') + is_expected.to contain_nova_config('ironic/admin_url').with_value('http://10.0.0.10:35357/v2.0') + is_expected.to contain_nova_config('ironic/admin_tenant_name').with_value('services2') + is_expected.to contain_nova_config('ironic/api_endpoint').with_value('http://10.0.0.10:6385/v1') + is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('ironic.FoobarDriver') + end end context 'with deprecated parameters' do diff --git a/spec/classes/nova_compute_libvirt_spec.rb b/spec/classes/nova_compute_libvirt_spec.rb index 87b144054..0082578ac 100644 --- a/spec/classes/nova_compute_libvirt_spec.rb +++ b/spec/classes/nova_compute_libvirt_spec.rb @@ -58,10 +58,12 @@ describe 'nova::compute::libvirt' do :remove_unused_kernels => true, :remove_unused_resized_minimum_age_seconds => 3600, :remove_unused_original_minimum_age_seconds => 3600, - :libvirt_service_name => 'custom_service' + :libvirt_service_name => 'custom_service', + :compute_driver => 'libvirt.FoobarDriver', } end + it { is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('libvirt.FoobarDriver')} it { is_expected.to contain_nova_config('libvirt/virt_type').with_value('qemu')} it { is_expected.to contain_nova_config('libvirt/cpu_mode').with_value('host-passthrough')} it { is_expected.to contain_nova_config('libvirt/disk_cachemodes').with_value('file=directsync,block=none')} diff --git a/spec/classes/nova_compute_vmware_spec.rb b/spec/classes/nova_compute_vmware_spec.rb index 90ef18b53..9bd295045 100644 --- a/spec/classes/nova_compute_vmware_spec.rb +++ b/spec/classes/nova_compute_vmware_spec.rb @@ -14,7 +14,8 @@ describe 'nova::compute::vmware' do :maximum_objects => 100, :task_poll_interval => 10.5, :use_linked_clone => false, - :wsdl_location => 'http://127.0.0.1:8080/vmware/SDK/wsdl/vim25/vimService.wsdl'} + :wsdl_location => 'http://127.0.0.1:8080/vmware/SDK/wsdl/vim25/vimService.wsdl', + :compute_driver => 'vmwareapi.FoobarDriver' } end it 'configures vmwareapi in nova.conf' do @@ -42,6 +43,7 @@ describe 'nova::compute::vmware' do end it 'configures vmwareapi in nova.conf' do + is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value(params[:compute_driver]) is_expected.to contain_nova_config('VMWARE/api_retry_count').with_value(params[:api_retry_count]) is_expected.to contain_nova_config('VMWARE/maximum_objects').with_value(params[:maximum_objects]) is_expected.to contain_nova_config('VMWARE/task_poll_interval').with_value(params[:task_poll_interval]) diff --git a/spec/classes/nova_compute_xenserver_spec.rb b/spec/classes/nova_compute_xenserver_spec.rb index ccb8cfb87..b47a44894 100644 --- a/spec/classes/nova_compute_xenserver_spec.rb +++ b/spec/classes/nova_compute_xenserver_spec.rb @@ -26,4 +26,14 @@ describe 'nova::compute::xenserver' do ) end end + + context 'with overridden parameters' do + before do + params.merge!({:compute_driver => 'xenapi.FoobarDriver'}) + end + + it 'configures xenapi in nova.conf' do + is_expected.to contain_nova_config('DEFAULT/compute_driver').with_value('xenapi.FoobarDriver') + end + end end