Skip to content

Commit

Permalink
Use archive instead of staging
Browse files Browse the repository at this point in the history
  • Loading branch information
RiANOl committed Dec 2, 2016
1 parent f1e9df5 commit 9487482
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
@@ -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}"
91 changes: 48 additions & 43 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
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": ">=1.0.0 <2.0.0"
}
],
"operatingsystem_support": [
Expand Down
35 changes: 26 additions & 9 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down Expand Up @@ -73,28 +76,45 @@
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

context "When installing via URL by with a custom url" do
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'
Expand All @@ -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) }
Expand Down Expand Up @@ -392,6 +410,5 @@
}}
it { should contain_file('/etc/init/nomad.conf').with_content(/\$NOMAD -S -- agent .*-some-extra-argument$/) }
end
# Service Stuff

end
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 => '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

0 comments on commit 9487482

Please sign in to comment.