diff --git a/.kitchen.yml b/.kitchen.yml index 196fe52..e11cab5 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -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 \ No newline at end of file diff --git a/resources/karaf_config.rb b/resources/karaf_config.rb new file mode 100644 index 0000000..cc37d36 --- /dev/null +++ b/resources/karaf_config.rb @@ -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 \ No newline at end of file diff --git a/test/cookbooks/karaf_test/recipes/config.rb b/test/cookbooks/karaf_test/recipes/config.rb new file mode 100644 index 0000000..32aa65a --- /dev/null +++ b/test/cookbooks/karaf_test/recipes/config.rb @@ -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 \ No newline at end of file diff --git a/test/integration/config/serverspec/config_spec.rb b/test/integration/config/serverspec/config_spec.rb new file mode 100644 index 0000000..32edb60 --- /dev/null +++ b/test/integration/config/serverspec/config_spec.rb @@ -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