From f0101c709f29c18285a155230c62e7f15e736ea8 Mon Sep 17 00:00:00 2001 From: Michal Adamczyk Date: Fri, 23 Dec 2016 12:16:37 +0100 Subject: [PATCH] Xenserver - adding type and provider too manage rootwrap.conf This simple patch is adding following stuff: 1. Adding minimize_polling parameter to ovs ml2 agent class. 2. Adding type and provider to mange rootwrap.conf file mainly to manipulate XenServer connection parameters. Change-Id: I3dad47a34af7bab7eefe46db39b3a5eedc7c3c7f --- .../neutron_rootwrap_config/ini_setting.rb | 15 ++++ lib/puppet/type/neutron_rootwrap_config.rb | 28 +++++++ manifests/agents/ml2/ovs.pp | 7 ++ manifests/rootwrap.pp | 36 +++++++++ ...nf-type-and-provider-095249f1440e7b39.yaml | 5 ++ spec/classes/neutron_agents_ml2_ovs_spec.rb | 1 + spec/classes/neutron_rootwrap_spec.rb | 39 ++++++++++ .../ini_setting_spec.rb | 74 +++++++++++++++++++ .../unit/type/neutron_rootwrap_config_spec.rb | 20 +++++ 9 files changed, 225 insertions(+) create mode 100644 lib/puppet/provider/neutron_rootwrap_config/ini_setting.rb create mode 100644 lib/puppet/type/neutron_rootwrap_config.rb create mode 100644 manifests/rootwrap.pp create mode 100644 releasenotes/notes/add-rootwrap.conf-type-and-provider-095249f1440e7b39.yaml create mode 100644 spec/classes/neutron_rootwrap_spec.rb create mode 100644 spec/unit/provider/neutron_rootwrap_config/ini_setting_spec.rb create mode 100644 spec/unit/type/neutron_rootwrap_config_spec.rb diff --git a/lib/puppet/provider/neutron_rootwrap_config/ini_setting.rb b/lib/puppet/provider/neutron_rootwrap_config/ini_setting.rb new file mode 100644 index 000000000..238869448 --- /dev/null +++ b/lib/puppet/provider/neutron_rootwrap_config/ini_setting.rb @@ -0,0 +1,15 @@ +Puppet::Type.type(:neutron_rootwrap_config).provide( + :ini_setting, + :parent => Puppet::Type.type(:openstack_config).provider(:ini_setting) +) do + + def self.file_path + '/etc/neutron/rootwrap.conf' + 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_rootwrap_config.rb b/lib/puppet/type/neutron_rootwrap_config.rb new file mode 100644 index 000000000..efbd3a741 --- /dev/null +++ b/lib/puppet/type/neutron_rootwrap_config.rb @@ -0,0 +1,28 @@ +Puppet::Type.newtype(:neutron_rootwrap_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from rootwrap config.' + 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 + 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(:package) do + 'neutron-common' + end + +end diff --git a/manifests/agents/ml2/ovs.pp b/manifests/agents/ml2/ovs.pp index af8c47b4c..0b8a76085 100644 --- a/manifests/agents/ml2/ovs.pp +++ b/manifests/agents/ml2/ovs.pp @@ -140,6 +140,11 @@ # (optional) Enable or not DPDK with OVS # Defaults to false. # +# [*minimize_polling*] +# (optional) Minimize polling by monitoring ovsdb for interface +# changes. (boolean value) +# Defaults to $::os_service_default +# # === Deprecated Parameters # # [*prevent_arp_spoofing*] @@ -177,6 +182,7 @@ class neutron::agents::ml2::ovs ( $ovsdb_interface = $::os_service_default, $purge_config = false, $enable_dpdk = false, + $minimize_polling = $::os_service_default, # DEPRECATED PARAMETERS $prevent_arp_spoofing = $::os_service_default, $enable_tunneling = false, @@ -279,6 +285,7 @@ class neutron::agents::ml2::ovs ( 'agent/drop_flows_on_start': value => $drop_flows_on_start; 'agent/prevent_arp_spoofing': value => $prevent_arp_spoofing; 'agent/extensions': value => join(any2array($extensions), ','); + 'agent/minimize_polling': value => $minimize_polling; 'ovs/integration_bridge': value => $integration_bridge; 'ovs/datapath_type': value => $datapath_type; 'ovs/vhostuser_socket_dir': value => $vhostuser_socket_dir; diff --git a/manifests/rootwrap.pp b/manifests/rootwrap.pp new file mode 100644 index 000000000..2f1320812 --- /dev/null +++ b/manifests/rootwrap.pp @@ -0,0 +1,36 @@ +# == Class: neutron::rootwrap +# +# Manages the neutron rootwrap.conf file on systems +# +# === Parameters: +# +# [*xenapi_connection_url*] +# (optional) XenAPI connection URL. Only needed when target a XenServer/XCP +# compute host's dom0 +# Defaults to $::os_service_default. +# +# [*xenapi_connection_username*] +# (optional) XenAPI username. Only needed when target a XenServer/XCP +# compute host's dom0 +# Defaults to $::os_service_default. +# +# [*xenapi_connection_password*] +# (optional) XenAPI connection password. Only needed when target a XenServer/XCP +# compute host's dom0 +# Defaults to $::os_service_default. +# +class neutron::rootwrap ( + $xenapi_connection_url = $::os_service_default, + $xenapi_connection_username = $::os_service_default, + $xenapi_connection_password = $::os_service_default, +) { + + Neutron_rootwrap_config <||> ~> Service['neutron-ovs-agent-service'] + + neutron_rootwrap_config { + 'xenapi/xenapi_connection_url': value => $xenapi_connection_url; + 'xenapi/xenapi_connection_username': value => $xenapi_connection_username; + 'xenapi/xenapi_connection_password': value => $xenapi_connection_password; + } + +} diff --git a/releasenotes/notes/add-rootwrap.conf-type-and-provider-095249f1440e7b39.yaml b/releasenotes/notes/add-rootwrap.conf-type-and-provider-095249f1440e7b39.yaml new file mode 100644 index 000000000..86f6c6448 --- /dev/null +++ b/releasenotes/notes/add-rootwrap.conf-type-and-provider-095249f1440e7b39.yaml @@ -0,0 +1,5 @@ +--- +features: + - Add minimize_polling parameter to ovs ml2 agent class. + - Add type and provider to mange rootwrap.conf file mainly + to manipulate XenServer connection parameters. diff --git a/spec/classes/neutron_agents_ml2_ovs_spec.rb b/spec/classes/neutron_agents_ml2_ovs_spec.rb index c0907d0ba..693d54f22 100644 --- a/spec/classes/neutron_agents_ml2_ovs_spec.rb +++ b/spec/classes/neutron_agents_ml2_ovs_spec.rb @@ -46,6 +46,7 @@ describe 'neutron::agents::ml2::ovs' do is_expected.to contain_neutron_agent_ovs('agent/prevent_arp_spoofing').with_value('') is_expected.to contain_neutron_agent_ovs('agent/drop_flows_on_start').with_value(p[:drop_flows_on_start]) is_expected.to contain_neutron_agent_ovs('agent/extensions').with_value(['']) + is_expected.to contain_neutron_agent_ovs('agent/minimize_polling').with_value(['']) is_expected.to contain_neutron_agent_ovs('ovs/datapath_type').with_value(['']) is_expected.to contain_neutron_agent_ovs('ovs/vhostuser_socket_dir').with_value(['']) is_expected.to contain_neutron_agent_ovs('ovs/ovsdb_interface').with_value(['']) diff --git a/spec/classes/neutron_rootwrap_spec.rb b/spec/classes/neutron_rootwrap_spec.rb new file mode 100644 index 000000000..96a66c35c --- /dev/null +++ b/spec/classes/neutron_rootwrap_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe 'neutron::rootwrap' do + + let :pre_condition do + "class { 'neutron::agents::ml2::ovs': }" + end + + let :params do + { :xenapi_connection_url => 'http://127.0.0.1', + :xenapi_connection_username => 'user', + :xenapi_connection_password => 'passw0rd', + } + end + + shared_examples_for 'neutron rootwrap' do + + it 'configures rootwrap.conf' do + is_expected.to contain_neutron_rootwrap_config('xenapi/xenapi_connection_url').with_value(params[:xenapi_connection_url]); + is_expected.to contain_neutron_rootwrap_config('xenapi/xenapi_connection_username').with_value(params[:xenapi_connection_username]); + is_expected.to contain_neutron_rootwrap_config('xenapi/xenapi_connection_password').with_value(params[:xenapi_connection_password]); + 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 + + it_configures 'neutron rootwrap' + end + end +end diff --git a/spec/unit/provider/neutron_rootwrap_config/ini_setting_spec.rb b/spec/unit/provider/neutron_rootwrap_config/ini_setting_spec.rb new file mode 100644 index 000000000..6acd6591e --- /dev/null +++ b/spec/unit/provider/neutron_rootwrap_config/ini_setting_spec.rb @@ -0,0 +1,74 @@ +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'inifile', + 'lib') +) +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'openstacklib', + 'lib') +) + +require 'spec_helper' + +provider_class = Puppet::Type.type(:neutron_rootwrap_config).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_rootwrap_config.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/rootwrap.conf') + end + + it 'should allow setting to be set explicitly' do + resource = Puppet::Type::Neutron_rootwrap_config.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/rootwrap.conf') + end + + it 'should ensure absent when is specified as a value' do + resource = Puppet::Type::Neutron_rootwrap_config.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_rootwrap_config.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_rootwrap_config_spec.rb b/spec/unit/type/neutron_rootwrap_config_spec.rb new file mode 100644 index 000000000..c656fb841 --- /dev/null +++ b/spec/unit/type/neutron_rootwrap_config_spec.rb @@ -0,0 +1,20 @@ +require 'puppet' +require 'puppet/type/neutron_rootwrap_config' + +describe 'Puppet::Type.type(:neutron_rootwrap_config)' do + + before :each do + @neutron_rootwrap_config = Puppet::Type.type(:neutron_rootwrap_config).new(:name => 'DEFAULT/foo', :value => 'bar') + end + + it 'should autorequire the package that install the file' do + catalog = Puppet::Resource::Catalog.new + package = Puppet::Type.type(:package).new(:name => 'neutron-common') + catalog.add_resource package, @neutron_rootwrap_config + dependency = @neutron_rootwrap_config.autorequire + expect(dependency.size).to eq(1) + expect(dependency[0].target).to eq(@neutron_rootwrap_config) + expect(dependency[0].source).to eq(package) + end + +end