From 8523e6670be132b929ba8c2348fb1eccfe96b220 Mon Sep 17 00:00:00 2001 From: Joshua Hoblitt Date: Wed, 2 Oct 2013 15:10:32 -0700 Subject: [PATCH] rename class selenium::install -> selenium and refactor it as common base --- manifests/config.pp | 7 +- manifests/{install.pp => init.pp} | 42 ++++---- manifests/params.pp | 4 +- manifests/server.pp | 23 ++--- spec/classes/selenium_install_spec.rb | 46 --------- spec/classes/selenium_server_spec.rb | 104 ++++---------------- spec/classes/selenium_spec.rb | 135 ++++++++++++++++++++++++++ spec/defines/selenium_config_spec.rb | 6 +- 8 files changed, 197 insertions(+), 170 deletions(-) rename manifests/{install.pp => init.pp} (55%) delete mode 100644 spec/classes/selenium_install_spec.rb create mode 100644 spec/classes/selenium_spec.rb diff --git a/manifests/config.pp b/manifests/config.pp index af7dbf2..495590f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -25,9 +25,9 @@ $user = $selenium::params::user, $group = $selenium::params::group, $install_root = $selenium::params::install_root, - $options = $selenium::params::default_options, + $options = $selenium::params::server_options, $java = $selenium::params::java, - $jar_name = $selenium::install::jar_name, + $jar_name = $selenium::jar_name, ) { validate_string($display) validate_string($user) @@ -35,9 +35,10 @@ validate_string($install_root) validate_string($options) validate_string($java) + validate_string($jar_name) # prog is the 'name' of the init.d script. - $prog = $name + $prog = $name file { "/etc/init.d/${prog}": ensure => 'file', diff --git a/manifests/install.pp b/manifests/init.pp similarity index 55% rename from manifests/install.pp rename to manifests/init.pp index d0241e3..4193697 100644 --- a/manifests/install.pp +++ b/manifests/init.pp @@ -1,8 +1,4 @@ -# == Class: megaraid::lsiget -# -# installs the `lsiget` utility for LSI MegaRAID controllers -# -# See: http://mycusthelp.info/LSI/_cs/AnswerDetail.aspx?inc=8264 +# == Class: selenium # # # === Parameters @@ -12,7 +8,7 @@ # # === Examples # -# class{ 'megaraid::lsiget': } +# class{ 'selenium': } # # # === Authors @@ -20,19 +16,27 @@ # Joshua Hoblitt # # -class selenium::install( - $version = '2.35.0', - $url = undef, -) { +class selenium( + $user = $selenium::params::user, + $group = $selenium::params::group, + $install_root = $selenium::params::install_root, + $java = $selenium::params::java, + $version = $selenium::params::version, + $url = undef, +) inherits selenium::params { + validate_string($user) + validate_string($group) + validate_string($install_root) + validate_string($java) validate_string($version) validate_string($url) include wget - user { $selenium::server::user: - gid => [$selenium::server::group], + user { $user: + gid => [$group], } - group { $selenium::server::group: } + group { $group: } $jar_name = "selenium-server-standalone-${version}.jar" @@ -43,16 +47,16 @@ } File { - owner => $selenium::server::user, - group => $selenium::server::group, + owner => $user, + group => $group, } - file { $selenium::server::install_root: + file { $install_root: ensure => directory, } - $jar_path = "${selenium::server::install_root}/jars" - $log_path = "${selenium::server::install_root}/log" + $jar_path = "${install_root}/jars" + $log_path = "${install_root}/log" file { $jar_path: ensure => directory, @@ -73,7 +77,7 @@ source => $jar_url, destination => "${jar_path}/${jar_name}", timeout => 90, - execuser => $selenium::server::user, + execuser => $user, require => File[$jar_path], } diff --git a/manifests/params.pp b/manifests/params.pp index 2c7b117..81af212 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -8,8 +8,10 @@ $user = 'selenium' $group = $user $install_root = '/opt/selenium' - $default_options = '-Dwebdriver.enable.native.events=1' + $server_options = '-Dwebdriver.enable.native.events=1' + $hub_options = '-role hub' $java = 'java' + $version = '2.35.0' case $::osfamily { 'redhat': {} diff --git a/manifests/server.pp b/manifests/server.pp index a2323e2..4356e39 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -8,26 +8,21 @@ # class selenium::server( $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, + $options = $selenium::params::server_options, ) inherits selenium::params { validate_string($display) - validate_string($user) - validate_string($group) - validate_string($install_root) validate_string($options) - validate_string($java) - class { 'selenium::install': } -> + include selenium + + Class[ 'selenium' ] -> selenium::config{ 'seleniumstandalone': display => $display, - user => $user, - group => $group, - install_root => $install_root, - java => $java, + user => $selenium::user, + group => $selenium::group, + install_root => $selenium::install_root, + options => $options, + java => $selenium::java, } -> class { 'selenium::service': } -> Class[ 'selenium::server' ] diff --git a/spec/classes/selenium_install_spec.rb b/spec/classes/selenium_install_spec.rb deleted file mode 100644 index bd77e75..0000000 --- a/spec/classes/selenium_install_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'spec_helper' - -describe 'selenium::install', :type => :class do - - context 'for osfamily RedHat' do - let(:facts) {{ :osfamily => 'RedHat' }} - - context 'no params' do - let :pre_condition do - 'include selenium::server' - end - - it do - should include_class('wget') - should contain_class('selenium::install').with_version('2.35.0') - should contain_file('/opt/selenium').with({ - 'ensure' => 'directory', - 'owner' => 'selenium', - 'group' => 'selenium', - }) - should contain_file('/opt/selenium/jars').with({ - 'ensure' => 'directory', - 'owner' => 'selenium', - 'group' => 'selenium', - }) - should contain_file('/opt/selenium/log').with({ - 'ensure' => 'directory', - 'owner' => 'selenium', - 'group' => 'selenium', - }) - should contain_file('/var/log/selenium').with({ - 'ensure' => 'link', - 'owner' => 'root', - 'group' => 'root', - }) - should contain_wget__fetch('selenium-server-standalone').with({ - 'source' => 'https://selenium.googlecode.com/files/selenium-server-standalone-2.35.0.jar', - 'destination' => '/opt/selenium/jars/selenium-server-standalone-2.35.0.jar', - 'timeout' => '90', - 'execuser' => 'selenium', - }) - end - end - end - -end diff --git a/spec/classes/selenium_server_spec.rb b/spec/classes/selenium_server_spec.rb index e295476..2eff1a8 100644 --- a/spec/classes/selenium_server_spec.rb +++ b/spec/classes/selenium_server_spec.rb @@ -2,14 +2,22 @@ describe 'selenium::server', :type => :class do - shared_examples 'server' do |user, group| + shared_examples 'server' do |params| + p = { + :display => ':0', + :options => '-Dwebdriver.enable.native.events=1', + } + + p.merge!(params) if params + it do - should contain_class('selenium::server') - should contain_class('selenium::install') - should contain_file('/etc/init.d/seleniumstandalone') + should include_class('selenium') + should contain_selenium__config('seleniumstandalone').with({ + 'display' => p[:display], + 'options' => p[:options], + }) should contain_class('selenium::service') - should contain_user(user).with_gid(group) - should contain_group(group) + should contain_class('selenium::server') end end @@ -17,13 +25,14 @@ let(:facts) {{ :osfamily => 'RedHat' }} context 'no params' do - it_behaves_like 'server', 'selenium', 'selenium' + it_behaves_like 'server', {} end context 'display => :42' do - let(:params) {{ :display => ':42' }} + p = { :display => ':42' } + let(:params) { p } - it_behaves_like 'server', 'selenium', 'selenium' + it_behaves_like 'server', p end context 'display => :42' do @@ -36,66 +45,11 @@ end end - context 'user => foo' do - let(:params) {{ :user => 'foo' }} - - it_behaves_like 'server', 'foo', 'selenium' - end - - context 'user => []' do - let(:params) {{ :user => [] }} - - it 'should fail' do - expect { - should contain_class('selenium::server') - }.to raise_error - end - end - - context 'group => foo' do - let(:params) {{ :group => 'foo' }} - - it_behaves_like 'server', 'selenium', 'foo' - end - - context 'group => []' do - let(:params) {{ :group => [] }} - - it 'should fail' do - expect { - should contain_class('selenium::server') - }.to raise_error - end - end - - context 'install_root => /foo/selenium' do - let(:params) {{ :install_root => '/foo/selenium' }} - - it_behaves_like 'server', 'selenium', 'selenium' - - it do - should contain_file('/foo/selenium').with({ - 'ensure' => 'directory', - 'owner' => 'selenium', - 'group' => 'selenium', - }) - end - end - - 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' }} + p = { :options => '-foo' } + let(:params) { p } - it_behaves_like 'server', 'selenium', 'selenium' + it_behaves_like 'server', p end context 'options => []' do @@ -107,22 +61,6 @@ }.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 { - should contain_class('selenium::server') - }.to raise_error - end - end end end diff --git a/spec/classes/selenium_spec.rb b/spec/classes/selenium_spec.rb new file mode 100644 index 0000000..96e0e8c --- /dev/null +++ b/spec/classes/selenium_spec.rb @@ -0,0 +1,135 @@ +require 'spec_helper' + +describe 'selenium', :type => :class do + + shared_examples 'selenium' do |params| + # XXX need to test $url + p = { + :user => 'selenium', + :group => 'selenium', + :install_root => '/opt/selenium', + :java => 'java', + :version => '2.35.0', + :url => '', + } + + if params + p.merge!(params) + end + + it do + should contain_user(p[:user]).with_gid(p[:group]) + should contain_group(p[:group]) + should include_class('wget') + should contain_class('selenium').with_version(p[:version]) + should contain_file("#{p[:install_root]}").with({ + 'ensure' => 'directory', + 'owner' => p[:user], + 'group' => p[:group], + }) + should contain_file("#{p[:install_root]}/jars").with({ + 'ensure' => 'directory', + 'owner' => p[:user], + 'group' => p[:group], + }) + should contain_file("#{p[:install_root]}/log").with({ + 'ensure' => 'directory', + 'owner' => p[:user], + 'group' => p[:group], + }) + should contain_file('/var/log/selenium').with({ + 'ensure' => 'link', + 'owner' => 'root', + 'group' => 'root', + 'target' => "#{p[:install_root]}/log", + }) + should contain_wget__fetch('selenium-server-standalone').with({ + 'source' => "https://selenium.googlecode.com/files/selenium-server-standalone-#{p[:version]}.jar", + 'destination' => "#{p[:install_root]}/jars/selenium-server-standalone-#{p[:version]}.jar", + 'timeout' => '90', + 'execuser' => p[:user], + }) + end + end + + context 'for osfamily RedHat' do + let(:facts) {{ :osfamily => 'RedHat' }} + + context 'no params' do + it_behaves_like 'selenium', {} + end + + context 'user => foo' do + p = { :user => 'foo' } + let(:params) { p } + + it_behaves_like 'selenium', p + end + + context 'user => []' do + p = { :user => [] } + let(:params) { p } + + it 'should fail' do + expect { + should contain_class('selenium') + }.to raise_error + end + end + + context 'group => foo' do + p = { :group => 'foo' } + let(:params) { p } + + it_behaves_like 'selenium', p + end + + context 'group => []' do + p = { :group => [] } + let(:params) { p } + + it 'should fail' do + expect { + should contain_class('selenium') + }.to raise_error + end + end + + context 'install_root => /foo/selenium' do + p = { :install_root => '/foo/selenium' } + let(:params) { p } + + it_behaves_like 'selenium', p + end + + context 'install_root => []' do + p = { :install_root => [] } + let(:params) { p } + + it 'should fail' do + expect { + should contain_class('selenium') + }.to raise_error + end + end + + context 'java => /opt/java' do + p = { :java => '/opt/java' } + let(:params) { p } + + it_behaves_like 'selenium', p + end + + context 'java => []' do + p = { :java => [] } + let(:params) { p } + + it 'should fail' do + expect { + should contain_class('selenium') + }.to raise_error + end + end + end + +end diff --git a/spec/defines/selenium_config_spec.rb b/spec/defines/selenium_config_spec.rb index 19a69ed..64beeba 100644 --- a/spec/defines/selenium_config_spec.rb +++ b/spec/defines/selenium_config_spec.rb @@ -5,7 +5,7 @@ shared_examples 'config' do |params| let :pre_condition do - "include selenium::params, selenium::install" + "include selenium" end p = { @@ -17,9 +17,7 @@ :java => 'java', } - if params - p.merge!(params) - end + p.merge!(params) if params it do should contain_file("/etc/init.d/#{title}").with({