Adding database sync for L2 Gateway service plugin

It includes unit test

Change-Id: I9f36f66eeb7aba7f37bbd53245e795f51e7faa9f
Signed-off-by: Ricardo Noriega <rnoriega@redhat.com>
This commit is contained in:
Ricardo Noriega 2017-03-30 12:43:03 +02:00
parent 032e0114d9
commit e8a9f7cf5c
2 changed files with 61 additions and 25 deletions

View File

@ -28,6 +28,11 @@
# Must be in form: <service_type>:<name>:<driver>[:default]
# Defaults to $::os_service_default
#
# [*sync_db*]
# Whether 'l2gw-db-sync' should run to create and/or synchronize the
# database with networking-l2gw specific tables.
# Default to false
#
# [*package_ensure*]
# (optional) Ensure state for package.
# Defaults to 'present'.
@ -43,6 +48,7 @@ class neutron::services::l2gw (
$quota_l2_gateway = $::os_service_default,
$periodic_monitoring_interval = $::os_service_default,
$service_providers = $::os_service_default,
$sync_db = false,
$package_ensure = 'present',
$purge_config = false,
) {
@ -71,4 +77,19 @@ class neutron::services::l2gw (
'DEFAULT/periodic_monitoring_interval': value => $periodic_monitoring_interval;
'service_providers/service_provider': value => $service_providers;
}
if $sync_db {
Package<| title == $::neutron::params::l2gw_package |> ~> Exec['l2gw-db-sync']
exec { 'l2gw-db-sync':
command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --subproject networking-l2gw upgrade head',
path => '/usr/bin',
subscribe => [
Anchor['neutron::install::end'],
Anchor['neutron::config::end'],
Anchor['neutron::dbsync::begin']
],
notify => Anchor['neutron::dbsync::end'],
refreshonly => true
}
}
}

View File

@ -18,7 +18,7 @@ require 'spec_helper'
describe 'neutron::services::l2gw' do
let :pre_condition do
let :pre_condition do
"class { '::neutron::keystone::authtoken':
password => 'passw0rd',
}
@ -43,37 +43,40 @@ describe 'neutron::services::l2gw' do
end
shared_examples_for 'neutron l2gw service plugin' do
let :p do
default_params.merge(params)
end
context 'with default params' do
let :p do
default_params.merge(params)
end
it 'passes purge to resource' do
is_expected.to contain_resources('neutron_l2gw_service_config').with({
:purge => false
})
end
it 'passes purge to resource' do
is_expected.to contain_resources('neutron_l2gw_service_config').with({
:purge => false
})
end
it 'should contain python-networking-l2gw package' do
is_expected.to contain_package('python-networking-l2gw').with({ :ensure => 'present' })
end
it 'should contain python-networking-l2gw package' do
is_expected.to contain_package('python-networking-l2gw').with({ :ensure => 'present' })
end
it 'services_provider with default parameter' do
is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('<SERVICE DEFAULT>')
end
it 'configures l2gw_plugin.ini' do
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/default_interface_name').with_value(p[:default_interface_name])
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/default_device_name').with_value('<SERVICE DEFAULT>')
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/quota_l2_gateway').with_value('<SERVICE DEFAULT>')
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/periodic_monitoring_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('<SERVICE DEFAULT>')
it 'services_provider with default parameter' do
is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('<SERVICE DEFAULT>')
end
it 'configures l2gw_plugin.ini' do
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/default_interface_name').with_value(p[:default_interface_name])
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/default_device_name').with_value('<SERVICE DEFAULT>')
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/quota_l2_gateway').with_value('<SERVICE DEFAULT>')
is_expected.to contain_neutron_l2gw_service_config('DEFAULT/periodic_monitoring_interval').with_value('<SERVICE DEFAULT>')
is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('<SERVICE DEFAULT>')
end
end
context 'with multiple service providers' do
before :each do
params.merge!(
{ :service_providers => ['provider1', 'provider2'] }
{ :service_providers => ['provider1', 'provider2'],
:sync_db => true,
}
)
end
@ -82,6 +85,19 @@ describe 'neutron::services::l2gw' do
'service_providers/service_provider'
).with_value(['provider1', 'provider2'])
end
it 'runs neutron-db-sync' do
is_expected.to contain_exec('l2gw-db-sync').with(
:command => 'neutron-db-manage --config-file /etc/neutron/neutron.conf --subproject networking-l2gw upgrade head',
:path => '/usr/bin',
:subscribe => ['Anchor[neutron::install::end]',
'Anchor[neutron::config::end]',
'Anchor[neutron::dbsync::begin]'
],
:notify => 'Anchor[neutron::dbsync::end]',
:refreshonly => 'true',
)
end
end
end
@ -105,5 +121,4 @@ describe 'neutron::services::l2gw' do
it_configures 'neutron l2gw service plugin'
end
end
end
end