From 0d0bef00195b8724d04dfc51234c0f926624aac8 Mon Sep 17 00:00:00 2001 From: Tomasz Setkowski Date: Sun, 25 Oct 2015 10:28:58 +0000 Subject: [PATCH] #52 chefspec with shared examples for Go server on rhel and debian we force java to 7 - user does not have to set it anymore removed ubuntu 14.10 and 13.10 from test suites - they are EOF and very similar to LTS anyway --- .kitchen.docker.yml | 30 ----------------------- .kitchen.openstack.yml | 2 +- README.md | 7 ++++++ recipes/agent_linux.rb | 2 +- recipes/java.rb | 3 +++ recipes/server_linux.rb | 2 +- spec/go_server_spec.rb | 54 +++++++++++++++++++++++++---------------- spec/shared_examples.rb | 16 ++++++++++++ spec/spec_helper.rb | 1 + 9 files changed, 63 insertions(+), 54 deletions(-) create mode 100644 recipes/java.rb create mode 100644 spec/shared_examples.rb diff --git a/.kitchen.docker.yml b/.kitchen.docker.yml index db28675..f3c6b67 100644 --- a/.kitchen.docker.yml +++ b/.kitchen.docker.yml @@ -24,20 +24,6 @@ platforms: - "cd /tmp/fuse ; cat DEBIAN/postinst" - "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb" - "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb" -# - name: ubuntu-13.10 -# driver: -# provision_command: -# - "apt-get install -y net-tools" # netstat, needed to run specs -# - "apt-get install -y libfuse2" -# - "mkdir -p /tmp/fuse" -# - "cd /tmp/fuse ; apt-get download fuse" -# - "cd /tmp/fuse ; dpkg-deb -x fuse_* ." -# - "cd /tmp/fuse ; dpkg-deb -e fuse_*" -# - "cd /tmp/fuse ; rm fuse_*.deb" -# - "cd /tmp/fuse ; echo '#!/bin/bash\\nexit 0\\n' > DEBIAN/postinst" -# - "cd /tmp/fuse ; cat DEBIAN/postinst" -# - "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb" -# - "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb" - name: ubuntu-14.04 driver: provision_command: @@ -52,28 +38,12 @@ platforms: - "cd /tmp/fuse ; cat DEBIAN/postinst" - "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb" - "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb" -# - name: ubuntu-14.10 -# driver: -# provision_command: -# - "apt-get install -y net-tools" # netstat, needed to run specs -# - "apt-get install -y libfuse2" -# - "mkdir -p /tmp/fuse" -# - "cd /tmp/fuse ; apt-get download fuse" -# - "cd /tmp/fuse ; dpkg-deb -x fuse_* ." -# - "cd /tmp/fuse ; dpkg-deb -e fuse_*" -# - "cd /tmp/fuse ; rm fuse_*.deb" -# - "cd /tmp/fuse ; echo '#!/bin/bash\\nexit 0\\n' > DEBIAN/postinst" -# - "cd /tmp/fuse ; cat DEBIAN/postinst" -# - "cd /tmp/fuse ; dpkg-deb -b . /tmp/fuse.deb" -# - "cd /tmp/fuse ; dpkg -i /tmp/fuse.deb" suites: - name: default run_list: - recipe[gocd] attributes: - java: - jdk_version: 7 gocd: server: max_mem: '1024m' diff --git a/.kitchen.openstack.yml b/.kitchen.openstack.yml index 46ea0e3..da8919c 100644 --- a/.kitchen.openstack.yml +++ b/.kitchen.openstack.yml @@ -11,7 +11,7 @@ platforms: box: 'debian-7.8-bpk-chef-12.4.1' customize: server_name: 'kt-go' - flavor: 'p.c1.m1536.d5.e0' + flavor: 'v.c1.m1536.d5.e0' server_create_timeout: 540 server_active_timeout: 540 diff --git a/README.md b/README.md index a9208c9..c02e20a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,13 @@ This cookbook has been tested on the following platforms: * RedHat >= 6 * Windows - primitive support, but enhancements welcome :) +### Java + +Please note that java (>= 7) is needed to run Go server and agents. This cookbook +sets `node['java']['jdk_version']` at `force_default` level but it may not work properly +when you include `java` in node run_list before `gocd` cookbook. The safest approach +is to set java version in node attributes (in a role or environment). + # GoCD Server gocd::server will install and start a GoCD server. diff --git a/recipes/agent_linux.rb b/recipes/agent_linux.rb index 969dade..353e74a 100644 --- a/recipes/agent_linux.rb +++ b/recipes/agent_linux.rb @@ -1,5 +1,5 @@ include_recipe 'gocd::repository' -include_recipe "java" +include_recipe "gocd::java" package "go-agent" do notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately diff --git a/recipes/java.rb b/recipes/java.rb new file mode 100644 index 0000000..b1de44d --- /dev/null +++ b/recipes/java.rb @@ -0,0 +1,3 @@ +# must be early so that java home attrbute gets assigned soon enough +node.force_default['java']['jdk_version'] = '7' +include_recipe 'java' diff --git a/recipes/server_linux.rb b/recipes/server_linux.rb index 1697928..4a40f08 100644 --- a/recipes/server_linux.rb +++ b/recipes/server_linux.rb @@ -1,5 +1,5 @@ include_recipe 'gocd::repository' -include_recipe "java" +include_recipe "gocd::java" package "go-server" do notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately diff --git a/spec/go_server_spec.rb b/spec/go_server_spec.rb index 229f6d4..70b3c3b 100644 --- a/spec/go_server_spec.rb +++ b/spec/go_server_spec.rb @@ -1,36 +1,48 @@ require 'spec_helper' describe 'gocd::server' do - describe 'debian' do - let(:chef_run) do - run = ChefSpec::SoloRunner.new do |node| - node.automatic['lsb']['id'] = 'Debian' - node.automatic['platform_family'] = 'debian' - node.automatic['platform'] = 'debian' - node.automatic['os'] = 'linux' - node.normal['java']['jdk_version'] = '7' - end - run.converge(described_recipe) - end - - it 'includes apt recipe' do - expect(chef_run).to include_recipe('apt::default') - end + shared_examples_for :server_recipe do it 'includes java recipe' do expect(chef_run).to include_recipe('java::default') end - it 'adds thoughtworks apt repository' do - expect(chef_run).to add_apt_repository('gocd') - end - it 'installs go-server apt package' do + it 'installs go-server package' do expect(chef_run).to install_package('go-server') end - it 'creates go server configuration in /etc/default/go-server' do expect(chef_run).to render_file('/etc/default/go-server').with_content { |content| - expect(content).to_not include('java-6-openjdk') + expect(content).to_not include('java-6') } end + it 'configures go-server service' do + expect(chef_run).to enable_service('go-server') + expect(chef_run).to start_service('go-server') + end + end + context 'When all attributes are default and platform is debian' do + let(:chef_run) do + run = ChefSpec::SoloRunner.new do |node| + node.automatic['lsb']['id'] = 'Debian' + node.automatic['platform_family'] = 'debian' + node.automatic['platform'] = 'debian' + node.automatic['os'] = 'linux' + end + run.converge(described_recipe) + end + it_behaves_like :server_recipe + it_behaves_like :apt_repository_recipe + end + context 'When all attributes are default and platform is centos' do + let(:chef_run) do + run = ChefSpec::SoloRunner.new do |node| + node.automatic['platform_family'] = 'rhel' + node.automatic['platform'] = 'centos' + node.automatic['os'] = 'linux' + end + run.converge(described_recipe) + end + it_behaves_like :server_recipe + it_behaves_like :yum_repository_recipe end + #TODO: server on windows end diff --git a/spec/shared_examples.rb b/spec/shared_examples.rb new file mode 100644 index 0000000..918852d --- /dev/null +++ b/spec/shared_examples.rb @@ -0,0 +1,16 @@ +shared_examples_for :apt_repository_recipe do + it 'includes apt recipe' do + expect(chef_run).to include_recipe('apt') + end + it 'adds gocd apt repository' do + expect(chef_run).to add_apt_repository('gocd') + end +end +shared_examples_for :yum_repository_recipe do + it 'includes yum recipe' do + expect(chef_run).to include_recipe('yum') + end + it 'adds gocd yum repository' do + expect(chef_run).to create_yum_repository('gocd') + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a2316ae..44bbff8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,4 @@ require 'chefspec' require 'chefspec/berkshelf' +require_relative 'shared_examples' ChefSpec::Coverage.start!