Skip to content

Commit

Permalink
Fixes 242 by switching from using the staging module to the new archi…
Browse files Browse the repository at this point in the history
…ve module instead
  • Loading branch information
Daniel Hopper committed Mar 18, 2016
1 parent dd5ddf0 commit 67e0d57
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 42 deletions.
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'

This comment has been minimized.

Copy link
@sjoeboo

sjoeboo Mar 24, 2016

Contributor

so i don't think we need/can use this include here. ::archive has no class defined, so this can't be found...

This comment has been minimized.

Copy link
@hopperd

hopperd Mar 24, 2016

Contributor

Not sure what you referencing, but there is in fact a class reference for this and is required for various systems (specifically windows).

https://github.com/voxpupuli/puppet-archive/blob/master/manifests/init.pp#L24

This comment has been minimized.

Copy link
@sjoeboo

sjoeboo via email Mar 24, 2016

Contributor
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
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
2 changes: 1 addition & 1 deletion spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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/archive'), { :acceptable_exit_codes => [0,1] }
end
end
end

0 comments on commit 67e0d57

Please sign in to comment.