From 94874823cd6d47fdd82875e2e2c0f3fee552abb1 Mon Sep 17 00:00:00 2001 From: Rianol Jou Date: Fri, 2 Dec 2016 15:21:42 +0800 Subject: [PATCH] Use archive instead of staging --- .fixtures.yml | 4 +- manifests/install.pp | 91 ++++++++++++++++++---------------- metadata.json | 4 +- spec/classes/init_spec.rb | 35 +++++++++---- spec/spec_helper_acceptance.rb | 2 +- 5 files changed, 80 insertions(+), 56 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 168a72f..d6d4afa 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,6 +1,8 @@ fixtures: repositories: stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" - staging: "https://github.com/nanliu/puppet-staging.git" + archive: + repo: "https://github.com/voxpupuli/puppet-archive.git" + ref: "v1.1.2" symlinks: nomad: "#{source_dir}" diff --git a/manifests/install.pp b/manifests/install.pp index 322ea81..cc94737 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -4,79 +4,84 @@ # class nomad::install { - if $nomad::data_dir { - file { $nomad::data_dir: - ensure => 'directory', - owner => $nomad::user, - group => $nomad::group, + if $::nomad::data_dir { + file { $::nomad::data_dir: + ensure => directory, + owner => $::nomad::user, + group => $::nomad::group, mode => '0755', } } - case $nomad::install_method { + case $::nomad::install_method { 'url': { - include staging - staging::file { "nomad-${nomad::version}.${nomad::download_extension}": - source => $nomad::real_download_url, - } -> - file { "${::staging::path}/nomad-${nomad::version}": + $install_path = $::nomad::archive_path + + # only notify if we are installing a new version (work around for switching to archive module) + if $::nomad_version != $::nomad::version { + $do_notify_service = $::nomad::notify_service + } else { + $do_notify_service = undef + } + + include ::archive + file { [$install_path, "${install_path}/nomad-${::nomad::version}"]: ensure => directory, - } -> - staging::extract { "nomad-${nomad::version}.${nomad::download_extension}": - target => "${::staging::path}/nomad-${nomad::version}", - creates => "${::staging::path}/nomad-${nomad::version}/nomad", - } -> + owner => 'root', + group => 0, # 0 instead of root because OS X uses "wheel". + mode => '0555'; + }-> + archive { "${install_path}/nomad-${::nomad::version}.${::nomad::download_extension}": + ensure => present, + source => $::nomad::real_download_url, + extract => true, + extract_path => "${install_path}/nomad-${::nomad::version}", + creates => "${install_path}/nomad-${::nomad::version}/nomad", + }-> file { - "${::staging::path}/nomad-${nomad::version}/nomad": + "${install_path}/nomad-${::nomad::version}/nomad": owner => 'root', group => 0, # 0 instead of root because OS X uses "wheel". mode => '0555'; - "${nomad::bin_dir}/nomad": + "${::nomad::bin_dir}/nomad": ensure => link, - notify => $nomad::notify_service, - target => "${::staging::path}/nomad-${nomad::version}/nomad"; + notify => $do_notify_service, + target => "${install_path}/nomad-${::nomad::version}/nomad"; } } 'package': { - package { $nomad::package_name: - ensure => $nomad::package_ensure, - } - - if $nomad::ui_dir { - package { $nomad::ui_package_name: - ensure => $nomad::ui_package_ensure, - require => Package[$nomad::package_name] - } + package { $::nomad::package_name: + ensure => $::nomad::package_ensure, } - if $nomad::manage_user { - User[$nomad::user] -> Package[$nomad::package_name] + if $::nomad::manage_user { + User[$::nomad::user] -> Package[$::nomad::package_name] } - if $nomad::data_dir { - Package[$nomad::package_name] -> File[$nomad::data_dir] + if $::nomad::data_dir { + Package[$::nomad::package_name] -> File[$::nomad::data_dir] } } 'none': {} default: { - fail("The provided install method ${nomad::install_method} is invalid") + fail("The provided install method ${::nomad::install_method} is invalid") } } - if $nomad::manage_user { - user { $nomad::user: - ensure => 'present', + if $::nomad::manage_user { + user { $::nomad::user: + ensure => present, system => true, - groups => $nomad::extra_groups, + groups => $::nomad::extra_groups, } - if $nomad::manage_group { - Group[$nomad::group] -> User[$nomad::user] + if $::nomad::manage_group { + Group[$::nomad::group] -> User[$::nomad::user] } } - if $nomad::manage_group { - group { $nomad::group: - ensure => 'present', + if $::nomad::manage_group { + group { $::nomad::group: + ensure => present, system => true, } } diff --git a/metadata.json b/metadata.json index f7d6a97..8c003ea 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": ">=1.0.0 <2.0.0" } ], "operatingsystem_support": [ diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 70222d8..0daf3ac 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -9,8 +9,11 @@ :osfamily => 'Debian', :operatingsystemrelease => '10.04', :kernel => 'Linux', + :ipaddress_lo => '127.0.0.1', + :nomad_version => 'unknown', } end + # Installation Stuff context 'On an unsupported arch' do let(:facts) {{ :architecture => 'bogus' }} @@ -73,16 +76,34 @@ end context "When installing via URL by default" do - it { should contain_staging__file('nomad-0.2.3.zip').with(:source => 'https://releases.hashicorp.com/nomad/0.2.3/nomad_0.2.3_linux_amd64.zip') } + it { should contain_archive('/opt/puppet-archive/nomad-0.5.0.zip').with(:source => 'https://releases.hashicorp.com/nomad/0.5.0/nomad_0.5.0_linux_amd64.zip') } + it { should contain_file('/opt/puppet-archive').with(:ensure => 'directory') } + it { should contain_file('/opt/puppet-archive/nomad-0.5.0').with(:ensure => 'directory') } + it { should contain_file('/usr/local/bin/nomad').that_notifies('Class[nomad::run_service]') } + end + + context "When installing via URL with a special archive_path" do + let(:params) {{ + :archive_path => '/usr/share/puppet-archive', + }} + it { should contain_archive('/usr/share/puppet-archive/nomad-0.5.0.zip').with(:source => 'https://releases.hashicorp.com/nomad/0.5.0/nomad_0.5.0_linux_amd64.zip') } + it { should contain_file('/usr/share/puppet-archive').with(:ensure => 'directory') } + it { should contain_file('/usr/share/puppet-archive/nomad-0.5.0').with(:ensure => 'directory') } it { should contain_file('/usr/local/bin/nomad').that_notifies('Class[nomad::run_service]') } - #it { should contain_notify(['Class[nomad::run_service]']) } + end + + context "When installing by archive via URL and current version is already installed" do + let(:facts) {{ :nomad_version => '0.5.0' }} + it { should contain_archive('/opt/puppet-archive/nomad-0.5.0.zip').with(:source => 'https://releases.hashicorp.com/nomad/0.5.0/nomad_0.5.0_linux_amd64.zip') } + it { should contain_file('/usr/local/bin/nomad') } + it { should_not contain_notify(['Class[nomad::run_service]']) } end context "When installing via URL by with a special version" do let(:params) {{ :version => '42', }} - it { should contain_staging__file('nomad-42.zip').with(:source => 'https://releases.hashicorp.com/nomad/42/nomad_42_linux_amd64.zip') } + it { should contain_archive('/opt/puppet-archive/nomad-42.zip').with(:source => 'https://releases.hashicorp.com/nomad/42/nomad_42_linux_amd64.zip') } it { should contain_file('/usr/local/bin/nomad').that_notifies('Class[nomad::run_service]') } end @@ -90,11 +111,10 @@ let(:params) {{ :download_url => 'http://myurl', }} - it { should contain_staging__file('nomad-0.2.3.zip').with(:source => 'http://myurl') } + it { should contain_archive('/opt/puppet-archive/nomad-0.5.0.zip').with(:source => 'http://myurl') } it { should contain_file('/usr/local/bin/nomad').that_notifies('Class[nomad::run_service]') } end - context 'When requesting to install via a package with defaults' do let(:params) {{ :install_method => 'package' @@ -107,11 +127,9 @@ :install_method => 'none' }} it { should_not contain_package('nomad') } - it { should_not contain_staging__file('nomad.zip') } + it { should_not contain_archive('/opt/puppet-archive/nomad-0.5.0.zip') } end - - context "By default, a user and group should be installed" do it { should contain_user('nomad').with(:ensure => :present) } it { should contain_group('nomad').with(:ensure => :present) } @@ -392,6 +410,5 @@ }} it { should contain_file('/etc/init/nomad.conf').with_content(/\$NOMAD -S -- agent .*-some-extra-argument$/) } end - # Service Stuff end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 1805144..5b44adc 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 => 'nomad') 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