From e8a9f7cf5c6f332e1e562eadc3deaad0987d7327 Mon Sep 17 00:00:00 2001 From: Ricardo Noriega Date: Thu, 30 Mar 2017 12:43:03 +0200 Subject: [PATCH] Adding database sync for L2 Gateway service plugin It includes unit test Change-Id: I9f36f66eeb7aba7f37bbd53245e795f51e7faa9f Signed-off-by: Ricardo Noriega --- manifests/services/l2gw.pp | 21 +++++++ spec/classes/neutron_services_l2gw_spec.rb | 65 +++++++++++++--------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/manifests/services/l2gw.pp b/manifests/services/l2gw.pp index 01d1fb1df..1db342eda 100644 --- a/manifests/services/l2gw.pp +++ b/manifests/services/l2gw.pp @@ -28,6 +28,11 @@ # Must be in form: ::[: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 + } + } } diff --git a/spec/classes/neutron_services_l2gw_spec.rb b/spec/classes/neutron_services_l2gw_spec.rb index 78c0f698c..42d54454e 100644 --- a/spec/classes/neutron_services_l2gw_spec.rb +++ b/spec/classes/neutron_services_l2gw_spec.rb @@ -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('') - 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('') - is_expected.to contain_neutron_l2gw_service_config('DEFAULT/quota_l2_gateway').with_value('') - is_expected.to contain_neutron_l2gw_service_config('DEFAULT/periodic_monitoring_interval').with_value('') - is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('') + it 'services_provider with default parameter' do + is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('') + 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('') + is_expected.to contain_neutron_l2gw_service_config('DEFAULT/quota_l2_gateway').with_value('') + is_expected.to contain_neutron_l2gw_service_config('DEFAULT/periodic_monitoring_interval').with_value('') + is_expected.to contain_neutron_l2gw_service_config('service_providers/service_provider').with_value('') + 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 \ No newline at end of file +end