|
3 | 3 |
|
4 | 4 | describe 'zabbix_proxy type' do |
5 | 5 | context 'create zabbix_proxy resources' do |
6 | | - it 'runs successfully' do |
7 | | - # This will deploy a running Zabbix setup (server, web, db) which we can |
8 | | - # use for custom type tests |
9 | | - pp = <<-EOS |
10 | | - class { 'apache': |
11 | | - mpm_module => 'prefork', |
12 | | - } |
13 | | - include apache::mod::php |
14 | | - include postgresql::server |
15 | | -
|
16 | | - class { 'zabbix': |
17 | | - zabbix_version => '3.0', # zabbixapi gem doesn't currently support higher versions |
18 | | - zabbix_url => 'localhost', |
19 | | - zabbix_api_user => 'Admin', |
20 | | - zabbix_api_pass => 'zabbix', |
21 | | - apache_use_ssl => false, |
22 | | - manage_resources => true, |
23 | | - require => [ Class['postgresql::server'], Class['apache'], ], |
24 | | - } |
25 | | -
|
26 | | - zabbix_proxy { 'ZabbixProxy1': |
27 | | - ipaddress => '127.0.0.1', |
28 | | - use_ip => true, |
29 | | - mode => 0, |
30 | | - port => 10051, |
31 | | - require => [ Service['zabbix-server'], Package['zabbixapi'], ], |
32 | | - } |
33 | | - zabbix_proxy { 'ZabbixProxy2': |
34 | | - ipaddress => '127.0.0.3', |
35 | | - use_ip => false, |
36 | | - mode => 1, |
37 | | - port => 10055, |
38 | | - require => [ Service['zabbix-server'], Package['zabbixapi'], ], |
39 | | - } |
40 | | - EOS |
41 | | - |
42 | | - shell('yum clean metadata') if fact('os.family') == 'RedHat' |
43 | | - |
44 | | - # Cleanup old database |
45 | | - cleanup_zabbix |
46 | | - |
47 | | - apply_manifest(pp, catch_failures: true) |
| 6 | + # This will deploy a running Zabbix setup (server, web, db) which we can |
| 7 | + # use for custom type tests |
| 8 | + pp1 = <<-EOS |
| 9 | + $compile_packages = $facts['os']['family'] ? { |
| 10 | + 'RedHat' => [ 'make', 'gcc-c++', 'rubygems', 'ruby'], |
| 11 | + 'Debian' => [ 'make', 'g++', 'ruby-dev', 'ruby', 'pkg-config',], |
| 12 | + default => [], |
| 13 | + } |
| 14 | + ensure_packages($compile_packages, { before => Package['zabbixapi'], }) |
| 15 | + class { 'apache': |
| 16 | + mpm_module => 'prefork', |
| 17 | + } |
| 18 | + include apache::mod::php |
| 19 | + include postgresql::server |
| 20 | +
|
| 21 | + class { 'zabbix': |
| 22 | + zabbix_version => '3.0', # zabbixapi gem doesn't currently support higher versions |
| 23 | + zabbix_url => 'localhost', |
| 24 | + zabbix_api_user => 'Admin', |
| 25 | + zabbix_api_pass => 'zabbix', |
| 26 | + apache_use_ssl => false, |
| 27 | + manage_resources => true, |
| 28 | + require => [ Class['postgresql::server'], Class['apache'], ], |
| 29 | + } |
| 30 | + EOS |
| 31 | + |
| 32 | + # Cleanup old database |
| 33 | + cleanup_zabbix |
| 34 | + |
| 35 | + it 'works idempotently with no errors' do |
| 36 | + # Run it twice and test for idempotency |
| 37 | + apply_manifest(pp1, catch_failures: true) |
| 38 | + apply_manifest(pp1, catch_changes: true) |
| 39 | + end |
| 40 | + |
| 41 | + # setup proxies within zabbix |
| 42 | + pp2 = <<-EOS |
| 43 | + zabbix_proxy { 'ZabbixProxy1': |
| 44 | + mode => 0, |
| 45 | + } |
| 46 | + zabbix_proxy { 'ZabbixProxy2': |
| 47 | + ipaddress => '127.0.0.3', |
| 48 | + use_ip => false, |
| 49 | + mode => 1, |
| 50 | + port => 10055, |
| 51 | + } |
| 52 | + EOS |
| 53 | + |
| 54 | + it 'works idempotently with no errors' do |
| 55 | + # Run it twice and test for idempotency |
| 56 | + apply_manifest(pp2, catch_failures: true) |
| 57 | + apply_manifest(pp2, catch_changes: true) |
48 | 58 | end |
49 | 59 |
|
50 | 60 | let(:result_proxies) do |
@@ -87,27 +97,81 @@ class { 'zabbix': |
87 | 97 | end |
88 | 98 | end |
89 | 99 |
|
| 100 | + context 'update zabbix_proxy resources' do |
| 101 | + # This will update the Zabbix proxies created above by switching their configuration |
| 102 | + pp_update = <<-EOS |
| 103 | + zabbix_proxy { 'ZabbixProxy1': |
| 104 | + ipaddress => '127.0.0.3', |
| 105 | + use_ip => false, |
| 106 | + mode => 1, |
| 107 | + port => 10055, |
| 108 | + } |
| 109 | + zabbix_proxy { 'ZabbixProxy2': |
| 110 | + mode => 0, |
| 111 | + } |
| 112 | + EOS |
| 113 | + |
| 114 | + it 'works idempotently with no errors' do |
| 115 | + # Run it twice and test for idempotency |
| 116 | + apply_manifest(pp_update, catch_failures: true) |
| 117 | + apply_manifest(pp_update, catch_changes: true) |
| 118 | + end |
| 119 | + |
| 120 | + let(:result_proxies) do |
| 121 | + zabbixapi('localhost', 'Admin', 'zabbix', 'proxy.get', selectInterface: %w[dns ip port useip], |
| 122 | + output: ['host']).result |
| 123 | + end |
| 124 | + |
| 125 | + context 'ZabbixProxy1' do |
| 126 | + let(:proxy1) { result_proxies.select { |h| h['host'] == 'ZabbixProxy1' }.first } |
| 127 | + |
| 128 | + it 'is created' do |
| 129 | + expect(proxy1['host']).to eq('ZabbixProxy1') |
| 130 | + end |
| 131 | + |
| 132 | + it 'has a interfaces dns configured' do |
| 133 | + expect(proxy1['interface']['dns']).to eq('ZabbixProxy1') |
| 134 | + end |
| 135 | + it 'has a interfaces ip configured' do |
| 136 | + expect(proxy1['interface']['ip']).to eq('127.0.0.3') |
| 137 | + end |
| 138 | + it 'has a interfaces port configured' do |
| 139 | + expect(proxy1['interface']['port']).to eq('10055') |
| 140 | + end |
| 141 | + it 'has a interfaces useip configured' do |
| 142 | + expect(proxy1['interface']['useip']).to eq('0') |
| 143 | + end |
| 144 | + end |
| 145 | + |
| 146 | + context 'ZabbixProxy2' do |
| 147 | + let(:proxy2) { result_proxies.select { |h| h['host'] == 'ZabbixProxy2' }.first } |
| 148 | + |
| 149 | + it 'is created' do |
| 150 | + expect(proxy2['host']).to eq('ZabbixProxy2') |
| 151 | + end |
| 152 | + |
| 153 | + it 'has no interfaces configured' do |
| 154 | + # Active proxies do not have interface |
| 155 | + expect(proxy2['interface']).to eq([]) |
| 156 | + end |
| 157 | + end |
| 158 | + end |
| 159 | + |
90 | 160 | context 'delete zabbix_proxy resources' do |
91 | | - it 'runs successfully' do |
92 | | - # This will delete the Zabbix proxies create above |
93 | | - pp = <<-EOS |
94 | | - zabbix_proxy { 'ZabbixProxy1': |
95 | | - ensure => absent, |
96 | | - ipaddress => '127.0.0.1', |
97 | | - use_ip => true, |
98 | | - mode => 0, |
99 | | - port => 10051, |
100 | | - } |
101 | | - zabbix_proxy { 'ZabbixProxy2': |
102 | | - ensure => absent, |
103 | | - ipaddress => '127.0.0.3', |
104 | | - use_ip => false, |
105 | | - mode => 1, |
106 | | - port => 10055, |
107 | | - } |
108 | | - EOS |
109 | | - |
110 | | - apply_manifest(pp, catch_failures: true) |
| 161 | + # This will delete the Zabbix proxies create above |
| 162 | + pp_delete = <<-EOS |
| 163 | + zabbix_proxy { 'ZabbixProxy1': |
| 164 | + ensure => absent, |
| 165 | + } |
| 166 | + zabbix_proxy { 'ZabbixProxy2': |
| 167 | + ensure => absent, |
| 168 | + } |
| 169 | + EOS |
| 170 | + |
| 171 | + it 'works idempotently with no errors' do |
| 172 | + # Run it twice and test for idempotency |
| 173 | + apply_manifest(pp_delete, catch_failures: true) |
| 174 | + apply_manifest(pp_delete, catch_changes: true) |
111 | 175 | end |
112 | 176 |
|
113 | 177 | let(:result_proxies) do |
|
0 commit comments