Skip to content

Commit

Permalink
Merge pull request voxpupuli#344 from electrical/testing_fixes
Browse files Browse the repository at this point in the history
Add some small fixes
  • Loading branch information
Richard Pijnenburg committed May 27, 2015
2 parents 80e29ff + b7e7996 commit 3988d95
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
7 changes: 4 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@
) inherits elasticsearch::params {

anchor {'elasticsearch::begin': }
anchor {'elasticsearch::end': }


#### Validate parameters
Expand Down Expand Up @@ -337,7 +336,7 @@
distribution => 'jre',
}

# ensure we first java java and then manage the service
# ensure we first install java, the package and then the rest
Anchor['elasticsearch::begin']
-> Class['::java']
-> Class['elasticsearch::package']
Expand Down Expand Up @@ -380,10 +379,12 @@
-> Class['elasticsearch::config']
-> Elasticsearch::Instance <| |>
-> Elasticsearch::Template <| |>

} else {

# make sure all services are getting stopped before software removal
Elasticsearch::Instance <| |>
Anchor['elasticsearch::begin']
-> Elasticsearch::Instance <| |>
-> Class['elasticsearch::config']
-> Class['elasticsearch::package']

Expand Down
12 changes: 6 additions & 6 deletions manifests/service/systemd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@
notify => $notify_service,
}

} elsif ($init_defaults != undef and is_hash($init_defaults) ) {
} else {
if ($init_defaults != undef and is_hash($init_defaults) ) {

if(has_key($init_defaults, 'ES_USER')) {
if($init_defaults['ES_USER'] != $elasticsearch::elasticsearch_user) {
fail('Found ES_USER setting for init_defaults but is not same as elasticsearch_user setting. Please use elasticsearch_user setting.')
if(has_key($init_defaults, 'ES_USER')) {
if($init_defaults['ES_USER'] != $elasticsearch::elasticsearch_user) {
fail('Found ES_USER setting for init_defaults but is not same as elasticsearch_user setting. Please use elasticsearch_user setting.')
}
}
}

$init_defaults_pre_hash = { 'ES_USER' => $elasticsearch::elasticsearch_user, 'ES_GROUP' => $elasticsearch::elasticsearch_group, 'MAX_OPEN_FILES' => '65535' }
$new_init_defaults = merge($init_defaults_pre_hash, $init_defaults)

Expand All @@ -140,7 +141,6 @@
before => Service["elasticsearch-instance-${name}"],
notify => $notify_service,
}

}

# init file from template
Expand Down
2 changes: 2 additions & 0 deletions spec/classes/000_elasticsearch_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
context 'main class tests' do

# init.pp
it { should compile.with_all_deps }
it { should contain_class('elasticsearch') }
it { should contain_anchor('elasticsearch::begin') }
it { should contain_class('elasticsearch::params') }
it { should contain_class('elasticsearch::package').that_requires('Anchor[elasticsearch::begin]') }
Expand Down
6 changes: 5 additions & 1 deletion spec/classes/001_hiera_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@
})
}

it { should contain_elasticsearch__plugin('mobz/elasticsearch-head').with(:ensure => 'present', :module_dir => 'head', :instances => 'es-01') }
it { should contain_elasticsearch__plugin('mobz/elasticsearch-head/1.0.0').with(:ensure => 'present', :module_dir => 'head', :instances => 'es-01') }
it { should contain_exec('install_plugin_mobz/elasticsearch-head/1.0.0').with(:command => '/usr/share/elasticsearch/bin/plugin -install mobz/elasticsearch-head/1.0.0', :creates => '/usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
it { should contain_file('/usr/share/elasticsearch/plugins/head/.name').with(:content => 'mobz/elasticsearch-head/1.0.0') }
it { should contain_exec('purge_plugin_head_old').with(:onlyif => "test -e /usr/share/elasticsearch/plugins/head && test \"$(cat /usr/share/elasticsearch/plugins/head/.name)\" != 'mobz/elasticsearch-head/1.0.0'", :command => '/usr/share/elasticsearch/bin/plugin --remove head', :before => 'Exec[install_plugin_mobz/elasticsearch-head/1.0.0]') }


end

Expand Down
19 changes: 12 additions & 7 deletions spec/defines/004_elasticsearch_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe 'elasticsearch::plugin', :type => 'define' do

let(:title) { 'mobz/elasticsearch-head' }
let(:title) { 'mobz/elasticsearch-head/1.0.0' }
let :facts do {
:operatingsystem => 'CentOS',
:kernel => 'Linux',
Expand All @@ -21,8 +21,10 @@
:instances => 'es-01'
} end

it { should contain_elasticsearch__plugin('mobz/elasticsearch-head') }
it { should contain_exec('install_plugin_mobz/elasticsearch-head').with(:command => '/usr/share/elasticsearch/bin/plugin -install mobz/elasticsearch-head', :creates => '/usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
it { should contain_elasticsearch__plugin('mobz/elasticsearch-head/1.0.0') }
it { should contain_exec('install_plugin_mobz/elasticsearch-head/1.0.0').with(:command => '/usr/share/elasticsearch/bin/plugin -install mobz/elasticsearch-head/1.0.0', :creates => '/usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
it { should contain_file('/usr/share/elasticsearch/plugins/head/.name').with(:content => 'mobz/elasticsearch-head/1.0.0') }
it { should contain_exec('purge_plugin_head_old').with(:onlyif => "test -e /usr/share/elasticsearch/plugins/head && test \"$(cat /usr/share/elasticsearch/plugins/head/.name)\" != 'mobz/elasticsearch-head/1.0.0'", :command => '/usr/share/elasticsearch/bin/plugin --remove head', :before => 'Exec[install_plugin_mobz/elasticsearch-head/1.0.0]') }
end

context "Remove a plugin" do
Expand All @@ -33,8 +35,8 @@
:instances => 'es-01'
} end

it { should contain_elasticsearch__plugin('mobz/elasticsearch-head') }
it { should contain_exec('remove_plugin_mobz/elasticsearch-head').with(:command => '/usr/share/elasticsearch/bin/plugin --remove head', :onlyif => 'test -d /usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
it { should contain_elasticsearch__plugin('mobz/elasticsearch-head/1.0.0') }
it { should contain_exec('remove_plugin_mobz/elasticsearch-head/1.0.0').with(:command => '/usr/share/elasticsearch/bin/plugin --remove head', :onlyif => 'test -d /usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
end

context "Use a proxy" do
Expand All @@ -47,8 +49,11 @@
:proxy_port => 3128
} end

it { should contain_elasticsearch__plugin('mobz/elasticsearch-head') }
it { should contain_exec('install_plugin_mobz/elasticsearch-head').with(:command => '/usr/share/elasticsearch/bin/plugin -DproxyPort=3128 -DproxyHost=my.proxy.com -install mobz/elasticsearch-head', :creates => '/usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
it { should contain_elasticsearch__plugin('mobz/elasticsearch-head/1.0.0') }
it { should contain_exec('install_plugin_mobz/elasticsearch-head/1.0.0').with(:command => '/usr/share/elasticsearch/bin/plugin -DproxyPort=3128 -DproxyHost=my.proxy.com -install mobz/elasticsearch-head/1.0.0', :creates => '/usr/share/elasticsearch/plugins/head', :notify => 'Elasticsearch::Service[es-01]') }
it { should contain_file('/usr/share/elasticsearch/plugins/head/.name').with(:content => 'mobz/elasticsearch-head/1.0.0') }
it { should contain_exec('purge_plugin_head_old').with(:onlyif => "test -e /usr/share/elasticsearch/plugins/head && test \"$(cat /usr/share/elasticsearch/plugins/head/.name)\" != 'mobz/elasticsearch-head/1.0.0'", :command => '/usr/share/elasticsearch/bin/plugin --remove head', :before => 'Exec[install_plugin_mobz/elasticsearch-head/1.0.0]') }

end

end
2 changes: 1 addition & 1 deletion spec/fixtures/hiera/hieradata/singleplugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ elasticsearch::instances:
config:
node.name: 'es-01'
elasticsearch::plugins:
'mobz/elasticsearch-head':
'mobz/elasticsearch-head/1.0.0':
ensure: 'present'
module_dir: 'head'
instances:
Expand Down

0 comments on commit 3988d95

Please sign in to comment.