From 67e0d572a27cda36971f4b663b925b9fdef3fb80 Mon Sep 17 00:00:00 2001 From: Daniel Hopper Date: Thu, 17 Mar 2016 12:16:25 -0400 Subject: [PATCH 1/2] Fixes 242 by switching from using the staging module to the new archive module instead --- .fixtures.yml | 2 +- manifests/install.pp | 64 +++++++++++++++++++--------------- metadata.json | 4 +-- spec/classes/init_spec.rb | 28 +++++++++------ spec/spec_helper_acceptance.rb | 2 +- 5 files changed, 58 insertions(+), 42 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index c497f4ab..85309e3c 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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}" diff --git a/manifests/install.pp b/manifests/install.pp index aa12ef04..b0ebeb0e 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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, diff --git a/metadata.json b/metadata.json index cb5c50fa..d8a4a8d3 100644 --- a/metadata.json +++ b/metadata.json @@ -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": [ diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 4d1dbaeb..5eb447fa 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -84,16 +84,24 @@ 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 @@ -101,7 +109,7 @@ 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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index c7f1f0aa..bea821d1 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -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 From 19b029eb8271bfdaf5c7564e7f93d43d84752833 Mon Sep 17 00:00:00 2001 From: Kyle Anderson Date: Sat, 19 Mar 2016 13:33:01 -0700 Subject: [PATCH 2/2] Fix integration tests to work correctly with puppet-archive --- spec/acceptance/standard_spec.rb | 25 +++++++++++----- spec/acceptance/ui_spec.rb | 45 ----------------------------- spec/acceptance/unsupported_spec.rb | 10 ------- spec/spec_helper_acceptance.rb | 4 +-- 4 files changed, 20 insertions(+), 64 deletions(-) delete mode 100644 spec/acceptance/ui_spec.rb delete mode 100644 spec/acceptance/unsupported_spec.rb diff --git a/spec/acceptance/standard_spec.rb b/spec/acceptance/standard_spec.rb index 9ba9c122..9235767c 100644 --- a/spec/acceptance/standard_spec.rb +++ b/spec/acceptance/standard_spec.rb @@ -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 diff --git a/spec/acceptance/ui_spec.rb b/spec/acceptance/ui_spec.rb deleted file mode 100644 index 05a8aecf..00000000 --- a/spec/acceptance/ui_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'spec_helper_acceptance' - -describe 'consul class' do - - context 'UI parameters' do - # Using puppet_apply as a helper - it 'should work with no errors based on the UI example' do - pp = <<-EOS - class { 'consul': - version => '0.5.2', - config_hash => { - 'datacenter' => 'east-aws', - 'data_dir' => '/opt/consul', - 'ui_dir' => '/opt/consul/ui', - 'client_addr' => '0.0.0.0', - 'log_level' => 'INFO', - 'node_name' => 'foobar', - '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) - end - - describe file('/opt/consul') do - it { should be_directory } - end - - describe file('/opt/consul/ui') do - it { should be_linked_to '/opt/consul/0.5.2_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/ } - end - - end -end diff --git a/spec/acceptance/unsupported_spec.rb b/spec/acceptance/unsupported_spec.rb deleted file mode 100644 index 4615c1f1..00000000 --- a/spec/acceptance/unsupported_spec.rb +++ /dev/null @@ -1,10 +0,0 @@ -#require 'spec_helper_acceptance' -# -#describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do -# it 'should fail' do -# pp = <<-EOS -# class { 'consul': } -# EOS -# expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/unsupported osfamily/i) -# end -#end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index bea821d1..7fba0f4d 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -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', 'puppet/archive'), { :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