aboutsummaryrefslogtreecommitdiff
path: root/spec/classes/dhcp_spec.rb
blob: 5bc4a5bdf0d61a3d71b1b652c99d2aeee307e975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
require 'spec_helper'

describe 'dhcp' do
  context 'when on an unsupported OS' do
    let (:facts) { {
      :operatingsystem => 'RedHat',
      :osfamily        => 'Redhat',
      :lsbdistcodename => 'Santiago',
      :id              => 'root',
      :path            => '/foo/bar'
    } }

    it 'should fail' do
      expect {
        should contain_package('dhcp-server')
      }.to raise_error(Puppet::Error, /Unsupported OS RedHat\/Santiago/)
    end
  end

  context 'when on Debian lenny' do
    let (:facts) { {
      :operatingsystem => 'Debian',
      :osfamily        => 'Debian',
      :lsbdistcodename => 'lenny',
      :id              => 'root',
      :path            => '/foo/bar'
    } }

    # Package
    it { should contain_package('dhcp-server').with(
      :name => 'dhcp3-server'
    ) }

    # Config
    it { should contain_concat('/etc/dhcp3/dhcpd.conf').with(
      :owner => 'root',
      :group => 'root',
      :mode  => '0644'
    ) }

    it { should contain_concat__fragment('00.dhcp.server.base').with(
      :ensure  => 'present',
      :target  => '/etc/dhcp3/dhcpd.conf',
      :content => /log-facility/
      ).with_content(/ddns-update-style none;/).with_content(/#authoritative/)
    }

    # Service
    it { should contain_service('dhcpd').with(
      :ensure  => 'running',
      :name    => 'dhcp3-server',
      :enable  => true,
      :pattern => '/usr/sbin/dhcpd3'
    ) }
  end

  context 'when on Debian squeeze' do
    let (:facts) { {
      :operatingsystem => 'Debian',
      :osfamily        => 'Debian',
      :lsbdistcodename => 'squeeze',
      :id              => 'root',
      :path            => '/foo/bar'
    } }

    # Package
    it { should contain_package('dhcp-server').with(
      :name => 'isc-dhcp-server'
    ) }

    # Config
    it { should contain_concat('/etc/dhcp/dhcpd.conf').with(
      :owner => 'root',
      :group => 'root',
      :mode  => '0644'
    ) }

    it { should contain_concat__fragment('00.dhcp.server.base').with(
        :ensure  => 'present',
        :target  => '/etc/dhcp/dhcpd.conf',
        :content => /log-facility/
      ).with_content(/ddns-update-style none;/).with_content(/#authoritative/)
    }

    # Service
    it { should contain_service('dhcpd').with(
      :ensure  => 'running',
      :name    => 'isc-dhcp-server',
      :enable  => true,
      :pattern => '/usr/sbin/dhcpd'
    ) }
  end

  context 'when passing ddns_update' do
    context 'when passing wrong type' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :lsbdistcodename => 'squeeze',
        :id              => 'root',
        :path            => '/foo/bar'
      } }
      let (:params) { {
        :server_ddns_update => true
      } }

      it 'should fail' do
        expect {
          should contain_concat__fragment('00.dhcp.server.base')
        }.to raise_error(Puppet::Error, /true is not a string./)
      end
    end

    context 'when passing valid value' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :lsbdistcodename => 'squeeze',
        :id              => 'root',
        :path            => '/foo/bar'
      } }
      let (:params) { {
        :server_ddns_update => 'foo'
      } }

      it { should contain_concat__fragment('00.dhcp.server.base').with(
          :ensure  => 'present',
          :target  => '/etc/dhcp/dhcpd.conf',
          :content => /log-facility/
        ).with_content(/ddns-update-style foo;/).with_content(/#authoritative/)
      }
    end
  end

  context 'when passing authoritative' do
    context 'when passing wrong type' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :lsbdistcodename => 'squeeze',
        :id              => 'root',
        :path            => '/foo/bar'
      } }
      let (:params) { {
        :server_authoritative => 'foo'
      } }

      it 'should fail' do
        expect {
          should contain_concat__fragment('00.dhcp.server.base')
        }.to raise_error(Puppet::Error, /"foo" is not a boolean./)
      end
    end

    context 'when passing valid value' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :lsbdistcodename => 'squeeze',
        :id              => 'root',
        :path            => '/foo/bar'
      } }
      let (:params) { {
        :server_authoritative => true
      } }

      it { should contain_concat__fragment('00.dhcp.server.base').with(
          :ensure  => 'present',
          :target  => '/etc/dhcp/dhcpd.conf',
          :content => /log-facility/
        ).with_content(/ddns-update-style none;/).with_content(/[^#]authoritative/)
      }
    end
  end

  context 'when passing opts' do
    context 'when passing wrong type' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :lsbdistcodename => 'squeeze',
        :id              => 'root',
        :path            => '/foo/bar'
      } }
      let (:params) { {
        :server_opts => 'foo'
      } }

      it 'should fail' do
        expect {
          should contain_concat__fragment('00.dhcp.server.base')
        }.to raise_error(Puppet::Error, /"foo" is not an Array./)
      end
    end

    context 'when passing valid value' do
      let (:facts) { {
        :operatingsystem => 'Debian',
        :osfamily        => 'Debian',
        :lsbdistcodename => 'squeeze',
        :id              => 'root',
        :path            => '/foo/bar'
      } }
      let (:params) { {
        :server_opts => ['foo', 'bar', 'baz']
      } }

      it { should contain_concat__fragment('00.dhcp.server.base').with(
          :ensure  => 'present',
          :target  => '/etc/dhcp/dhcpd.conf',
          :content => /log-facility/
        ).with_content(/ddns-update-style none;/).with_content(/#authoritative/).with_content(/foo;\nbar;\nbaz;\n/)
      }
    end
  end
end