Skip to content

Commit

Permalink
refactor concat to wrap electrical/file_concat
Browse files Browse the repository at this point in the history
  • Loading branch information
bmjen committed Apr 9, 2015
1 parent 15ecb98 commit 51bd49f
Show file tree
Hide file tree
Showing 26 changed files with 143 additions and 1,503 deletions.
5 changes: 4 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ fixtures:
repositories:
'stdlib':
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
ref: '4.2.0'
ref: '4.5.1'
'file_concat':
repo: 'git://github.com/electrical/puppet-lib-file_concat.git'
branch: '1.0.0'
symlinks:
'concat': '#{source_dir}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ spec/fixtures/
coverage/
.idea/
*.iml
*.swp
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ end

group :development, :unit_tests do
gem 'rake', :require => false
gem 'rspec-core', '3.1.7', :require => false
gem 'rspec-puppet', '~> 1.0', :require => false
gem 'rspec-core', '~> 3.1.7', :require => false
gem 'rspec-puppet', '~> 2.0', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'simplecov', :require => false
gem 'puppet_facts', :require => false
gem 'json', :require => false
gem 'pry'
end

beaker_version = ENV['BEAKER_VERSION']
Expand Down
153 changes: 0 additions & 153 deletions files/concatfragments.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/facter/concat_basedir.rb

This file was deleted.

35 changes: 0 additions & 35 deletions lib/puppet/parser/functions/concat_getparam.rb

This file was deleted.

22 changes: 0 additions & 22 deletions lib/puppet/parser/functions/concat_is_bool.rb

This file was deleted.

100 changes: 11 additions & 89 deletions manifests/fragment.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# == Define: concat::fragment
#
# Puts a file fragment into a directory previous setup using concat
# Creates a file_fragment in the catalogue
#
# === Options:
#
Expand All @@ -13,115 +13,37 @@
# [*order*]
# By default all files gets a 10_ prefix in the directory you can set it to
# anything else using this to influence the order of the content in the file
# [*ensure*]
# Present/Absent or destination to a file to include another file
# [*mode*]
# Deprecated
# [*owner*]
# Deprecated
# [*group*]
# Deprecated
# [*backup*]
# Deprecated
#
define concat::fragment(
$target,
$content = undef,
$source = undef,
$order = '10',
$ensure = undef,
$mode = undef,
$owner = undef,
$group = undef,
$backup = undef
) {
validate_string($target)
validate_string($content)
if !(is_string($source) or is_array($source)) {
fail('$source is not a string or an Array.')
}

if !(is_string($order) or is_integer($order)) {
fail('$order is not a string or integer.')
} elsif (is_string($order) and $order =~ /[:\n\/]/) {
fail("Order cannot contain '/', ':', or '\n'.")
}
if $mode {
warning('The $mode parameter to concat::fragment is deprecated and has no effect')
}
if $owner {
warning('The $owner parameter to concat::fragment is deprecated and has no effect')
}
if $group {
warning('The $group parameter to concat::fragment is deprecated and has no effect')
}
if $backup {
warning('The $backup parameter to concat::fragment is deprecated and has no effect')
}
$my_backup = concat_getparam(Concat[$target], 'backup')
if $ensure == undef {
$my_ensure = concat_getparam(Concat[$target], 'ensure')
} else {
if ! ($ensure in [ 'present', 'absent' ]) {
warning('Passing a value other than \'present\' or \'absent\' as the $ensure parameter to concat::fragment is deprecated. If you want to use the content of a file as a fragment please use the $source parameter.')
}
$my_ensure = $ensure
}

include concat::setup

$safe_name = regsubst($name, '[/:\n]', '_', 'GM')
$safe_target_name = regsubst($target, '[/:\n]', '_', 'GM')
$concatdir = $concat::setup::concatdir
$fragdir = "${concatdir}/${safe_target_name}"
$fragowner = $concat::setup::fragment_owner
$fraggroup = $concat::setup::fragment_group
$fragmode = $concat::setup::fragment_mode

# The file type's semantics are problematic in that ensure => present will
# not over write a pre-existing symlink. We are attempting to provide
# backwards compatiblity with previous concat::fragment versions that
# supported the file type's ensure => /target syntax

# be paranoid and only allow the fragment's file resource's ensure param to
# be file, absent, or a file target
$safe_ensure = $my_ensure ? {
'' => 'file',
undef => 'file',
'file' => 'file',
'present' => 'file',
'absent' => 'absent',
default => $my_ensure,
}

# if it looks line ensure => /target syntax was used, fish that out
if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) {
$ensure_target = $my_ensure
} else {
$ensure_target = undef
}

# the file type's semantics only allows one of: ensure => /target, content,
# or source
if ($ensure_target and $source) or
($ensure_target and $content) or
($source and $content) {
fail('You cannot specify more than one of $content, $source, $ensure => /target')
}

if ! ($content or $source or $ensure_target) {
if ! ($content or $source) {
crit('No content, source or symlink specified')
} elsif ($content and $source) {
fail("Can't use 'source' and 'content' at the same time")
}

file { "${fragdir}/fragments/${order}_${safe_name}":
ensure => $safe_ensure,
owner => $fragowner,
group => $fraggroup,
mode => $fragmode,
source => $source,
$safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')

file_fragment { $name:
tag => $safe_target_name,
order => $order,
content => $content,
backup => $my_backup,
replace => true,
alias => "concat_fragment_${name}",
notify => Exec["concat_${target}"]
source => $source,
}
}
Loading

0 comments on commit 51bd49f

Please sign in to comment.