Add VPNaaS service support

VPNaaS is a new service in Neutron (Havana release).
This patchs aims to support default driver (OpenSwan) by installing
packages & configuring vpn_agent.ini.

implement blueprint vpnaas-support
Change-Id: I7f8a3fbc1b175eb0ea3a8868a04ea648c2b8f1b2
Signed-off-by: Emilien Macchi <emilien.macchi@enovance.com>
This commit is contained in:
Emilien Macchi 2013-09-24 13:56:41 +02:00
parent c5adbbc9d5
commit 8b69cf03e8
5 changed files with 260 additions and 0 deletions

View File

@ -0,0 +1,22 @@
Puppet::Type.type(:neutron_vpnaas_agent_config).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/vpn_agent.ini'
end
end

View File

@ -0,0 +1,18 @@
Puppet::Type.newtype(:neutron_vpnaas_agent_config) do
ensurable
newparam(:name, :namevar => true) do
desc 'Section/setting name to manage from vpn_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
end
end

View File

@ -0,0 +1,94 @@
#
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# 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::agents:vpnaas
#
# Setups Neutron VPN agent.
#
# === Parameters
#
# [*package_ensure*]
# (optional) Ensure state for package. Defaults to 'present'.
#
# [*enabled*]
# (optional) Enable state for service. Defaults to 'true'.
#
# [*vpn_device_driver*]
# (optional) Defaults to 'neutron.services.vpn.device_drivers.ipsec.OpenSwanDriver'.
#
# [*ipsec_status_check_interval*]
# (optional) Status check interval. Defaults to '60'.
#
class neutron::agents::vpnaas (
$package_ensure = present,
$enabled = true,
$vpn_device_driver = 'neutron.services.vpn.device_drivers.ipsec.OpenSwanDriver',
$ipsec_status_check_interval = '60'
) {
include neutron::params
Neutron_config<||> ~> Service['neutron-vpnaas-service']
Neutron_vpnaas_agent_config<||> ~> Service['neutron-vpnaas-service']
case $vpn_device_driver {
/\.OpenSwan/: {
Package['openswan'] -> Package<| title == 'neutron-vpnaas-agent' |>
package { 'openswan':
ensure => present,
name => $::neutron::params::openswan_package,
}
}
default: {
fail("Unsupported vpn_device_driver ${vpn_device_driver}")
}
}
# The VPNaaS agent loads both neutron.ini and its own file.
# This only lists config specific to the agent. neutron.ini supplies
# the rest.
neutron_vpnaas_agent_config {
'vpnagent/vpn_device_driver': value => $vpn_device_driver;
'ipsec/ipsec_status_check_interval': value => $ipsec_status_check_interval;
}
if $::neutron::params::vpnaas_agent_package {
Package['neutron'] -> Package['neutron-vpnaas-agent']
Package['neutron-vpnaas-agent'] -> Neutron_vpnaas_agent_config<||>
package { 'neutron-vpnaas-agent':
ensure => $package_ensure,
name => $::neutron::params::vpnaas_agent_package,
}
} else {
# Some platforms (RedHat) do not provide a neutron VPNaaS agent package.
# The neutron VPNaaS agent config file is provided by the neutron package.
Package['neutron'] -> Neutron_vpnaas_agent_config<||>
}
if $enabled {
$ensure = 'running'
} else {
$ensure = 'stopped'
}
service { 'neutron-vpnaas-service':
ensure => $ensure,
name => $::neutron::params::vpnaas_agent_service,
enable => $enabled,
require => Class['neutron'],
}
}

View File

@ -29,6 +29,10 @@ class neutron::params {
$haproxy_package = 'haproxy'
$vpnaas_agent_package = false
$vpnaas_agent_service = 'neutron-vpnaas-agent'
$openswan_package = 'openswan'
$l3_agent_package = false
$l3_agent_service = 'neutron-l3-agent'
@ -65,6 +69,10 @@ class neutron::params {
$haproxy_package = 'haproxy'
$vpnaas_agent_package = 'neutron-plugin-vpn-agent'
$vpnaas_agent_service = 'neutron-vpnaas-agent'
$openswan_package = 'openswan'
$metadata_agent_package = 'neutron-metadata-agent'
$metadata_agent_service = 'neutron-metadata-agent'

View File

@ -0,0 +1,118 @@
#
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# 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::agents::vpnaas class
#
require 'spec_helper'
describe 'neutron::agents::vpnaas' do
let :pre_condition do
"class { 'neutron': rabbit_password => 'passw0rd' }"
end
let :params do
{}
end
let :default_params do
{ :package_ensure => 'present',
:enabled => true,
:vpn_device_driver => 'neutron.services.vpn.device_drivers.ipsec.OpenSwanDriver',
:ipsec_status_check_interval => '60'
}
end
shared_examples_for 'neutron vpnaas agent' do
let :p do
default_params.merge(params)
end
it { should include_class('neutron::params') }
it_configures 'openswan vpnaas_driver'
it 'configures vpnaas_agent.ini' do
should contain_neutron_vpnaas_agent_config('vpnagent/vpn_device_driver').with_value(p[:vpn_device_driver]);
should contain_neutron_vpnaas_agent_config('ipsec/ipsec_status_check_interval').with_value(p[:ipsec_status_check_interval]);
end
it 'installs neutron vpnaas agent package' do
if platform_params.has_key?(:vpnaas_agent_package)
should contain_package('neutron-vpnaas-agent').with(
:name => platform_params[:vpnaas_agent_package],
:ensure => p[:package_ensure]
)
should contain_package('neutron').with_before(/Package\[neutron-vpnaas-agent\]/)
should contain_package('neutron-vpnaas-agent').with_before(/Neutron_vpnaas_agent_config\[.+\]/)
else
should contain_package('neutron').with_before(/Neutron_vpnaas_agent_config\[.+\]/)
end
end
it 'configures neutron vpnaas agent service' do
should contain_service('neutron-vpnaas-service').with(
:name => platform_params[:vpnaas_agent_service],
:enable => true,
:ensure => 'running',
:require => 'Class[Neutron]'
)
end
end
shared_examples_for 'openswan vpnaas_driver' do
it 'installs openswan packages' do
if platform_params.has_key?(:vpnaas_agent_package)
should contain_package('openswan').with_before('Package[neutron-vpnaas-agent]')
end
should contain_package('openswan').with(
:ensure => 'present',
:name => platform_params[:openswan_package]
)
end
end
context 'on Debian platforms' do
let :facts do
{ :osfamily => 'Debian' }
end
let :platform_params do
{ :openswan_package => 'openswan',
:vpnaas_agent_package => 'neutron-plugin-vpn-agent',
:vpnaas_agent_service => 'neutron-vpnaas-agent' }
end
it_configures 'neutron vpnaas agent'
end
context 'on RedHat platforms' do
let :facts do
{ :osfamily => 'RedHat' }
end
let :platform_params do
{ :openswan_package => 'openswan',
:vpnaas_agent_service => 'neutron-vpnaas-agent'}
end
it_configures 'neutron vpnaas agent'
end
end