Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unify the handling of sysconfig/defaults in params #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/**/*",
Expand All @@ -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,
]
31 changes: 10 additions & 21 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

}

4 changes: 4 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
}
$radvd_package = 'radvd'
$sysconfig = {}
$defaults_file = '/etc/sysconfig/libvirtd'
$defaults_template = "${module_name}/sysconfig/libvirtd.erb"
$deb_default = false
}
'Debian': {
$libvirt_package = 'libvirt-bin'
$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'
Expand Down
32 changes: 22 additions & 10 deletions spec/classes/libvirt_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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