Skip to content

Commit ab02789

Browse files
author
Toby McLaughlin
committed
Support installing modules from 'puppet://' urls.
1 parent ef836b5 commit ab02789

File tree

10 files changed

+76
-19
lines changed

10 files changed

+76
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ spec/fixtures/artifacts/*
33
!spec/fixtures/artifacts/.gitignore
44
spec/fixtures/modules/*
55
!spec/fixtures/modules/logstash
6+
files/*.gem
67
.bundle
78
.vendor
89
.vagrant

.travis.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
sudo: required
2+
3+
# Use Travis' Ubuntu Trusty machines. They have more RAM.
4+
# It does not affect which OSs we are testing, since they all provided
5+
# by Docker containers. This simply defines which OS Docker itself will
6+
# be running on.
27
dist: trusty
38

49
services:
@@ -9,10 +14,16 @@ language: ruby
914
rvm:
1015
- 1.9.3
1116

12-
1317
script:
14-
# - make test-unit
15-
- travis_wait 30 bundle exec rake beaker
18+
# Some of our test can take long time, and not output anything while they
19+
# are running. If this goes on for too long (ten minutes), then Travis
20+
# will assume the build has stalled, and kill it.
21+
#
22+
# It' a bit cheeky, but lets make sure that _something_ goes to STDOUT
23+
# every five minutes, so that our build won't be killed unjustly.
24+
- (while true; do date --iso-8601=seconds; sleep 300; done) &
25+
- bundle exec rake beaker 2>&1 | grep -Fv 'localhost $ scp /tmp/beaker'
26+
# ^ filter out annoying debug lines from Beaker.
1627

1728
env:
1829
global:

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ gem 'rspec', '~> 3.0'
2222
gem 'rake'
2323
gem 'puppet-doc-lint'
2424
gem 'puppet-lint'
25+
gem 'puppet-strings'
2526
gem 'puppetlabs_spec_helper'
2627
gem 'puppet-syntax'
2728
gem 'rspec-puppet-facts'
2829
gem 'rubocop'
2930
gem 'serverspec'
3031
gem 'webmock'
32+
gem 'redcarpet'
3133

3234
# Extra Puppet-lint gems
3335
gem 'puppet-lint-appends-check', :require => false

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# opensuse-121 \
22
# sles-11sp3 \
33
4+
default: deps lint test-unit docs
5+
46
distros = \
57
centos-6 \
68
centos-7 \
@@ -21,6 +23,9 @@ puppet-module-deps:
2123
done
2224
touch spec/fixtures/manifests/site.pp
2325

26+
docs:
27+
bundle exec puppet strings
28+
2429
lint:
2530
bundle exec rake lint
2631
bundle exec rake validate

Vagrantfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
shell_script = <<-END
88
if [[ ! -L /usr/local/bin/puppet ]]; then
9-
apt-get update
10-
apt-get --assume-yes upgrade
11-
129
for mod in puppetlabs-apt puppetlabs-stdlib electrical-file_concat; do
1310
puppet module install --target-dir=/opt/puppetlabs/puppet/modules $mod
1411
done
@@ -26,7 +23,7 @@ module_root = '/etc/puppetlabs/code/environments/production/modules/logstash'
2623
Vagrant.configure(2) do |config|
2724
config.vm.box = 'puppetlabs/debian-8.2-64-puppet'
2825
config.vm.provision('shell', inline: shell_script)
29-
%w(manifests templates).each do |dir|
26+
%w(manifests templates files).each do |dir|
3027
config.vm.synced_folder(dir, "#{module_root}/#{dir}")
3128
end
3229
end

files/.gitignore

Whitespace-only changes.

manifests/plugin.pp

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# Manage the installation of a Logstash plugin.
22
#
33
# By default, plugins are downloaded from RubyGems, but it is also possible
4-
# to install from a local Gem.
4+
# to install from a local Gem, or one stored in Puppet.
55
#
66
# @example install a plugin
77
# logstash::plugin { 'logstash-input-stdin': }
88
#
99
# @example remove a plugin
1010
# logstash::plugin { 'logstash-input-stout':
11-
# ensure => absent
11+
# ensure => absent,
1212
# }
1313
#
1414
# @example install a plugin from a local file
1515
# logstash::plugin { 'logstash-input-custom':
16-
# source => 'file:///tmp/logstash-input-custom.gem'
16+
# source => 'file:///tmp/logstash-input-custom.gem',
1717
# }
1818
#
19-
# @example install a plugin from a file on the puppetmaster
19+
# @example install a plugin from a Puppet module.
2020
# logstash::plugin { 'logstash-input-custom':
21-
# source => 'puppet:///plugin-module/logstash-input-custom.gem'
21+
# source => 'puppet:///modules/logstash-site-plugins/logstash-input-custom.gem',
2222
# }
2323
#
2424
# @param source [String] install from this file, not from RubyGems.
@@ -31,11 +31,34 @@
3131
require logstash
3232
$exe = '/opt/logstash/bin/plugin'
3333

34-
if($source) {
35-
$plugin = $source
36-
}
37-
else {
38-
$plugin = $name
34+
case $source { # Where should we get the plugin from?
35+
undef: {
36+
# No explict source, so search Rubygems for the plugin, by name.
37+
# ie. "/opt/logstash/bin/plugin install logstash-output-elasticsearch"
38+
$plugin = $name
39+
}
40+
41+
/^\//: {
42+
# A gem file that is already available on the local filesystem.
43+
# Install from the local path.
44+
# ie. "/opt/logstash/bin/plugin install /tmp/logtash-filter-custom.gem"
45+
$plugin = $source
46+
}
47+
48+
/^puppet:/: {
49+
# A 'puppet:///' URL. Download the gem from Puppet, then install
50+
# the plugin from the downloaded file.
51+
$downloaded_file = sprintf('/tmp/%s', basename($source))
52+
file { $downloaded_file:
53+
source => $source,
54+
before => Exec["install-${name}"],
55+
}
56+
$plugin = $downloaded_file
57+
}
58+
59+
default: {
60+
fail('"source" should be a local path, a "puppet:///" url, or undef.')
61+
}
3962
}
4063

4164
case $ensure {

spec/acceptance/003_plugin_spec.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ def installed_plugins
2323
end
2424

2525
def remove(plugin)
26-
stop_logstash
2726
shell("/opt/logstash/bin/plugin uninstall #{plugin} || true")
2827
end
2928

29+
before(:all) do
30+
install_logstash
31+
end
32+
33+
before(:each) do
34+
stop_logstash
35+
end
36+
3037
context 'when output-csv is not installed' do
3138
before(:each) do
3239
remove('logstash-output-csv')
@@ -61,7 +68,15 @@ def remove(plugin)
6168

6269
it 'can install a plugin from a local gem' do
6370
plugin = 'logstash-output-cowsay'
64-
ensure_plugin('present', plugin, "source => '/tmp/#{plugin}-0.1.0.gem'")
71+
source = "/tmp/#{plugin}-0.1.0.gem"
72+
ensure_plugin('present', plugin, "source => '#{source}'")
73+
expect(installed_plugins).to contain(plugin)
74+
end
75+
76+
it 'can install a plugin from a "puppet://" url' do
77+
plugin = 'logstash-output-cowthink'
78+
source = "puppet:///modules/logstash/#{plugin}-0.1.0.gem"
79+
ensure_plugin('present', plugin, "source => '#{source}'")
6580
expect(installed_plugins).to contain(plugin)
6681
end
6782
end
Binary file not shown.

spec/spec_helper_acceptance.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ def puppet_enterprise?
118118
# Provide a Logstash plugin as a local Gem.
119119
scp_to(host, './spec/fixtures/plugins/logstash-output-cowsay-0.1.0.gem', '/tmp/')
120120

121+
# ...and another plugin that can be fetched from Puppet with "puppet:///"
122+
FileUtils.cp('./spec/fixtures/plugins/logstash-output-cowthink-0.1.0.gem', './files/')
123+
121124
project_root = File.dirname(File.dirname(__FILE__))
122125
install_dev_puppet_module_on(host, source: project_root, module_name: 'logstash')
123126
install_puppet_module_via_pmt_on(host, module_name: 'puppetlabs-stdlib')

0 commit comments

Comments
 (0)