diff --git a/manifests/cli.pp b/manifests/cli.pp index 0230cef1..7ad775d7 100644 --- a/manifests/cli.pp +++ b/manifests/cli.pp @@ -75,6 +75,7 @@ $projects.each |$_name, $_attr| { rundeck::config::project { $_name: + * => $_attr, require => Exec['Check rundeck cli connection'], } } diff --git a/spec/classes/cli_spec.rb b/spec/classes/cli_spec.rb index 4f3785c6..da7787ce 100644 --- a/spec/classes/cli_spec.rb +++ b/spec/classes/cli_spec.rb @@ -10,33 +10,124 @@ end context 'with default parameters' do - it { is_expected.not_to compile } - end + it { is_expected.to compile } - context 'with manage_repo => true' do - let(:params) do - { - 'manage_repo' => true, - } - end + it { is_expected.to contain_package('jq').with(ensure: 'present') } case facts[:os]['family'] when 'RedHat' - it do + it { is_expected.to contain_yumrepo('rundeck').with( baseurl: 'https://packages.rundeck.com/pagerduty/rundeck/rpm_any/rpm_any/$basearch', repo_gpgcheck: 1, gpgcheck: 0, enabled: 1, gpgkey: 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey' - ).that_comes_before('Package[rundeck]') - end + ).that_comes_before('Package[rundeck-cli]') + } when 'Debian' - it { is_expected.to contain_apt__source('rundeck').with_location('https://packages.rundeck.com/pagerduty/rundeck/any') } - it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') } - it { is_expected.to contain_package('rundeck').that_notifies('Class[rundeck::service]') } + it { + is_expected.to contain_apt__source('rundeck').with( + location: 'https://packages.rundeck.com/pagerduty/rundeck/any', + release: 'any', + repos: 'main', + key: { + 'name' => 'rundeck', + 'source' => 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey', + } + ).that_comes_before('Package[rundeck-cli]') + } + + it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck-cli]') } + it { is_expected.to contain_package('rundeck-cli').with(ensure: 'installed') } + it { is_expected.to contain_file('/usr/local/bin/rd_project_diff.sh').with(ensure: 'file', mode: '0755') } + + it { + is_expected.to contain_exec('Check rundeck cli connection').with( + command: 'rd system info', + path: ['/bin', '/usr/bin', '/usr/local/bin'], + environment: [ + 'RD_FORMAT=json', + 'RD_URL=http://localhost:4440', + 'RD_BYPASS_URL=http://localhost:4440', + 'RD_USER=admin', + 'RD_PASSWORD=admin', + ], + tries: 60, + try_sleep: 5, + unless: 'rd system info &> /dev/null' + ).that_requires('Package[rundeck-cli]') + } end end + + context 'with different urls and token auth' do + let(:params) do + { + url: 'http://rundeck01.example.com', + bypass_url: 'http://rundeck.example.com', + token: 'very_secure' + } + end + + it { + is_expected.to contain_exec('Check rundeck cli connection').with( + environment: [ + 'RD_FORMAT=json', + 'RD_URL=http://rundeck01.example.com', + 'RD_BYPASS_URL=http://rundeck.example.com', + 'RD_TOKEN=very_secure', + ] + ) + } + end + + context 'with projects config' do + let(:params) do + { + projects: { + 'MyProject' => { + 'update_method' => 'set', + 'config' => { + 'project.description' => 'This is My rundeck project', + 'project.disable.executions' => 'false', + }, + }, + 'TestProject' => { + 'config' => { + 'project.description' => 'This is a rundeck test project', + 'project.disable.schedule' => 'false', + }, + }, + }, + } + end + + it { + is_expected.to contain_rundeck__config__project('MyProject').with( + update_method: 'set', + config: { + 'project.description' => 'This is My rundeck project', + 'project.disable.executions' => 'false', + } + ) + } + + it { is_expected.to contain_exec('Create rundeck project: MyProject') } + it { is_expected.to contain_exec('Manage rundeck project: MyProject') } + + it { + is_expected.to contain_rundeck__config__project('TestProject').with( + config: { + 'project.description' => 'This is a rundeck test project', + 'project.disable.schedule' => 'false', + } + ) + } + + it { is_expected.to contain_exec('Create rundeck project: TestProject') } + it { is_expected.to contain_exec('Manage rundeck project: TestProject') } + end end end end diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index d25d2de0..3b16e179 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -12,15 +12,15 @@ facts end - context 'without any parameters test rundeck::config' do - it { is_expected.to contain_file('/var/lib/rundeck').with('ensure' => 'directory') } - it { is_expected.to contain_file('/var/lib/rundeck/libext').with('ensure' => 'directory') } - it { is_expected.to contain_file('/etc/rundeck').with('ensure' => 'directory') } - it { is_expected.to contain_file('/var/lib/rundeck/var').with('ensure' => 'directory') } - it { is_expected.to contain_file('/var/lib/rundeck/var/tmp').with('ensure' => 'directory') } - it { is_expected.to contain_file('/var/lib/rundeck/var/logs').with('ensure' => 'directory') } + context 'with default parameters test rundeck::config' do + it { is_expected.to contain_file('/var/lib/rundeck').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/libext').with(ensure: 'directory') } + it { is_expected.to contain_file('/etc/rundeck').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/var').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/var/tmp').with(ensure: 'directory') } + it { is_expected.to contain_file('/var/lib/rundeck/var/logs').with(ensure: 'directory') } - it { is_expected.to contain_file('/var/log/rundeck').with('ensure' => 'directory') } + it { is_expected.to contain_file('/var/log/rundeck').with(ensure: 'directory') } it { is_expected.to contain_file('/etc/rundeck/log4j2.properties') } @@ -50,8 +50,8 @@ it { is_expected.to contain_class('rundeck::config::jaas_auth') } it { is_expected.to contain_class('rundeck::config::framework') } - it { is_expected.to contain_file('/etc/rundeck/project.properties').with('ensure' => 'absent') } - it { is_expected.to contain_file('/etc/rundeck/rundeck-config.properties').with('ensure' => 'file') } + it { is_expected.to contain_file('/etc/rundeck/project.properties').with(ensure: 'absent') } + it { is_expected.to contain_file('/etc/rundeck/rundeck-config.properties').with(ensure: 'file') } it 'generates valid content for rundeck-config.properties' do content = catalogue.resource('file', '/etc/rundeck/rundeck-config.properties')[:content] diff --git a/spec/classes/install_spec.rb b/spec/classes/install_spec.rb index 698a08a2..282f9511 100644 --- a/spec/classes/install_spec.rb +++ b/spec/classes/install_spec.rb @@ -9,14 +9,13 @@ facts end - context 'without any parameters test rundeck::install' do - let(:params) { {} } - + context 'with default parameters test rundeck::install' do + it { is_expected.not_to contain_group('rundeck') } it { is_expected.not_to contain_user('rundeck') } case facts[:os]['family'] when 'RedHat' - it do + it { is_expected.to contain_yumrepo('rundeck').with( baseurl: 'https://packages.rundeck.com/pagerduty/rundeck/rpm_any/rpm_any/$basearch', repo_gpgcheck: 1, @@ -24,11 +23,22 @@ enabled: 1, gpgkey: 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey' ).that_comes_before('Package[rundeck]') - end + } when 'Debian' - it { is_expected.to contain_apt__source('rundeck').with_location('https://packages.rundeck.com/pagerduty/rundeck/any') } + it { + is_expected.to contain_apt__source('rundeck').with( + location: 'https://packages.rundeck.com/pagerduty/rundeck/any', + release: 'any', + repos: 'main', + key: { + 'name' => 'rundeck', + 'source' => 'https://packages.rundeck.com/pagerduty/rundeck/gpgkey', + } + ).that_comes_before('Package[rundeck]') + } + it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') } - it { is_expected.to contain_package('rundeck').that_notifies('Class[rundeck::service]') } + it { is_expected.to contain_package('rundeck').with(ensure: 'installed') } end end @@ -42,13 +52,13 @@ } end - it { is_expected.to contain_group('A1234').with('ensure' => 'present') } + it { is_expected.to contain_group('A1234').with(ensure: 'present') } - it { is_expected.to contain_group('rundeck').with('ensure' => 'absent') } + it { is_expected.to contain_group('rundeck').with(ensure: 'absent') } - it { is_expected.to contain_user('A1234').with('ensure' => 'present') } + it { is_expected.to contain_user('A1234').with(ensure: 'present') } - it { is_expected.to contain_user('rundeck').with('ensure' => 'absent') } + it { is_expected.to contain_user('rundeck').with(ensure: 'absent') } end context 'different user and group with ids' do @@ -63,20 +73,8 @@ } end - it do - is_expected.to contain_group('A1234').with( - 'ensure' => 'present', - 'gid' => 10_000 - ) - end - - it do - is_expected.to contain_user('A1234').with( - 'ensure' => 'present', - 'gid' => '10000', - 'uid' => '10000' - ) - end + it { is_expected.to contain_group('A1234').with(ensure: 'present', gid: 10_000) } + it { is_expected.to contain_user('A1234').with(ensure: 'present', gid: 10_000, uid: 10_000) } end end end diff --git a/spec/classes/rundeck_spec.rb b/spec/classes/rundeck_spec.rb index 9f434c1b..148471ff 100644 --- a/spec/classes/rundeck_spec.rb +++ b/spec/classes/rundeck_spec.rb @@ -9,9 +9,7 @@ facts end - context 'without any parameters test rundeck' do - let(:params) { {} } - + context 'with default parameters test rundeck' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('rundeck::install').that_comes_before('Class[rundeck::config]') } it { is_expected.to contain_class('rundeck::config').that_notifies('Class[rundeck::service]') } @@ -59,6 +57,17 @@ expect(content).to include('rundeck.server.uuid = ac7c2cbd-14fa-5ba3-b3f2-d436e9b8a3b0') end end + + context 'with manage_cli => false' do + let(:params) do + { + manage_cli: false + } + end + + it { is_expected.to compile.with_all_deps } + it { is_expected.not_to contain_class('rundeck::cli') } + end end end end diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 23428d89..615873a2 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -9,10 +9,8 @@ facts end - context 'without any parameters test rundeck::service' do - let(:params) { {} } - - it { is_expected.to contain_service('rundeckd') } + context 'with default parameters test rundeck::service' do + it { is_expected.to contain_service('rundeckd').with(ensure: 'running') } end end end