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 25, 2024
1 parent 0ca4ae0 commit 9ced038
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 52 deletions.
43 changes: 41 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 @@ -35,6 +38,8 @@
# Wheter to enable cluster mode.
# @param execution_mode
# Set the execution mode to 'active' or 'passive'.
# @param api_token_max_duration
# Set the token max duration.
# @param java_home
# Set the home directory of java.
# @param jvm_args
Expand Down Expand Up @@ -106,6 +111,18 @@
# Allows you to use your own override template instead to config rundeckd init script.
# @param service_script
# Allows you to use your own override template instead of the default from the package maintainer for rundeckd init script.
# @param manage_cli
# Wheter to manage rundeck cli config and resource with the rundeck class or not.
# @param cli_version
# Ensure the state of the rundeck cli package, either present, absent or a specific version.
# @param cli_user
# Cli user to authenticate.
# @param cli_password
# Cli password to authenticate.
# @param cli_token
# Cli token to authenticate.
# @param cli_projects
# Cli projects config.
#
class rundeck (
Stdlib::Absolutepath $override_dir,
Expand Down Expand Up @@ -222,6 +239,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[String, Rundeck::Project] $cli_projects = {},
) {
validate_rd_policy($admin_policies)
validate_rd_policy($api_policies)
Expand All @@ -239,4 +262,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']
}
}
16 changes: 8 additions & 8 deletions spec/classes/config/ssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
it { is_expected.to contain_file('/etc/rundeck/ssl').with('ensure' => 'directory') }
it { is_expected.to contain_file('/etc/rundeck/ssl/ssl.properties') }

it {
it do
is_expected.to contain_java_ks('keystore').with(
ensure: 'present',
certificate: '/etc/rundeck/ssl/rundeck.crt',
Expand All @@ -35,15 +35,15 @@
password: 'adminadmin',
target: '/etc/rundeck/ssl/keystore'
)
}
end

it {
it do
is_expected.to contain_java_ks('truststore').with(
ensure: 'present',
password: 'adminadmin',
target: '/etc/rundeck/ssl/truststore'
)
}
end

ssl_details.each do |key, value|
it 'generates valid content for ssl.properties' do
Expand All @@ -61,19 +61,19 @@
}
end

it {
it do
is_expected.to contain_java_ks('keystore').with(
ensure: 'present',
destkeypass: 'verysecure'
)
}
end

it {
it do
is_expected.to contain_java_ks('truststore').with(
ensure: 'present',
destkeypass: 'verysecure'
)
}
end

it 'generates valid content for ssl.properties' do
content = catalogue.resource('file', '/etc/rundeck/ssl/ssl.properties')[:content]
Expand Down
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
31 changes: 9 additions & 22 deletions spec/classes/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
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']
Expand All @@ -35,7 +34,7 @@
'name' => 'rundeck.asc',
'content' => %r{^-----BEGIN PGP PUBLIC KEY BLOCK-----},
}
)
).that_comes_before('Package[rundeck]')
end

it { is_expected.to contain_class('apt::update').that_comes_before('Package[rundeck]') }
Expand All @@ -54,13 +53,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 @@ -75,20 +74,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
12 changes: 6 additions & 6 deletions spec/defines/config/aclpolicyfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
}
end

it {
it do
is_expected.to contain_file('/etc/rundeck/test.aclpolicy').with(
owner: 'rundeck',
group: 'rundeck',
mode: '0644',
content: test_acl
)
}
end
end

context 'with test acl and custom parameters' do
Expand All @@ -112,22 +112,22 @@
}
end

it {
it do
is_expected.to contain_file('/etc/rundeck-acl').with(
ensure: 'directory',
owner: 'myUser',
group: 'myGroup',
mode: '0755'
)
}
end

it {
it do
is_expected.to contain_file('/etc/rundeck-acl/test.aclpolicy').with(
owner: 'myUser',
group: 'myGroup',
mode: '0644',
content: test_acl
)
}
end
end
end

0 comments on commit 9ced038

Please sign in to comment.