Skip to content

Commit

Permalink
Add cli support in rundeck class and update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joris29 committed Jan 16, 2024
1 parent 0dd4b4b commit 8bf5f4e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 41 deletions.
29 changes: 27 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# @summary Class to manage installation and configuration of Rundeck.
#
# @param manage_repo
# Whether to manage the package repository.
# @param override_dir
# An absolute path to the overrides directory.
# Examples/defaults for yumrepo can be found at RedHat.yaml, and for apt at Debian.yaml
# @param repo_config
# A hash of repository attributes for configuring the rundeck package repositories.
# Examples/defaults for yumrepo can be found at RedHat.yaml, and for apt at Debian.yaml
# @param manage_repo
# Whether to manage the package repository.
# @param package_ensure
# Ensure the state of the rundeck package, either present, absent or a specific version.
# @param manage_home
Expand Down Expand Up @@ -222,6 +225,12 @@
Boolean $service_notify = true,
Optional[String[1]] $service_config = undef,
Optional[String[1]] $service_script = undef,
Boolean $manage_cli = true,
String[1] $cli_version = 'installed',
String[1] $cli_user = 'admin',
String[1] $cli_password = 'admin',
Optional[String[8]] $cli_token = undef,
Hash $cli_projects = {},
) {
validate_rd_policy($admin_policies)
validate_rd_policy($api_policies)
Expand All @@ -239,4 +248,20 @@
-> Class['rundeck::config']
-> Class['rundeck::service']
}

if $manage_cli {
class { 'rundeck::cli':
manage_repo => false,
version => $cli_version,
url => $rundeck::config::framework_config['framework.server.url'],
bypass_url => $grails_server_url,
user => $cli_user,
password => $cli_password,
token => $cli_token,
projects => $cli_projects,
}

Class['rundeck::service']
-> Class['rundeck::cli']
}
}
18 changes: 11 additions & 7 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +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/log/rundeck').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('/etc/rundeck/log4j2.properties') }

Expand Down Expand Up @@ -46,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]
Expand Down
48 changes: 23 additions & 25 deletions spec/classes/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@
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,
gpgcheck: 0,
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

Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 14 additions & 3 deletions spec/classes/rundeck_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
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]') }
it { is_expected.to contain_class('rundeck::service') }
it { is_expected.to contain_class('rundeck::config::jaas_auth') }
it { is_expected.to contain_class('rundeck::config::framework') }
it { is_expected.not_to contain_class('rundeck::config::ssl') }
it { is_expected.to contain_class('rundeck::cli') }
end

context 'with service_notify => false' do
Expand All @@ -31,6 +30,7 @@
it { is_expected.to contain_class('rundeck::install').that_comes_before('Class[rundeck::config]') }
it { is_expected.to contain_class('rundeck::config').that_comes_before('Class[rundeck::service]') }
it { is_expected.to contain_class('rundeck::service') }
it { is_expected.to contain_class('rundeck::cli') }
end

context 'with ssl_enabled => true' do
Expand All @@ -57,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
6 changes: 2 additions & 4 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bf5f4e

Please sign in to comment.