Skip to content

Commit

Permalink
gocd#52 chefspec with shared examples for Go server on rhel and debian
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tomzo committed Oct 25, 2015
1 parent 92edb55 commit 0d0bef0
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 54 deletions.
30 changes: 0 additions & 30 deletions .kitchen.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .kitchen.openstack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion recipes/agent_linux.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions recipes/java.rb
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion recipes/server_linux.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
54 changes: 33 additions & 21 deletions spec/go_server_spec.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'chefspec'
require 'chefspec/berkshelf'
require_relative 'shared_examples'
ChefSpec::Coverage.start!

0 comments on commit 0d0bef0

Please sign in to comment.