-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accpetance test for custom types
- Loading branch information
Showing
7 changed files
with
535 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'zabbix_application type' do | ||
context 'create zabbix_application resources' do | ||
it 'runs successfully' do | ||
# This will deploy a running Zabbix setup (server, web, db) which we can | ||
# use for custom type tests | ||
pp = <<-EOS | ||
class { 'apache': | ||
mpm_module => 'prefork', | ||
} | ||
include apache::mod::php | ||
include postgresql::server | ||
class { 'zabbix': | ||
zabbix_version => '3.0', # zabbixapi gem doesn't currently support higher versions | ||
zabbix_url => 'localhost', | ||
manage_resources => true, | ||
require => [ Class['postgresql::server'], Class['apache'], ], | ||
} | ||
Zabbix_application { | ||
zabbix_user => 'Admin', | ||
zabbix_pass => 'zabbix', | ||
zabbix_url => 'localhost', | ||
apache_use_ssl => false, | ||
require => [ Service['zabbix-server'], Package['zabbixapi'], ], | ||
} | ||
zabbix_application { 'TestApplication1': | ||
template => 'Template OS Linux', | ||
} | ||
EOS | ||
|
||
shell('yum clean metadata') if fact('os.family') == 'RedHat' | ||
|
||
# Cleanup old database | ||
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"') | ||
|
||
apply_manifest(pp, expect_failures: true) # Error: Could not find a suitable provider for zabbix_application | ||
apply_manifest(pp, catch_failures: true) | ||
end | ||
|
||
let(:result_templates) do | ||
zabbixapi('localhost', 'Admin', 'zabbix', 'template.get', selectApplications: ['name'], | ||
output: ['host']).result | ||
end | ||
|
||
context 'TestApplication1' do | ||
let(:template1) { result_templates.select { |t| t['host'] == 'Template OS Linux' }.first } | ||
|
||
it 'is attached to Template OS Linux' do | ||
expect(template1['applications'].map { |a| a['name'] }).to include('TestApplication1') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'zabbix_host type' do | ||
context 'create zabbix_host resources' do | ||
it 'runs successfully' do | ||
# This will deploy a running Zabbix setup (server, web, db) which we can | ||
# use for custom type tests | ||
pp = <<-EOS | ||
class { 'apache': | ||
mpm_module => 'prefork', | ||
} | ||
include apache::mod::php | ||
include postgresql::server | ||
class { 'zabbix': | ||
zabbix_version => '3.0', # zabbixapi gem doesn't currently support higher versions | ||
zabbix_url => 'localhost', | ||
manage_resources => true, | ||
require => [ Class['postgresql::server'], Class['apache'], ], | ||
} | ||
Zabbix_host { | ||
zabbix_user => 'Admin', | ||
zabbix_pass => 'zabbix', | ||
zabbix_url => 'localhost', | ||
apache_use_ssl => false, | ||
require => [ Service['zabbix-server'], Package['zabbixapi'], ], | ||
} | ||
zabbix_host { 'test1.example.com': | ||
ipaddress => '127.0.0.1', | ||
use_ip => true, | ||
port => 10050, | ||
group => 'TestgroupOne', | ||
group_create => true, | ||
templates => [ 'Template OS Linux', ], | ||
} | ||
zabbix_host { 'test2.example.com': | ||
ipaddress => '127.0.0.2', | ||
use_ip => false, | ||
port => 1050, | ||
group => 'Virtual machines', | ||
templates => [ 'Template OS Linux', 'Template ICMP Ping', ], | ||
} | ||
EOS | ||
|
||
shell('yum clean metadata') if fact('os.family') == 'RedHat' | ||
|
||
# Cleanup old database | ||
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"') | ||
|
||
apply_manifest(pp, catch_failures: true) | ||
end | ||
|
||
let(:result_hosts) do | ||
zabbixapi('localhost', 'Admin', 'zabbix', 'host.get', selectParentTemplates: ['host'], | ||
selectInterfaces: %w[dns ip main port type useip], | ||
selectGroups: ['name'], output: ['host', '']).result | ||
end | ||
|
||
context 'test1.example.com' do | ||
let(:test1) { result_hosts.select { |h| h['host'] == 'test1.example.com' }.first } | ||
|
||
it 'is created' do | ||
expect(test1['host']).to eq('test1.example.com') | ||
end | ||
it 'is in group TestgroupOne' do | ||
expect(test1['groups'].map { |g| g['name'] }).to eq(['TestgroupOne']) | ||
end | ||
it 'has a correct interface dns configured' do | ||
expect(test1['interfaces'][0]['dns']).to eq('test1.example.com') | ||
end | ||
it 'has a correct interface ip configured' do | ||
expect(test1['interfaces'][0]['ip']).to eq('127.0.0.1') | ||
end | ||
it 'has a correct interface main configured' do | ||
expect(test1['interfaces'][0]['main']).to eq('1') | ||
end | ||
it 'has a correct interface port configured' do | ||
expect(test1['interfaces'][0]['port']).to eq('10050') | ||
end | ||
it 'has a correct interface type configured' do | ||
expect(test1['interfaces'][0]['type']).to eq('1') | ||
end | ||
it 'has a correct interface useip configured' do | ||
expect(test1['interfaces'][0]['useip']).to eq('1') | ||
end | ||
it 'has templates attached' do | ||
expect(test1['parentTemplates'].map { |t| t['host'] }.sort).to eq(['Template OS Linux']) | ||
end | ||
end | ||
|
||
context 'test2.example.com' do | ||
let(:test2) { result_hosts.select { |h| h['host'] == 'test2.example.com' }.first } | ||
|
||
it 'is created' do | ||
expect(test2['host']).to eq('test2.example.com') | ||
end | ||
it 'is in group Virtual machines' do | ||
expect(test2['groups'].map { |g| g['name'] }).to eq(['Virtual machines']) | ||
end | ||
it 'has a correct interface dns configured' do | ||
expect(test2['interfaces'][0]['dns']).to eq('test2.example.com') | ||
end | ||
it 'has a correct interface ip configured' do | ||
expect(test2['interfaces'][0]['ip']).to eq('127.0.0.2') | ||
end | ||
it 'has a correct interface main configured' do | ||
expect(test2['interfaces'][0]['main']).to eq('1') | ||
end | ||
it 'has a correct interface port configured' do | ||
expect(test2['interfaces'][0]['port']).to eq('1050') | ||
end | ||
it 'has a correct interface type configured' do | ||
expect(test2['interfaces'][0]['type']).to eq('1') | ||
end | ||
it 'has a correct interface useip configured' do | ||
expect(test2['interfaces'][0]['useip']).to eq('0') | ||
end | ||
it 'has templates attached' do | ||
expect(test2['parentTemplates'].map { |t| t['host'] }.sort).to eq(['Template ICMP Ping', 'Template OS Linux']) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'zabbix_hostgroup type' do | ||
context 'create zabbix_hostgroup resources' do | ||
it 'runs successfully' do | ||
# This will deploy a running Zabbix setup (server, web, db) which we can | ||
# use for custom type tests | ||
pp = <<-EOS | ||
class { 'apache': | ||
mpm_module => 'prefork', | ||
} | ||
include apache::mod::php | ||
include postgresql::server | ||
class { 'zabbix': | ||
zabbix_version => '3.0', # zabbixapi gem doesn't currently support higher versions | ||
zabbix_url => 'localhost', | ||
manage_resources => true, | ||
require => [ Class['postgresql::server'], Class['apache'], ], | ||
} | ||
Zabbix_hostgroup { | ||
zabbix_user => 'Admin', | ||
zabbix_pass => 'zabbix', | ||
zabbix_url => 'localhost', | ||
apache_use_ssl => false, | ||
require => [ Service['zabbix-server'], Package['zabbixapi'], ], | ||
} | ||
zabbix_hostgroup { 'Testgroup2': } | ||
zabbix_hostgroup { 'Linux servers': | ||
ensure => absent, | ||
} | ||
EOS | ||
|
||
shell('yum clean metadata') if fact('os.family') == 'RedHat' | ||
|
||
# Cleanup old database | ||
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"') | ||
|
||
apply_manifest(pp, catch_failures: true) | ||
end | ||
|
||
let(:result_hostgroups) do | ||
zabbixapi('localhost', 'Admin', 'zabbix', 'hostgroup.get', output: 'extend').result | ||
end | ||
|
||
context 'Testgroup2' do | ||
it 'is created' do | ||
expect(result_hostgroups.map { |t| t['name'] }).to include('Testgroup2') | ||
end | ||
end | ||
|
||
context 'Linux servers' do | ||
it 'is absent' do | ||
expect(result_hostgroups.map { |t| t['name'] }).not_to include('Linux servers') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require 'spec_helper_acceptance' | ||
|
||
describe 'zabbix_proxy type' do | ||
context 'create zabbix_proxy resources' do | ||
it 'runs successfully' do | ||
# This will deploy a running Zabbix setup (server, web, db) which we can | ||
# use for custom type tests | ||
pp = <<-EOS | ||
class { 'apache': | ||
mpm_module => 'prefork', | ||
} | ||
include apache::mod::php | ||
include postgresql::server | ||
class { 'zabbix': | ||
zabbix_version => '3.0', # zabbixapi gem doesn't currently support higher versions | ||
zabbix_url => 'localhost', | ||
manage_resources => true, | ||
require => [ Class['postgresql::server'], Class['apache'], ], | ||
} | ||
Zabbix_proxy { | ||
zabbix_user => 'Admin', | ||
zabbix_pass => 'zabbix', | ||
zabbix_url => 'localhost', | ||
apache_use_ssl => false, | ||
require => [ Service['zabbix-server'], Package['zabbixapi'], ], | ||
} | ||
zabbix_proxy { 'ZabbixProxy1': | ||
ipaddress => '127.0.0.1', | ||
use_ip => true, | ||
mode => 0, | ||
port => 10051, | ||
} | ||
zabbix_proxy { 'ZabbixProxy2': | ||
ipaddress => '127.0.0.3', | ||
use_ip => false, | ||
mode => 1, | ||
port => 10055, | ||
} | ||
EOS | ||
|
||
shell('yum clean metadata') if fact('os.family') == 'RedHat' | ||
|
||
# Cleanup old database | ||
shell('/opt/puppetlabs/bin/puppet resource service zabbix-server ensure=stopped; /opt/puppetlabs/bin/puppet resource package zabbix-server-pgsql ensure=purged; rm -f /etc/zabbix/.*done; su - postgres -c "psql -c \'drop database if exists zabbix_server;\'"') | ||
|
||
apply_manifest(pp, catch_failures: true) | ||
end | ||
|
||
let(:result_proxies) do | ||
zabbixapi('localhost', 'Admin', 'zabbix', 'proxy.get', selectInterface: %w[dns ip port useip], | ||
output: ['host']).result | ||
end | ||
|
||
context 'ZabbixProxy1' do | ||
let(:proxy1) { result_proxies.select { |h| h['host'] == 'ZabbixProxy1' }.first } | ||
|
||
it 'is created' do | ||
expect(proxy1['host']).to eq('ZabbixProxy1') | ||
end | ||
|
||
it 'has no interfaces configured' do | ||
# Active proxies do not have interface | ||
expect(proxy1['interface']).to eq([]) | ||
end | ||
end | ||
|
||
context 'ZabbixProxy2' do | ||
let(:proxy2) { result_proxies.select { |h| h['host'] == 'ZabbixProxy2' }.first } | ||
|
||
it 'is created' do | ||
expect(proxy2['host']).to eq('ZabbixProxy2') | ||
end | ||
|
||
it 'has a interfaces dns configured' do | ||
expect(proxy2['interface']['dns']).to eq('ZabbixProxy2') | ||
end | ||
it 'has a interfaces ip configured' do | ||
expect(proxy2['interface']['ip']).to eq('127.0.0.3') | ||
end | ||
it 'has a interfaces port configured' do | ||
expect(proxy2['interface']['port']).to eq('10055') | ||
end | ||
it 'has a interfaces useip configured' do | ||
expect(proxy2['interface']['useip']).to eq('0') | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.