diff --git a/manifests/config.pp b/manifests/config.pp index 73d8b08..7c03467 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -115,9 +115,12 @@ group => $choria::config_group, mode => "0640", content => choria::hash2config($config), - notify => Class["choria::service"], require => Class["choria::install"] } + + if $choria::server { + File[$choria::server_config_file] ~> Class["choria::service"] + } } if $choria::server_provisioning_token { @@ -126,9 +129,12 @@ group => $choria::config_group, mode => "0640", content => $choria::server_provisioning_token, - notify => Class["choria::service"], require => Class["choria::install"], } + + if $choria::server { + File[$choria::server_config_file] ~> Class["choria::service"] + } } } diff --git a/manifests/init.pp b/manifests/init.pp index 04afa66..d89e746 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -87,10 +87,24 @@ class{"choria::install": } -> class{"choria::config": } -> class{"choria::scout_checks": } - -> class{"choria::service": } + + # We use a different class to disable choria service than enable it + # to help the discovery system find machines where the service is actually + # running vs those with it off - it searches on all machines with class + # choria::service so this facilitates client oly installs by setting server false + if $server { + class{"choria::service": + require => Class["choria::scout_checks"] + } + contain choria::service + } else { + class{"choria::service_disable": + require => Class["choria::scout_checks"] + } + contain choria::service_disable + } contain choria::install contain choria::scout_checks contain choria::scout_metrics - contain choria::service } diff --git a/manifests/service.pp b/manifests/service.pp index 3d31f2f..5630cda 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -8,27 +8,16 @@ if $choria::server { service{$choria::server_service_name: ensure => "running", - enable => true + enable => true, } - # Since the installation of mcollective plugins are handled in another module at - # the moment we have to do this ugly hackery here to ensure we restart choria - # service when new plugins are installed - # - # Eventually this module will own installation of plugins and things will improve - # for now its a bit meh - Service<| title == "mcollective" |> ~> Service[$choria::server_service_name] + # Ensures that module plugin changes will restart choria + Mcollective::Module_plugin <| |> ~> Service[$choria::server_service_name] # Without this when a mcollective plugin is removed if purge is on the service # would not be restarted, unfortunate side effect that a client uninstall will # also yield a restart File<| tag == "mcollective::plugin_dirs" |> ~> Service[$choria::server_service_name] - - } else { - service{$choria::server_service_name: - ensure => "stopped", - enable => false - } } } } diff --git a/manifests/service_disable.pp b/manifests/service_disable.pp new file mode 100644 index 0000000..2a40fad --- /dev/null +++ b/manifests/service_disable.pp @@ -0,0 +1,16 @@ +# Manages the `choria-server` service +# +# @private +class choria::service_disable { + assert_private() + + if $choria::manage_service { + if !$choria::server { + service{$choria::server_service_name: + ensure => "stopped", + enable => false + } + } + } +} + diff --git a/spec/classes/broker_spec.rb b/spec/classes/broker_spec.rb index 6e58ca7..c7e691c 100644 --- a/spec/classes/broker_spec.rb +++ b/spec/classes/broker_spec.rb @@ -3,7 +3,7 @@ describe 'choria' do let :node do - 'rspec.puppet.com' + "rspec.puppet.com" end on_supported_os.each do |os, facts| diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index bec34c8..2f2b07a 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -13,85 +13,85 @@ end context 'with all defaults' do it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_class('choria') } - it { is_expected.to contain_class('choria::config') } - it { is_expected.to contain_class('choria::install') } - it { is_expected.to contain_class('choria::service') } - it { is_expected.to contain_class('choria::scout_checks') } - it { is_expected.to contain_class('choria::scout_metrics') } - - if facts[:kernel] == 'windows' - it { is_expected.not_to contain_service('choria-server') } + it { is_expected.to contain_class("choria") } + it { is_expected.to contain_class("choria::config") } + it { is_expected.to contain_class("choria::install") } + it { is_expected.to contain_class("choria::service") } + it { is_expected.to contain_class("choria::scout_checks") } + it { is_expected.to contain_class("choria::scout_metrics") } + + if facts[:kernel] == "windows" + it { is_expected.not_to contain_service("choria-server") } else - it { is_expected.to contain_service('choria-server').with_ensure('running').with_enable('true') } - end - - context 'on Windows', if: facts[:kernel] == 'windows' do - it { is_expected.to contain_file('C:/Program Files/choria/bin/choria_mcollective_agent_compat.bat') } - it { is_expected.to contain_file('C:/Program Files/choria/bin/choria_mcollective_agent_compat.rb') } - it { is_expected.to contain_file('C:/ProgramData/choria/etc/machine').with_ensure('directory') } - it { is_expected.to contain_file('C:/ProgramData/choria/etc/overrides.json') } - it { is_expected.to contain_file('C:/ProgramData/choria/etc/server.conf') } - end - context 'on linux', if: facts[:kernel] == 'Linux' do - it { is_expected.to contain_file('/etc/choria/machine') } - it { is_expected.to contain_file('/etc/choria/machine') } - it { is_expected.to contain_file('/etc/choria/machine') } - it { is_expected.to contain_file('/etc/choria/machine') } - it { is_expected.to contain_file('/etc/choria/overrides.json') } - it { is_expected.to contain_file('/etc/choria/plugin.d').with_ensure('link') } - it { is_expected.to contain_file('/etc/choria/policies').with_ensure('link') } - it { is_expected.to contain_file('/etc/choria/machine').with_ensure('directory') } - end - context 'on FreeBSD', if: facts[:os]['name'] == 'FreeBSD' do - it { is_expected.to contain_file('/usr/local/bin/choria_mcollective_agent_compat.rb') } - it { is_expected.to contain_file('/usr/local/etc/choria/overrides.json') } - it { is_expected.to contain_file('/usr/local/etc/choria/plugin.d').with_ensure('link') } - it { is_expected.to contain_file('/usr/local/etc/choria/policies').with_ensure('link') } - it { is_expected.to contain_file('/usr/local/etc/choria/server.conf') } - it { is_expected.to contain_file('/usr/local/etc/choria/machine').with_ensure('directory') } - end - - if ['FreeBSD', 'AIX', 'Solaris', 'windows', 'SLES'].include? facts[:os]['name'] - it { is_expected.not_to contain_class('choria::repo') } + it { is_expected.to contain_service("choria-server").with_ensure("running").with_enable("true") } + end + + context "on Windows", if: facts[:kernel] == "windows" do + it { is_expected.to contain_file("C:/Program Files/choria/bin/choria_mcollective_agent_compat.bat") } + it { is_expected.to contain_file("C:/Program Files/choria/bin/choria_mcollective_agent_compat.rb") } + it { is_expected.to contain_file("C:/ProgramData/choria/etc/machine").with_ensure("directory") } + it { is_expected.to contain_file("C:/ProgramData/choria/etc/overrides.json") } + it { is_expected.to contain_file("C:/ProgramData/choria/etc/server.conf") } + end + context "on linux", if: facts[:kernel] == "Linux" do + it { is_expected.to contain_file("/etc/choria/machine") } + it { is_expected.to contain_file("/etc/choria/machine") } + it { is_expected.to contain_file("/etc/choria/machine") } + it { is_expected.to contain_file("/etc/choria/machine") } + it { is_expected.to contain_file("/etc/choria/overrides.json") } + it { is_expected.to contain_file("/etc/choria/plugin.d").with_ensure("link") } + it { is_expected.to contain_file("/etc/choria/policies").with_ensure("link") } + it { is_expected.to contain_file("/etc/choria/machine").with_ensure("directory") } + end + context "on FreeBSD", if: facts[:os]["name"] == "FreeBSD" do + it { is_expected.to contain_file("/usr/local/bin/choria_mcollective_agent_compat.rb") } + it { is_expected.to contain_file("/usr/local/etc/choria/overrides.json") } + it { is_expected.to contain_file("/usr/local/etc/choria/plugin.d").with_ensure("link") } + it { is_expected.to contain_file("/usr/local/etc/choria/policies").with_ensure("link") } + it { is_expected.to contain_file("/usr/local/etc/choria/server.conf") } + it { is_expected.to contain_file("/usr/local/etc/choria/machine").with_ensure("directory") } + end + + if ["FreeBSD", "AIX", "Solaris", "windows", "SLES"].include? facts[:os]["name"] + it { is_expected.not_to contain_class("choria::repo") } else - it { is_expected.to contain_class('choria::repo') } + it { is_expected.to contain_class("choria::repo") } end end - context 'repo related tests' do - context 'should not manage the repo if its disabled' do + context "repo related tests" do + context "should not manage the repo if its disabled" do let :params do { manage_package_repo: false } end - it { is_expected.to_not contain_class('choria::repo') } + it { is_expected.to_not contain_class("choria::repo") } end - context 'with manage_package_repo set to true' do + context "with manage_package_repo set to true" do let :params do { manage_package_repo: true } end - if facts[:kernel] == 'Linux' and facts[:os]['family'] != 'Suse' + if facts[:kernel] == "Linux" and facts[:os]["family"] != "Suse" it { is_expected.to contain_class("choria::repo").with_nightly(false) } it { is_expected.to contain_class("choria::repo").with_ensure("present") } else it { is_expected.to compile.and_raise_error(/Choria Repositories are not supported on/) } end - context 'on Debian OS family', if: facts[:os]['family'] == 'Debian' do - it { is_expected.to contain_apt__source('choria-release') } - it { is_expected.to contain_apt__source('choria-nightly') } + context "on Debian OS family", if: facts[:os]["family"] == "Debian" do + it { is_expected.to contain_apt__source("choria-release") } + it { is_expected.to contain_apt__source("choria-nightly") } end - context 'on RedHat OS family', if: facts[:os]['family'] == 'RedHat' do - it { is_expected.to contain_yumrepo('choria_nightly') } - it { is_expected.to contain_yumrepo('choria_release') } + context "on RedHat OS family", if: facts[:os]["family"] == "RedHat" do + it { is_expected.to contain_yumrepo("choria_nightly") } + it { is_expected.to contain_yumrepo("choria_release") } end end - context 'with managed repos', if: (facts[:kernel] == 'Linux' and facts[:os]['family'] != 'Suse') do + context "with managed repos", if: (facts[:kernel] == "Linux" and facts[:os]["family"] != "Suse") do let(:params) do { "manage_package_repo" => true, @@ -106,55 +106,56 @@ end end - context 'with custom repo on CentOS', if: facts[:os]['name'] == 'CentOS' do + context "with custom repo on CentOS", if: facts[:os]["name"] == "CentOS" do let(:params) do { "manage_package_repo" => true, - "repo_baseurl" => 'http://internal-mirror.com/choria' + "repo_baseurl" => "http://internal-mirror.com/choria" } end it "should support managing the repo by default" do is_expected.to contain_class("choria::repo").with_nightly(false) is_expected.to contain_class("choria::repo").with_ensure("present") - is_expected.to contain_yumrepo("choria_release").with_ensure("present").with_baseurl('http://internal-mirror.com/choria/release/el/$releasever/$basearch') + is_expected.to contain_yumrepo("choria_release").with_ensure("present").with_baseurl("http://internal-mirror.com/choria/release/el/$releasever/$basearch") end end - context "when managing an ubuntu bionic node", if: facts[:os]['release']['major'] == '18.04' do + context "when managing an ubuntu bionic node", if: facts[:os]["release"]["major"] == "18.04" do let(:params) do { "manage_package_repo" => true, - "repo_baseurl" => 'http://internal-mirror.com/choria' + "repo_baseurl" => "http://internal-mirror.com/choria" } end it "should manage the main repo" do is_expected.to contain_class("choria::repo").with_nightly(false) is_expected.to contain_class("choria::repo").with_ensure("present") - is_expected.to contain_file('/etc/apt/sources.list.d/choria-release.list') - is_expected.to contain_apt__source('choria-release').with(release: 'bionic') - .with(location: 'http://internal-mirror.com/choria/release/ubuntu/') + is_expected.to contain_file("/etc/apt/sources.list.d/choria-release.list") + is_expected.to contain_apt__source("choria-release").with(release: "bionic") + .with(location: "http://internal-mirror.com/choria/release/ubuntu/") end end - context "when managing an ubuntu xenial node", if: facts[:os]['release']['major'] == '16.04' do + context "when managing an ubuntu xenial node", if: facts[:os]["release"]["major"] == "16.04" do let :params do { "manage_package_repo" => true, - "repo_baseurl" => 'http://internal-mirror.com/choria' + "repo_baseurl" => "http://internal-mirror.com/choria" } end it "should manage the main repo" do - is_expected.to contain_file('/etc/apt/sources.list.d/choria-release.list') - is_expected.to contain_apt__source('choria-release') - .with(release: 'xenial') - .with(location: 'http://internal-mirror.com/choria/release/ubuntu/') + is_expected.to contain_file("/etc/apt/sources.list.d/choria-release.list") + is_expected.to contain_apt__source("choria-release") + .with(release: "xenial") + .with(location: "http://internal-mirror.com/choria/release/ubuntu/") end end end - context "default server config", if: facts[:kernel] == 'Linux' do + + context "default server config", if: facts[:kernel] == "Linux" do it "should work out of the box" do is_expected.to contain_file("/etc/choria/server.conf") .with_content(/logfile = .var.log.choria.log/) @@ -182,7 +183,7 @@ end end - context "custom server config", if: facts[:kernel] == 'Linux' do + context "custom server config", if: facts[:kernel] == "Linux" do let :params do { server_config: { @@ -197,7 +198,7 @@ end end - context "custom logging", if: facts[:kernel] == 'Linux' do + context "custom logging", if: facts[:kernel] == "Linux" do let :params do { server_logfile: "/var/log/choria-server.log", @@ -210,19 +211,20 @@ .with_content(/loglevel = debug/) end end + context "with package set to a specific version" do let :params do - { version: '1.2.3' } + { version: "1.2.3" } end - if facts[:kernel] == 'SunOS' and facts[:os]['release']['major'].to_i == 10 + if facts[:kernel] == "SunOS" and facts[:os]["release"]["major"].to_i == 10 it { is_expected.not_to compile } else it { is_expected.to compile.with_all_deps } end - if facts[:kernel] == 'windows' - it { is_expected.not_to contain_package('choria') } + if facts[:kernel] == "windows" + it { is_expected.not_to contain_package("choria") } else it "should use the correct ensure value" do is_expected.to contain_package("choria").with_ensure("1.2.3") @@ -230,21 +232,43 @@ end end - context 'with package ensure set to absent' do + context "with package ensure set to absent" do let :params do - { ensure: 'absent' } + { ensure: "absent" } end - it { should compile.with_all_deps } + it { should compile.with_all_deps } - if facts[:kernel] == 'windows' - it { is_expected.not_to contain_package('choria') } + if facts[:kernel] == "windows" + it { is_expected.not_to contain_package("choria") } else - it 'should use the correct ensure value' do - is_expected.to contain_package('choria').with_ensure('absent') + it "should use the correct ensure value" do + is_expected.to contain_package("choria").with_ensure("absent") end end end + + context "with server enabled" do + let :params do + { server: true } + end + + it { should compile.with_all_deps } + + it { is_expected.to contain_class("choria::service") } + it { is_expected.not_to contain_class("choria::service_disable") } + end + + context "with server disabled" do + let :params do + { server: false } + end + + it { should compile.with_all_deps } + + it { is_expected.to contain_class("choria::service_disable") } + it { is_expected.not_to contain_class("choria::service") } + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f1a67b8..f4e9ef4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require 'rspec-puppet-facts' +require "rspec-puppet-facts" include RspecPuppetFacts require "rspec-puppet/spec_helper"