diff --git a/lib/puppet/provider/neutron_vpnaas_service_config/openstackconfig.rb b/lib/puppet/provider/neutron_vpnaas_service_config/openstackconfig.rb new file mode 100644 index 000000000..404c1de3a --- /dev/null +++ b/lib/puppet/provider/neutron_vpnaas_service_config/openstackconfig.rb @@ -0,0 +1,10 @@ +Puppet::Type.type(:neutron_vpnaas_service_config).provide( + :openstackconfig, + :parent => Puppet::Type.type(:openstack_config).provider(:ruby) +) do + + def file_path + '/etc/neutron/neutron_vpnaas.conf' + end + +end diff --git a/lib/puppet/type/neutron_vpnaas_service_config.rb b/lib/puppet/type/neutron_vpnaas_service_config.rb new file mode 100644 index 000000000..b68189849 --- /dev/null +++ b/lib/puppet/type/neutron_vpnaas_service_config.rb @@ -0,0 +1,40 @@ +Puppet::Type.newtype(:neutron_vpnaas_service_config) do + + ensurable + + newparam(:name, :namevar => true) do + desc 'Section/setting name to manage from neutron_vpnaas.conf' + newvalues(/\S+\/\S+/) + end + + newproperty(:value, :array_matching => :all) do + desc 'The value of the setting to be defined.' + def insync?(is) + return true if @should.empty? + return false unless is.is_a? Array + return false unless is.length == @should.length + # we don't care about the order of items in array, hence + # it is necessary to override insync + return ( + is & @should == is or + is & @should.map(&:to_s) == is + ) + end + + 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-vpnaas-agent' + end + +end diff --git a/manifests/services/vpnaas.pp b/manifests/services/vpnaas.pp new file mode 100644 index 000000000..986f8f4b0 --- /dev/null +++ b/manifests/services/vpnaas.pp @@ -0,0 +1,58 @@ +# +# Copyright (C) 2015 Kylinos Inc. +# +# Author: nanhai liao +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# +# == Class: neutron::services::vpnaas +# +# Configure the VPN as a Service Neutron Plugin +# +# === Parameters: +# +# [*package_ensure*] +# (required) Whether or not to install the VPNaas Neutron plugin package +# Defaults to present +# +# [*service_providers*] +# (optional) Array of allowed service types or ''. +# Note: The default upstream value is empty. +# If you plan to activate VPNaaS service, you'll need to set this +# parameter otherwise neutron-server won't start correctly. +# See https://bugs.launchpad.net/puppet-neutron/+bug/1538971 +# Must be in form ::[:default]. +# Defaults to $::os_service_default +# +class neutron::services::vpnaas ( + $package_ensure = 'present', + $service_providers = $::os_service_default, +) { + + include ::neutron::params + + # agent package contains both agent and service resources + ensure_resource( 'package', 'neutron-vpnaas-agent', { + ensure => $package_ensure, + name => $::neutron::params::vpnaas_agent_package, + tag => ['openstack', 'neutron-package'], + }) + + if !is_service_default($service_providers) { + # default value is uncommented setting, so we should not touch it at all + neutron_vpnaas_service_config { 'service_providers/service_provider': + value => $service_providers, + } + } +} diff --git a/spec/classes/neutron_services_vpnaas_spec.rb b/spec/classes/neutron_services_vpnaas_spec.rb new file mode 100644 index 000000000..6fcbcde1a --- /dev/null +++ b/spec/classes/neutron_services_vpnaas_spec.rb @@ -0,0 +1,88 @@ +# +# Copyright (C) 2014 Red Hat Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# Unit tests for neutron::services::vpnaas class +# + +require 'spec_helper' + +describe 'neutron::services::vpnaas' do + + let :default_params do + { :package_ensure => 'present', + :service_providers => ''} + end + + shared_examples_for 'neutron vpnaas service plugin' do + + context 'with default params' do + let :params do + default_params + end + + it 'installs vpnaas package' do + is_expected.to contain_package('neutron-vpnaas-agent').with( + :ensure => params[:package_ensure], + :name => platform_params[:vpnaas_package_name], + ) + end + end + + context 'with multiple service providers' do + let :params do + default_params.merge( + { :service_providers => ['provider1', 'provider2'] } + ) + end + + it 'configures neutron_vpnaas.conf' do + is_expected.to contain_neutron_vpnaas_service_config( + 'service_providers/service_provider' + ).with_value(['provider1', 'provider2']) + end + end + + end + + context 'on Debian platforms' do + let :facts do + @default_facts.merge({ + :osfamily => 'Debian' + }) + end + + let :platform_params do + { :vpnaas_package_name => 'neutron-vpn-agent'} + end + + it_configures 'neutron vpnaas service plugin' + end + + context 'on Red Hat platforms' do + let :facts do + @default_facts.merge({ + :osfamily => 'RedHat', + :operatingsystemrelease => '7' + }) + end + + let :platform_params do + { :vpnaas_package_name => 'openstack-neutron-vpnaas'} + end + + it_configures 'neutron vpnaas service plugin' + end + +end