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

Introduce rspec-puppet-facts for some tests #218

Merged
merged 12 commits into from
May 13, 2016
13 changes: 3 additions & 10 deletions manifests/database/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@
case $zabbix_version {
'3.0': {
if ($database_schema_path == false) or ($database_schema_path == '') {
case $::operatingsystem {
'CentOS', 'RedHat', 'OracleLinux': {
$schema_path = "/usr/share/doc/zabbix-*-mysql-${zabbix_version}**/"
}
default : {
$schema_path = '/usr/share/doc/zabbix-*-mysql'
}
}
$schema_path = '/usr/share/doc/zabbix-*-mysql*'
}
else {
$schema_path = $database_schema_path
Expand All @@ -55,8 +48,8 @@
}
default: {
if ($database_schema_path == false) or ($database_schema_path == '') {
case $::operatingsystem {
'CentOS', 'RedHat', 'OracleLinux': {
case $::osfamily {
'RedHat': {
$schema_path = "/usr/share/doc/zabbix-*-mysql-${zabbix_version}*/create"
}
default : {
Expand Down
10 changes: 4 additions & 6 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
}
}

case $::operatingsystemrelease {
/\/sid$/ : { $releasename = regsubst($::operatingsystemrelease, '/sid$', '') }
default : { $releasename = $::lsbdistcodename }
}

case $::osfamily {
'RedHat' : {
yumrepo { 'zabbix':
Expand Down Expand Up @@ -93,7 +88,10 @@
}
} else {
$operatingsystem = downcase($::operatingsystem)

case $::operatingsystemrelease {
/\/sid$/ : { $releasename = regsubst($::operatingsystemrelease, '/sid$', '') }
default : { $releasename = $::lsbdistcodename }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is lsbdistcodename a thing on newer facter? I seem to recall the lsb* facts being deprecated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ionly know that it requires the lsb-release package installed and in general the facts are only present on Debian based systems. I was looking for alternative core facts but didn't find any :(

}
apt::source { 'zabbix':
location => "http://repo.zabbix.com/zabbix/${zabbix_version}/${operatingsystem}/",
repos => 'main',
Expand Down
131 changes: 85 additions & 46 deletions spec/classes/database_mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,97 @@
let :node do
'rspec.puppet.com'
end
on_supported_os.each do |os, facts|
context "on #{os} " do
let(:facts) do
facts.merge(
is_pe: false
)
end
context 'with all defaults' do
it 'fails' do
should raise_error(Puppet::Error, /We do not work./)
end
end
path2 = if facts[:osfamily] == 'RedHat'
# path to sql files on zabbix 2.4 on RedHat
'/usr/share/doc/zabbix-*-mysql-2.4*/create'
else
# path to sql files on zabbix 2.4 on Debian
'/usr/share/zabbix-*-mysql'
end
# path to sql files on zabbix 3.X on Debian and RedHat
path3 = '/usr/share/doc/zabbix-*-mysql*'

context 'On RedHat 6.5' do
let :facts do
{
osfamily: 'RedHat',
operatingsystem: 'RedHat',
operatingsystemrelease: '6.5',
operatingsystemmajrelease: '6',
architecture: 'x86_64',
lsbdistid: 'RedHat',
concat_basedir: '/tmp',
is_pe: false,
puppetversion: Puppet.version,
facterversion: Facter.version,
ipaddress: '192.168.1.10',
lsbdistcodename: '',
id: 'root',
kernel: 'Linux',
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin'
}
end
context 'when zabbix_type is server and zabbix version is 2.4' do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'rspec.puppet.com',
zabbix_type: 'server',
zabbix_version: '2.4'
}
end

describe 'when zabbix_type is server' do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'node01.example.com',
zabbix_type: 'server',
zabbix_version: '2.4'
}
it { should contain_class('zabbix::database::mysql') }
it { should compile.with_all_deps }
it { should contain_exec('zabbix_server_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < schema.sql && touch /etc/zabbix/.schema.done") }
it { should contain_exec('zabbix_server_images.sql').with_command("cd #{path2} && if [ -f images.sql.gz ]; then gunzip images.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < images.sql && touch /etc/zabbix/.images.done") }
it { should contain_exec('zabbix_server_data.sql').with_command("cd #{path2} && if [ -f data.sql.gz ]; then gunzip data.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < data.sql && touch /etc/zabbix/.data.done") }
end

it { should contain_exec('zabbix_server_create.sql').with_command("cd /usr/share/doc/zabbix-*-mysql-2.4*/create && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && mysql -h 'node01.example.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < schema.sql && touch /etc/zabbix/.schema.done") }
it { should contain_exec('zabbix_server_images.sql').with_command("cd /usr/share/doc/zabbix-*-mysql-2.4*/create && if [ -f images.sql.gz ]; then gunzip images.sql.gz ; fi && mysql -h 'node01.example.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < images.sql && touch /etc/zabbix/.images.done") }
it { should contain_exec('zabbix_server_data.sql').with_command("cd /usr/share/doc/zabbix-*-mysql-2.4*/create && if [ -f data.sql.gz ]; then gunzip data.sql.gz ; fi && mysql -h 'node01.example.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < data.sql && touch /etc/zabbix/.data.done") }
end

describe 'when zabbix_type is proxy' do
let :params do
{
database_name: 'zabbix-proxy',
database_user: 'zabbix-proxy',
database_password: 'zabbix-proxy',
database_host: 'node01.example.com',
zabbix_type: 'proxy',
zabbix_version: '2.4'
}
describe 'when zabbix_type is proxy and zabbix version is 2.4' do
let :params do
{
database_name: 'zabbix-proxy',
database_user: 'zabbix-proxy',
database_password: 'zabbix-proxy',
database_host: 'rspec.puppet.com',
zabbix_type: 'proxy',
zabbix_version: '2.4'
}
end
it { should contain_class('zabbix::database::mysql') }
# this doesn't make much sense because the class requires other classes
# it { should compile.with_all_deps }
it { should contain_exec('zabbix_proxy_create.sql').with_command("cd #{path2} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
context 'when zabbix_type is server and zabbix version is 3.0' do
let :params do
{
database_name: 'zabbix-server',
database_user: 'zabbix-server',
database_password: 'zabbix-server',
database_host: 'rspec.puppet.com',
zabbix_type: 'server',
zabbix_version: '3.0'
}
end
it { should contain_class('zabbix::database::mysql') }
it { should compile.with_all_deps }
it { should contain_exec('zabbix_server_create.sql').with_command("cd #{path3} && if [ -f create.sql.gz ]; then gunzip create.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-server' -p'zabbix-server' -D 'zabbix-server' < create.sql && touch /etc/zabbix/.schema.done") }
it { should contain_exec('zabbix_server_images.sql').with_command('touch /etc/zabbix/.images.done') }
it { should contain_exec('zabbix_server_data.sql').with_command('touch /etc/zabbix/.data.done') }
end

it { should contain_exec('zabbix_proxy_create.sql').with_command("cd /usr/share/doc/zabbix-*-mysql-2.4*/create && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && mysql -h 'node01.example.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
describe 'when zabbix_type is proxy and zabbix version is 3.0' do
let :params do
{
database_name: 'zabbix-proxy',
database_user: 'zabbix-proxy',
database_password: 'zabbix-proxy',
database_host: 'rspec.puppet.com',
zabbix_type: 'proxy',
zabbix_version: '3.0'
}
end
it { should contain_class('zabbix::database::mysql') }
# this doesn't make much sense because the class requires other classes
# it { should compile.with_all_deps }
it { should contain_exec('zabbix_proxy_create.sql').with_command("cd #{path3} && if [ -f schema.sql.gz ]; then gunzip schema.sql.gz ; fi && mysql -h 'rspec.puppet.com' -u 'zabbix-proxy' -p'zabbix-proxy' -D 'zabbix-proxy' < schema.sql && touch /etc/zabbix/.schema.done") }
end
end
end
end
62 changes: 28 additions & 34 deletions spec/classes/sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,35 @@
let :node do
'agent.example.com'
end

context 'On RedHat 7.1' do
let :facts do
{
osfamily: 'RedHat',
operatingsystem: 'RedHat',
operatingsystemrelease: '7.1',
operatingsystemmajrelease: '7',
architecture: 'x86_64',
lsbdistid: 'RedHat',
concat_basedir: '/tmp',
is_pe: false,
puppetversion: Puppet.version,
facterversion: Facter.version,
ipaddress: '192.168.1.10',
lsbdistcodename: '',
id: 'root',
kernel: 'Linux',
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin'
}
end

# Make sure package will be installed, service running and ensure of directory.
it { should contain_package('zabbix-sender').with_ensure('present') }
it { should contain_package('zabbix-sender').with_name('zabbix-sender') }

context 'when declaring manage_repo is true' do
let :params do
{
manage_repo: true
}
on_supported_os.each do |os, facts|
context "on #{os} " do
let(:facts) do
facts.merge(
is_pe: false
)
end
context 'with all defaults' do
it { should contain_class('zabbix::sender') }
it { should compile.with_all_deps }
# Make sure package will be installed, service running and ensure of directory.
it { should contain_package('zabbix-sender').with_ensure('present') }
it { should contain_package('zabbix-sender').with_name('zabbix-sender') }
end
context 'when declaring manage_repo is true' do
let :params do
{
manage_repo: true
}
end
if facts[:osfamily] == 'Archlinux'
it 'fails' do
should raise_error(Puppet::Error, /Unrecognized operating system for webserver/)
end
else
it { should contain_class('zabbix::repo').with_zabbix_version('3.0') }
it { should contain_package('zabbix-sender').with_require('Class[Zabbix::Repo]') }
end
end

it { should contain_class('zabbix::repo').with_zabbix_version('3.0') }
it { should contain_package('zabbix-sender').with_require('Class[Zabbix::Repo]') }
end
end
end
30 changes: 9 additions & 21 deletions spec/classes/userparameter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,15 @@
let :node do
'agent.example.com'
end

context 'On RedHat 7.1' do
let :facts do
{
osfamily: 'RedHat',
operatingsystem: 'RedHat',
operatingsystemrelease: '7.1',
operatingsystemmajrelease: '7',
architecture: 'x86_64',
lsbdistid: 'RedHat',
concat_basedir: '/tmp',
is_pe: false,
puppetversion: Puppet.version,
facterversion: Facter.version,
ipaddress: '192.168.1.10',
lsbdistcodename: '',
id: 'root',
kernel: 'Linux',
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin'
}
on_supported_os.each do |os, facts|
context "on #{os} " do
let(:facts) do
facts
end
context 'with all defaults' do
it { should contain_class('zabbix::userparameter') }
it { should compile.with_all_deps }
end
end
it { should compile }
end
end