diff --git a/manifests/compute/libvirt.pp b/manifests/compute/libvirt.pp index b8538b82f..9c559e888 100644 --- a/manifests/compute/libvirt.pp +++ b/manifests/compute/libvirt.pp @@ -23,11 +23,20 @@ # Defaults to 'host-model' if libvirt_type is set to either # kvm or qemu, otherwise defaults to 'None'. # +# [*libvirt_disk_cachemodes*] +# (optional) A list of cachemodes for different disk types, e.g. +# ["file=directsync", "block=none"] +# If an empty list is specified, the disk_cachemodes directive +# will be removed from nova.conf completely. +# Defaults to an empty list +# + class nova::compute::libvirt ( - $libvirt_type = 'kvm', - $vncserver_listen = '127.0.0.1', - $migration_support = false, - $libvirt_cpu_mode = false, + $libvirt_type = 'kvm', + $vncserver_listen = '127.0.0.1', + $migration_support = false, + $libvirt_cpu_mode = false, + $libvirt_disk_cachemodes = [], ) { include nova::params @@ -93,4 +102,14 @@ 'DEFAULT/vncserver_listen': value => $vncserver_listen; 'DEFAULT/libvirt_cpu_mode': value => $libvirt_cpu_mode_real; } + + if size($libvirt_disk_cachemodes) > 0 { + nova_config { + 'DEFAULT/disk_cachemodes': value => join($libvirt_disk_cachemodes, ','); + } + } else { + nova_config { + 'DEFAULT/disk_cachemodes': ensure => absent; + } + } } diff --git a/spec/classes/nova_compute_libvirt_spec.rb b/spec/classes/nova_compute_libvirt_spec.rb index ab820baf4..cc2494b03 100644 --- a/spec/classes/nova_compute_libvirt_spec.rb +++ b/spec/classes/nova_compute_libvirt_spec.rb @@ -38,19 +38,22 @@ it { should contain_nova_config('DEFAULT/connection_type').with_value('libvirt')} it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('127.0.0.1')} it { should contain_nova_config('DEFAULT/libvirt_cpu_mode').with_value('host-model')} + it { should contain_nova_config('DEFAULT/disk_cachemodes').with_ensure('absent')} end describe 'with params' do let :params do { :libvirt_type => 'qemu', :vncserver_listen => '0.0.0.0', - :libvirt_cpu_mode => 'host-passthrough' + :libvirt_cpu_mode => 'host-passthrough', + :libvirt_disk_cachemodes => ['file=directsync','block=none'] } end it { should contain_nova_config('DEFAULT/libvirt_type').with_value('qemu')} it { should contain_nova_config('DEFAULT/vncserver_listen').with_value('0.0.0.0')} it { should contain_nova_config('DEFAULT/libvirt_cpu_mode').with_value('host-passthrough')} + it { should contain_nova_config('DEFAULT/disk_cachemodes').with_value('file=directsync,block=none')} end describe 'with migration_support enabled' do