diff --git a/CHANGELOG.md b/CHANGELOG.md index b7d93d6e..4d80f4a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix wildfly_resource's with array of hashes values. - Allow custom templates or file for module.xml. - Support for jgroups stacks. +- Rewrite functions in Puppet language. ## 2.0.1 diff --git a/functions/service_config.pp b/functions/service_config.pp new file mode 100644 index 00000000..6041daa6 --- /dev/null +++ b/functions/service_config.pp @@ -0,0 +1,68 @@ +function wildfly::service_config( + Enum['wildfly', 'jboss-eap'] $distribution, + String $version, + Enum['standalone', 'domain'] $mode, + Enum['sysvinit', 'systemd', 'upstart'] $init_system) { + + case $distribution { + + # intentionally not using $facts (see rspec-puppet #503) + + 'wildfly' : { + $conf_file = $::osfamily ? { + 'Debian' => '/etc/default/wildfly', + default => '/etc/default/wildfly.conf' + } + + $service_file = "wildfly-init-${downcase($::osfamily)}.sh" + + case [versioncmp($version, '10'), $init_system] { + [-1, default] : { + { + 'service_name' => 'wildfly', + 'conf_file' => $conf_file, + 'conf_template' => 'wildfly/wildfly.sysvinit.conf', + 'service_file' => "bin/init.d/${service_file}", + } + } + [default, 'systemd'] : { + { + 'service_name' => 'wildfly', + 'conf_file' => '/etc/wildfly/wildfly.conf', + 'conf_template' => 'wildfly/wildfly.systemd.conf', + 'service_file' => "docs/contrib/scripts/init.d/${service_file}", + 'systemd_template' => 'wildfly/wildfly.systemd.service', + } + } + [default, default] : { + { + 'service_name' => 'wildfly', + 'conf_file' => $conf_file, + 'conf_template' => 'wildfly/wildfly.sysvinit.conf', + 'service_file' => "docs/contrib/scripts/init.d/${service_file}", + } + } + } + } + 'jboss-eap' : { + case versioncmp($version, '7') { + -1 : { + { + 'service_name' => 'jboss-as', + 'conf_file' => '/etc/jboss-as/jboss-as.conf', + 'conf_template' => 'wildfly/wildfly.sysvinit.conf', + 'service_file' => "bin/init.d/jboss-as-${mode}.sh", + } + } + default : { + { + 'service_name' => 'jboss-eap', + 'conf_file' => '/etc/default/jboss-eap.conf', + 'conf_template' => 'wildfly/wildfly.sysvinit.conf', + 'service_file' => 'bin/init.d/jboss-eap-rhel.sh', + } + } + } + } + } +} diff --git a/lib/puppet/parser/functions/service_config.rb b/lib/puppet/parser/functions/service_config.rb deleted file mode 100644 index 42797f82..00000000 --- a/lib/puppet/parser/functions/service_config.rb +++ /dev/null @@ -1,58 +0,0 @@ -module Puppet::Parser::Functions - newfunction(:service_config, :type => :rvalue) do |args| - distribution = args[0] - version = args[1] - mode = args[2] - init_system = args[3] - - config = {} - - case distribution - when 'wildfly' - if function_versioncmp([version, '10']) >= 0 - if init_system == 'systemd' - config['systemd_native'] = true - config['systemd_template'] = 'wildfly/wildfly.systemd.service' - config['conf_file'] = '/etc/wildfly/wildfly.conf' - config['conf_template'] = 'wildfly/wildfly.systemd.conf' - else - path = 'docs/contrib/scripts/init.d' - end - else - path = 'bin/init.d' - end - - osfamily = lookupvar('osfamily') - config['service_file'] = "#{path}/wildfly-init-#{osfamily.downcase}.sh" - - unless config['systemd_native'] - case osfamily - when 'RedHat' - config['conf_file'] = '/etc/default/wildfly.conf' - when 'Debian' - config['conf_file'] = '/etc/default/wildfly' - end - config['conf_template'] = 'wildfly/wildfly.sysvinit.conf' - end - - config['service_name'] = 'wildfly' - when 'jboss-eap' - if function_versioncmp([version, '7']) >= 0 - config['service_file'] = 'bin/init.d/jboss-eap-rhel.sh' - config['conf_file'] = '/etc/default/jboss-eap.conf' - config['service_name'] = 'jboss-eap' - else - config['service_file'] = "bin/init.d/jboss-as-#{mode}.sh" - config['conf_file'] = '/etc/jboss-as/jboss-as.conf' - config['service_name'] = 'jboss-as' - end - config['conf_template'] = 'wildfly/wildfly.sysvinit.conf' - end - - if init_system == 'systemd' && config['systemd_template'].nil? - config['systemd_template'] = 'wildfly/wildfly.sysvinit.service' - end - - config - end -end diff --git a/manifests/service.pp b/manifests/service.pp index 750627e1..74679503 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,7 +1,7 @@ # Manages Wildfly service. class wildfly::service { - $config = service_config($wildfly::distribution, $wildfly::version, $wildfly::mode, $wildfly::init_system) + $config = wildfly::service_config($wildfly::distribution, $wildfly::version, $wildfly::mode, $wildfly::init_system) debug("${wildfly::distribution}.${wildfly::version}.${wildfly::mode}.${wildfly::init_system}: ${config}") @@ -9,9 +9,7 @@ $conf_template = pick($wildfly::conf_template, $config['conf_template']) $service_name = pick($wildfly::service_name, $config['service_name']) $service_file = pick($wildfly::service_file, $config['service_file']) - - $systemd_template = $config['systemd_template'] - $systemd_native = $config['systemd_native'] + $systemd_template = pick($wildfly::systemd_template, $config['systemd_template'], 'wildfly/wildfly.sysvinit.service') if !$wildfly::package_name { contain "wildfly::service::${wildfly::init_system}" diff --git a/manifests/service/systemd.pp b/manifests/service/systemd.pp index 3df8302d..22f24477 100644 --- a/manifests/service/systemd.pp +++ b/manifests/service/systemd.pp @@ -1,9 +1,9 @@ # Wildfly systemd configuration # class wildfly::service::systemd { - $systemd_template = pick($wildfly::systemd_template, $wildfly::service::systemd_template) - if $wildfly::service::systemd_native { + if $wildfly::service::systemd_template == 'wildfly/wildfly.systemd.service' { + # Use native script file { "${wildfly::dirname}/bin/launch.sh" : ensure => present, mode => '0755', diff --git a/spec/functions/service_config_spec.rb b/spec/functions/service_config_spec.rb index 9801f790..e0e9ccd4 100644 --- a/spec/functions/service_config_spec.rb +++ b/spec/functions/service_config_spec.rb @@ -1,16 +1,18 @@ -describe 'service_config' do +describe 'wildfly::service_config' do context 'Wildfly 10' do let(:distribution) { 'wildfly' } let(:version) { '10.0' } - before(:each) { scope.expects(:lookupvar).at_most_once.with('osfamily').returns('RedHat') } + let(:facts) do + { :osfamily => 'RedHat' } + end it 'using sysvinit' do - is_expected.to run.with_params(distribution, version, 'standalone', 'sysvinit').and_return('service_name' => 'wildfly', 'conf_file' => '/etc/default/wildfly.conf', 'service_file' => 'docs/contrib/scripts/init.d/wildfly-init-redhat.sh', 'conf_template' => 'wildfly/wildfly.sysvinit.conf') + is_expected.to run.with_params(distribution, version, 'standalone', 'sysvinit').and_return('service_name' => 'wildfly', 'conf_file' => '/etc/default/wildfly.conf', 'conf_template' => 'wildfly/wildfly.sysvinit.conf', 'service_file' => 'docs/contrib/scripts/init.d/wildfly-init-redhat.sh') end it 'using systemd' do - is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('systemd_native' => true, 'systemd_template' => 'wildfly/wildfly.systemd.service', 'conf_file' => '/etc/wildfly/wildfly.conf', 'conf_template' => 'wildfly/wildfly.systemd.conf', 'service_file' => '/wildfly-init-redhat.sh', 'service_name' => 'wildfly') + is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_name' => 'wildfly', 'conf_file' => '/etc/wildfly/wildfly.conf', 'conf_template' => 'wildfly/wildfly.systemd.conf', 'service_file' => 'docs/contrib/scripts/init.d/wildfly-init-redhat.sh', 'systemd_template' => 'wildfly/wildfly.systemd.service') end end @@ -18,14 +20,16 @@ let(:distribution) { 'wildfly' } let(:version) { '9.0.2' } - before(:each) { scope.expects(:lookupvar).with('osfamily').returns('RedHat') } + let(:facts) do + { :osfamily => 'RedHat' } + end it 'using sysvinit' do is_expected.to run.with_params(distribution, version, 'standalone', 'sysvinit').and_return('service_name' => 'wildfly', 'conf_file' => '/etc/default/wildfly.conf', 'service_file' => 'bin/init.d/wildfly-init-redhat.sh', 'conf_template' => 'wildfly/wildfly.sysvinit.conf') end it 'using systemd' do - is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_name' => 'wildfly', 'conf_file' => '/etc/default/wildfly.conf', 'service_file' => 'bin/init.d/wildfly-init-redhat.sh', 'conf_template' => 'wildfly/wildfly.sysvinit.conf', 'systemd_template' => 'wildfly/wildfly.sysvinit.service') + is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_name' => 'wildfly', 'conf_file' => '/etc/default/wildfly.conf', 'service_file' => 'bin/init.d/wildfly-init-redhat.sh', 'conf_template' => 'wildfly/wildfly.sysvinit.conf') end end @@ -38,7 +42,7 @@ end it 'using systemd' do - is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_file' => 'bin/init.d/jboss-eap-rhel.sh', 'conf_file' => '/etc/default/jboss-eap.conf', 'service_name' => 'jboss-eap', 'conf_template' => 'wildfly/wildfly.sysvinit.conf', 'systemd_template' => 'wildfly/wildfly.sysvinit.service') + is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_file' => 'bin/init.d/jboss-eap-rhel.sh', 'conf_file' => '/etc/default/jboss-eap.conf', 'service_name' => 'jboss-eap', 'conf_template' => 'wildfly/wildfly.sysvinit.conf') end end @@ -51,7 +55,7 @@ end it 'using systemd' do - is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_file' => 'bin/init.d/jboss-as-standalone.sh', 'conf_file' => '/etc/jboss-as/jboss-as.conf', 'service_name' => 'jboss-as', 'conf_template' => 'wildfly/wildfly.sysvinit.conf', 'systemd_template' => 'wildfly/wildfly.sysvinit.service') + is_expected.to run.with_params(distribution, version, 'standalone', 'systemd').and_return('service_file' => 'bin/init.d/jboss-as-standalone.sh', 'conf_file' => '/etc/jboss-as/jboss-as.conf', 'service_name' => 'jboss-as', 'conf_template' => 'wildfly/wildfly.sysvinit.conf') end end end