diff --git a/manifests/config.pp b/manifests/config.pp index 12dd701..af7dbf2 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,7 +1,9 @@ -# == Class: selenium::config +# == Define: selenium::config # -# This class should be considered private. +# This define should be considered private. # +# Note that selenium::params && selnenium::install must be included in the +# manifest before this define may be used. # # === Parameters # @@ -10,7 +12,7 @@ # # === Examples # -# class{ 'selenium::config': } +# selenium::config{ 'seleniumstandalone': } # # # === Authors @@ -18,12 +20,26 @@ # Joshua Hoblitt # # -class selenium::config { +define selenium::config( + $display = $selenium::params::display, + $user = $selenium::params::user, + $group = $selenium::params::group, + $install_root = $selenium::params::install_root, + $options = $selenium::params::default_options, + $java = $selenium::params::java, + $jar_name = $selenium::install::jar_name, +) { + validate_string($display) + validate_string($user) + validate_string($group) + validate_string($install_root) + validate_string($options) + validate_string($java) - $options = '-Dwebdriver.enable.native.events=1' - $prog = 'selenium' + # prog is the 'name' of the init.d script. + $prog = $name - file { '/etc/init.d/selenium': + file { "/etc/init.d/${prog}": ensure => 'file', owner => 'root', group => 'root', diff --git a/manifests/install.pp b/manifests/install.pp index 04a082f..d0241e3 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -47,12 +47,12 @@ group => $selenium::server::group, } - file { $selenium::server::install_path: + file { $selenium::server::install_root: ensure => directory, } - $jar_path = "${selenium::server::install_path}/jars" - $log_path = "${selenium::server::install_path}/log" + $jar_path = "${selenium::server::install_root}/jars" + $log_path = "${selenium::server::install_root}/log" file { $jar_path: ensure => directory, diff --git a/manifests/params.pp b/manifests/params.pp index 582f2f3..2c7b117 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -4,10 +4,12 @@ # # class selenium::params { - $display = ':0' - $user = 'selenium' - $group = $user - $install_path = '/opt/selenium' + $display = ':0' + $user = 'selenium' + $group = $user + $install_root = '/opt/selenium' + $default_options = '-Dwebdriver.enable.native.events=1' + $java = 'java' case $::osfamily { 'redhat': {} diff --git a/manifests/server.pp b/manifests/server.pp index e430ffe..a2323e2 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -10,15 +10,25 @@ $display = $selenium::params::display, $user = $selenium::params::user, $group = $selenium::params::group, - $install_path = $selenium::params::install_path, + $install_root = $selenium::params::install_root, + $options = $selenium::params::default_options, + $java = $selenium::params::java, ) inherits selenium::params { validate_string($display) validate_string($user) validate_string($group) - validate_string($install_path) + validate_string($install_root) + validate_string($options) + validate_string($java) class { 'selenium::install': } -> - class { 'selenium::config': } -> + selenium::config{ 'seleniumstandalone': + display => $display, + user => $user, + group => $group, + install_root => $install_root, + java => $java, + } -> class { 'selenium::service': } -> Class[ 'selenium::server' ] diff --git a/spec/classes/selenium_config_spec.rb b/spec/classes/selenium_config_spec.rb deleted file mode 100644 index 15fe38d..0000000 --- a/spec/classes/selenium_config_spec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'spec_helper' - -describe 'selenium::config', :type => :class do - - context 'for osfamily RedHat' do - let(:facts) {{ :osfamily => 'RedHat' }} - - context 'no params' do - let :pre_condition do - "class { 'selenium::server': }" - end - - it do - should contain_class('selenium::config') - should contain_file('/etc/init.d/selenium').with({ - 'ensure' => 'file', - 'owner' => 'root', - 'group' => 'root', - 'mode' => '0755', - }). - with_content(/SLNM_DISPLAY=':0'/). - with_content(/SLNM_USER='selenium'/). - with_content(/SLNM_INSTALL_PATH='\/opt\/selenium'/). - with_content(/SLNM_JAR_NAME='selenium-server-standalone-2.35.0.jar'/). - with_content(/SLNM_OPTIONS='-Dwebdriver.enable.native.events=1'/). - with_content(/prog='selenium'/) - end - end - end - -end diff --git a/spec/classes/selenium_server_spec.rb b/spec/classes/selenium_server_spec.rb index 0cee2c1..e295476 100644 --- a/spec/classes/selenium_server_spec.rb +++ b/spec/classes/selenium_server_spec.rb @@ -6,7 +6,7 @@ it do should contain_class('selenium::server') should contain_class('selenium::install') - should contain_class('selenium::config') + should contain_file('/etc/init.d/seleniumstandalone') should contain_class('selenium::service') should contain_user(user).with_gid(group) should contain_group(group) @@ -68,8 +68,8 @@ end end - context 'install_path => /foo/selenium' do - let(:params) {{ :install_path => '/foo/selenium' }} + context 'install_root => /foo/selenium' do + let(:params) {{ :install_root => '/foo/selenium' }} it_behaves_like 'server', 'selenium', 'selenium' @@ -82,8 +82,40 @@ end end - context 'install_path => []' do - let(:params) {{ :install_path => [] }} + context 'install_root => []' do + let(:params) {{ :install_root => [] }} + + it 'should fail' do + expect { + should contain_class('selenium::server') + }.to raise_error + end + end + + context 'options => -foo' do + let(:params) {{ :options => '-foo' }} + + it_behaves_like 'server', 'selenium', 'selenium' + end + + context 'options => []' do + let(:params) {{ :options => [] }} + + it 'should fail' do + expect { + should contain_class('selenium::server') + }.to raise_error + end + end + + context 'java => /opt/java' do + let(:params) {{ :java => '/opt/java' }} + + it_behaves_like 'server', 'selenium', 'selenium' + end + + context 'java => []' do + let(:params) {{ :java => [] }} it 'should fail' do expect { diff --git a/spec/defines/selenium_config_spec.rb b/spec/defines/selenium_config_spec.rb new file mode 100644 index 0000000..19a69ed --- /dev/null +++ b/spec/defines/selenium_config_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe 'selenium::config', :type => :define do + let(:title) { 'seleniumstandalone' } + + shared_examples 'config' do |params| + let :pre_condition do + "include selenium::params, selenium::install" + end + + p = { + :display => ':0', + :user => 'selenium', + :install_root => '/opt/selenium', + :jar_name => 'selenium-server-standalone-2.35.0.jar', + :options => '-Dwebdriver.enable.native.events=1', + :java => 'java', + } + + if params + p.merge!(params) + end + + it do + should contain_file("/etc/init.d/#{title}").with({ + 'ensure' => 'file', + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0755', + }). + with_content(/# #{title} Selenium server init script/). + with_content(/SLNM_DISPLAY='#{p[:display]}'/). + with_content(/SLNM_USER='#{p[:user]}'/). + with_content(/SLNM_INSTALL_ROOT='#{p[:install_root]}'/). + with_content(/SLNM_JAR_NAME='#{p[:jar_name]}'/). + with_content(/SLNM_OPTIONS='#{p[:options]}'/). + with_content(/SLNM_JAVA='#{p[:java]}'/). + with_content(/prog='#{title}'/) + end + end + + context 'for osfamily RedHat' do + let(:facts) {{ :osfamily => 'RedHat' }} + + context 'no params' do + it_behaves_like 'config', {} + end + + context 'all params' do + params = { + :display => 'X:0', + :user => 'Xselenium', + :install_root => 'X/opt/selenium', + :jar_name => 'Xselenium-server-standalone-2.35.0.jar', + :options => 'X-Dwebdriver.enable.native.events=1', + :java => 'Xjava', + } + + let(:params) { params } + + it_behaves_like 'config', params + end + end + +end diff --git a/templates/init.d/selenium.erb b/templates/init.d/selenium.erb index c2f84dd..ac12034 100644 --- a/templates/init.d/selenium.erb +++ b/templates/init.d/selenium.erb @@ -1,6 +1,6 @@ #!/bin/sh # -# selenium +# <%= @prog %> Selenium server init script # # chkconfig: 2345 99 99 # @@ -22,17 +22,18 @@ # Source function library. . /etc/rc.d/init.d/functions -SLNM_DISPLAY='<%= scope.lookupvar('selenium::server::display') %>' -SLNM_USER='<%= scope.lookupvar('selenium::server::user') %>' -SLNM_INSTALL_PATH='<%= scope.lookupvar('selenium::server::install_path') %>' -SLNM_JAR_NAME='<%= scope.lookupvar('selenium::install::jar_name') %>' -SLNM_OPTIONS='<%= scope.lookupvar('selenium::config::options') %>' +SLNM_DISPLAY='<%= @display %>' +SLNM_USER='<%= @user %>' +SLNM_INSTALL_ROOT='<%= @install_root %>' +SLNM_JAR_NAME='<%= @jar_name %>' +SLNM_OPTIONS='<%= @options %>' +SLNM_JAVA='<%= @java %>' +prog='<%= @prog %>' -SLNM_LOG="${SLNM_INSTALL_PATH}/log/server.log" -SLNM_ERROR_LOG="${SLNM_INSTALL_PATH}/log/error.log" -SLNM_JAR="${SLNM_INSTALL_PATH}/jars/${SLNM_JAR_NAME}" +SLNM_LOG="${SLNM_INSTALL_ROOT}/log/${prog}_stdout.log" +SLNM_ERROR_LOG="${SLNM_INSTALL_ROOT}/log/${prog)_stderr.log" +SLNM_JAR="${SLNM_INSTALL_ROOT}/jars/${SLNM_JAR_NAME}" -prog='<%= scope.lookupvar('selenium::config::prog') %>' #config="" #[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog