diff --git a/lib/puppet/provider/neutron_plugin_plumgrid/ini_setting.rb b/lib/puppet/provider/neutron_plugin_plumgrid/ini_setting.rb new file mode 100644 index 000000000..f7ab15679 --- /dev/null +++ b/lib/puppet/provider/neutron_plugin_plumgrid/ini_setting.rb @@ -0,0 +1,22 @@ +Puppet::Type.type(:neutron_plugin_plumgrid).provide( + :ini_setting, + :parent => Puppet::Type.type(:ini_setting).provider(:ruby) +) do + + def section + resource[:name].split('/', 2).first + end + + def setting + resource[:name].split('/', 2).last + end + + def separator + '=' + end + + def file_path + '/etc/neutron/plugins/plumgrid/plumgrid.ini' + end + +end diff --git a/lib/puppet/provider/neutron_plumlib_plumgrid/ini_setting.rb b/lib/puppet/provider/neutron_plumlib_plumgrid/ini_setting.rb new file mode 100644 index 000000000..c65a4d7cf --- /dev/null +++ b/lib/puppet/provider/neutron_plumlib_plumgrid/ini_setting.rb @@ -0,0 +1,22 @@ +Puppet::Type.type(:neutron_plumlib_plumgrid).provide( + :ini_setting, + :parent => Puppet::Type.type(:ini_setting).provider(:ruby) +) do + + def section + resource[:name].split('/', 2).first + end + + def setting + resource[:name].split('/', 2).last + end + + def separator + '=' + end + + def file_path + '/etc/neutron/plugins/plumgrid/plumlib.ini' + end + +end diff --git a/lib/puppet/type/neutron_plugin_plumgrid.rb b/lib/puppet/type/neutron_plugin_plumgrid.rb new file mode 100644 index 000000000..e068a1a67 --- /dev/null +++ b/lib/puppet/type/neutron_plugin_plumgrid.rb @@ -0,0 +1,47 @@ +Puppet::Type.newtype(:neutron_plugin_plumgrid) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from plumgrid.ini' + newvalues(/\S+\/\S+/) + end + + autorequire(:file) do + ['/etc/neutron/plugins/plumgrid'] + 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 + +end diff --git a/lib/puppet/type/neutron_plumlib_plumgrid.rb b/lib/puppet/type/neutron_plumlib_plumgrid.rb new file mode 100644 index 000000000..8266fba29 --- /dev/null +++ b/lib/puppet/type/neutron_plumlib_plumgrid.rb @@ -0,0 +1,47 @@ +Puppet::Type.newtype(:neutron_plumlib_plumgrid) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from plumlib.ini' + newvalues(/\S+\/\S+/) + end + + autorequire(:file) do + ['/etc/neutron/plugins/plumgrid'] + 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 + +end diff --git a/manifests/config.pp b/manifests/config.pp index 164ff0b45..d2616fe64 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -57,6 +57,9 @@ # [**plugin_midonet_config**] # (optional) Manage configuration of plugins/midonet/midonet.ini # +# [**plugin_plumgrid_config**] +# (optional) Manage configuration of plugins/plumgrid/plumgrid.ini +# # [**plugin_ml2_config**] # (optional) Manage configuration of ml2_conf.ini # @@ -80,6 +83,7 @@ class neutron::config ( $plugin_cisco_l2network_config = {}, $plugin_cisco_config = {}, $plugin_midonet_config = {}, + $plugin_plumgrid_config = {}, $plugin_ml2_config = {}, $plugin_ovs_config = {}, ) { @@ -97,6 +101,7 @@ class neutron::config ( validate_hash($plugin_cisco_l2network_config) validate_hash($plugin_cisco_config) validate_hash($plugin_midonet_config) + validate_hash($plugin_plumgrid_config) validate_hash($plugin_ml2_config) validate_hash($plugin_ovs_config) @@ -112,6 +117,7 @@ class neutron::config ( create_resources('neutron_plugin_cisco_l2network', $plugin_cisco_l2network_config) create_resources('neutron_plugin_cisco', $plugin_cisco_config) create_resources('neutron_plugin_midonet', $plugin_midonet_config) + create_resources('neutron_plugin_plumgrid', $plugin_plumgrid_config) create_resources('neutron_plugin_ml2', $plugin_ml2_config) create_resources('neutron_plugin_ovs', $plugin_ovs_config) } diff --git a/manifests/params.pp b/manifests/params.pp index e00e8becf..72b2935ce 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -34,6 +34,10 @@ class neutron::params { $midonet_server_package = 'python-neutron-plugin-midonet' $midonet_config_file = '/etc/neutron/plugins/midonet/midonet.ini' + $plumgrid_plugin_package = 'openstack-neutron-plumgrid' + $plumgrid_pythonlib_package = 'plumgrid-pythonlib' + $plumgrid_config_file = '/etc/neutron/plugins/plumgrid/plumgrid.ini' + $nvp_server_package = 'openstack-neutron-nicira' $dhcp_agent_package = false @@ -106,6 +110,10 @@ class neutron::params { $midonet_server_package = 'python-neutron-plugin-midonet' $midonet_config_file = '/etc/neutron/plugins/midonet/midonet.ini' + $plumgrid_plugin_package = 'neutron-plugin-plumgrid' + $plumgrid_pythonlib_package = 'plumgrid-pythonlib' + $plumgrid_config_file = '/etc/neutron/plugins/plumgrid/plumgrid.ini' + $nvp_server_package = 'neutron-plugin-nicira' $dhcp_agent_package = 'neutron-dhcp-agent' diff --git a/manifests/plugins/plumgrid.pp b/manifests/plugins/plumgrid.pp new file mode 100644 index 000000000..19165a93a --- /dev/null +++ b/manifests/plugins/plumgrid.pp @@ -0,0 +1,108 @@ +# This class installs and configures Plumgrid Neutron Plugin. +# +# === Parameters +# +# [*director_server*] +# IP address of the PLUMgrid Director Server +# Defaults to 127.0.0.1 +# [*director_server_port*] +# Port of the PLUMgrid Director Server. +# Defaults to 443 +# [*username*] +# PLUMgrid platform username +# [*password*] +# PLUMgrid platform password +# [*servertimeout*] +# Request timeout duration (seconds) to PLUMgrid paltform +# Defaults to 99 +# [*connection*] +# Database connection +# Defaults to http://127.0.0.1:35357/v2.0 +# [*admin_password*] +# Keystone admin password +# [*controller_priv_host*] +# Controller private host IP +# Defaults to 127.0.0.1 + +class neutron::plugins::plumgrid ( + $director_server = '127.0.0.1', + $director_server_port = '443', + $username = undef, + $password = undef, + $servertimeout = '99', + $connection = 'http://127.0.0.1:35357/v2.0', + $admin_password = undef, + $controller_priv_host = '127.0.0.1', + $package_ensure = 'present' +) { + + include ::neutron::params + + Package[neutron-plugin-plumgrid] -> Neutron_plugin_plumgrid<||> + Neutron_plugin_plumgrid<||> ~> Service['neutron-server'] + Package[neutron-plumlib-plumgrid] -> Neutron_plumlib_plumgrid<||> + Neutron_plumlib_plumgrid<||> ~> Service['neutron-server'] + + ensure_resource('file', '/etc/neutron/plugins/plumgrid', { + ensure => directory, + owner => 'root', + group => 'neutron', + mode => '0640'} + ) + + # Ensure the neutron package is installed before config is set + # under both RHEL and Ubuntu + if ($::neutron::params::server_package) { + Package['neutron-server'] -> Neutron_plugin_plumgrid<||> + Package['neutron-server'] -> Neutron_plumlib_plumgrid<||> + } else { + Package['neutron'] -> Neutron_plugin_plumgrid<||> + Package['neutron'] -> Neutron_plumlib_plumgrid<||> + } + + package { 'neutron-plugin-plumgrid': + ensure => $package_ensure, + name => $::neutron::params::plumgrid_plugin_package + } + + package { 'neutron-plumlib-plumgrid': + ensure => $package_ensure, + name => $::neutron::params::plumgrid_pythonlib_package + } + + if $::osfamily == 'Debian' { + file_line { '/etc/default/neutron-server:NEUTRON_PLUGIN_CONFIG': + path => '/etc/default/neutron-server', + match => '^NEUTRON_PLUGIN_CONFIG=(.*)$', + line => "NEUTRON_PLUGIN_CONFIG=${::neutron::params::plumgrid_config_file}", + require => [ Package['neutron-server'], Package['neutron-plugin-plumgrid'] ], + notify => Service['neutron-server'], + } + } + + if $::osfamily == 'Redhat' { + file { '/etc/neutron/plugin.ini': + ensure => link, + target => $::neutron::params::plumgrid_config_file, + require => Package['neutron-plugin-plumgrid'], + } + } + + neutron_plugin_plumgrid { + 'PLUMgridDirector/director_server': value => $director_server; + 'PLUMgridDirector/director_server_port': value => $director_server_port; + 'PLUMgridDirector/username': value => $username; + 'PLUMgridDirector/password': value => $password, secret =>true; + 'PLUMgridDirector/servertimeout': value => $servertimeout; + 'database/connection': value => $connection; + } + + neutron_plumlib_plumgrid { + 'keystone_authtoken/admin_user' : value => 'admin'; + 'keystone_authtoken/admin_password': value => $admin_password, secret =>true; + 'keystone_authtoken/auth_uri': value => "http://${controller_priv_host}:35357/v2.0"; + 'keystone_authtoken/admin_tenant_name': value => 'admin'; + 'PLUMgridMetadata/enable_pg_metadata' : value => 'True'; + 'PLUMgridMetadata/metadata_mode': value => 'local'; + } +} diff --git a/spec/classes/neutron_plugins_plumgrid_spec.rb b/spec/classes/neutron_plugins_plumgrid_spec.rb new file mode 100644 index 000000000..bb9b8ca76 --- /dev/null +++ b/spec/classes/neutron_plugins_plumgrid_spec.rb @@ -0,0 +1,96 @@ +require 'spec_helper' + +describe 'neutron::plugins::plumgrid' do + + let :pre_condition do + "class { 'neutron::server': auth_password => 'password' } + class { 'neutron': rabbit_password => 'passw0rd' }" + end + + let :default_params do + { + :director_server => '127.0.0.1', + :director_server_port => '443', + :servertimeout => '99', + :connection => 'http://127.0.0.1:35357/v2.0', + :controller_priv_host => '127.0.0.1' + } + end + + shared_examples_for 'neutron plumgrid plugin' do + + let :params do + {} + end + + before do + params.merge!(default_params) + end + + it 'installs plumgrid plugin package' do + is_expected.to contain_package('neutron-plugin-plumgrid').with( + :ensure => 'present' + ) + end + + it 'installs plumgrid plumlib package' do + is_expected.to contain_package('neutron-plumlib-plumgrid').with( + :ensure => 'present' + ) + end + + it 'should perform default configuration of plumgrid plugin' do + is_expected.to contain_neutron_plugin_plumgrid('PLUMgridDirector/director_server').with_value(params[:director_server]) + is_expected.to contain_neutron_plugin_plumgrid('PLUMgridDirector/director_server_port').with_value(params[:director_server_port]) + is_expected.to contain_neutron_plugin_plumgrid('PLUMgridDirector/username').with_value(params[:username]) + is_expected.to contain_neutron_plugin_plumgrid('PLUMgridDirector/password').with_value(params[:password]) + is_expected.to contain_neutron_plugin_plumgrid('PLUMgridDirector/servertimeout').with_value(params[:servertimeout]) + is_expected.to contain_neutron_plugin_plumgrid('database/connection').with_value(params[:connection]) + end + + it 'should perform default configuration of plumgrid plumlib' do + is_expected.to contain_neutron_plumlib_plumgrid('keystone_authtoken/admin_user').with_value('admin') + is_expected.to contain_neutron_plumlib_plumgrid('keystone_authtoken/admin_password').with_value(params[:admin_password]) + is_expected.to contain_neutron_plumlib_plumgrid('keystone_authtoken/admin_tenant_name').with_value('admin') + auth_uri = "http://" + params[:controller_priv_host] + ":" + "35357/v2.0"; + is_expected.to contain_neutron_plumlib_plumgrid('keystone_authtoken/auth_uri').with_value(auth_uri) + is_expected.to contain_neutron_plumlib_plumgrid('PLUMgridMetadata/enable_pg_metadata').with_value('True') + is_expected.to contain_neutron_plumlib_plumgrid('PLUMgridMetadata/metadata_mode').with_value('local') + end + + end + + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian'} + end + + it 'configures /etc/default/neutron-server' do + is_expected.to contain_file_line('/etc/default/neutron-server:NEUTRON_PLUGIN_CONFIG').with( + :path => '/etc/default/neutron-server', + :match => '^NEUTRON_PLUGIN_CONFIG=(.*)$', + :line => 'NEUTRON_PLUGIN_CONFIG=/etc/neutron/plugins/plumgrid/plumgrid.ini', + :require => ['Package[neutron-server]', 'Package[neutron-plugin-plumgrid]'], + :notify => 'Service[neutron-server]' + ) + end + + it_configures 'neutron plumgrid plugin' + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat'} + end + + it 'should create plugin symbolic link' do + is_expected.to contain_file('/etc/neutron/plugin.ini').with( + :ensure => 'link', + :target => '/etc/neutron/plugins/plumgrid/plumgrid.ini', + :require => 'Package[neutron-plugin-plumgrid]') + end + + it_configures 'neutron plumgrid plugin' + end + +end diff --git a/spec/unit/provider/neutron_plugin_plumgrid/ini_setting_spec.rb b/spec/unit/provider/neutron_plugin_plumgrid/ini_setting_spec.rb new file mode 100644 index 000000000..bb5667d1c --- /dev/null +++ b/spec/unit/provider/neutron_plugin_plumgrid/ini_setting_spec.rb @@ -0,0 +1,36 @@ +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'inifile', + 'lib') +) + +require 'spec_helper' + +provider_class = Puppet::Type.type(:neutron_plugin_plumgrid).provider(:ini_setting) +describe provider_class do + let(:resource ) do + Puppet::Type::Neutron_plugin_plumgrid.new({ + :name => 'DEFAULT/foo', + :value => 'bar', + }) + end + + let (:provider) { resource.provider } + + [ 'RedHat', 'Debian' ].each do |os| + context "on #{os} with default setting" do + it 'it should fall back to default and use plumgrid.ini' do + Facter.fact(:operatingsystem).stubs(:value).returns("#{os}") + expect(provider.section).to eq('DEFAULT') + expect(provider.setting).to eq('foo') + expect(provider.file_path).to eq('/etc/neutron/plugins/plumgrid/plumgrid.ini') + end + end + end +end diff --git a/spec/unit/provider/neutron_plumlib_plumgrid/ini_setting_spec.rb b/spec/unit/provider/neutron_plumlib_plumgrid/ini_setting_spec.rb new file mode 100644 index 000000000..358eab90b --- /dev/null +++ b/spec/unit/provider/neutron_plumlib_plumgrid/ini_setting_spec.rb @@ -0,0 +1,36 @@ +$LOAD_PATH.push( + File.join( + File.dirname(__FILE__), + '..', + '..', + '..', + 'fixtures', + 'modules', + 'inifile', + 'lib') +) + +require 'spec_helper' + +provider_class = Puppet::Type.type(:neutron_plumlib_plumgrid).provider(:ini_setting) +describe provider_class do + let(:resource ) do + Puppet::Type::Neutron_plumlib_plumgrid.new({ + :name => 'DEFAULT/foo', + :value => 'bar', + }) + end + + let (:provider) { resource.provider } + + [ 'RedHat', 'Debian' ].each do |os| + context "on #{os} with default setting" do + it 'it should fall back to default and use plumlib.ini' do + Facter.fact(:operatingsystem).stubs(:value).returns("#{os}") + expect(provider.section).to eq('DEFAULT') + expect(provider.setting).to eq('foo') + expect(provider.file_path).to eq('/etc/neutron/plugins/plumgrid/plumlib.ini') + end + end + end +end