Skip to content
This repository was archived by the owner on Feb 18, 2020. It is now read-only.

Support Chef 13 and amazon platform_family #133

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ def fetch_go_version_from_url(url)

def package_extension
value_for_platform_family('debian' => '.deb',
%w(rhel fedora) => '.noarch.rpm',
%w(rhel fedora amazon) => '.noarch.rpm',
'windows' => '-setup.exe',
'default' => '.zip')
end

def os_dir
value_for_platform_family('debian' => 'deb',
%w(rhel fedora) => 'rpm',
%w(rhel fedora amazon) => 'rpm',
'windows' => 'win',
'default' => 'generic')
end
Expand Down
2 changes: 1 addition & 1 deletion recipes/agent_linux_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
source package_path
notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately
end
when 'rhel', 'fedora'
when 'rhel', 'fedora', 'amazon'
rpm_package 'go-agent' do
source package_path
notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately
Expand Down
2 changes: 1 addition & 1 deletion recipes/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
key node['gocd']['repository']['apt']['key'] unless node['gocd']['repository']['apt']['key'] == false
end

when 'rhel', 'fedora'
when 'rhel', 'fedora', 'amazon'
include_recipe 'yum'

yum_repository 'gocd' do
Expand Down
2 changes: 1 addition & 1 deletion recipes/server_linux_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
source package_path
notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately
end
when 'rhel', 'fedora'
when 'rhel', 'fedora', 'amazon'
rpm_package 'go-server' do
source package_path
notifies :reload, 'ohai[reload_passwd_for_go_user]', :immediately
Expand Down
86 changes: 86 additions & 0 deletions spec/go_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@
expect(chef_run).to upgrade_package('go-agent')
end
end
context 'When all attributes are default and platform is amazon' do
let(:chef_run) do
run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node|
node.automatic['platform_family'] = 'amazon'
node.automatic['platform'] = 'amazon'
node.automatic['os'] = 'linux'
node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go'
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe_linux
it_behaves_like :yum_repository_recipe
it 'installs go-agent package' do
expect(chef_run).to install_package('go-agent')
end

it 'upgrades go-agent package if version is set to `latest`' do
chef_run.node.set['gocd']['version'] = 'latest'
chef_run.converge(described_recipe)
expect(chef_run).to upgrade_package('go-agent')
end
end

context 'When many agents and all attributes are default and platform is debian' do
let(:chef_run) do
Expand Down Expand Up @@ -264,6 +289,31 @@
expect(chef_run).to install_rpm_package('go-agent')
end
end
context 'When installing from package file and platform is amazon' do
let(:chef_run) do
run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node|
node.automatic['platform_family'] = 'amazon'
node.automatic['platform'] = 'amazon'
node.automatic['os'] = 'linux'
node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go'
node.normal['gocd']['install_method'] = 'package_file'
end
allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content)
.and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}')
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe_linux
it 'downloads go-agent .rpm from remote URL' do
expect(chef_run).to create_remote_file('go-agent-stable.noarch.rpm').with(
source: 'https://download.gocd.org/binaries/16.2.1-3027/rpm/go-agent-16.2.1-3027.noarch.rpm')
end
it 'installs go-agent package from file' do
expect(chef_run).to install_rpm_package('go-agent')
end
end

context 'When installing from custom repository and platform is debian' do
let(:chef_run) do
Expand Down Expand Up @@ -333,6 +383,42 @@
expect(chef_run).to install_package('go-agent')
end

it 'upgrades go-agent package if version is set to `latest`' do
chef_run.node.set['gocd']['version'] = 'latest'
chef_run.converge(described_recipe)
expect(chef_run).to upgrade_package('go-agent')
end
end
context 'When installing from custom repository and platform is amazon' do
let(:chef_run) do
run = ChefSpec::SoloRunner.new(step_into: 'gocd_agent') do |node|
node.automatic['platform_family'] = 'amazon'
node.automatic['platform'] = 'amazon'
node.automatic['os'] = 'linux'
node.normal['gocd']['agent']['go_server_url'] = 'https://localhost:8154/go'
node.normal['gocd']['install_method'] = 'repository'
node.normal['gocd']['repository']['yum']['baseurl'] = 'http://mycustom/gocd-rpm'
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe_linux
it 'includes yum recipe' do
expect(chef_run).to include_recipe('yum')
end
it 'adds my custom gocd yum repository' do
expect(chef_run).to create_yum_repository('gocd').with(
baseurl: 'http://mycustom/gocd-rpm',
gpgcheck: true
)
end

it 'installs go-agent package' do
expect(chef_run).to install_package('go-agent')
end

it 'upgrades go-agent package if version is set to `latest`' do
chef_run.node.set['gocd']['version'] = 'latest'
chef_run.converge(described_recipe)
Expand Down
73 changes: 73 additions & 0 deletions spec/go_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@
expect(chef_run).to upgrade_package('go-server')
end
end
context 'When all attributes are default and platform is amazon' do
let(:chef_run) do
run = ChefSpec::SoloRunner.new do |node|
node.automatic['platform_family'] = 'amazon'
node.automatic['platform'] = 'amazon'
node.automatic['os'] = 'linux'
end
run.converge(described_recipe)
end
it_behaves_like :server_recipe
it_behaves_like :yum_repository_recipe
it 'installs go-server package' do
expect(chef_run).to install_package('go-server')
end
it 'upgrades go-server package if version is set to `latest`' do
chef_run.node.set['gocd']['version'] = 'latest'
chef_run.converge(described_recipe)
expect(chef_run).to upgrade_package('go-server')
end
end
# TODO: server on windows

context 'When installing from package_file and platform is debian' do
Expand Down Expand Up @@ -123,6 +143,27 @@
expect(chef_run).to install_rpm_package('go-server')
end
end
context 'When installing from package file and platform is amazon' do
let(:chef_run) do
run = ChefSpec::SoloRunner.new do |node|
node.automatic['platform_family'] = 'amazon'
node.automatic['platform'] = 'amazon'
node.automatic['os'] = 'linux'
node.normal['gocd']['install_method'] = 'package_file'
end
allow_any_instance_of(Chef::Resource::RemoteFile).to receive(:fetch_content)
.and_return('{"message": "{\"latest-version\": \"16.2.1-3027\"}"}')
run.converge(described_recipe)
end
it_behaves_like :server_recipe
it 'downloads go-server .rpm from remote URL' do
expect(chef_run).to create_remote_file('go-server-stable.noarch.rpm').with(
source: 'https://download.gocd.org/binaries/16.2.1-3027/rpm/go-server-16.2.1-3027.noarch.rpm')
end
it 'installs go-server package from file' do
expect(chef_run).to install_rpm_package('go-server')
end
end

context 'When installing from custom repository and platform is debian' do
let(:chef_run) do
Expand Down Expand Up @@ -185,6 +226,38 @@
expect(chef_run).to install_package('go-server')
end

it 'upgrades go-server package if version is set to `latest`' do
chef_run.node.set['gocd']['version'] = 'latest'
chef_run.converge(described_recipe)
expect(chef_run).to upgrade_package('go-server')
end
end
context 'When installing from custom repository and platform is amazon' do
let(:chef_run) do
run = ChefSpec::SoloRunner.new do |node|
node.automatic['platform_family'] = 'amazon'
node.automatic['platform'] = 'amazon'
node.automatic['os'] = 'linux'
node.normal['gocd']['install_method'] = 'repository'
node.normal['gocd']['repository']['yum']['baseurl'] = 'http://mycustom/gocd-rpm'
end
run.converge(described_recipe)
end
it_behaves_like :server_recipe
it 'includes yum recipe' do
expect(chef_run).to include_recipe('yum')
end
it 'adds my custom gocd yum repository' do
expect(chef_run).to create_yum_repository('gocd').with(
baseurl: 'http://mycustom/gocd-rpm',
gpgcheck: true
)
end

it 'installs go-server package' do
expect(chef_run).to install_package('go-server')
end

it 'upgrades go-server package if version is set to `latest`' do
chef_run.node.set['gocd']['version'] = 'latest'
chef_run.converge(described_recipe)
Expand Down