diff --git a/lib/puppet/provider/neutron_agent_ovn/ini_setting.rb b/lib/puppet/provider/neutron_agent_ovn/ini_setting.rb new file mode 100644 index 000000000..506b793bc --- /dev/null +++ b/lib/puppet/provider/neutron_agent_ovn/ini_setting.rb @@ -0,0 +1,14 @@ +Puppet::Type.type(:neutron_agent_ovn).provide( + :ini_setting, + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) +) do + + def self.file_path + '/etc/neutron/plugins/ml2/ovn_agent.ini' + end + + # added for backwards compatibility with older versions of inifile + def file_path + self.class.file_path + end +end diff --git a/lib/puppet/type/neutron_agent_ovn.rb b/lib/puppet/type/neutron_agent_ovn.rb new file mode 100644 index 000000000..7778cec7d --- /dev/null +++ b/lib/puppet/type/neutron_agent_ovn.rb @@ -0,0 +1,52 @@ +Puppet::Type.newtype(:neutron_agent_ovn) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from ovn_agent.ini' + newvalues(/\S+\/\S+/) + end + + newproperty(:value) do + desc 'The value of the setting to be defined.' + munge do |value| + value = value.to_s.strip + value.capitalize! if value =~ /^(true|false)$/i + value + end + + def is_to_s( currentvalue ) + if resource.secret? + return '[old secret redacted]' + else + return currentvalue + end + end + + def should_to_s( newvalue ) + if resource.secret? + return '[new secret redacted]' + else + return newvalue + end + end + end + + newparam(:secret, :boolean => true) do + desc 'Whether to hide the value from Puppet logs. Defaults to `false`.' + + newvalues(:true, :false) + + defaultto false + end + + newparam(:ensure_absent_val) do + desc 'A value that is specified as the value property will behave as if ensure => absent was specified' + defaultto('') + end + + autorequire(:anchor) do + ['neutron::install::end'] + end + +end diff --git a/manifests/agents/ml2/ovn.pp b/manifests/agents/ml2/ovn.pp new file mode 100644 index 000000000..5a8771acd --- /dev/null +++ b/manifests/agents/ml2/ovn.pp @@ -0,0 +1,189 @@ +# == Class: neutron::agents::ml2::ovn +# +# Setup and configure neutron OVN Neutron Agent. +# +# === Parameters +# +# [*package_ensure*] +# Ensure state of the package. Defaults to 'present'. +# +# [*enabled*] +# State of the service. Defaults to true. +# +# [*manage_service*] +# (optional) Whether to start/stop the service +# Defaults to true +# +# [*debug*] +# Debug. Defaults to $facts['os_service_default']. +# +# [*ovsdb_connection*] +# (optional) The URI used to connect to the local OVSDB server. +# Defaults to 'tcp:127.0.0.1:6640' +# +# [*ovs_manager*] +# The manager target that will be set to OVS so that the metadata agent can +# connect to. +# Defaults to 'ptcp:6640:127.0.0.1' +# +# [*ovn_nb_connection*] +# (optional) The connection string for the OVN_Northbound OVSDB. +# Defaults to 'tcp:127.0.0.1:6641' +# +# [*ovn_sb_connection*] +# (optional) The connection string for the OVN_Southbound OVSDB +# Defaults to '$facts['os_service_default']' +# +# [*ovn_nb_private_key*] +# (optional) The PEM file with private key for SSL connection to OVN-NB-DB +# Defaults to $facts['os_service_default'] +# +# [*ovn_nb_certificate*] +# (optional) The PEM file with certificate that certifies the private +# key specified in ovn_nb_private_key +# Defaults to $facts['os_service_default'] +# +# [*ovn_nb_ca_cert*] +# (optional) The PEM file with CA certificate that OVN should use to +# verify certificates presented to it by SSL peers +# Defaults to $facts['os_service_default'] +# +# [*ovn_sb_private_key*] +# (optional) TThe PEM file with private key for SSL connection to OVN-SB-DB +# Defaults to $facts['os_service_default'] +# +# [*ovn_sb_certificate*] +# (optional) The PEM file with certificate that certifies the +# private key specified in ovn_sb_private_key +# Defaults to $facts['os_service_default'] +# +# [*ovn_sb_ca_cert*] +# (optional) TThe PEM file with CA certificate that OVN should use to +# verify certificates presented to it by SSL peers +# Defaults to $facts['os_service_default'] +# +# [*ovsdb_connection_timeout*] +# (optional) Timeout in seconds for the OVSDB connection transaction. +# Defaults to $facts['os_service_default'] +# +# [*ovndb_connection_timeout*] +# (optional) Timeout in seconds for the OVNDB connection transaction. This +# is used for OVN DB connection. +# Defaults to $facts['os_service_default'] +# +# [*ovsdb_retry_max_interval*] +# (optional) Max interval in seconds between each retry to get the OVN NB +# and SB IDLs. +# Defaults to $facts['os_service_default']. +# +# [*ovsdb_probe_interval*] +# (optional) The probe interval for the OVSDB session in milliseconds. +# Defaults to $facts['os_service_default']. +# +# [*root_helper*] +# (optional) Use "sudo neutron-rootwrap /etc/neutron/rootwrap.conf" to use the real +# root filter facility. Change to "sudo" to skip the filtering and just run the command +# directly +# Defaults to 'sudo neutron-rootwrap /etc/neutron/rootwrap.conf'. +# +# [*root_helper_daemon*] +# (optional) Root helper daemon application to use when possible. +# Defaults to $facts['os_service_default']. +# +# [*state_path*] +# (optional) Where to store state files. This directory must be writable +# by the user executing the agent +# Defaults to '/var/lib/neutron'. +# +# [*purge_config*] +# (optional) Whether to set only the specified config options +# in the metadata config. +# Defaults to false. +# +class neutron::agents::ml2::ovn ( + $package_ensure = 'present', + $enabled = true, + $manage_service = true, + $debug = $facts['os_service_default'], + $ovsdb_connection = 'tcp:127.0.0.1:6640', + $ovs_manager = 'ptcp:6640:127.0.0.1', + $ovn_nb_connection = $facts['os_service_default'], + $ovn_sb_connection = $facts['os_service_default'], + $ovn_nb_private_key = $facts['os_service_default'], + $ovn_nb_certificate = $facts['os_service_default'], + $ovn_nb_ca_cert = $facts['os_service_default'], + $ovn_sb_private_key = $facts['os_service_default'], + $ovn_sb_certificate = $facts['os_service_default'], + $ovn_sb_ca_cert = $facts['os_service_default'], + $ovsdb_connection_timeout = $facts['os_service_default'], + $ovndb_connection_timeout = $facts['os_service_default'], + $ovsdb_retry_max_interval = $facts['os_service_default'], + $ovsdb_probe_interval = $facts['os_service_default'], + $root_helper = 'sudo neutron-rootwrap /etc/neutron/rootwrap.conf', + $root_helper_daemon = $facts['os_service_default'], + $state_path = '/var/lib/neutron', + $purge_config = false, +) { + + validate_legacy(Boolean, 'validate_bool', $manage_service) + validate_legacy(Boolean, 'validate_bool', $enabled) + + include neutron::deps + include neutron::params + + resources { 'neutron_agent_ovn': + purge => $purge_config, + } + + neutron_agent_ovn { + 'DEFAULT/debug': value => $debug; + 'DEFAULT/state_path': value => $state_path; + 'agent/root_helper': value => $root_helper; + 'agent/root_helper_daemon': value => $root_helper_daemon; + 'ovs/ovsdb_connection': value => $ovsdb_connection; + 'ovs/ovsdb_connection_timeout': value => $ovsdb_connection_timeout; + 'ovn/ovsdb_connection_timeout': value => $ovndb_connection_timeout; + 'ovn/ovsdb_retry_max_interval': value => $ovsdb_retry_max_interval; + 'ovn/ovsdb_probe_interval': value => $ovsdb_probe_interval; + 'ovn/ovn_sb_connection': value => join(any2array($ovn_sb_connection), ','); + 'ovn/ovn_nb_connection': value => join(any2array($ovn_nb_connection), ','); + 'ovn/ovn_nb_private_key': value => $ovn_nb_private_key; + 'ovn/ovn_nb_certificate': value => $ovn_nb_certificate; + 'ovn/ovn_nb_ca_cert': value => $ovn_nb_ca_cert; + 'ovn/ovn_sb_private_key': value => $ovn_sb_private_key; + 'ovn/ovn_sb_certificate': value => $ovn_sb_certificate; + 'ovn/ovn_sb_ca_cert': value => $ovn_sb_ca_cert; + } + + package { 'neutron-ovn-agent': + ensure => $package_ensure, + name => $::neutron::params::ovn_agent_package, + tag => ['openstack', 'neutron-package'], + } + + if $manage_service { + if $enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + service { 'neutron-ovn-agent': + ensure => $service_ensure, + name => $::neutron::params::ovn_agent_service, + enable => $enabled, + tag => 'neutron-service', + } + Exec['Set OVS Manager'] -> Service['neutron-ovn-agent'] + } + + # Set OVS manager so that the OVN Neutron Agent can connect to Open vSwitch + # NOTE(tkajinam): We use ensure_resource to avoid conflict with + # neutron::agents::ovn_metadata + ensure_resource('exec', 'Set OVS Manager', { + 'command' => "ovs-vsctl set-manager ${ovs_manager}", + 'unless' => "ovs-vsctl get-manager | grep \"${ovs_manager}\"", + 'path' => '/usr/sbin:/usr/bin:/sbin:/bin', + }) + + Package<| title == 'neutron-ovn-agent' |> -> Exec['Set OVS Manager'] +} diff --git a/manifests/agents/ovn_metadata.pp b/manifests/agents/ovn_metadata.pp index e87b21ea3..c896b3397 100644 --- a/manifests/agents/ovn_metadata.pp +++ b/manifests/agents/ovn_metadata.pp @@ -207,11 +207,13 @@ class neutron::agents::ovn_metadata ( } # Set OVS manager so that metadata agent can connect to Open vSwitch - exec { 'Set OVS Manager': - command => "ovs-vsctl set-manager ${ovs_manager}", - unless => "ovs-vsctl get-manager | grep \"${ovs_manager}\"", - path => '/usr/sbin:/usr/bin:/sbin:/bin', - } + # NOTE(tkajinam): We use ensure_resource to avoid conflict with + # neutron::agents::ml2::ovn + ensure_resource('exec', 'Set OVS Manager', { + 'command' => "ovs-vsctl set-manager ${ovs_manager}", + 'unless' => "ovs-vsctl get-manager | grep \"${ovs_manager}\"", + 'path' => '/usr/sbin:/usr/bin:/sbin:/bin', + }) Package<| title == 'ovn-metadata' |> -> Exec['Set OVS Manager'] } diff --git a/manifests/config.pp b/manifests/config.pp index 1f2f22ca8..50fe8723f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -33,6 +33,9 @@ # [*sriov_agent_config*] # (optional) Manage configuration of sriov_agent.ini # +# [*ovn_agent_config*] +# (optional) Manage configuration of ovn_agent.ini +# # [*macvtap_agent_config*] # (optional) Manage configuration of macvtap_agent.ini # @@ -93,6 +96,7 @@ class neutron::config ( $server_config = {}, $api_paste_ini = {}, $ovs_agent_config = {}, + $ovn_agent_config = {}, $sriov_agent_config = {}, $macvtap_agent_config = {}, $bgpvpn_bagpipe_config = {}, @@ -126,6 +130,7 @@ class neutron::config ( validate_legacy(Hash, 'validate_hash', $server_config) validate_legacy(Hash, 'validate_hash', $api_paste_ini) validate_legacy(Hash, 'validate_hash', $ovs_agent_config) + validate_legacy(Hash, 'validate_hash', $ovn_agent_config) validate_legacy(Hash, 'validate_hash', $sriov_agent_config) validate_legacy(Hash, 'validate_hash', $linuxbridge_agent_config_real) validate_legacy(Hash, 'validate_hash', $macvtap_agent_config) @@ -148,6 +153,7 @@ class neutron::config ( create_resources('neutron_config', $server_config) create_resources('neutron_api_paste_ini', $api_paste_ini) create_resources('neutron_agent_ovs', $ovs_agent_config) + create_resources('neutron_agent_ovn', $ovn_agent_config) create_resources('neutron_sriov_agent_config', $sriov_agent_config) create_resources('neutron_agent_linuxbridge', $linuxbridge_agent_config_real) create_resources('neutron_agent_macvtap', $macvtap_agent_config) diff --git a/manifests/deps.pp b/manifests/deps.pp index c34ff21ef..6f261302a 100644 --- a/manifests/deps.pp +++ b/manifests/deps.pp @@ -36,6 +36,7 @@ class neutron::deps { Anchor['neutron::config::begin'] -> Neutron_agent_linuxbridge<||> ~> Anchor['neutron::config::end'] Anchor['neutron::config::begin'] -> Neutron_agent_macvtap<||> ~> Anchor['neutron::config::end'] Anchor['neutron::config::begin'] -> Neutron_agent_ovs<||> ~> Anchor['neutron::config::end'] + Anchor['neutron::config::begin'] -> Neutron_agent_ovn<||> ~> Anchor['neutron::config::end'] Anchor['neutron::config::begin'] -> Neutron_api_paste_ini<||> ~> Anchor['neutron::config::end'] Anchor['neutron::config::begin'] -> Neutron_bgpvpn_bagpipe_config<||> ~> Anchor['neutron::config::end'] Anchor['neutron::config::begin'] -> Neutron_bgpvpn_service_config<||> ~> Anchor['neutron::config::end'] diff --git a/manifests/params.pp b/manifests/params.pp index f40918148..795d75be3 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -18,6 +18,7 @@ class neutron::params { $l3_agent_service = 'neutron-l3-agent' $metadata_agent_service = 'neutron-metadata-agent' $ovn_metadata_agent_service = 'neutron-ovn-metadata-agent' + $ovn_agent_service = 'neutron-ovn-agent' $bgp_dragent_service = 'neutron-bgp-dragent' $bagpipe_bgp_package = 'openstack-bagpipe-bgp' $bgpvpn_bagpipe_package = 'python3-networking-bagpipe' @@ -51,6 +52,7 @@ class neutron::params { $l2gw_agent_package = 'openstack-neutron-l2gw-agent' $l2gw_package = 'python3-networking-l2gw' $ovn_metadata_agent_package = 'openstack-neutron-ovn-metadata-agent' + $ovn_agent_package = 'openstack-neutron-ovn-agent' $dynamic_routing_package = false $bgp_dragent_package = 'openstack-neutron-bgp-dragent' $openswan_package = 'libreswan' @@ -106,6 +108,7 @@ class neutron::params { $l2gw_agent_package = 'neutron-l2gateway-agent' $l2gw_package = 'python3-networking-l2gw' $ovn_metadata_agent_package = 'neutron-ovn-metadata-agent' + $ovn_agent_package = 'neutron-ovn-agent' $neutron_wsgi_script_path = '/usr/lib/cgi-bin/neutron' $neutron_wsgi_script_source = '/usr/bin/neutron-api' $networking_baremetal_package = 'python3-ironic-neutron-agent' diff --git a/releasenotes/notes/ovn-neutron-agent-3c7f0eae56a870a6.yaml b/releasenotes/notes/ovn-neutron-agent-3c7f0eae56a870a6.yaml new file mode 100644 index 000000000..de0888930 --- /dev/null +++ b/releasenotes/notes/ovn-neutron-agent-3c7f0eae56a870a6.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Adds the ability to configure the OVN Neutron Agent. diff --git a/spec/acceptance/99_neutron_config_spec.rb b/spec/acceptance/99_neutron_config_spec.rb index 05e4d6fdd..18d8f5af7 100644 --- a/spec/acceptance/99_neutron_config_spec.rb +++ b/spec/acceptance/99_neutron_config_spec.rb @@ -13,6 +13,9 @@ describe 'basic neutron_config resource' do '/etc/neutron/plugins/ml2/ml2_conf.ini', '/etc/neutron/vpn_agent.ini', '/etc/neutron/plugins/opencontrail/ContrailPlugin.ini', + '/etc/neutron/plugins/ml2/linuxbridge_agent.ini', + '/etc/neutron/plugins/ml2/openvswitch_agent.ini', + '/etc/neutron/plugins/ml2/ovn_agent.ini', '/etc/neutron/plugins/ml2/sriov_agent.ini', '/etc/neutron/neutron_ovn_metadata_agent.ini'] @@ -31,6 +34,7 @@ describe 'basic neutron_config resource' do File <||> -> Neutron_plugin_opencontrail <||> File <||> -> Neutron_agent_linuxbridge <||> File <||> -> Neutron_agent_ovs <||> + File <||> -> Neutron_agent_ovn <||> File <||> -> Neutron_sriov_agent_config <||> File <||> -> Neutron_l2gw_agent_config <||> File <||> -> Ovn_metadata_agent_config <||> @@ -52,6 +56,9 @@ describe 'basic neutron_config resource' do '/etc/neutron/plugins/ml2/ml2_conf.ini', '/etc/neutron/vpn_agent.ini', '/etc/neutron/plugins/opencontrail/ContrailPlugin.ini', + '/etc/neutron/plugins/ml2/linuxbridge_agent.ini', + '/etc/neutron/plugins/ml2/openvswitch_agent.ini', + '/etc/neutron/plugins/ml2/ovn_agent.ini', '/etc/neutron/plugins/ml2/sriov_agent.ini', '/etc/neutron/neutron_ovn_metadata_agent.ini'] @@ -260,6 +267,24 @@ describe 'basic neutron_config resource' do ensure_absent_val => 'toto', } + neutron_agent_ovn { 'DEFAULT/thisshouldexist' : + value => 'foo', + } + + neutron_agent_ovn { 'DEFAULT/thisshouldnotexist' : + value => '', + } + + neutron_agent_ovn { 'DEFAULT/thisshouldexist2' : + value => '', + ensure_absent_val => 'toto', + } + + neutron_agent_ovn { 'DEFAULT/thisshouldnotexist2' : + value => 'toto', + ensure_absent_val => 'toto', + } + neutron_sriov_agent_config { 'DEFAULT/thisshouldexist' : value => 'foo', } @@ -345,6 +370,7 @@ describe 'basic neutron_config resource' do 'neutron_plugin_opencontrail', 'neutron_agent_linuxbridge', 'neutron_agent_ovs', + 'neutron_agent_ovn', 'neutron_sriov_agent_config', 'neutron_l2gw_service_config', 'neutron_l2gw_agent_config', diff --git a/spec/classes/neutron_agents_ml2_ovn_spec.rb b/spec/classes/neutron_agents_ml2_ovn_spec.rb new file mode 100644 index 000000000..fa4c22b3b --- /dev/null +++ b/spec/classes/neutron_agents_ml2_ovn_spec.rb @@ -0,0 +1,88 @@ +require 'spec_helper' + +describe 'neutron::agents::ml2::ovn' do + let :pre_condition do + "class { 'neutron': }" + end + + shared_examples 'OVN Neutron Agent' do + it { should contain_class('neutron::params') } + + it 'configures OVN Neutron Agent service' do + should contain_service('neutron-ovn-agent').with( + :name => platform_params[:neutron_ovn_agent_service], + :enable => true, + :ensure => 'running', + :tag => 'neutron-service', + ) + should contain_service('neutron-ovn-agent').that_subscribes_to('Anchor[neutron::service::begin]') + should contain_service('neutron-ovn-agent').that_notifies('Anchor[neutron::service::end]') + end + + context 'with manage_service as false' do + let :params do + { :manage_service => false } + end + + it 'should not manage the service' do + should_not contain_service('neutron-ovn-agent') + end + end + + it 'passes purge to resource' do + should contain_resources('neutron_agent_ovn').with({ + :purge => false + }) + end + + it 'configures ovn_agent.ini' do + should contain_neutron_agent_ovn('DEFAULT/debug').with(:value => '') + should contain_neutron_agent_ovn('DEFAULT/state_path').with(:value => '/var/lib/neutron') + should contain_neutron_agent_ovn('agent/root_helper').with(:value => 'sudo neutron-rootwrap /etc/neutron/rootwrap.conf') + should contain_neutron_agent_ovn('agent/root_helper_daemon').with(:value => '') + should contain_neutron_agent_ovn('ovs/ovsdb_connection').with(:value => 'tcp:127.0.0.1:6640') + should contain_neutron_agent_ovn('ovs/ovsdb_connection_timeout').with(:value => '') + should contain_neutron_agent_ovn('ovn/ovsdb_connection_timeout').with(:value => '') + should contain_neutron_agent_ovn('ovn/ovn_nb_connection').with(:value => '') + should contain_neutron_agent_ovn('ovn/ovn_sb_connection').with(:value => '') + should contain_neutron_agent_ovn('ovn/ovsdb_retry_max_interval').with(:value => '') + should contain_neutron_agent_ovn('ovn/ovsdb_probe_interval').with(:value => '') + end + + it 'installs OVN Neutron Agent package' do + should contain_package('neutron-ovn-agent').with( + :ensure => 'present', + :name => platform_params[:neutron_ovn_agent_package], + :tag => ['openstack', 'neutron-package'], + ) + end + + it 'configures subscription to neutron-ovn-agent package' do + should contain_service('neutron-ovn-agent').that_subscribes_to('Anchor[neutron::service::begin]') + should contain_service('neutron-ovn-agent').that_notifies('Anchor[neutron::service::end]') + end + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + let (:platform_params) do + case facts[:osfamily] + when 'Debian' + { :neutron_ovn_agent_package => 'neutron-ovn-agent', + :neutron_ovn_agent_service => 'neutron-ovn-agent' } + when 'RedHat' + { :neutron_ovn_agent_package => 'openstack-neutron-ovn-agent', + :neutron_ovn_agent_service => 'neutron-ovn-agent' } + end + end + + it_behaves_like 'OVN Neutron Agent' + end + end +end diff --git a/spec/classes/neutron_config_spec.rb b/spec/classes/neutron_config_spec.rb index da90adc2f..3ea9d8ced 100644 --- a/spec/classes/neutron_config_spec.rb +++ b/spec/classes/neutron_config_spec.rb @@ -57,6 +57,7 @@ describe 'neutron::config' do shared_examples 'neutron_agent_config' do let :params do { :ovs_agent_config => config_hash, + :ovn_agent_config => config_hash, :sriov_agent_config => config_hash, :linuxbridge_agent_config => config_hash, :macvtap_agent_config => config_hash, @@ -76,6 +77,12 @@ describe 'neutron::config' do should contain_neutron_agent_ovs('DEFAULT/baz').with_ensure('absent') end + it 'configures arbitrary neutron_agent_ovn configurations' do + should contain_neutron_agent_ovn('DEFAULT/foo').with_value('fooValue') + should contain_neutron_agent_ovn('DEFAULT/bar').with_value('barValue') + should contain_neutron_agent_ovn('DEFAULT/baz').with_ensure('absent') + end + it 'configures arbitrary neutron_sriov_agent_config configurations' do should contain_neutron_sriov_agent_config('DEFAULT/foo').with_value('fooValue') should contain_neutron_sriov_agent_config('DEFAULT/bar').with_value('barValue') diff --git a/spec/unit/provider/neutron_agent_ovn/ini_setting_spec.rb b/spec/unit/provider/neutron_agent_ovn/ini_setting_spec.rb new file mode 100644 index 000000000..90f6e00b7 --- /dev/null +++ b/spec/unit/provider/neutron_agent_ovn/ini_setting_spec.rb @@ -0,0 +1,50 @@ +require 'spec_helper' + +provider_class = Puppet::Type.type(:neutron_agent_ovn).provider(:ini_setting) + +describe provider_class do + + it 'should default to the default setting when no other one is specified' do + resource = Puppet::Type::Neutron_agent_ovn.new( + { + :name => 'DEFAULT/foo', + :value => 'bar' + } + ) + provider = provider_class.new(resource) + expect(provider.section).to eq('DEFAULT') + expect(provider.setting).to eq('foo') + expect(provider.file_path).to eq('/etc/neutron/plugins/ml2/ovn_agent.ini') + end + + it 'should allow setting to be set explicitly' do + resource = Puppet::Type::Neutron_agent_ovn.new( + { + :name => 'dude/foo', + :value => 'bar' + } + ) + provider = provider_class.new(resource) + expect(provider.section).to eq('dude') + expect(provider.setting).to eq('foo') + expect(provider.file_path).to eq('/etc/neutron/plugins/ml2/ovn_agent.ini') + end + + it 'should ensure absent when is specified as a value' do + resource = Puppet::Type::Neutron_agent_ovn.new( + {:name => 'dude/foo', :value => ''} + ) + provider = provider_class.new(resource) + provider.exists? + expect(resource[:ensure]).to eq :absent + end + + it 'should ensure absent when value matches ensure_absent_val' do + resource = Puppet::Type::Neutron_agent_ovn.new( + {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' } + ) + provider = provider_class.new(resource) + provider.exists? + expect(resource[:ensure]).to eq :absent + end +end diff --git a/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb b/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb index e7f23ea3f..f9570213b 100644 --- a/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb +++ b/spec/unit/provider/neutron_agent_ovs/ini_setting_spec.rb @@ -1,23 +1,50 @@ require 'spec_helper' provider_class = Puppet::Type.type(:neutron_agent_ovs).provider(:ini_setting) + describe provider_class do - let(:resource ) do - Puppet::Type::Neutron_agent_ovs.new({ - :name => 'DEFAULT/foo', - :value => 'bar', - }) + + it 'should default to the default setting when no other one is specified' do + resource = Puppet::Type::Neutron_agent_ovs.new( + { + :name => 'DEFAULT/foo', + :value => 'bar' + } + ) + provider = provider_class.new(resource) + expect(provider.section).to eq('DEFAULT') + expect(provider.setting).to eq('foo') + expect(provider.file_path).to eq('/etc/neutron/plugins/ml2/openvswitch_agent.ini') end - let (:provider) { resource.provider } + it 'should allow setting to be set explicitly' do + resource = Puppet::Type::Neutron_agent_ovs.new( + { + :name => 'dude/foo', + :value => 'bar' + } + ) + provider = provider_class.new(resource) + expect(provider.section).to eq('dude') + expect(provider.setting).to eq('foo') + expect(provider.file_path).to eq('/etc/neutron/plugins/ml2/openvswitch_agent.ini') + end - [ 'RedHat', 'Debian', 'Ubuntu' ].each do |os| - context "on #{os} with default setting" do - it 'it should fall back to default and use plugins/ml2/openvswitch_agent.ini' do - expect(provider.section).to eq('DEFAULT') - expect(provider.setting).to eq('foo') - expect(provider.file_path).to eq('/etc/neutron/plugins/ml2/openvswitch_agent.ini') - end - end + it 'should ensure absent when is specified as a value' do + resource = Puppet::Type::Neutron_agent_ovs.new( + {:name => 'dude/foo', :value => ''} + ) + provider = provider_class.new(resource) + provider.exists? + expect(resource[:ensure]).to eq :absent + end + + it 'should ensure absent when value matches ensure_absent_val' do + resource = Puppet::Type::Neutron_agent_ovs.new( + {:name => 'dude/foo', :value => 'foo', :ensure_absent_val => 'foo' } + ) + provider = provider_class.new(resource) + provider.exists? + expect(resource[:ensure]).to eq :absent end end diff --git a/spec/unit/type/neutron_agent_ovn_spec.rb b/spec/unit/type/neutron_agent_ovn_spec.rb new file mode 100644 index 000000000..b0d580535 --- /dev/null +++ b/spec/unit/type/neutron_agent_ovn_spec.rb @@ -0,0 +1,20 @@ +require 'puppet' +require 'puppet/type/neutron_agent_ovn' + +describe 'Puppet::Type.type(:neutron_agent_ovn)' do + + before :each do + @neutron_agent_ovn = Puppet::Type.type(:neutron_agent_ovn).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + anchor = Puppet::Type.type(:anchor).new(:name => 'neutron::install::end') + catalog.add_resource anchor, @neutron_agent_ovn + dependency = @neutron_agent_ovn.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@neutron_agent_ovn) + expect(dependency[0].source).to eq(anchor) + end + +end