From 98503c05111dac37c451873c5ca9d0d39e704285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 21 May 2015 12:54:01 +0200 Subject: [PATCH 1/2] unify the handling of sysconfig/defaults in params unify, and simplify. --- manifests/init.pp | 31 ++++++++++--------------------- manifests/params.pp | 4 ++++ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 14be7a5..ed85ba9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -31,6 +31,8 @@ $virtinst_package = $::libvirt::params::virtinst_package, $radvd_package = $::libvirt::params::radvd_package, $sysconfig = $::libvirt::params::sysconfig, + $defaults_file = $::libvirt::params::defaults_file, + $defaults_template = $::libvirt::params::defaults_template, $deb_default = $::libvirt::params::deb_default, # libvirtd.conf options $listen_tls = undef, @@ -134,30 +136,17 @@ package { $radvd_package: ensure => installed } } - # Optional changes to the sysconfig file (on RedHat) - if $sysconfig != false { - file { '/etc/sysconfig/libvirtd': - owner => 'root', - group => 'root', - mode => '0644', - content => template("${module_name}/sysconfig/libvirtd.erb"), - notify => Service['libvirtd'], - } - } - - # Optional changes to the /etc/default file (on Debian) - if $deb_default != false { - file { '/etc/default/libvirt-bin': - owner => 'root', - group => 'root', - mode => '0644', - content => template("${module_name}/default/libvirt-bin.erb"), - notify => Service['libvirtd'], - } + # Optional changes to the sysconfig file (on RedHat), or the defaults file + file { 'defaults_file': + path => $defaults_file, + owner => 'root', + group => 'root', + mode => '0644', + content => template($defaults_template), + notify => Service['libvirtd'], } # Create Optional networks create_resources(libvirt::network, $networks, $networks_defaults) } - diff --git a/manifests/params.pp b/manifests/params.pp index b32872d..3a2ef22 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -15,6 +15,8 @@ } $radvd_package = 'radvd' $sysconfig = {} + $defaults_file = '/etc/sysconfig/libvirtd' + $defaults_template = "${module_name}/sysconfig/libvirtd.erb" $deb_default = false } 'Debian': { @@ -22,6 +24,8 @@ $virtinst_package = 'virtinst' $radvd_package = 'radvd' $sysconfig = false + $defaults_file = '/etc/default/libvirt-bin' + $defaults_template = "${module_name}/default/libvirt-bin.erb" $deb_default = {} # UNIX socket $auth_unix_ro = 'none' From 4d5a13572a783ea22d344f3b7f25871a6c563da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 21 May 2015 17:05:40 +0200 Subject: [PATCH 2/2] fix tests: introduce rspec-puppet-facts to only test supported OSes ;) --- Gemfile | 15 +++++++++------ Rakefile | 11 ++++++++++- spec/classes/libvirt_spec.rb | 32 ++++++++++++++++++++++---------- spec/spec_helper.rb | 9 +++++++++ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index 1a01c12..a5e2cd2 100644 --- a/Gemfile +++ b/Gemfile @@ -2,19 +2,22 @@ source "https://rubygems.org" group :test do gem "rake" - gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0' - gem "puppet-lint" + gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.7.0' gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' - gem "puppet-syntax" gem "puppetlabs_spec_helper" + gem "metadata-json-lint" + gem "rspec-puppet-facts" + gem "rspec", "< 3.2.0", { "platforms" => ["ruby_18"] } end group :development do gem "travis" gem "travis-lint" - gem "beaker" - gem "beaker-rspec" - gem "vagrant-wrapper" gem "puppet-blacksmith" gem "guard-rake" end + +group :system_tests do + gem "beaker" + gem "beaker-rspec" +end diff --git a/Rakefile b/Rakefile index 623b0b3..a46ebe6 100644 --- a/Rakefile +++ b/Rakefile @@ -2,13 +2,16 @@ require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' require 'puppet-syntax/tasks/puppet-syntax' -# These two gems aren't always present, for instance +# These gems aren't always present, for instance # on Travis with --without development begin require 'puppet_blacksmith/rake_tasks' rescue LoadError end +Rake::Task[:lint].clear + +PuppetLint.configuration.relative = true PuppetLint.configuration.send("disable_80chars") PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" PuppetLint.configuration.fail_on_warnings = true @@ -20,6 +23,7 @@ PuppetLint.configuration.send('disable_class_parameter_defaults') PuppetLint.configuration.send('disable_class_inherits_from_params_class') exclude_paths = [ + "bundle/**/*", "pkg/**/*", "vendor/**/*", "spec/**/*", @@ -32,9 +36,14 @@ RSpec::Core::RakeTask.new(:acceptance) do |t| t.pattern = 'spec/acceptance' end +task :metadata do + sh "metadata-json-lint metadata.json" +end + desc "Run syntax, lint, and spec tests." task :test => [ :syntax, :lint, :spec, + :metadata, ] diff --git a/spec/classes/libvirt_spec.rb b/spec/classes/libvirt_spec.rb index e8fd5aa..1fa20d1 100644 --- a/spec/classes/libvirt_spec.rb +++ b/spec/classes/libvirt_spec.rb @@ -1,4 +1,4 @@ -# Copyright 2013 Brainsware +# Copyright 2015 any number of authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,18 +15,30 @@ require 'spec_helper' describe 'libvirt', :type => :class do - let(:title) { 'libvirt' } + context 'supported operating systems' do + on_supported_os.each do |os, facts| + context "on #{os} #{facts}" do + let(:facts) do + facts + end - it { should contain_class('libvirt') } - it { should contain_file('/etc/libvirt/qemu/networks/autostart/default.xml') - .with_ensure('absent') - } + context 'with default parameters' do + let(:title) { 'libvirt' } - describe 'with default network enabled' do - let(:params) {{ :defaultnetwork => true }} + it { should contain_class('libvirt') } + it { should contain_file('/etc/libvirt/qemu/networks/autostart/default.xml') + .with_ensure('absent') + } + end - it { should contain_class('libvirt') } - it { should contain_exec('virsh-net-autostart-default') } + context 'with default network enabled' do + let(:params) {{ :defaultnetwork => true }} + + it { should contain_class('libvirt') } + it { should contain_exec('virsh-net-autostart-default') } + end + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f566..484885a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,10 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts + +RSpec.configure do |c| + c.before do + # avoid "Only root can execute commands as other users" + Puppet.features.stubs(:root? => true) + end +end