diff --git a/manifests/compute/neutron.pp b/manifests/compute/neutron.pp index 59623b00a..91ee91cfc 100644 --- a/manifests/compute/neutron.pp +++ b/manifests/compute/neutron.pp @@ -10,9 +10,14 @@ # (optional) The libvirt VIF driver to configure the VIFs. # Defaults to 'nova.virt.libvirt.vif.LibvirtGenericVIFDriver'. # - +# [*force_snat_range*] +# (optional) Force SNAT rule to specified network for nova-network +# Default to 0.0.0.0/0 +# Due to architecture constraints in nova_config, it's not possible to setup +# more than one SNAT rule though initial parameter is MultiStrOpt class nova::compute::neutron ( - $libvirt_vif_driver = 'nova.virt.libvirt.vif.LibvirtGenericVIFDriver' + $libvirt_vif_driver = 'nova.virt.libvirt.vif.LibvirtGenericVIFDriver', + $force_snat_range = '0.0.0.0/0', ) { if $libvirt_vif_driver == 'nova.virt.libvirt.vif.LibvirtOpenVswitchDriver' { @@ -22,4 +27,21 @@ class nova::compute::neutron ( nova_config { 'libvirt/vif_driver': value => $libvirt_vif_driver; } + + if $libvirt_vif_driver == 'nova.virt.libvirt.vif.LibvirtGenericVIFDriver' and $force_snat_range { + # Validate ip and mask for force_snat_range + $force_snat_range_array = split($force_snat_range, '/') + if is_ip_address($force_snat_range_array[0]) and is_integer($force_snat_range_array[1]) { + nova_config { + 'DEFAULT/force_snat_range': value => $force_snat_range; + } + } else { + fail('force_snat_range should be IPv4 or IPv6 CIDR notation') + } + } else { + nova_config { + 'DEFAULT/force_snat_range': ensure => absent; + } + } + } diff --git a/spec/classes/nova_compute_neutron_spec.rb b/spec/classes/nova_compute_neutron_spec.rb index b67c9fc4b..030968fa8 100644 --- a/spec/classes/nova_compute_neutron_spec.rb +++ b/spec/classes/nova_compute_neutron_spec.rb @@ -1,13 +1,17 @@ require 'spec_helper' describe 'nova::compute::neutron' do - it { should contain_nova_config('libvirt/vif_driver').with_value('nova.virt.libvirt.vif.LibvirtGenericVIFDriver')} + context 'with default parameters' do + it { should contain_nova_config('libvirt/vif_driver').with_value('nova.virt.libvirt.vif.LibvirtGenericVIFDriver')} + it { should contain_nova_config('DEFAULT/force_snat_range').with(:value => '0.0.0.0/0') } + end context 'when overriding params' do let :params do {:libvirt_vif_driver => 'foo' } end it { should contain_nova_config('libvirt/vif_driver').with_value('foo')} + it { should contain_nova_config('DEFAULT/force_snat_range').with_ensure(:absent) } end context 'when overriding with a removed libvirt_vif_driver param' do @@ -19,4 +23,36 @@ describe 'nova::compute::neutron' do end end + context 'with force_snat_range parameter set to false' do + let :params do + { :force_snat_range => false, } + end + it { should contain_nova_config('DEFAULT/force_snat_range').with_ensure('absent') } + end + + context 'with force_snat_range parameter set to 10.0.0.0/24' do + let :params do + { :force_snat_range => '10.0.0.0/24', } + end + + it { should contain_nova_config('DEFAULT/force_snat_range').with_value('10.0.0.0/24') } + end + + context 'with force_snat_range parameter set to fe80::/64' do + let :params do + { :force_snat_range => 'fe80::/64', } + end + + it { should contain_nova_config('DEFAULT/force_snat_range').with_value('fe80::/64') } + end + + context 'with force_snat_range parameter set ip without mask' do + let :params do + { :force_snat_range => '10.0.0.0', } + end + + it { expect { should contain_nova_config('DEFAULT/force_snat_range') }.to \ + raise_error(Puppet::Error, /force_snat_range should be IPv4 or IPv6/) } + end + end