From 85acd41e41d258f62b81fdf97c4a64850d35d6b3 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Sat, 11 Jan 2014 13:19:28 -0500 Subject: [PATCH] improve unit tests Signed-off-by: Emilien Macchi --- .fixtures.yml | 1 + manifests/loadbalancer.pp | 9 +- .../privatecloud_compute_hypervisor_spec.rb | 10 ++ .../classes/privatecloud_database_sql_spec.rb | 2 +- .../classes/privatecloud_loadbalancer_spec.rb | 98 +++++++++++++++++++ .../classes/privatecloud_network_dhcp_spec.rb | 2 +- 6 files changed, 112 insertions(+), 10 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index a05f6c38..6160d67b 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -13,6 +13,7 @@ fixtures: 'apache': 'git://github.com/puppetlabs/puppetlabs-apache.git' 'concat': 'git://github.com/puppetlabs/puppetlabs-concat.git' 'haproxy': 'git://github.com/puppetlabs/puppetlabs-haproxy.git' + 'keepalived': 'git://github.com/puppetlabs/puppetlabs-keepalived.git' 'firewall': 'git://github.com/puppetlabs/puppetlabs-firewall.git' 'mongodb': 'git://github.com/puppetlabs/puppetlabs-mongodb.git' 'mysql': diff --git a/manifests/loadbalancer.pp b/manifests/loadbalancer.pp index f5906a69..1ade6c38 100644 --- a/manifests/loadbalancer.pp +++ b/manifests/loadbalancer.pp @@ -27,19 +27,15 @@ class privatecloud::loadbalancer( $nova_api = true, $ec2_api = true, $metadata_api = true, - $spice_api = true, $swift_api = true, $keystone_api_admin = true, $keystone_api = true, $horizon = true, $spice = true, $haproxy_auth = $os_params::haproxy_auth, - $keepalived_email = $os_params::keepalived_email, $keepalived_interface = $os_params::keepalived_interface, $keepalived_ipvs = [ $os_params::openstack_vip, $os_params::mysql_vip ], $keepalived_localhost_ip = $os_params::keepalived_localhost_ip, - $keepalived_smtp = $os_params::keepalived_smtp, - $ks_cinder_ceilometer_port = $os_params::ks_ceilometer_public_port, $ks_cinder_public_port = $os_params::ks_cinder_public_port, $ks_ceilometer_public_port = $os_params::ks_ceilometer_public_port, $ks_ec2_public_port = $os_params::ks_ec2_public_port, @@ -61,10 +57,7 @@ class privatecloud::loadbalancer( class { 'haproxy': } - class { 'keepalived': - notification_email_to => $keepalived_email, - smtp_server => $keepalived_smtp, - } + class { 'keepalived': } keepalived::vrrp_script { 'haproxy': name_is_process => true diff --git a/spec/classes/privatecloud_compute_hypervisor_spec.rb b/spec/classes/privatecloud_compute_hypervisor_spec.rb index 5dee6e2e..38a59788 100644 --- a/spec/classes/privatecloud_compute_hypervisor_spec.rb +++ b/spec/classes/privatecloud_compute_hypervisor_spec.rb @@ -59,6 +59,16 @@ describe 'privatecloud::compute::hypervisor' do should contain_nova_config('DEFAULT/resume_guests_state_on_host_boot').with('value' => true) end + it 'insert and activate nbd module' do + should contain_exec('insert_module_nbd').with('command' => '/bin/echo "nbd" > /etc/modules', 'unless' => '/bin/grep "nbd" /etc/modules') + should contain_exec('/sbin/modprobe nbd').with('unless' => '/bin/grep -q "^nbd " "/proc/modules"') + end + + it 'start and stop isci service' do + should contain_exec('/etc/init.d/open-iscsi start').with('onlyif' => '/bin/grep "GenerateName=yes" /etc/iscsi/initiatorname.iscsi') + should contain_exec('/etc/init.d/open-iscsi stop').with('refreshonly' => true) + end + it 'configure nova-compute' do should contain_class('nova::compute').with( :enabled => true, diff --git a/spec/classes/privatecloud_database_sql_spec.rb b/spec/classes/privatecloud_database_sql_spec.rb index 9877e149..3b8d38dc 100644 --- a/spec/classes/privatecloud_database_sql_spec.rb +++ b/spec/classes/privatecloud_database_sql_spec.rb @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. # -# Unit tests for privatecloud::compute::hypervisor class +# Unit tests for privatecloud::database::sql class # require 'spec_helper' diff --git a/spec/classes/privatecloud_loadbalancer_spec.rb b/spec/classes/privatecloud_loadbalancer_spec.rb index e69de29b..55707ebb 100644 --- a/spec/classes/privatecloud_loadbalancer_spec.rb +++ b/spec/classes/privatecloud_loadbalancer_spec.rb @@ -0,0 +1,98 @@ +# +# Copyright (C) 2014 eNovance SAS +# +# 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 privatecloud::loadbalancer class +# + +require 'spec_helper' + +describe 'privatecloud::loadbalancer' do + + shared_examples_for 'openstack loadbalancer' do + + let :params do + { :ceilometer_api => true, + :cinder_api => true, + :glance_api => true, + :neutron_api => true, + :heat_api => true, + :heat_cfn_api => true, + :heat_cloudwatch_api => true, + :nova_api => true, + :ec2_api => true, + :metadata_api => true, + :swift_api => true, + :keystone_api_admin => true, + :keystone_api => true, + :horizon => true, + :spice => true, + :haproxy_auth => 'root:secrete', + :keepalived_interface => 'eth0', + :keepalived_ipvs => ['10.0.0.1', '10.0.0.2'], + :keepalived_localhost_ip => '127.0.0.1', + :horizon_port => '80', + :spice_port => '6082', + :openstack_vip => '10.0.0.3', + :mysql_vip => '10.0.0.4', + :ks_ceilometer_public_port => '8777', + :ks_nova_public_port => '8774', + :ks_ec2_public_port => '8773', + :ks_metadata_public_port => '8777', + :ks_glance_public_port => '9292', + :ks_swift_public_port => '8080', + :ks_keystone_public_port => '5000', + :ks_keystone_admin_port => '35357', + :ks_cinder_public_port => '8776', + :ks_neutron_public_port => '9696', + :ks_heat_public_port => '8004', + :ks_heat_cfn_public_port => '8000', + :ks_heat_cloudwatch_public_port => '8003' } + end + + it 'configure haproxy server' do + should contain_class('haproxy') + end + + it 'configure keepalived server' do + should contain_class('keepalived') + end + + it 'configure haproxy vrrp script' do + should contain_keepalived_vrrp_script('haproxy').with( + :name_is_process => true + ) + end + + end + + context 'on Debian platforms' do + let :facts do + { :osfamily => 'Debian', + :concat_basedir => '/var/lib/puppet/concat' } + end + + it_configures 'openstack loadbalancer' + end + + context 'on RedHat platforms' do + let :facts do + { :osfamily => 'RedHat', + :concat_basedir => '/var/lib/puppet/concat' } + end + + it_configures 'openstack loadbalancer' + end + +end diff --git a/spec/classes/privatecloud_network_dhcp_spec.rb b/spec/classes/privatecloud_network_dhcp_spec.rb index e7df8f7f..e8eff992 100644 --- a/spec/classes/privatecloud_network_dhcp_spec.rb +++ b/spec/classes/privatecloud_network_dhcp_spec.rb @@ -41,7 +41,7 @@ describe 'privatecloud::network::dhcp' do :allow_overlapping_ips => true, :dhcp_agents_per_network => '2', :verbose => true, - :debug => true, + :debug => false, :rabbit_user => 'neutron', :rabbit_hosts => ['10.0.0.1'], :rabbit_password => 'secrete',