diff options
-rw-r--r-- | spec/classes/dhcp_spec.rb | 300 | ||||
-rw-r--r-- | spec/defines/dhcp_hosts_spec.rb | 707 | ||||
-rw-r--r-- | spec/defines/dhcp_shared_network_spec.rb | 135 | ||||
-rw-r--r-- | spec/defines/dhcp_subnet_spec.rb | 494 |
4 files changed, 791 insertions, 845 deletions
diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb index 5bc4a5b..d11cf7c 100644 --- a/spec/classes/dhcp_spec.rb +++ b/spec/classes/dhcp_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe 'dhcp' do + context 'when on an unsupported OS' do let (:facts) { { :operatingsystem => 'RedHat', @@ -17,200 +18,137 @@ describe 'dhcp' do 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 + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :concat_basedir => '/var/lib/puppet/concat', + }) + end - context 'when on Debian squeeze' do - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } + case facts[:osfamily] + when 'Debian' + case facts[:operatingsystemmajrelease] + when '5' + let(:pkg_name) { 'dhcp3-server' } + let(:confdir) { '/etc/dhcp3' } + let(:srv_name) { 'dhcp3-server' } + let(:srv_pattern) { '/usr/sbin/dhcp3' } + else + let(:pkg_name) { 'isc-dhcp-server' } + let(:confdir) { '/etc/dhcp' } + let(:srv_name) { 'isc-dhcp-server' } + let(:srv_pattern) { '/usr/sbin/dhcpd' } + end + end - # Package - it { should contain_package('dhcp-server').with( - :name => 'isc-dhcp-server' - ) } + # Package + it { should contain_package('dhcp-server').with( + :name => pkg_name + ) } - # Config - it { should contain_concat('/etc/dhcp/dhcpd.conf').with( - :owner => 'root', - :group => 'root', - :mode => '0644' - ) } + # Config + it { should contain_concat("#{confdir}/dhcpd.conf").with( + :owner => 'root', + :group => 'root', + :mode => '0644' + ) } - it { should contain_concat__fragment('00.dhcp.server.base').with( + it { should contain_concat__fragment('00.dhcp.server.base').with( :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', + :target => "#{confdir}/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./) + # Service + it { should contain_service('dhcpd').with( + :ensure => 'running', + :name => srv_name, + :enable => true, + :pattern => srv_pattern + ) } + + context 'when passing ddns_update' do + context 'when passing wrong type' do + 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 (: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 - 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./) + context 'when passing authoritative' do + context 'when passing wrong type' do + 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 (: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 - 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/) - } + context 'when passing opts' do + context 'when passing wrong type' do + 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 (: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 end end diff --git a/spec/defines/dhcp_hosts_spec.rb b/spec/defines/dhcp_hosts_spec.rb index 693760d..b6af1fd 100644 --- a/spec/defines/dhcp_hosts_spec.rb +++ b/spec/defines/dhcp_hosts_spec.rb @@ -2,385 +2,388 @@ require 'spec_helper' describe 'dhcp::hosts' do let (:title) { 'My hosts' } - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - - context 'when passing wrong value for ensure' do - let (:params) { { - :hash_data => {}, - :subnet => '1.2.3.4', - :ensure => 'running' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) - end - end - - context 'when hash_data is not passed' do - let (:params) { { - :subnet => '1.2.3.4', - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /Must pass hash_data to Dhcp::Hosts/) - end - end - context 'when passing wrong type for hash_data' do - let (:params) { { - :hash_data => 'foo', - :subnet => '1.2.3.4', - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /"foo" is not a Hash\./) - end - end - - context 'when subnet is not passed' do - let (:params) { { - :hash_data => {}, - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /Must pass subnet to Dhcp::Hosts/) - end - end - - context 'when passing wrong type for subnet' do - let (:params) { { - :hash_data => {}, - :subnet => true - } } + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :concat_basedir => '/var/lib/puppet/concat', + }) + end - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /true is not a string\./) - end - end + context 'when passing wrong value for ensure' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :ensure => 'running' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end - context 'when passing wrong value for subnet' do - let (:params) { { - :hash_data => {}, - :subnet => 'foo' - } } + context 'when hash_data is not passed' do + let (:params) { { + :subnet => '1.2.3.4', + } } - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /"foo" does not match/) - end - end + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Must pass hash_data to Dhcp::Hosts/) + end + end - context 'when passing wrong type for global_options' do - let (:params) { { - :hash_data => {}, - :subnet => '1.2.3.4', - :global_options => 'foo' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /"foo" is not an Array\./) - end - end + context 'when passing wrong type for hash_data' do + let (:params) { { + :hash_data => 'foo', + :subnet => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" is not a Hash\./) + end + end - context 'when passing wrong type for template' do - let (:params) { { - :hash_data => {}, - :subnet => '1.2.3.4', - :template => true - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /true is not a string\./) - end - end + context 'when subnet is not passed' do + let (:params) { { + :hash_data => {}, + } } - context 'when passing one entry in hash_data' do - context 'when passing wrong type for an host data' do - let (:params) { { - :hash_data => { - 'host1' => true, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /true is not a Hash/) + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Must pass subnet to Dhcp::Hosts/) + end end - end - context 'when interfaces is not passed' do - let (:params) { { - :hash_data => { - 'host1' => { - }, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /Missing interfaces hash for host 'host1'/) + context 'when passing wrong type for subnet' do + let (:params) { { + :hash_data => {}, + :subnet => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end end - end - context 'when passing wrong value for an interface' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth 0' => '00:11:22:33:44:55', - }, - }, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /"eth 0" does not match/) + context 'when passing wrong value for subnet' do + let (:params) { { + :hash_data => {}, + :subnet => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end end - end - context 'when passing wrong type for a mac address' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => true, - }, - }, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /true is not a string\./) + context 'when passing wrong type for global_options' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :global_options => 'foo' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"foo" is not an Array\./) + end end - end - context 'when passing wrong value for a mac address' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => 'my mac', - }, - }, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /"my mac" does not match/) + context 'when passing wrong type for template' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :template => true + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end end - end - context 'when passing wrong type for fixed_address' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + context 'when passing one entry in hash_data' do + context 'when passing wrong type for an host data' do + let (:params) { { + :hash_data => { + 'host1' => true, }, - 'fixed_address' => true, - }, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /true is not a string/) - end - end - - context 'when passing wrong value for fixed_address' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a Hash/) + end + end + + context 'when interfaces is not passed' do + let (:params) { { + :hash_data => { + 'host1' => { + }, }, - 'fixed_address' => 'my wrong value', - }, - }, - :subnet => '1.2.3.4' - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /"my wrong value" does not match/) - end - end - - context 'when not passing fixed_address' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Missing interfaces hash for host 'host1'/) + end + end + + context 'when passing wrong value for an interface' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth 0' => '00:11:22:33:44:55', + }, + }, }, - }, - }, - :subnet => '1.2.3.4' - } } - - it { should contain_concat__fragment('dhcp.host.My hosts').with( - :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', - :content => /fixed-address host1;/ - ) } - end - - context 'when not passing options' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"eth 0" does not match/) + end + end + + context 'when passing wrong type for a mac address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => true, + }, + }, }, - }, - }, - :subnet => '1.2.3.4', - :global_options => ['foo', 'bar'], - } } - - it { should contain_concat__fragment('dhcp.host.My hosts').with( - :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', - :content => /foo;\nbar;\n/ - ) } - end - - context 'when overriding options' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for a mac address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => 'my mac', + }, + }, }, - 'options' => ['baz'], - }, - }, - :subnet => '1.2.3.4', - :global_options => ['foo', 'bar'], - } } - - it { should contain_concat__fragment('dhcp.host.My hosts').with( - :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', - :content => /baz;\n/ - ) } - end - - context 'when passing wrong type for options' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my mac" does not match/) + end + end + + context 'when passing wrong type for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => true, + }, }, - 'options' => true, - }, - }, - :subnet => '1.2.3.4', - :global_options => ['foo', 'bar'], - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /true is not an Array\./) - end - end - - context 'when not passing options' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not a string/) + end + end + + context 'when passing wrong value for fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'fixed_address' => 'my wrong value', + }, }, - }, - }, - :subnet => '1.2.3.4', - :global_options => ['foo', 'bar'], - } } - - it { should contain_concat__fragment('dhcp.host.My hosts').with( - :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', - :content => /foo;\nbar;\n/ - ) } - end - - context 'when passing two hosts' do - let (:params) { { - :hash_data => { - 'host1' => { - 'interfaces' => { - 'eth0' => '00:11:22:33:44:55', - 'wlan0' => '00:aa:bb:44:55:ff', + :subnet => '1.2.3.4' + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /"my wrong value" does not match/) + end + end + + context 'when not passing fixed_address' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, }, - }, - 'host2' => { - 'interfaces' => { - 'eth1' => '00:11:AF:33:44:55', + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', + :content => /fixed-address host1;/ + ) } + end + + context 'when not passing options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, }, - 'fixed_address' => 'foo.example.com', - 'options' => ['opt1'], - }, - }, - :subnet => '1.2.3.4' - } } - - it { should contain_concat__fragment('dhcp.host.My hosts').with( - :target => '/etc/dhcp/hosts.d/1.2.3.4.conf').with_content( - /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content( - /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content( - /host host2-eth1 \{\n hardware ethernet 00:11:AF:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/) - } - end - end + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', + :content => /foo;\nbar;\n/ + ) } + end + + context 'when overriding options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'options' => ['baz'], + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', + :content => /baz;\n/ + ) } + end + + context 'when passing wrong type for options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + 'options' => true, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end + + context 'when not passing options' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + }, + }, + }, + :subnet => '1.2.3.4', + :global_options => ['foo', 'bar'], + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', + :content => /foo;\nbar;\n/ + ) } + end + + context 'when passing two hosts' do + let (:params) { { + :hash_data => { + 'host1' => { + 'interfaces' => { + 'eth0' => '00:11:22:33:44:55', + 'wlan0' => '00:aa:bb:44:55:ff', + }, + }, + 'host2' => { + 'interfaces' => { + 'eth1' => '00:11:AF:33:44:55', + }, + 'fixed_address' => 'foo.example.com', + 'options' => ['opt1'], + }, + }, + :subnet => '1.2.3.4' + } } + + it { should contain_concat__fragment('dhcp.host.My hosts').with( + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf').with_content( + /host host1-eth0 \{\n hardware ethernet 00:11:22:33:44:55;\n fixed-address host1;\n\}/).with_content( + /host host1-wlan0 \{\n hardware ethernet 00:aa:bb:44:55:ff;\n fixed-address host1;\n\}/).with_content( + /host host2-eth1 \{\n hardware ethernet 00:11:AF:33:44:55;\n fixed-address foo\.example\.com;\n opt1;\n\}/) + } + end + end - context 'when overriding template' do - let (:params) { { - :hash_data => {}, - :subnet => '1.2.3.4', - :template => 'wrong/path', - } } - - it 'should fail' do - expect { - should contain_concat__fragment('dhcp.host.My hosts') - }.to raise_error(Puppet::Error, /Could not find template 'wrong\/path'/) + context 'when overriding template' do + let (:params) { { + :hash_data => {}, + :subnet => '1.2.3.4', + :template => 'wrong/path', + } } + + it 'should fail' do + expect { + should contain_concat__fragment('dhcp.host.My hosts') + }.to raise_error(Puppet::Error, /Could not find template 'wrong\/path'/) + end + end end end end diff --git a/spec/defines/dhcp_shared_network_spec.rb b/spec/defines/dhcp_shared_network_spec.rb index aa22d9e..5fda39e 100644 --- a/spec/defines/dhcp_shared_network_spec.rb +++ b/spec/defines/dhcp_shared_network_spec.rb @@ -2,82 +2,85 @@ require 'spec_helper' describe 'dhcp::shared_network' do let (:title) { 'My network' } - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :id => 'root', - :path => '/foo/bar' - } } - context 'when passing wrong value for ensure' do - let (:params) { { - :ensure => 'running', - } } + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :concat_basedir => '/var/lib/puppet/concat', + }) + end - it 'should fail' do - expect { - should contain_concat__fragment('dhcp-shared-My network') - }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) - end - end + context 'when passing wrong value for ensure' do + let (:params) { { + :ensure => 'running', + } } - context 'when passing wrong type for subnets' do - let (:params) { { - :subnets => true, - } } + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end - it 'should fail' do - expect { - should contain_concat__fragment('dhcp-shared-My network') - }.to raise_error(Puppet::Error, /true is not an Array\./) - end - end + context 'when passing wrong type for subnets' do + let (:params) { { + :subnets => true, + } } - context 'when passing no parameters' do - it { should contain_concat__fragment('dhcp-shared-My network').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf' - ).with_content( - /shared-network My network \{\n\}/ - ) - } - end + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end - context 'when passing wrong type for a subnet' do - let (:params) { { - :subnets => [true], - } } + context 'when passing no parameters' do + it { should contain_concat__fragment('dhcp-shared-My network').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf' + ).with_content( + /shared-network My network \{\n\}/ + ) + } + end - it 'should fail' do - expect { - should contain_concat__fragment('dhcp-shared-My network') - }.to raise_error(Puppet::Error, /true is not a string\./) - end - end + context 'when passing wrong type for a subnet' do + let (:params) { { + :subnets => [true], + } } - context 'when passing wrong value for a subnet' do - let (:params) { { - :subnets => ['wrong value'], - } } + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end - it 'should fail' do - expect { - should contain_concat__fragment('dhcp-shared-My network') - }.to raise_error(Puppet::Error, /"wrong value" does not match/) - end - end + context 'when passing wrong value for a subnet' do + let (:params) { { + :subnets => ['wrong value'], + } } - context 'when passing subnets' do - let (:params) { { - :subnets => ['1.2.3.4', '5.6.7.8'], - } } + it 'should fail' do + expect { + should contain_concat__fragment('dhcp-shared-My network') + }.to raise_error(Puppet::Error, /"wrong value" does not match/) + end + end - it { should contain_concat__fragment('dhcp-shared-My network').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf' - ).with_content( - /shared-network My network \{\n include "\/etc\/dhcp\/subnets\/1\.2\.3\.4\.conf";\n include "\/etc\/dhcp\/subnets\/5\.6\.7\.8\.conf";\n\}/) - } + context 'when passing subnets' do + let (:params) { { + :subnets => ['1.2.3.4', '5.6.7.8'], + } } + + it { should contain_concat__fragment('dhcp-shared-My network').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf' + ).with_content( + /shared-network My network \{\n include "\/etc\/dhcp\/subnets\/1\.2\.3\.4\.conf";\n include "\/etc\/dhcp\/subnets\/5\.6\.7\.8\.conf";\n\}/) + } + end + end end end diff --git a/spec/defines/dhcp_subnet_spec.rb b/spec/defines/dhcp_subnet_spec.rb index 6a7d604..b0f7ab7 100644 --- a/spec/defines/dhcp_subnet_spec.rb +++ b/spec/defines/dhcp_subnet_spec.rb @@ -2,253 +2,255 @@ require 'spec_helper' describe 'dhcp::subnet' do let (:title) { '1.2.3.4' } - let (:facts) { { - :operatingsystem => 'Debian', - :osfamily => 'Debian', - :lsbdistcodename => 'squeeze', - :netmask_eth0 => '255.255.255.0', - :domain => 'example.com', - :id => 'root', - :path => '/foo/bar' - } } - - context 'when passing wrong value for ensure' do - let (:params) { { - :ensure => 'running', - :broadcast => '1.2.3.4', - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) - end - end - - context 'when not passing broadcast' do - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /Must pass broadcast to Dhcp::Subnet/) - end - end - - context 'when passing wrong type for broadcast' do - let (:params) { { - :broadcast => true, - } } - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /true is not a string\./) + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge({ + :concat_basedir => '/var/lib/puppet/concat', + :domain => 'example.com', + }) + end + + context 'when passing wrong value for ensure' do + let (:params) { { + :ensure => 'running', + :broadcast => '1.2.3.4', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /\$ensure must be either 'present' or 'absent', got 'running'/) + end + end + + context 'when not passing broadcast' do + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /Must pass broadcast to Dhcp::Subnet/) + end + end + + context 'when passing wrong type for broadcast' do + let (:params) { { + :broadcast => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for broadcast' do + let (:params) { { + :broadcast => 'foo', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end + end + + context 'when passing wrong type for netmask' do + let (:params) { { + :broadcast => '1.2.3.4', + :netmask => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong value for netmask' do + let (:params) { { + :broadcast => '1.2.3.4', + :netmask => 'foo', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /"foo" does not match/) + end + end + + context 'when passing wrong type for routers' do + let (:params) { { + :broadcast => '1.2.3.4', + :routers => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not an Array\./) + end + end + + context 'when passing wrong type for subnet_mask' do + let (:params) { { + :broadcast => '1.2.3.4', + :subnet_mask => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong type for domain_name' do + let (:params) { { + :broadcast => '1.2.3.4', + :domain_name => true, + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /true is not a string\./) + end + end + + context 'when passing wrong type for is_shared' do + let (:params) { { + :broadcast => '1.2.3.4', + :is_shared => 'foo', + } } + + it 'should fail' do + expect { + should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') + }.to raise_error(Puppet::Error, /"foo" is not a boolean\./) + end + end + + context 'when using defaults' do + let (:params) { { + :broadcast => '1.2.3.4', + } } + + it { should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf').with( + :owner => 'root', + :group => 'root', + :mode => '0644' + ) } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + /subnet 1\.2\.3\.4 netmask 255\.255\.255\.0 \{\n/ + ).with_content( + /option routers 255\.255\.255\.0;\n/ + ).with_content( + /option subnet-mask 255\.255\.255\.0;\n/ + ).with_content( + /option broadcast-address 1\.2\.3\.4;\n/ + ).with_content( + /option domain-name "example\.com";\n/ + ) } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => "include \"/etc/dhcp/subnets/1.2.3.4.conf\";\n" + ) } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.hosts').with( + :ensure => 'present', + :target => '/etc/dhcp/dhcpd.conf', + :content => "include \"/etc/dhcp/hosts.d/1\.2\.3\.4\.conf\";\n" + ) } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.base').with( + :ensure => 'present', + :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', + :content => "# File managed by puppet\n", + :order => '00' + ) } + end + + context 'when is_shared is true' do + let (:params) { { + :broadcast => '1.2.3.4', + :is_shared => true, + } } + + it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( + :ensure => 'absent' + ) } + end + + context 'when passing other_opts as array' do + let (:params) { { + :broadcast => '1.2.3.4', + :other_opts => ['foo', 'bar'], + } } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + / foo;\n bar;\n/ + ) } + end + + context 'when passing other_opts as string' do + let (:params) { { + :broadcast => '1.2.3.4', + :other_opts => 'bar', + } } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + / bar;\n/ + ) } + end + + context 'when overriding all parameters' do + let (:params) { { + :broadcast => '1.2.3.4', + :netmask => '255.1.2.0', + :routers => ['2.3.4.5', '3.4.5.6'], + :subnet_mask => '255.255.1.0', + :domain_name => 'foo.io', + :other_opts => ['foo', 'bar'], + } } + + it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( + :ensure => 'present', + :owner => 'root', + :group => 'root' + ).with_content( + /subnet 1\.2\.3\.4 netmask 255\.1\.2\.0 \{\n/ + ).with_content( + /option routers 2\.3\.4\.5,3\.4\.5\.6;\n/ + ).with_content( + /option subnet-mask 255\.255\.1\.0;\n/ + ).with_content( + /option broadcast-address 1\.2\.3\.4;\n/ + ).with_content( + /option domain-name "foo\.io";\n/ + ).with_content( + / foo;\n bar;\n/ + ) } + end end end - - context 'when passing wrong value for broadcast' do - let (:params) { { - :broadcast => 'foo', - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /"foo" does not match/) - end - end - - context 'when passing wrong type for netmask' do - let (:params) { { - :broadcast => '1.2.3.4', - :netmask => true, - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /true is not a string\./) - end - end - - context 'when passing wrong value for netmask' do - let (:params) { { - :broadcast => '1.2.3.4', - :netmask => 'foo', - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /"foo" does not match/) - end - end - - context 'when passing wrong type for routers' do - let (:params) { { - :broadcast => '1.2.3.4', - :routers => true, - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /true is not an Array\./) - end - end - - context 'when passing wrong type for subnet_mask' do - let (:params) { { - :broadcast => '1.2.3.4', - :subnet_mask => true, - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /true is not a string\./) - end - end - - context 'when passing wrong type for domain_name' do - let (:params) { { - :broadcast => '1.2.3.4', - :domain_name => true, - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /true is not a string\./) - end - end - - context 'when passing wrong type for is_shared' do - let (:params) { { - :broadcast => '1.2.3.4', - :is_shared => 'foo', - } } - - it 'should fail' do - expect { - should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf') - }.to raise_error(Puppet::Error, /"foo" is not a boolean\./) - end - end - - context 'when using defaults' do - let (:params) { { - :broadcast => '1.2.3.4', - } } - - it { should contain_concat('/etc/dhcp/hosts.d/1.2.3.4.conf').with( - :owner => 'root', - :group => 'root', - :mode => '0644' - ) } - - it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( - :ensure => 'present', - :owner => 'root', - :group => 'root' - ).with_content( - /subnet 1\.2\.3\.4 netmask 255\.255\.255\.0 \{\n/ - ).with_content( - /option routers 255\.255\.255\.0;\n/ - ).with_content( - /option subnet-mask 255\.255\.255\.0;\n/ - ).with_content( - /option broadcast-address 1\.2\.3\.4;\n/ - ).with_content( - /option domain-name "example\.com";\n/ - ) } - - it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', - :content => "include \"/etc/dhcp/subnets/1.2.3.4.conf\";\n" - ) } - - it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.hosts').with( - :ensure => 'present', - :target => '/etc/dhcp/dhcpd.conf', - :content => "include \"/etc/dhcp/hosts.d/1\.2\.3\.4\.conf\";\n" - ) } - - it { should contain_concat__fragment('dhcp.subnet.1.2.3.4.base').with( - :ensure => 'present', - :target => '/etc/dhcp/hosts.d/1.2.3.4.conf', - :content => "# File managed by puppet\n", - :order => '00' - ) } - end - - context 'when is_shared is true' do - let (:params) { { - :broadcast => '1.2.3.4', - :is_shared => true, - } } - - it { should contain_concat__fragment('dhcp.subnet.1.2.3.4').with( - :ensure => 'absent' - ) } - end - - context 'when passing other_opts as array' do - let (:params) { { - :broadcast => '1.2.3.4', - :other_opts => ['foo', 'bar'], - } } - - it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( - :ensure => 'present', - :owner => 'root', - :group => 'root' - ).with_content( - / foo;\n bar;\n/ - ) } - end - - context 'when passing other_opts as string' do - let (:params) { { - :broadcast => '1.2.3.4', - :other_opts => 'bar', - } } - - it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( - :ensure => 'present', - :owner => 'root', - :group => 'root' - ).with_content( - / bar;\n/ - ) } - end - - context 'when overriding all parameters' do - let (:params) { { - :broadcast => '1.2.3.4', - :netmask => '255.1.2.0', - :routers => ['2.3.4.5', '3.4.5.6'], - :subnet_mask => '255.255.1.0', - :domain_name => 'foo.io', - :other_opts => ['foo', 'bar'], - } } - - it { should contain_file('/etc/dhcp/subnets/1.2.3.4.conf').with( - :ensure => 'present', - :owner => 'root', - :group => 'root' - ).with_content( - /subnet 1\.2\.3\.4 netmask 255\.1\.2\.0 \{\n/ - ).with_content( - /option routers 2\.3\.4\.5,3\.4\.5\.6;\n/ - ).with_content( - /option subnet-mask 255\.255\.1\.0;\n/ - ).with_content( - /option broadcast-address 1\.2\.3\.4;\n/ - ).with_content( - /option domain-name "foo\.io";\n/ - ).with_content( - / foo;\n bar;\n/ - ) } - end end |