Skip to content

Commit 2c23f71

Browse files
committed
Merge pull request jdowning#4 from duritong/master
Make it possible to install from a repository
2 parents bcc6fd1 + 4ce5432 commit 2c23f71

5 files changed

Lines changed: 122 additions & 33 deletions

File tree

Rakefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
require 'puppet-lint/tasks/puppet-lint'
1+
require 'bundler'
2+
Bundler.require(:rake)
3+
24
require 'puppetlabs_spec_helper/rake_tasks'
5+
require 'puppet-lint/tasks/puppet-lint'
36
require 'puppet_blacksmith/rake_tasks'
47

5-
PuppetLint.configuration.send("disable_80chars")
6-
PuppetLint.configuration.ignore_paths = ["pkg/**/**/*.pp"]
8+
Rake::Task[:lint].clear
9+
PuppetLint::RakeTask.new :lint do |config|
10+
config.ignore_paths = ["pkg/**/**/*.pp"]
11+
config.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}'
12+
config.disable_checks = [ "80chars" ]
13+
end
14+
15+
task :default => [:spec, :lint]
16+

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class influxdb (
33
$ensure = $influxdb::params::ensure,
44
$version = $influxdb::params::version,
5+
$install_from_repository = $influxdb::params::install_from_repository,
56
$config_path = $influxdb::params::config_path,
67
$hostname = $influxdb::params::hostname,
78
$bind_address = $influxdb::params::bind_address,

manifests/install.pp

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
# == Class: influxdb::install
22
# DO NO CALL DIRECTLY
33
class influxdb::install {
4-
# package source and provider
5-
case $::osfamily {
6-
'Debian': {
7-
$package_provider = 'dpkg'
8-
$package_source = $::architecture ? {
9-
/64/ => "http://s3.amazonaws.com/influxdb/influxdb_${influxdb::version}_amd64.deb",
10-
default => "http://s3.amazonaws.com/influxdb/influxdb_${influxdb::version}_i386.deb",
4+
package { 'influxdb':
5+
ensure => $influxdb::ensure,
6+
}
7+
if !$influxdb::install_from_repository {
8+
# package source and provider
9+
case $::osfamily {
10+
'Debian': {
11+
$package_provider = 'dpkg'
12+
$package_source = $::architecture ? {
13+
/64/ => "http://s3.amazonaws.com/influxdb/influxdb_${influxdb::version}_amd64.deb",
14+
default => "http://s3.amazonaws.com/influxdb/influxdb_${influxdb::version}_i386.deb",
15+
}
1116
}
12-
}
13-
'RedHat', 'Amazon': {
14-
$package_provider = 'rpm'
15-
$package_source = $::architecture ? {
16-
/64/ => "http://s3.amazonaws.com/influxdb/influxdb-${influxdb::version}-1.x86_64.rpm",
17-
default => "http://s3.amazonaws.com/influxdb/influxdb-${influxdb::version}-1.i686.rpm",
17+
'RedHat', 'Amazon': {
18+
$package_provider = 'rpm'
19+
$package_source = $::architecture ? {
20+
/64/ => "http://s3.amazonaws.com/influxdb/influxdb-${influxdb::version}-1.x86_64.rpm",
21+
default => "http://s3.amazonaws.com/influxdb/influxdb-${influxdb::version}-1.i686.rpm",
22+
}
23+
}
24+
default: {
25+
fail('Only supports Debian or RedHat $::osfamily')
1826
}
1927
}
20-
default: {
21-
fail('Only supports Debian or RedHat $::osfamily')
28+
29+
# get the package
30+
staging::file { 'influxdb-package':
31+
source => $package_source,
32+
}
33+
34+
# install the package
35+
Package['influxdb']{
36+
provider => $package_provider,
37+
source => '/opt/staging/influxdb/influxdb-package',
38+
require => Staging::File['influxdb-package'],
2239
}
23-
}
24-
25-
# get the package
26-
staging::file { 'influxdb-package':
27-
source => $package_source,
28-
}
29-
30-
# install the package
31-
package { 'influxdb':
32-
ensure => $influxdb::ensure,
33-
provider => $package_provider,
34-
source => '/opt/staging/influxdb/influxdb-package',
35-
require => Staging::File['influxdb-package'],
3640
}
3741
}

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class influxdb::params {
44
$ensure = 'installed'
55
$version = 'latest'
6+
$install_from_repository = false
67
$config_path = '/opt/influxdb/shared/config.toml'
78

89
$hostname = $::hostname

spec/classes/install_spec.rb

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,80 @@
11
require 'spec_helper'
22

33
describe 'influxdb::install' do
4-
let(:facts) { { :osfamily => 'Debian' } }
4+
context 'with default params' do
5+
let(:pre_condition) {
6+
'include influxdb'
7+
}
8+
context 'on debian' do
9+
let(:facts) {
10+
{
11+
:osfamily => 'Debian',
12+
:architecture => 'x86_64',
13+
}
14+
}
515

6-
it { should contain_package('influxdb') }
16+
it { should contain_staging__file('influxdb-package').with(
17+
:source => 'http://s3.amazonaws.com/influxdb/influxdb_latest_amd64.deb',
18+
)}
19+
20+
it { should contain_package('influxdb').with(
21+
:ensure => 'installed',
22+
:provider => 'dpkg',
23+
:source => '/opt/staging/influxdb/influxdb-package',
24+
:require => 'Staging::File[influxdb-package]',
25+
)}
26+
end
27+
context 'on redhat' do
28+
let(:facts) {
29+
{
30+
:osfamily => 'RedHat',
31+
:architecture => 'x86_64',
32+
}
33+
}
34+
35+
it { should contain_staging__file('influxdb-package').with(
36+
:source => 'http://s3.amazonaws.com/influxdb/influxdb-latest-1.x86_64.rpm',
37+
)}
38+
39+
it { should contain_package('influxdb').with(
40+
:ensure => 'installed',
41+
:provider => 'rpm',
42+
:source => '/opt/staging/influxdb/influxdb-package',
43+
:require => 'Staging::File[influxdb-package]',
44+
)}
45+
end
46+
end
47+
context 'installing from a repository' do
48+
let(:pre_condition) {
49+
'class{"influxdb":
50+
install_from_repository => true,
51+
}'
52+
}
53+
context 'on debian' do
54+
let(:facts) {
55+
{
56+
:osfamily => 'Debian',
57+
:architecture => 'x86_64',
58+
}
59+
}
60+
61+
it { should_not contain_staging__file('influxdb-package') }
62+
it { should contain_package('influxdb').with(
63+
:ensure => 'installed',
64+
)}
65+
end
66+
context 'on redhat' do
67+
let(:facts) {
68+
{
69+
:osfamily => 'RedHat',
70+
:architecture => 'x86_64',
71+
}
72+
}
73+
74+
it { should_not contain_staging__file('influxdb-package') }
75+
it { should contain_package('influxdb').with(
76+
:ensure => 'installed',
77+
)}
78+
end
79+
end
780
end

0 commit comments

Comments
 (0)