Giuseppe Lavagetto has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/394274 )
Change subject: spec: make network, puppetmaster, service, systemd compatible with puppet4 ...................................................................... spec: make network, puppetmaster, service, systemd compatible with puppet4 Change-Id: If05f38643ca2977d73bbe34f4af156f6178efd2b --- M modules/network/spec/functions/slice_network_constants_spec.rb M modules/puppetmaster/spec/classes/puppetmaster_geoip_spec.rb M modules/puppetmaster/spec/classes/puppetmaster_rsync_spec.rb M modules/puppetmaster/spec/classes/puppetmaster_scripts_spec.rb M modules/puppetmaster/spec/spec_helper.rb M modules/service/spec/defines/service_node_spec.rb M modules/systemd/spec/defines/systemd_syslog_spec.rb M modules/systemd/spec/defines/systemd_unit_spec.rb M modules/systemd/spec/spec_helper.rb 9 files changed, 185 insertions(+), 159 deletions(-) Approvals: Giuseppe Lavagetto: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/network/spec/functions/slice_network_constants_spec.rb b/modules/network/spec/functions/slice_network_constants_spec.rb index ec2a7ba..9cafb24 100644 --- a/modules/network/spec/functions/slice_network_constants_spec.rb +++ b/modules/network/spec/functions/slice_network_constants_spec.rb @@ -4,18 +4,17 @@ describe "slice_network_constants" do all_network_subnets = YAML.load_file(File.dirname(__FILE__) + "/../../data/data.yaml")['network::subnets'] - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } it "should exist" do expect(Puppet::Parser::Functions.function("slice_network_constants")).to eq "function_slice_network_constants" end it "should raise a ParseError if there are less than 1 arguments" do - expect { scope.function_slice_network_constants([])}.to raise_error(ArgumentError) + is_expected.to run.with_params.and_raise_error(ArgumentError) end it "should raise a ParseError if there are more than 2 arguments" do - expect { scope.function_slice_network_constants(['a', 'b', 'c']) }.to raise_error(ArgumentError) + is_expected.to run.with_params('a', 'b', 'c').and_raise_error(ArgumentError) end # Test realm diff --git a/modules/puppetmaster/spec/classes/puppetmaster_geoip_spec.rb b/modules/puppetmaster/spec/classes/puppetmaster_geoip_spec.rb index 7a207e7..35afeaa 100644 --- a/modules/puppetmaster/spec/classes/puppetmaster_geoip_spec.rb +++ b/modules/puppetmaster/spec/classes/puppetmaster_geoip_spec.rb @@ -1,9 +1,15 @@ require 'spec_helper' describe 'puppetmaster::geoip' do + let(:node_params) { {'site' => 'eqiad'}} let(:pre_condition) { ''' - class passwords::geoip {} + class puppetmaster { $volatiledir="/tmp" } + class passwords::geoip { + $user_id="foo" + $license_key="meh" + } + include ::puppetmaster ''' } it { should compile } diff --git a/modules/puppetmaster/spec/classes/puppetmaster_rsync_spec.rb b/modules/puppetmaster/spec/classes/puppetmaster_rsync_spec.rb index c11d4fe..a69a1b4 100644 --- a/modules/puppetmaster/spec/classes/puppetmaster_rsync_spec.rb +++ b/modules/puppetmaster/spec/classes/puppetmaster_rsync_spec.rb @@ -1,11 +1,24 @@ require 'spec_helper' +test_on = { + supported_os: [ + { + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => ['8', '9'], + } + ] +} describe 'puppetmaster::rsync' do - let(:params) { { - :server => 'puppetmaster_host', - } } - let(:facts) { { - :realm => 'production', - } } - it { should compile } + on_supported_os(test_on).each do |os, facts| + context "On #{os}" do + let(:facts) { facts } + let(:params) { { + :server => 'puppetmaster_host', + } } + let(:node_params) { { + 'realm' => 'production', + } } + it { should compile } + end + end end diff --git a/modules/puppetmaster/spec/classes/puppetmaster_scripts_spec.rb b/modules/puppetmaster/spec/classes/puppetmaster_scripts_spec.rb index 0e82b8d..405be25 100644 --- a/modules/puppetmaster/spec/classes/puppetmaster_scripts_spec.rb +++ b/modules/puppetmaster/spec/classes/puppetmaster_scripts_spec.rb @@ -1,5 +1,6 @@ require 'spec_helper' describe 'puppetmaster::scripts' do + let(:node_params) { {'site' => 'test', 'realm' => 'production'} } it { should compile } end diff --git a/modules/puppetmaster/spec/spec_helper.rb b/modules/puppetmaster/spec/spec_helper.rb index 421fd71..f603826 100644 --- a/modules/puppetmaster/spec/spec_helper.rb +++ b/modules/puppetmaster/spec/spec_helper.rb @@ -1,6 +1,8 @@ require 'rspec-puppet' require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) RSpec.configure do |c| diff --git a/modules/service/spec/defines/service_node_spec.rb b/modules/service/spec/defines/service_node_spec.rb index 24e7712..702eb43 100644 --- a/modules/service/spec/defines/service_node_spec.rb +++ b/modules/service/spec/defines/service_node_spec.rb @@ -3,7 +3,13 @@ describe 'service::node', :type => :define do let(:title) { 'my_service_name' } let(:facts) { { :initsystem => 'systemd' } } - + let(:node_params) { {'cluster' => 'test', 'site' => 'eqiad'} } + let(:pre_condition) { """ +class profile::base { + $notifications_enabled = '1' +} +include ::profile::base +""" } context 'when only port is given' do let(:params) { { :port => 1234 } } diff --git a/modules/systemd/spec/defines/systemd_syslog_spec.rb b/modules/systemd/spec/defines/systemd_syslog_spec.rb index 17e3436..884b9fe 100644 --- a/modules/systemd/spec/defines/systemd_syslog_spec.rb +++ b/modules/systemd/spec/defines/systemd_syslog_spec.rb @@ -1,62 +1,51 @@ require 'spec_helper' describe 'systemd::syslog' do - context 'when initsystem is unknown' do - let(:title) { 'dummyservice' } - let(:facts) { { :initsystem => 'unknown' } } - it { should compile.and_raise_error(/systemd::syslog is useful only with systemd/) } + let(:title) { 'dummyservice' } + context 'when initsystem is unknown' do + let(:facts) { { :initsystem => 'unknown' } } + it { should compile.and_raise_error(/systemd::syslog is useful only with systemd/) } + end + + context 'when a service is defined' do + let(:pre_condition) { 'service { "dummyservice": ensure => running, provider => "systemd"}' } + let(:facts) { {initsystem: 'systemd'} } + it 'should create syslog file before rsyslog configuration' do + should contain_file('/var/log/dummyservice/syslog.log') + .that_comes_before('Rsyslog::Conf[dummyservice]') end - - context 'when initsystem is systemd' do - let(:facts) { {:initsystem => 'systemd' } } - let(:title) { 'dummyservice' } - let(:pre_condition) { - """ - base::service_unit { 'dummyservice': } - """ - } - - describe 'when invoked with name "dummyservice"' do - it { should compile } - it 'should create syslog file before rsyslog configuration' do - should contain_file('/var/log/dummyservice/syslog.log') - .that_comes_before('Rsyslog::Conf[dummyservice]') - end - it 'should configure rsyslog before the service' do - should contain_rsyslog__conf('dummyservice') - .that_comes_before('Service[dummyservice]') - end - it 'should configure rsyslog to match programname dummyservice' do - should contain_file('/etc/rsyslog.d/20-dummyservice.conf') - .with_content(%r%^:programname, startswith, "dummyservice" /var/log/dummyservice/syslog\.log$%) - end - end - - describe 'when invoked with base_dir=/srv/log' do - let(:params) { { - :base_dir => '/srv/log', - } } - it { - should contain_file('/srv/log/dummyservice') - .with_ensure('directory') - } - it { - should contain_file('/srv/log/dummyservice/syslog.log') - } - it "should logrotates /srv/log/dummyservice/*.log" do - should contain_file('/etc/logrotate.d/dummyservice') - .with_content(%r%^/srv/log/dummyservice/\*\.log {$%) - end - end - - describe 'when invoked with log_filename=instance01.log' do - let(:params) { { - :log_filename => 'instance01.log' - } } - it 'should configure rsyslog to log to instance01.log' do - should contain_file('/etc/rsyslog.d/20-dummyservice.conf') - .with_content(%r%^:programname, .* /var/log/dummyservice/instance01\.log$%) - end - end + it 'should configure rsyslog before the service' do + should contain_rsyslog__conf('dummyservice') + .that_comes_before('Service[dummyservice]') end + it 'should configure rsyslog to match programname dummyservice' do + should contain_file('/etc/rsyslog.d/20-dummyservice.conf') + .with_content(%r%^:programname, startswith, "dummyservice" /var/log/dummyservice/syslog\.log$%) + end + end + + context 'when invoked with base_dir=/srv/log' do + let(:facts) { {initsystem: 'systemd'} } + let(:params) { { base_dir: '/srv/log', } } + it { + should contain_file('/srv/log/dummyservice') + .with_ensure('directory') + } + it { + should contain_file('/srv/log/dummyservice/syslog.log') + } + it "should logrotates /srv/log/dummyservice/*.log" do + should contain_file('/etc/logrotate.d/dummyservice') + .with_content(%r%^/srv/log/dummyservice/\*\.log {$%) + end + end + + context 'when invoked with log_filename=instance01.log' do + let(:facts) { {initsystem: 'systemd'} } + let(:params) { {log_filename: 'instance01.log'} } + it 'should configure rsyslog to log to instance01.log' do + should contain_file('/etc/rsyslog.d/20-dummyservice.conf') + .with_content(%r%^:programname, .* /var/log/dummyservice/instance01\.log$%) + end + end end diff --git a/modules/systemd/spec/defines/systemd_unit_spec.rb b/modules/systemd/spec/defines/systemd_unit_spec.rb index 1d44ed3..a98c966 100644 --- a/modules/systemd/spec/defines/systemd_unit_spec.rb +++ b/modules/systemd/spec/defines/systemd_unit_spec.rb @@ -1,108 +1,116 @@ require 'spec_helper' +test_on = { + supported_os: [ + { + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => ['8', '9'], + } + ] +} describe 'systemd::unit' do - context 'when initsystem is unknown' do - let(:title) { 'dummyservice' } - let(:facts) { { :initsystem => 'unknown' } } - let(:params) { - { - :ensure => 'present', - :content => 'dummy' - } - } - it { is_expected.to compile.and_raise_error(/You can only use systemd resources on systems with systemd/) } - end - - context 'when initsystem is sytemd' do - let(:facts) { {:initsystem => 'systemd' } } - - describe 'when using dummy parameters and a name without type' do - let(:title) { 'dummyservice' } - let(:params) { - { - :ensure => 'present', - :content => 'dummy' + on_supported_os(test_on).each do |os, facts| + context "On #{os}" do + let(:facts) do + facts.merge({initsystem: 'systemd'}) + end + context 'when initsystem is unknown' do + let(:title) { 'dummyservice' } + let(:facts) { facts.merge({ :initsystem => 'unknown' }) } + let(:params) { + { + :ensure => 'present', + :content => 'dummy' + } } - } - it { should compile } - - describe 'then the systemd service' do - it 'should define a unit file in the system directory' do - is_expected.to contain_file('/lib/systemd/system/dummyservice.service') - .with_content('dummy') - .that_notifies( - "Exec[systemd daemon-reload for dummyservice.service]" - ) - end - - it 'should contain a systemctl-reload exec' do - is_expected.to contain_exec('systemd daemon-reload for dummyservice.service') - .with_refreshonly(true) - end + it { is_expected.to compile.and_raise_error(/You can only use systemd resources on systems with systemd/) } end - end - describe 'when the title includes the unit type and is an override' do - let(:title) { 'usbstick.device' } - let(:params) { - { - :ensure => 'present', - :content => 'dummy', - :override => true - } - } - it { should compile } - - it 'should define the parent directory of the override file' do - is_expected.to contain_file('/etc/systemd/system/usbstick.device.d') - .with_ensure('directory') - .with_owner('root') - .with_group('root') - .with_mode('0555') - end - it 'should define the systemd override file' do - is_expected.to contain_file('/etc/systemd/system/usbstick.device.d/puppet-override.conf') - .with_ensure('present') - .with_mode('0444') - .with_owner('root') - .with_group('root') - end - it 'should contain a systemctl-reload exec' do - is_expected.to contain_exec('systemd daemon-reload for usbstick.device') - .with_refreshonly(true) - end - end - describe 'when the corresponding service is defined (implicit name)' do - let(:pre_condition) { - """ - service { 'hhvm': ensure => running} - """ - } - let(:title) { 'hhvm' } - let(:params) { - { - :ensure => 'present', - :content => 'dummy', - } - } - it { should compile } - it { - is_expected.to contain_exec('systemd daemon-reload for hhvm.service') - .that_comes_before('Service[hhvm]') - } - describe 'when managing the service restarts' do + context 'when the corresponding service is defined (implicit name)' do + let(:pre_condition) { "service { 'hhvm': ensure => running, provider => 'systemd'}" } + let(:title) { 'hhvm' } let(:params) { { :ensure => 'present', :content => 'dummy', - :restart => true + } + } + it { is_expected.to compile } + it { + is_expected.to contain_exec('systemd daemon-reload for hhvm.service') + .that_comes_before('Service[hhvm]') + } + context 'when managing the service restarts' do + let(:params) { + { + :ensure => 'present', + :content => 'dummy', + :restart => true + } + } + it { should compile } + it { + is_expected.to contain_exec('systemd daemon-reload for hhvm.service') + .that_notifies('Service[hhvm]') + } + end + end + + context 'when using dummy parameters and a name without type' do + let(:title) { 'dummyservice' } + let(:params) { + { + :ensure => 'present', + :content => 'dummy' } } it { should compile } - it { - is_expected.to contain_exec('systemd daemon-reload for hhvm.service') - .that_notifies('Service[hhvm]') + + describe 'then the systemd service' do + it 'should define a unit file in the system directory' do + is_expected.to contain_file('/lib/systemd/system/dummyservice.service') + .with_content('dummy') + .that_notifies( + "Exec[systemd daemon-reload for dummyservice.service]" + ) + end + + it 'should contain a systemctl-reload exec' do + is_expected.to contain_exec('systemd daemon-reload for dummyservice.service') + .with_refreshonly(true) + end + end + end + + context 'when the title includes the unit type and is an override' do + let(:title) { 'usbstick.device' } + let(:params) { + { + :ensure => 'present', + :content => 'dummy', + :override => true + } } + it { should compile } + + it 'should define the parent directory of the override file' do + is_expected.to contain_file('/etc/systemd/system/usbstick.device.d') + .with_ensure('directory') + .with_owner('root') + .with_group('root') + .with_mode('0555') + end + it 'should define the systemd override file' do + is_expected.to contain_file('/etc/systemd/system/usbstick.device.d/puppet-override.conf') + .with_ensure('present') + .with_mode('0444') + .with_owner('root') + .with_group('root') + end + it 'should contain a systemctl-reload exec' do + is_expected.to contain_exec('systemd daemon-reload for usbstick.device') + .with_refreshonly(true) + end end end end diff --git a/modules/systemd/spec/spec_helper.rb b/modules/systemd/spec/spec_helper.rb index 421fd71..f603826 100644 --- a/modules/systemd/spec/spec_helper.rb +++ b/modules/systemd/spec/spec_helper.rb @@ -1,6 +1,8 @@ require 'rspec-puppet' require 'puppetlabs_spec_helper/module_spec_helper' +require 'rspec-puppet-facts' +include RspecPuppetFacts fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) RSpec.configure do |c| -- To view, visit https://gerrit.wikimedia.org/r/394274 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: If05f38643ca2977d73bbe34f4af156f6178efd2b Gerrit-PatchSet: 2 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Alexandros Kosiaris <akosia...@wikimedia.org> Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits