Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching from staging to archive module #243

Merged
merged 2 commits into from
Mar 24, 2016
Merged
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
2 changes: 1 addition & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fixtures:
repositories:
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
staging: "https://github.com/nanliu/puppet-staging.git"
archive: "https://github.com/voxpupuli/puppet-archive.git"
symlinks:
consul: "#{source_dir}"
64 changes: 36 additions & 28 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,50 +15,58 @@

case $consul::install_method {
'url': {
include staging
staging::file { "consul-${consul::version}.${consul::download_extension}":
source => $consul::real_download_url,
} ->
file { "${::staging::path}/consul-${consul::version}":
$install_path = '/opt/puppet-archive'

# only notify if we are installing a new version (work around for switching to archive module)
if $::consul_version != $consul::version {
$do_notify_service = $consul::notify_service
}

include '::archive'
file { [
$install_path,
"${install_path}/consul-${consul::version}"]:
ensure => directory,
} ->
staging::extract { "consul-${consul::version}.${consul::download_extension}":
target => "${::staging::path}/consul-${consul::version}",
creates => "${::staging::path}/consul-${consul::version}/consul",
} ->
}->
archive { "${install_path}/consul-${consul::version}.${consul::download_extension}":
ensure => present,
source => $consul::real_download_url,
extract => true,
extract_path => "${install_path}/consul-${consul::version}",
creates => "${install_path}/consul-${consul::version}/consul",
}->
file {
"${::staging::path}/consul-${consul::version}/consul":
"${install_path}/consul-${consul::version}/consul":
owner => 'root',
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0555';
"${consul::bin_dir}/consul":
ensure => link,
notify => $consul::notify_service,
target => "${::staging::path}/consul-${consul::version}/consul";
notify => $do_notify_service,
target => "${install_path}/consul-${consul::version}/consul";
}

if ($consul::ui_dir and $consul::data_dir) {

# The 'dist' dir was removed from the web_ui archive in Consul version 0.6.0
if (versioncmp($::consul::version, '0.6.0') < 0) {
$staging_creates = "${consul::data_dir}/${consul::version}_web_ui/dist"
$ui_symlink_target = $staging_creates
$archive_creates = "${install_path}/consul-${consul::version}_web_ui/dist"
$ui_symlink_target = $archive_creates
} else {
$staging_creates = "${consul::data_dir}/${consul::version}_web_ui/index.html"
$ui_symlink_target = "${consul::data_dir}/${consul::version}_web_ui"
$archive_creates = "${install_path}/consul-${consul::version}_web_ui/index.html"
$ui_symlink_target = "${install_path}/consul-${consul::version}_web_ui"
}

file { "${consul::data_dir}/${consul::version}_web_ui":
ensure => 'directory',
owner => 'root',
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0755',
} ->
staging::deploy { "consul_web_ui-${consul::version}.zip":
source => $consul::real_ui_download_url,
target => "${consul::data_dir}/${consul::version}_web_ui",
creates => $staging_creates,
} ->
file { "${install_path}/consul-${consul::version}_web_ui":
ensure => directory,
}->
archive { "${install_path}/consul_web_ui-${consul::version}.zip":
ensure => present,
source => $consul::real_ui_download_url,
extract => true,
extract_path => "${install_path}/consul-${consul::version}_web_ui",
creates => $archive_creates,
}->
file { $consul::ui_dir:
ensure => 'symlink',
target => $ui_symlink_target,
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"version_requirement": ">= 4.6.0 <5.0.0"
},
{
"name": "nanliu/staging",
"version_requirement": ">=0.4.0 <2.0.0"
"name": "puppet/archive",
"version_requirement": ">=0.5.0 <1.0.0"
}
],
"operatingsystem_support": [
Expand Down
25 changes: 18 additions & 7 deletions spec/acceptance/standard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,47 @@
describe 'consul class' do

context 'default parameters' do
# Using puppet_apply as a helper
apply_manifest_opts = {
:catch_failures => true,
:debug => true,
}
it 'should work with no errors based on the example' do
pp = <<-EOS
package { 'zip': ensure => present } ->
# Don't manage the service as it doesn't work well in docker
class { 'consul':
version => '0.5.2',
config_hash => {
version => '0.6.4',
manage_service => false,
config_hash => {
'datacenter' => 'east-aws',
'data_dir' => '/opt/consul',
'ui_dir' => '/opt/consul/ui',
'log_level' => 'INFO',
'node_name' => 'foobar',
'server' => true
'server' => true,
}
}
EOS

# Run it twice and test for idempotency
expect(apply_manifest(pp).exit_code).to_not eq(1)
expect(apply_manifest(pp).exit_code).to eq(0)
expect(apply_manifest(pp, apply_manifest_opts).exit_code).to_not eq(1)
expect(apply_manifest(pp, apply_manifest_opts).exit_code).to eq(0)
end

describe file('/opt/consul') do
it { should be_directory }
end

describe file('/opt/consul/ui') do
it { should be_linked_to '/opt/puppet-archive/consul-0.6.4_web_ui' }
end

describe service('consul') do
it { should be_enabled }
end

describe command('consul version') do
its(:stdout) { should match /Consul v0\.5\.2/ }
its(:stdout) { should match /Consul v0\.6\.4/ }
end

end
Expand Down
45 changes: 0 additions & 45 deletions spec/acceptance/ui_spec.rb

This file was deleted.

10 changes: 0 additions & 10 deletions spec/acceptance/unsupported_spec.rb

This file was deleted.

28 changes: 18 additions & 10 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,32 @@
end

context "When installing via URL by default" do
it { should contain_staging__file('consul-0.5.2.zip').with(:source => 'https://releases.hashicorp.com/consul/0.5.2/consul_0.5.2_linux_amd64.zip') }
it { should contain_archive('/opt/puppet-archive/consul-0.5.2.zip').with(:source => 'https://releases.hashicorp.com/consul/0.5.2/consul_0.5.2_linux_amd64.zip') }
it { should contain_file('/opt/puppet-archive').with(:ensure => 'directory') }
it { should contain_file('/opt/puppet-archive/consul-0.5.2').with(:ensure => 'directory') }
it { should contain_file('/usr/local/bin/consul').that_notifies('Class[consul::run_service]') }
#it { should contain_notify(['Class[consul::run_service]']) }
end

context "When installing by archive via URL and current version is already installed" do
let(:facts) {{ :consul_version => '0.5.2' }}
it { should contain_archive('/opt/puppet-archive/consul-0.5.2.zip').with(:source => 'https://releases.hashicorp.com/consul/0.5.2/consul_0.5.2_linux_amd64.zip') }
it { should contain_file('/usr/local/bin/consul') }
it { should_not contain_notify(['Class[consul::run_service]']) }
end

context "When installing via URL by with a special version" do
let(:params) {{
:version => '42',
}}
it { should contain_staging__file('consul-42.zip').with(:source => 'https://releases.hashicorp.com/consul/42/consul_42_linux_amd64.zip') }
it { should contain_archive('/opt/puppet-archive/consul-42.zip').with(:source => 'https://releases.hashicorp.com/consul/42/consul_42_linux_amd64.zip') }
it { should contain_file('/usr/local/bin/consul').that_notifies('Class[consul::run_service]') }
end

context "When installing via URL by with a custom url" do
let(:params) {{
:download_url => 'http://myurl',
}}
it { should contain_staging__file('consul-0.5.2.zip').with(:source => 'http://myurl') }
it { should contain_archive('/opt/puppet-archive/consul-0.5.2.zip').with(:source => 'http://myurl') }
it { should contain_file('/usr/local/bin/consul').that_notifies('Class[consul::run_service]') }
end

Expand Down Expand Up @@ -143,8 +151,8 @@
'ui_dir' => '/dir1/dir2',
},
}}
it { should contain_staging__deploy('consul_web_ui-0.5.2.zip').with(:source => 'https://releases.hashicorp.com/consul/0.5.2/consul_0.5.2_web_ui.zip') }
it { should contain_file('/dir1/dir2').that_requires('Staging::Deploy[consul_web_ui-0.5.2.zip]') }
it { should contain_archive('/opt/puppet-archive/consul_web_ui-0.5.2.zip').with(:source => 'https://releases.hashicorp.com/consul/0.5.2/consul_0.5.2_web_ui.zip') }
it { should contain_file('/dir1/dir2').that_requires('Archive[/opt/puppet-archive/consul_web_ui-0.5.2.zip]') }
it { should contain_file('/dir1/dir2').with(:ensure => 'symlink') }
end

Expand All @@ -156,7 +164,7 @@
'ui_dir' => '/dir1/dir2',
},
}}
it { should contain_staging__deploy('consul_web_ui-42.zip').with(:source => 'https://releases.hashicorp.com/consul/42/consul_42_web_ui.zip') }
it { should contain_archive('/opt/puppet-archive/consul_web_ui-42.zip').with(:source => 'https://releases.hashicorp.com/consul/42/consul_42_web_ui.zip') }
end

context "When installing UI via URL when version < 0.6.0" do
Expand All @@ -167,7 +175,7 @@
'ui_dir' => '/dir1/dir2',
},
}}
it { should contain_staging__deploy('consul_web_ui-0.5.99.zip').with(:creates => %r{/dist$}) }
it { should contain_archive('/opt/puppet-archive/consul_web_ui-0.5.99.zip').with(:creates => %r{/dist$}) }
it { should contain_file('/dir1/dir2').with(:target => %r{/dist$}) }
end

Expand All @@ -179,7 +187,7 @@
'ui_dir' => '/dir1/dir2',
},
}}
it { should contain_staging__deploy('consul_web_ui-0.6.0.zip').with(:creates => %r{/index\.html$}) }
it { should contain_archive('/opt/puppet-archive/consul_web_ui-0.6.0.zip').with(:creates => %r{/index\.html$}) }
it { should contain_file('/dir1/dir2').with(:target => %r{_web_ui$}) }
end

Expand All @@ -191,7 +199,7 @@
'ui_dir' => '/dir1/dir2',
},
}}
it { should contain_staging__deploy('consul_web_ui-0.5.2.zip').with(:source => 'http://myurl') }
it { should contain_archive('/opt/puppet-archive/consul_web_ui-0.5.2.zip').with(:source => 'http://myurl') }
end

context "By default, a user and group should be installed" do
Expand Down
4 changes: 2 additions & 2 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# Install module and dependencies
puppet_module_install(:source => proj_root, :module_name => 'consul')
hosts.each do |host|
on host, puppet('module', 'install', 'puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'nanliu/staging'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppet-stdlib'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module', 'install', 'puppet-archive'), { :acceptable_exit_codes => [0,1] }
end
end
end