From d00b7475165a8c957296ef4d5a6961675f2912b6 Mon Sep 17 00:00:00 2001 From: what do you want? Date: Thu, 6 Nov 2014 15:07:44 -0800 Subject: [PATCH 1/2] Add support for jetty 9.1 - Update chefspec to 3.2 - Update berkshelf - Update cookbook-development --- Berksfile | 3 +- Berksfile.lock | 14 +- Gemfile | 1 + Gemfile.lock | 205 ++++++++++-------- attributes/default.rb | 8 +- files/default/jetty-9-1-start.ini | 96 ++++++++ files/default/jetty-9-start.ini | 1 - recipes/default.rb | 47 +++- spec/default_spec.rb | 167 +++++++------- spec/spec_helper.rb | 4 +- .../default/tests/minitest/jetty_9_1_test.rb | 30 +++ .../hipsnip-jetty_test/recipes/jetty_9_1.rb | 6 + 12 files changed, 383 insertions(+), 199 deletions(-) create mode 100644 files/default/jetty-9-1-start.ini create mode 100644 test/cookbooks/hipsnip-jetty_test/files/default/tests/minitest/jetty_9_1_test.rb create mode 100644 test/cookbooks/hipsnip-jetty_test/recipes/jetty_9_1.rb diff --git a/Berksfile b/Berksfile index fe42dc3..bc3d19c 100644 --- a/Berksfile +++ b/Berksfile @@ -2,6 +2,7 @@ site :opscode metadata +cookbook "java" cookbook "apt" cookbook "minitest-handler", "~> 0.2.1" -cookbook "hipsnip-jetty_test", :path => "test/cookbooks/hipsnip-jetty_test" \ No newline at end of file +cookbook "hipsnip-jetty_test", :path => "test/cookbooks/hipsnip-jetty_test" diff --git a/Berksfile.lock b/Berksfile.lock index 9acafcd..3574879 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -3,6 +3,9 @@ "hipsnip-jetty": { "path": "." }, + "java": { + "locked_version": "1.28.0" + }, "apt": { "locked_version": "2.1.0" }, @@ -12,17 +15,8 @@ "hipsnip-jetty_test": { "path": "./test/cookbooks/hipsnip-jetty_test" }, - "java": { - "locked_version": "1.14.0" - }, - "windows": { - "locked_version": "1.10.0" - }, "chef_handler": { - "locked_version": "1.1.4" - }, - "aws": { - "locked_version": "0.101.6" + "locked_version": "1.1.6" } } } diff --git a/Gemfile b/Gemfile index 0047bad..93a5aaf 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,4 @@ gem "json", "= 1.7.7" gem "minitest-chef-handler", "~> 1.0.1", :group => :integration gem "kitchen-vagrant", "~> 0.11.0", :group => :integration gem "cookbook-development", :github => "hipsnip-cookbooks/cookbook-development" +gem "chefspec" diff --git a/Gemfile.lock b/Gemfile.lock index c9a80aa..c03a86d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,171 +1,185 @@ GIT remote: git://github.com/hipsnip-cookbooks/cookbook-development.git - revision: 9c2f9baeebd80be2276c84785940dde7cd457417 + revision: 0fd89884cd3fcb235c38c8c13858e2fc15579444 specs: - cookbook-development (0.2.0) - chef (~> 11.6.0) - chefspec (~> 2.0.0) - foodcritic (~> 2.2.0) + cookbook-development (0.3.0) + chef (~> 11.10.0) + chefspec (~> 3.2.0) + foodcritic (~> 3.0.3) strainer (~> 3.3.0) GEM remote: https://rubygems.org/ specs: - activesupport (3.2.14) + activesupport (3.2.20) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - addressable (2.3.5) - akami (1.2.0) + addressable (2.3.6) + akami (1.2.2) gyoku (>= 0.4.0) - nokogiri (>= 1.4.0) - berkshelf (2.0.10) + nokogiri + berkshelf (2.0.18) activesupport (~> 3.2.0) addressable (~> 2.3.4) buff-shell_out (~> 0.1) chozo (>= 0.6.1) - faraday (>= 0.8.5) - hashie (>= 2.0.2) + faraday (~> 0.8.5) + hashie (~> 2.0) minitar (~> 0.5.4) rbzip2 (~> 0.2.0) retryable (~> 1.3.3) - ridley (~> 1.5.0) - solve (>= 0.5.0) + ridley (~> 1.7.0) + solve (~> 0.8.2) thor (~> 0.18.0) buff-config (0.4.0) buff-extensions (~> 0.3) varia_model (~> 0.1) buff-extensions (0.5.0) - buff-ignore (1.1.0) + buff-ignore (1.1.1) buff-platform (0.1.0) buff-ruby_engine (0.1.0) - buff-shell_out (0.1.0) + buff-shell_out (0.2.0) buff-ruby_engine (~> 0.1.0) builder (3.2.2) - celluloid (0.14.1) - timers (>= 1.0.0) - celluloid-io (0.14.1) - celluloid (>= 0.14.1) - nio4r (>= 0.4.5) - chef (11.6.0) - erubis - highline (>= 1.6.9) - json (>= 1.4.4, <= 1.7.7) - mixlib-authentication (>= 1.3.0) - mixlib-cli (~> 1.3.0) - mixlib-config (>= 1.1.2) - mixlib-log (>= 1.3.0) - mixlib-shellout + celluloid (0.16.0) + timers (~> 4.0.0) + celluloid-io (0.16.1) + celluloid (>= 0.16.0) + nio4r (>= 1.0.0) + chef (11.10.4) + chef-zero (~> 1.7, >= 1.7.2) + diff-lcs (~> 1.2, >= 1.2.4) + erubis (~> 2.7) + highline (~> 1.6, >= 1.6.9) + json (>= 1.4.4, <= 1.8.1) + mime-types (~> 1.16) + mixlib-authentication (~> 1.3) + mixlib-cli (~> 1.4) + mixlib-config (~> 2.0) + mixlib-log (~> 1.3) + mixlib-shellout (~> 1.3) net-ssh (~> 2.6) - net-ssh-multi (~> 1.1.0) - ohai (>= 0.6.0) + net-ssh-multi (~> 1.1) + ohai (~> 6.0) + pry (~> 0.9) + puma (~> 1.6) rest-client (>= 1.0.4, < 1.7.0) yajl-ruby (~> 1.1) - chefspec (2.0.1) - chef (>= 10.0) - erubis - fauxhai (~> 1.1) - minitest-chef-handler (>= 0.6.0) - rspec (~> 2.0) + chef-zero (1.7.3) + hashie (~> 2.0) + json + mixlib-log (~> 1.3) + moneta (< 0.7.0) + rack + chefspec (3.2.0) + chef (~> 11.0) + fauxhai (~> 2.0) + i18n (>= 0.6.9, < 1.0.0) + rspec (~> 2.14) chozo (0.6.1) activesupport (>= 3.2.0) hashie (>= 2.0.2) multi_json (>= 1.3.0) - ci_reporter (1.9.0) + ci_reporter (1.9.3) builder (>= 2.1.2) coderay (1.0.9) - diff-lcs (1.2.4) + diff-lcs (1.2.5) erubis (2.7.0) - faraday (0.8.8) + faraday (0.8.9) multipart-post (~> 1.2.0) - fauxhai (1.1.1) - httparty + fauxhai (2.2.0) net-ssh ohai - ffi (1.9.0) - foodcritic (2.2.0) + ffi (1.9.6) + foodcritic (3.0.3) erubis gherkin (~> 2.11.7) nokogiri (~> 1.5.4) + rake treetop (~> 1.4.10) yajl-ruby (~> 1.1.0) gherkin (2.11.8) multi_json (~> 1.3) gssapi (1.0.3) ffi (>= 1.0.1) - gyoku (1.1.0) + gyoku (1.2.2) builder (>= 2.1.2) - hashie (2.0.5) - highline (1.6.19) - httparty (0.11.0) - multi_json (~> 1.0) - multi_xml (>= 0.5.2) - httpclient (2.2.0.2) + hashie (2.1.2) + highline (1.6.21) + hitimes (1.2.2) + httpclient (2.5.3.2) httpi (0.9.7) rack - i18n (0.6.5) + i18n (0.6.11) ipaddress (0.8.0) json (1.7.7) kitchen-vagrant (0.11.1) test-kitchen (~> 1.0.0.beta.3) little-plugger (1.1.3) - logging (1.6.2) + logging (1.8.2) little-plugger (>= 1.1.3) + multi_json (>= 1.8.4) method_source (0.8.2) - mime-types (1.25) + mime-types (1.25.1) minitar (0.5.4) minitest (4.7.5) - minitest-chef-handler (1.0.1) - chef - ci_reporter + minitest-chef-handler (1.0.3) + chef (>= 10.12.0) + ci_reporter (< 2.0) minitest (~> 4.7.3) mixlib-authentication (1.3.0) mixlib-log - mixlib-cli (1.3.0) - mixlib-config (1.1.2) + mixlib-cli (1.5.0) + mixlib-config (2.1.0) mixlib-log (1.6.0) - mixlib-shellout (1.2.0) - multi_json (1.7.9) - multi_xml (0.5.5) + mixlib-shellout (1.6.0) + moneta (0.6.0) + multi_json (1.10.1) multipart-post (1.2.0) - net-http-persistent (2.9) + net-http-persistent (2.9.4) net-scp (1.1.2) net-ssh (>= 2.6.5) - net-ssh (2.6.8) + net-ssh (2.9.1) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) - net-ssh-multi (1.1) - net-ssh (>= 2.1.4) - net-ssh-gateway (>= 0.99.0) - nio4r (0.5.0) - nokogiri (1.5.10) + net-ssh-multi (1.2.0) + net-ssh (>= 2.6.5) + net-ssh-gateway (>= 1.2.0) + nio4r (1.0.1) + nokogiri (1.5.11) nori (1.1.5) - ohai (6.18.0) + ohai (6.24.2) ipaddress mixlib-cli mixlib-config mixlib-log mixlib-shellout - systemu + systemu (~> 2.5.2) yajl-ruby - polyglot (0.3.3) + polyglot (0.3.5) pry (0.9.12.2) coderay (~> 1.0.5) method_source (~> 0.8) slop (~> 3.4) + puma (1.6.3) + rack (~> 1.2) rack (1.5.2) rake (10.1.0) rbzip2 (0.2.0) - rest-client (1.6.7) - mime-types (>= 1.16) - retryable (1.3.3) - ridley (1.5.2) + rdoc (4.1.2) + json (~> 1.4) + rest-client (1.6.8) + mime-types (~> 1.16) + rdoc (>= 2.4.2) + retryable (1.3.6) + ridley (1.7.1) addressable buff-config (~> 0.2) buff-extensions (~> 0.3) buff-ignore (~> 1.1) buff-shell_out (~> 0.1) - celluloid (~> 0.14.0) - celluloid-io (~> 0.14.0) + celluloid (~> 0.15) + celluloid-io (~> 0.15) erubis faraday (>= 0.8.4) hashie (>= 2.0.2) @@ -173,19 +187,18 @@ GEM mixlib-authentication (>= 1.3.0) net-http-persistent (>= 2.8) net-ssh - nio4r (>= 0.5.0) retryable solve (>= 0.4.4) varia_model (~> 0.1) winrm (~> 1.1.0) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.5) - rspec-expectations (2.14.2) + rspec (2.99.0) + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + rspec-core (2.99.2) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.3) + rspec-mocks (2.99.2) rubyntlm (0.1.1) safe_yaml (0.9.5) savon (0.9.5) @@ -197,7 +210,7 @@ GEM nori (~> 1.0) wasabi (~> 1.0) slop (3.4.6) - solve (0.8.1) + solve (0.8.2) strainer (3.3.0) berkshelf (~> 2.0) buff-platform (~> 0.1) @@ -211,21 +224,22 @@ GEM safe_yaml (~> 0.9.5) thor thor (0.18.1) - timers (1.1.0) + timers (4.0.1) + hitimes treetop (1.4.15) polyglot polyglot (>= 0.3.1) - uuidtools (2.1.4) - varia_model (0.2.0) + uuidtools (2.1.5) + varia_model (0.3.2) buff-extensions (~> 0.2) hashie (>= 2.0.2) wasabi (1.0.0) nokogiri (>= 1.4.0) - winrm (1.1.2) + winrm (1.1.3) gssapi (~> 1.0.0) - httpclient (~> 2.2.0.2) - logging (~> 1.6.1) - nokogiri (~> 1.5.0) + httpclient (~> 2.2, >= 2.2.0.2) + logging (~> 1.6, >= 1.6.1) + nokogiri (~> 1.5) rubyntlm (~> 0.1.1) savon (= 0.9.5) uuidtools (~> 2.1.2) @@ -236,6 +250,7 @@ PLATFORMS DEPENDENCIES berkshelf (~> 2.0.9) + chefspec cookbook-development! json (= 1.7.7) kitchen-vagrant (~> 0.11.0) diff --git a/attributes/default.rb b/attributes/default.rb index 97452cc..ddf1e3f 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -30,9 +30,9 @@ # e.g: ['etc/jetty-webapps.xml', 'etc/jetty-http.xml'] default['jetty']['add_confs'] = [] -default['jetty']['version'] = '8.1.10.v20130312' -default['jetty']['link'] = 'http://eclipse.org/downloads/download.php?file=/jetty/8.1.10.v20130312/dist/jetty-distribution-8.1.10.v20130312.tar.gz&r=1' -default['jetty']['checksum'] = 'e966f87823adc323ce67e99485fea126b84fff5affdc28aa7526e40eb2ec1a5b' # SHA256 +default['jetty']['version'] = '9.2.3.v20140905' +default['jetty']['link'] = 'http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.2.3.v20140905.tar.gz&r=1' +default['jetty']['checksum'] = '9a47f2d02efa52583db3195623080ff7ccd96b6aa9150aeaa43e1203de22770a' # SHA256 default['jetty']['directory'] = '/usr/local/src' @@ -48,4 +48,4 @@ default['jetty']['syslog']['tag'] = '' default['jetty']['start_ini']['custom'] = false -default['jetty']['start_ini']['content'] = [] \ No newline at end of file +default['jetty']['start_ini']['content'] = [] diff --git a/files/default/jetty-9-1-start.ini b/files/default/jetty-9-1-start.ini new file mode 100644 index 0000000..42d71c4 --- /dev/null +++ b/files/default/jetty-9-1-start.ini @@ -0,0 +1,96 @@ +=========================================================== +# Jetty start.jar arguments +# +# The contents of this file, together with the *.ini +# files found in start.d directory are used to build +# the classpath and command line on a call to +# java -jar start.jar [arg...] +# +# Use the following command to see more options +# java -jar start.jar --help +# +# Each line in these files is prepended to the command line +# as arguments and may be either: +# + A property like: name=value +# + A module to enable like: --module=jmx +# + An XML configuration file like: etc/jetty-feature.xml +# + A start.jar option like: --dry-run +# +# If --exec or --dry-run are used, then this file may also +# contain lines with: +# + A JVM option like: -Xmx2000m +# + A System Property like: -Dcom.sun.management.jmxremote +# +# The --add-to-start=module option can be used to append +# a configuration template for a module to start.ini +# The --add-to-startd=module option can be used to create +# a configuration template for a module in start.d/module.ini +# For example configure and run with SPDY use +# +# java -jar start.jar --add-to-startd=spdy +# $EDITOR start.d/spdy.ini +# java -jar start.jar +# +#=========================================================== + + +# +# Initialize module server +# +--module=server +## +## Server Threading Configuration +## +# minimum number of threads +threads.min=10 +# maximum number of threads +threads.max=200 +# thread idle timeout in milliseconds +threads.timeout=60000 +# buffer size for output +jetty.output.buffer.size=32768 +# request header buffer size +jetty.request.header.size=8192 +# response header buffer size +jetty.response.header.size=8192 +# should jetty send the server version header? +jetty.send.server.version=true +# should jetty send the date header? +jetty.send.date.header=false +# What host to listen on (leave commented to listen on all interfaces) +#jetty.host=myhost.com +# Dump the state of the Jetty server, components, and webapps after startup +jetty.dump.start=false +# Dump the state of the Jetty server, before stop +jetty.dump.stop=false + + + +# +# Initialize module deploy +# +--module=deploy +## DeployManager configuration +# Monitored Directory name (relative to jetty.base) +# jetty.deploy.monitoredDirName=webapps + + +# +# Initialize module websocket +# +--module=websocket + +# +# Initialize module ext +# +--module=ext + +# +# Initialize module jmx +# +--module=jmx + +# +# Initialize http module +# +--module=http diff --git a/files/default/jetty-9-start.ini b/files/default/jetty-9-start.ini index 4303e92..aada7e6 100644 --- a/files/default/jetty-9-start.ini +++ b/files/default/jetty-9-start.ini @@ -234,4 +234,3 @@ etc/jetty-deploy.xml #=========================================================== # The start.d directory contains the active start.ini fragments start.d/ - diff --git a/recipes/default.rb b/recipes/default.rb index 8e128f0..88e6ded 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -35,6 +35,13 @@ else node.set['jetty']['contexts'] = "#{node['jetty']['home']}/contexts" end +minor_version = node['jetty']['version'].split(".")[1].to_i + +def above9_0?(major, minor) + val = false + val = true if major >= 9 and minor > 0 + val +end ################################################################################ # Set node attributes @@ -63,7 +70,9 @@ # Create few directories for jetty -[node['jetty']['home'], node['jetty']['contexts'], node['jetty']['webapps'], "#{node['jetty']['home']}/lib","#{node['jetty']['home']}/resources"].each do |d| +dirs = [node['jetty']['home'], node['jetty']['contexts'], node['jetty']['webapps'], "#{node['jetty']['home']}/lib","#{node['jetty']['home']}/resources"] +dirs << "#{node['jetty']['home']}/modules" if above9_0?(version, minor_version) +dirs.each do |d| directory d do owner node['jetty']['user'] group node['jetty']['group'] @@ -93,8 +102,6 @@ raise "Failed to extract Jetty package" unless File.exists?(node['jetty']['extracted']) end - action :create - not_if do File.exists?(node['jetty']['extracted']) end @@ -109,8 +116,6 @@ raise "Failed to copy Jetty libraries" if Dir[File.join(node['jetty']['home'], 'lib', '*')].empty? end - action :create - only_if do Dir[File.join(node['jetty']['home'], 'lib', '*')].empty? end @@ -126,8 +131,6 @@ raise "Failed to copy Jetty start.jar" unless File.exists?(File.join(node['jetty']['home'], 'start.jar')) end - action :create - not_if do File.exists?(File.join(node['jetty']['home'], 'start.jar')) end @@ -151,8 +154,6 @@ raise "Failed to copy Jetty init file (jetty.sh)" unless File.exists?("/etc/init.d/jetty") end - action :create - not_if do File.exists?("/etc/init.d/jetty") end @@ -194,13 +195,30 @@ raise "Failed to copy Jetty config files" if Dir[File.join(node['jetty']['home'], 'etc', '*')].empty? end - action :create - only_if do Dir[File.join(node['jetty']['home'], 'etc', '*')].empty? end end +if above9_0?(version, minor_version) + # Copy all the modules + # + ruby_block 'Copy Jetty modules' do + block do + Chef::Log.info "Copying Jetty modules files into #{node['jetty']['home']}/modules" + + FileUtils.cp_r File.join(node['jetty']['extracted'], 'modules', ''), node['jetty']['home'] + + FileUtils.chown_R(node['jetty']['user'],node['jetty']['group'],File.join(node['jetty']['home'], 'modules', '')) + raise "Failed to copy Jetty config files" if Dir[File.join(node['jetty']['home'], 'modules', '*')].empty? + end + + only_if do + Dir[File.join(node['jetty']['home'], 'modules', '*')].empty? + end + end +end + template '/etc/default/jetty' do source 'jetty.default.erb' mode '644' @@ -228,8 +246,13 @@ notifies :restart, "service[jetty]" end else + if above9_0?(version, minor_version) + source = "jetty-9-1-start.ini" + else + source = "jetty-#{version}-start.ini" + end cookbook_file "#{node['jetty']['home']}/start.ini" do - source "jetty-#{version}-start.ini" + source source mode '644' owner node['jetty']['user'] group node['jetty']['group'] diff --git a/spec/default_spec.rb b/spec/default_spec.rb index b89938e..a2db752 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -1,78 +1,95 @@ require_relative 'spec_helper' describe "hipsnip-jetty::default" do - chef_run = ChefSpec::ChefRunner.new.converge 'hipsnip-jetty::default' - node = chef_run.node - it "should include the java::default recipe" do - expect(chef_run).to include_recipe 'hipsnip-jetty::default' - end - it "should create the folders necessary for jetty" do - [node['jetty']['home'], node['jetty']['contexts'], node['jetty']['webapps'], "#{node['jetty']['home']}/lib","#{node['jetty']['home']}/resources"].each do |path| - expect(chef_run).to create_directory path - directory = chef_run.directory(path) - expect(directory).to be_owned_by(node['jetty']['user'], node['jetty']['group']) - end - end - it "should download jetty" do - expect(chef_run).to create_remote_file(node['jetty']['download']).with( - :source => node['jetty']['link'], - :checksum => node['jetty']['checksum'] - ) - end - it "should execute ruby block 'Extract Jetty'" do - expect(chef_run).to execute_ruby_block 'Extract Jetty' - end - it "should execute ruby block 'Copy Jetty lib files'" do - expect(chef_run).to execute_ruby_block 'Copy Jetty lib files' - end - it "should execute ruby block 'Copy Jetty start.jar'" do - expect(chef_run).to execute_ruby_block 'Copy Jetty start.jar' - end - it "should execute ruby block 'Copy Jetty init file (jetty.sh)'" do - expect(chef_run).to execute_ruby_block 'Copy Jetty init file (jetty.sh)' - end - it "should create the folder /etc/jetty" do - path = '/etc/jetty' - expect(chef_run).to create_directory path - directory = chef_run.directory(path) - expect(directory).to be_owned_by(node['jetty']['user'], node['jetty']['group']) - end - it "should create the folder #{node['jetty']['home']}/start.d" do - path = "#{node['jetty']['home']}/start.d" - expect(chef_run).to create_directory path - directory = chef_run.directory(path) - expect(directory).to be_owned_by(node['jetty']['user'], node['jetty']['group']) - end - it "should execute ruby block 'Copy Jetty config files'" do - expect(chef_run).to execute_ruby_block 'Copy Jetty config files' - end - it "should create the file /etc/default/jetty" do - path = '/etc/default/jetty'; - expect(chef_run).to create_file path - file = chef_run.file(path) - #expect(file).to be_owned_by(node['jetty']['user'], node['jetty']['group']) - end - it "should create the file /etc/jetty/jetty.conf" do - path = '/etc/jetty/jetty.conf'; - expect(chef_run).to create_file path - file = chef_run.file(path) - end - it "should create file 'start.ini'" do - expect(chef_run).to create_cookbook_file "#{node['jetty']['home']}/start.ini" - end - it "should create logs folder" do - path = !node['jetty']['logs'].empty? ? node['jetty']['logs'] : "#{node['jetty']['home']}/logs" - expect(chef_run).to create_directory path - directory = chef_run.directory(path) - expect(directory).to be_owned_by(node['jetty']['user'], node['jetty']['group']) - end - it "should create the file '#{node['jetty']['home']}/resources/jetty-logging.properties'" do - path = "#{node['jetty']['home']}/resources/jetty-logging.properties" - expect(chef_run).to create_file path - file = chef_run.file(path) - #expect(file).to be_owned_by(node['jetty']['user'], node['jetty']['group']) - end - it "should set to start on boot time" do - expect(chef_run).to set_service_to_start_on_boot 'jetty' - end -end \ No newline at end of file + ['9.2.3.v20140905', '8.1.10.v2013031'].each do |version| + context "jetty #{version}" do + let(:chef_run) { + ChefSpec::Runner.new do |n| + n.set['jetty']['version'] = version + end.converge 'hipsnip-jetty::default' + } + let(:node) { chef_run.node } + + it "should include java recipe" do + expect(chef_run).to include_recipe("java") + end + it "should include the java::default recipe" do + expect(chef_run).to include_recipe 'hipsnip-jetty::default' + end + it "should create the folders necessary for jetty" do + [node['jetty']['home'], node['jetty']['contexts'], node['jetty']['webapps'], "#{node['jetty']['home']}/lib","#{node['jetty']['home']}/resources"].each do |path| + expect(chef_run).to create_directory path + directory = chef_run.directory(path) + expect(directory.owner).to eq(node['jetty']['user']) + expect(directory.group).to eq(node['jetty']['group']) + end + end + it "should download jetty" do + expect(chef_run).to create_remote_file(node['jetty']['download']).with( + :source => node['jetty']['link'], + :checksum => node['jetty']['checksum'] + ) + end + it "should execute ruby block 'Extract Jetty'" do + expect(chef_run).to run_ruby_block 'Extract Jetty' + end + it "should execute ruby block 'Copy Jetty lib files'" do + expect(chef_run).to run_ruby_block 'Copy Jetty lib files' + end + it "should execute ruby block 'Copy Jetty start.jar'" do + expect(chef_run).to run_ruby_block 'Copy Jetty start.jar' + end + it "should execute ruby block 'Copy Jetty init file (jetty.sh)'" do + expect(chef_run).to run_ruby_block 'Copy Jetty init file (jetty.sh)' + end + it "should create the folder /etc/jetty" do + path = '/etc/jetty' + expect(chef_run).to create_directory path + directory = chef_run.directory(path) + expect(directory.owner).to eq(node['jetty']['user']) + expect(directory.group).to eq(node['jetty']['group']) + end + it "should create the folder start.d" do + path = "#{node['jetty']['home']}/start.d" + expect(chef_run).to create_directory path + directory = chef_run.directory(path) + expect(directory.owner).to eq(node['jetty']['user']) + expect(directory.group).to eq(node['jetty']['group']) + end + it "should execute ruby block 'Copy Jetty config files'" do + expect(chef_run).to run_ruby_block 'Copy Jetty config files' + end + it "should create the file /etc/default/jetty" do + path = '/etc/default/jetty'; + expect(chef_run).to render_file(path) + end + it "should create the file /etc/jetty/jetty.conf" do + path = '/etc/jetty/jetty.conf'; + expect(chef_run).to render_file(path) + end + it "should create file 'start.ini'" do + expect(chef_run).to create_cookbook_file "#{node['jetty']['home']}/start.ini" + end + it "should create logs folder" do + path = !node['jetty']['logs'].empty? ? node['jetty']['logs'] : "#{node['jetty']['home']}/logs" + expect(chef_run).to create_directory(path).with(owner: node.jetty.user, group: node.jetty.group) + end + it "should create the file '/resources/jetty-logging.properties'" do + path = "#{node['jetty']['home']}/resources/jetty-logging.properties" + expect(chef_run).to render_file(path) + end + it "should set to start on boot time" do + expect(chef_run).to enable_service 'jetty' + end + + if /9\.2\.3/.match(version) + it "should execute ruby block 'Extract modules'" do + expect(chef_run).to run_ruby_block 'Copy Jetty modules' + end + it "should create modules folder" do + expect(chef_run).to create_directory(File.join(node.jetty.home, "modules")) + end + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ee25a5e..0b5f741 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,8 @@ require "chefspec" +require "chefspec/berkshelf" +require "chefspec/deprecations" CHEF_RUN_OPTIONS = { :platform => 'ubuntu', :version => '12.04' -} \ No newline at end of file +} diff --git a/test/cookbooks/hipsnip-jetty_test/files/default/tests/minitest/jetty_9_1_test.rb b/test/cookbooks/hipsnip-jetty_test/files/default/tests/minitest/jetty_9_1_test.rb new file mode 100644 index 0000000..aa521d5 --- /dev/null +++ b/test/cookbooks/hipsnip-jetty_test/files/default/tests/minitest/jetty_9_1_test.rb @@ -0,0 +1,30 @@ +require File.expand_path('../support/helpers', __FILE__) +require 'net/http' + +describe_recipe "hipsnip-jetty_test::jetty_9_1" do + include Helpers::CookbookTest + + it "should have started a Jetty server" do + uri = URI("http://127.0.0.1:#{node['jetty']['port']}") + attempts_total = 3; + attempts_remaining = attempts_total + wait_between_attempt = 10 + while attempts_remaining != 0 + begin + if attempts_remaining != attempts_total + puts "New attempt in #{wait_between_attempt} seconds..." + sleep(wait_between_attempt) + end + attempts_remaining = attempts_remaining - 1 + response = Net::HTTP.get_response(uri) + break + rescue Errno::ECONNREFUSED => econnrefused + #catch connection error + puts econnrefused.inspect + puts "#{attempts_remaining}/#{attempts_total} remaining attempt(s) ..." + end + end + # no web app have been provisionned so it is expected to have a HTTP 404 response + assert_instance_of(Net::HTTPNotFound, response,"HTTP response") + end +end diff --git a/test/cookbooks/hipsnip-jetty_test/recipes/jetty_9_1.rb b/test/cookbooks/hipsnip-jetty_test/recipes/jetty_9_1.rb new file mode 100644 index 0000000..3e80b81 --- /dev/null +++ b/test/cookbooks/hipsnip-jetty_test/recipes/jetty_9_1.rb @@ -0,0 +1,6 @@ +node.set['java']['jdk_version'] = 7 + +node.set['jetty']['version'] = '9.2.3.v20140905' +node.set['jetty']['link'] = 'http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.2.3.v20140905.tar.gz&r=1' +node.set['jetty']['checksum'] = '9a47f2d02efa52583db3195623080ff7ccd96b6aa9150aeaa43e1203de22770a' +include_recipe 'hipsnip-jetty' From 012e28dcc1bcaaa92320c4bc0494f35277154e8e Mon Sep 17 00:00:00 2001 From: what do you want? Date: Tue, 11 Nov 2014 10:03:47 -0800 Subject: [PATCH 2/2] Create log directory for the request logs - Move calling tar to script block to fix tests - Fix the foodcritic test FWIW --- Berksfile.lock | 2 +- recipes/default.rb | 24 +++++++++++++----------- spec/default_spec.rb | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Berksfile.lock b/Berksfile.lock index 3574879..626a7b4 100644 --- a/Berksfile.lock +++ b/Berksfile.lock @@ -7,7 +7,7 @@ "locked_version": "1.28.0" }, "apt": { - "locked_version": "2.1.0" + "locked_version": "2.6.0" }, "minitest-handler": { "locked_version": "0.2.1" diff --git a/recipes/default.rb b/recipes/default.rb index 88e6ded..f4f85ce 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -94,19 +94,19 @@ def above9_0?(major, minor) mode 0644 end - -ruby_block 'Extract Jetty' do - block do - Chef::Log.info "Extracting Jetty archive #{node['jetty']['download']} into #{node['jetty']['directory']}" - `tar xzf #{node['jetty']['download']} -C #{node['jetty']['directory']}` - raise "Failed to extract Jetty package" unless File.exists?(node['jetty']['extracted']) - end +execute 'Extract Jetty' do + command "tar xzf #{node['jetty']['download']} -C #{node['jetty']['directory']}" not_if do File.exists?(node['jetty']['extracted']) end end +ruby_block 'Check the Extracted Jetty' do + block do + raise "Failed to extract Jetty package" unless File.exists?(node['jetty']['extracted']) + end +end ruby_block 'Copy Jetty lib files' do block do @@ -264,10 +264,12 @@ def above9_0?(major, minor) # Logs # folder for logs mandatory at least for the request logs -directory node['jetty']['logs'] do - mode '755' - owner node['jetty']['user'] - group node['jetty']['group'] +[node['jetty']['logs'], "#{node['jetty']['home']}/logs"].each do |dir| + directory dir do + mode '755' + owner node['jetty']['user'] + group node['jetty']['group'] + end end template File.join(node['jetty']['home'], 'resources/jetty-logging.properties') do diff --git a/spec/default_spec.rb b/spec/default_spec.rb index a2db752..9888d9a 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -31,7 +31,7 @@ ) end it "should execute ruby block 'Extract Jetty'" do - expect(chef_run).to run_ruby_block 'Extract Jetty' + expect(chef_run).to run_execute 'Extract Jetty' end it "should execute ruby block 'Copy Jetty lib files'" do expect(chef_run).to run_ruby_block 'Copy Jetty lib files'