From 81570757289d7fea6f7b780ab6b6380113d078d5 Mon Sep 17 00:00:00 2001 From: Thijs Terlouw Date: Mon, 18 May 2015 13:38:53 +0200 Subject: [PATCH] Upgrade and Downgrade with url --- manifests/install.pp | 37 +++++++++++++++++++++++++------------ manifests/params.pp | 2 +- spec/classes/init_spec.rb | 14 +++++++------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index c5e6c935..a677d024 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -15,37 +15,50 @@ if $consul::install_method == 'url' { + $version = $consul::version + $consul_archive_target = "consul_${version}.zip" + $consul_web_ui_archive_target = "consul_web_ui_${version}.zip" + if $::operatingsystem != 'darwin' { ensure_packages(['unzip']) } - staging::file { 'consul.zip': + staging::file { $consul_archive_target: source => $consul::download_url } -> - staging::extract { 'consul.zip': - target => $consul::bin_dir, - creates => "${consul::bin_dir}/consul", + file { "${consul::bin_dir}/consul_${version}/": + ensure => 'directory', + owner => 'root', + group => 0, + mode => '0755', + } -> + staging::extract { $consul_archive_target: + target => "${consul::bin_dir}/consul_${version}/", + creates => "${consul::bin_dir}/consul_${version}/consul", } -> file { "${consul::bin_dir}/consul": - owner => 'root', - group => 0, # 0 instead of root because OS X uses "wheel". - mode => '0555', + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0555', + target => "${consul::bin_dir}/consul_${version}/consul", + notify => Class['consul::run_service'], } + if ($consul::ui_dir and $consul::data_dir) { - file { "${consul::data_dir}/${consul::version}_web_ui": + file { "${consul::data_dir}/${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.zip': + staging::deploy { $consul_web_ui_archive_target: source => $consul::ui_download_url, - target => "${consul::data_dir}/${consul::version}_web_ui", - creates => "${consul::data_dir}/${consul::version}_web_ui/dist", + target => "${consul::data_dir}/${version}_web_ui", + creates => "${consul::data_dir}/${version}_web_ui/dist", } file { $consul::ui_dir: ensure => 'symlink', - target => "${consul::data_dir}/${consul::version}_web_ui/dist", + target => "${consul::data_dir}/${version}_web_ui/dist", } } diff --git a/manifests/params.pp b/manifests/params.pp index d5370264..9b44fdde 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -10,7 +10,7 @@ $package_ensure = 'latest' $ui_package_name = 'consul_ui' $ui_package_ensure = 'latest' - $version = '0.5.0' + $version = hiera('consul::version', '0.5.0') # ensure defaults resolve from hiera as well case $::architecture { 'x86_64', 'amd64': { $arch = 'amd64' } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 70c46ee3..df9031ef 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -29,7 +29,7 @@ }} it { expect { should compile }.to raise_error(/is not a boolean/) } end - + context 'When passing a non-bool as manage_service' do let(:params) {{ :manage_service => 'hello' @@ -72,21 +72,21 @@ end context "When installing via URL by default" do - it { should contain_staging__file('consul.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip') } + it { should contain_staging__file('consul_0.5.0.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/0.5.0_linux_amd64.zip') } end context "When installing via URL by with a special version" do let(:params) {{ :version => '42', }} - it { should contain_staging__file('consul.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/42_linux_amd64.zip') } + it { should contain_staging__file('consul_42.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/42_linux_amd64.zip') } end context "When installing via URL by with a custom url" do let(:params) {{ :download_url => 'http://myurl', }} - it { should contain_staging__file('consul.zip').with(:source => 'http://myurl') } + it { should contain_staging__file('consul_0.5.0.zip').with(:source => 'http://myurl') } end @@ -117,7 +117,7 @@ 'ui_dir' => '/dir1/dir2', }, }} - it { should contain_staging__file('consul_web_ui.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/0.5.0_web_ui.zip') } + it { should contain_staging__file('consul_web_ui_0.5.0.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/0.5.0_web_ui.zip') } end context "When installing UI via URL by with a special version" do @@ -128,7 +128,7 @@ 'ui_dir' => '/dir1/dir2', }, }} - it { should contain_staging__file('consul_web_ui.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/42_web_ui.zip') } + it { should contain_staging__file('consul_web_ui_42.zip').with(:source => 'https://dl.bintray.com/mitchellh/consul/42_web_ui.zip') } end context "When installing UI via URL by with a custom url" do @@ -139,7 +139,7 @@ 'ui_dir' => '/dir1/dir2', }, }} - it { should contain_staging__deploy('consul_web_ui.zip').with(:source => 'http://myurl') } + it { should contain_staging__deploy('consul_web_ui_0.5.0.zip').with(:source => 'http://myurl') } end context "By default, a user and group should be installed" do