Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ suites:
cpuexecutioncap: 25
excludes:
- ubuntu-14.04

- name: config
run_list:
- recipe[karaf_test::install]
- recipe[karaf_test::config]
attributes:
karaf_test:
version: '3.0.3'
excludes:
- ubuntu-14.04
69 changes: 69 additions & 0 deletions resources/karaf_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
resource_name :karaf_config

property :install_path, kind_of: String, default: '/usr/local'
property :client_user, kind_of: String, default: 'karaf'
property :pid, kind_of: String, required: true, name_property: true
property :property, kind_of: String
property :value, kind_of: String, default: ''

require 'chef/resource'
require 'chef/resource/bash'

default_action :list

client_command = 'bin/client'

def karaf_path
"#{install_path}/karaf"
end

action :list do

bash 'install feature' do
cwd karaf_path
code <<-EOH
#{client_command} -r 20 -d 3 -u #{client_user} config:list
EOH
end
end

# bin/client config:property-set foo bar
action :property_set do
bash 'property-set' do
cwd karaf_path
code <<-EOH
#{client_command} -r 20 -d 3 -u #{client_user} "config:edit #{pid}; config:property-set #{property} \"#{value}\"; config:update"
EOH
end
end

# bin/client config:property-append foo bar2
action :property_append do
bash 'property-append' do
cwd karaf_path
code <<-EOH
#{client_command} -r 20 -d 3 -u #{client_user} 'config:edit #{pid}; config:property-append #{property} \"'#{value}'\"; config:update'
EOH
end
end

# bin/client config:property-delete foo
action :property_delete do
# bin/client -u karaf "config:edit com.dummy; config:property-set foo bar; config:update"
bash 'property-delete' do
cwd karaf_path
code <<-EOH
#{client_command} -r 20 -d 3 -u #{client_user} 'config:edit #{pid}; config:property-delete #{property} ; config:update'
EOH
end
end

# bin/client config:delete my.test(.cfg)
action :delete do
bash 'delete config' do
cwd karaf_path
code <<-EOH
#{client_command} -r 20 -d 3 -u #{client_user} 'config:delete #{pid}'
EOH
end
end
52 changes: 52 additions & 0 deletions test/cookbooks/karaf_test/recipes/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
karaf_config 'list' do
end

# set a bunch of properties
karaf_config 'com.test.propset' do
action :property_set
property "foo"
value "bar"
end

karaf_config 'com.test.propappend' do
action :property_set
property "foo"
value "bar"
end

karaf_config 'com.test.propdelete' do
action :property_set
property "myprop"
value "bar"
end

karaf_config 'com.test.deleteme' do
action :property_set
property "foo"
value "bar"
end

# append to existing
karaf_config 'com.test.propappend' do
action :property_append
property "foo"
value ", appended"
end

# delete property
karaf_config 'com.test.propdelete' do
action :property_delete
property "myprop"
end

# delete configuration
karaf_config 'com.test.deleteme' do
action :delete
end

# test modifying an existing configuration
karaf_config 'org.apache.karaf.shell' do
action :property_set
property "sshIdleTimeout"
value 1800001.to_s
end
26 changes: 26 additions & 0 deletions test/integration/config/serverspec/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe 'config' do
it_behaves_like 'karaf_install'

describe file('/usr/local/karaf/etc/com.test.propset.cfg') do
its(:content) { should match(/foo = bar/) }
end

describe file('/usr/local/karaf/etc/com.test.propappend.cfg') do
its(:content) { should match(/foo = bar, append/) }
end

describe file('/usr/local/karaf/etc/com.test.propdelete.cfg') do
its(:content) { should_not match(/myprop =/) }
end

describe file('/usr/local/karaf/etc/com.test.deleteme.cfg') do
it { should_not exist }
end

describe file('/usr/local/karaf/etc/org.apache.karaf.shell.cfg') do
its(:content) { should match(/sshIdleTimeout = 1800001/) }
end

end