Skip to content

Commit

Permalink
convert class selenium::config into a define
Browse files Browse the repository at this point in the history
This is to allow selenium::config to create multiple init.d scripts in
the future for selenium hub and grid nodes.
  • Loading branch information
Joshua Hoblitt committed Oct 2, 2013
1 parent d742263 commit 50e63e6
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 63 deletions.
30 changes: 23 additions & 7 deletions manifests/config.pp
Original file line number Diff line number Diff line change
@@ -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
#
Expand All @@ -10,20 +12,34 @@
#
# === Examples
#
# class{ 'selenium::config': }
# selenium::config{ 'seleniumstandalone': }
#
#
# === Authors
#
# Joshua Hoblitt <jhoblitt@cpan.org>
#
#
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',
Expand Down
6 changes: 3 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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': {}
Expand Down
16 changes: 13 additions & 3 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]

Expand Down
31 changes: 0 additions & 31 deletions spec/classes/selenium_config_spec.rb

This file was deleted.

42 changes: 37 additions & 5 deletions spec/classes/selenium_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'

Expand All @@ -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 {
Expand Down
65 changes: 65 additions & 0 deletions spec/defines/selenium_config_spec.rb
Original file line number Diff line number Diff line change
@@ -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
21 changes: 11 additions & 10 deletions templates/init.d/selenium.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#
# selenium <summary>
# <%= @prog %> Selenium server init script
#
# chkconfig: 2345 99 99
#
Expand All @@ -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="<path to major config file>"
#[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
Expand Down

0 comments on commit 50e63e6

Please sign in to comment.