Skip to content

Commit 9970cc6

Browse files
committed
Merge pull request #290 from bmjen/refactor-native
Refactor concat to wrap electrical/file_concat
2 parents 15ecb98 + 51bd49f commit 9970cc6

26 files changed

Lines changed: 143 additions & 1503 deletions

.fixtures.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ fixtures:
22
repositories:
33
'stdlib':
44
repo: 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
5-
ref: '4.2.0'
5+
ref: '4.5.1'
6+
'file_concat':
7+
repo: 'git://github.com/electrical/puppet-lib-file_concat.git'
8+
branch: '1.0.0'
69
symlinks:
710
'concat': '#{source_dir}'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ spec/fixtures/
77
coverage/
88
.idea/
99
*.iml
10+
*.swp

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ end
1212

1313
group :development, :unit_tests do
1414
gem 'rake', :require => false
15-
gem 'rspec-core', '3.1.7', :require => false
16-
gem 'rspec-puppet', '~> 1.0', :require => false
15+
gem 'rspec-core', '~> 3.1.7', :require => false
16+
gem 'rspec-puppet', '~> 2.0', :require => false
1717
gem 'puppetlabs_spec_helper', :require => false
1818
gem 'puppet-lint', :require => false
1919
gem 'simplecov', :require => false
2020
gem 'puppet_facts', :require => false
2121
gem 'json', :require => false
22+
gem 'pry'
2223
end
2324

2425
beaker_version = ENV['BEAKER_VERSION']

files/concatfragments.rb

Lines changed: 0 additions & 153 deletions
This file was deleted.

lib/facter/concat_basedir.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

lib/puppet/parser/functions/concat_getparam.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/puppet/parser/functions/concat_is_bool.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

manifests/fragment.pp

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# == Define: concat::fragment
22
#
3-
# Puts a file fragment into a directory previous setup using concat
3+
# Creates a file_fragment in the catalogue
44
#
55
# === Options:
66
#
@@ -13,115 +13,37 @@
1313
# [*order*]
1414
# By default all files gets a 10_ prefix in the directory you can set it to
1515
# anything else using this to influence the order of the content in the file
16-
# [*ensure*]
17-
# Present/Absent or destination to a file to include another file
18-
# [*mode*]
19-
# Deprecated
20-
# [*owner*]
21-
# Deprecated
22-
# [*group*]
23-
# Deprecated
24-
# [*backup*]
25-
# Deprecated
2616
#
2717
define concat::fragment(
2818
$target,
2919
$content = undef,
3020
$source = undef,
3121
$order = '10',
32-
$ensure = undef,
33-
$mode = undef,
34-
$owner = undef,
35-
$group = undef,
36-
$backup = undef
3722
) {
3823
validate_string($target)
3924
validate_string($content)
4025
if !(is_string($source) or is_array($source)) {
4126
fail('$source is not a string or an Array.')
4227
}
28+
4329
if !(is_string($order) or is_integer($order)) {
4430
fail('$order is not a string or integer.')
4531
} elsif (is_string($order) and $order =~ /[:\n\/]/) {
4632
fail("Order cannot contain '/', ':', or '\n'.")
4733
}
48-
if $mode {
49-
warning('The $mode parameter to concat::fragment is deprecated and has no effect')
50-
}
51-
if $owner {
52-
warning('The $owner parameter to concat::fragment is deprecated and has no effect')
53-
}
54-
if $group {
55-
warning('The $group parameter to concat::fragment is deprecated and has no effect')
56-
}
57-
if $backup {
58-
warning('The $backup parameter to concat::fragment is deprecated and has no effect')
59-
}
60-
$my_backup = concat_getparam(Concat[$target], 'backup')
61-
if $ensure == undef {
62-
$my_ensure = concat_getparam(Concat[$target], 'ensure')
63-
} else {
64-
if ! ($ensure in [ 'present', 'absent' ]) {
65-
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.')
66-
}
67-
$my_ensure = $ensure
68-
}
69-
70-
include concat::setup
71-
72-
$safe_name = regsubst($name, '[/:\n]', '_', 'GM')
73-
$safe_target_name = regsubst($target, '[/:\n]', '_', 'GM')
74-
$concatdir = $concat::setup::concatdir
75-
$fragdir = "${concatdir}/${safe_target_name}"
76-
$fragowner = $concat::setup::fragment_owner
77-
$fraggroup = $concat::setup::fragment_group
78-
$fragmode = $concat::setup::fragment_mode
79-
80-
# The file type's semantics are problematic in that ensure => present will
81-
# not over write a pre-existing symlink. We are attempting to provide
82-
# backwards compatiblity with previous concat::fragment versions that
83-
# supported the file type's ensure => /target syntax
84-
85-
# be paranoid and only allow the fragment's file resource's ensure param to
86-
# be file, absent, or a file target
87-
$safe_ensure = $my_ensure ? {
88-
'' => 'file',
89-
undef => 'file',
90-
'file' => 'file',
91-
'present' => 'file',
92-
'absent' => 'absent',
93-
default => $my_ensure,
94-
}
9534

96-
# if it looks line ensure => /target syntax was used, fish that out
97-
if ! ($my_ensure in ['', 'present', 'absent', 'file' ]) {
98-
$ensure_target = $my_ensure
99-
} else {
100-
$ensure_target = undef
101-
}
102-
103-
# the file type's semantics only allows one of: ensure => /target, content,
104-
# or source
105-
if ($ensure_target and $source) or
106-
($ensure_target and $content) or
107-
($source and $content) {
108-
fail('You cannot specify more than one of $content, $source, $ensure => /target')
109-
}
110-
111-
if ! ($content or $source or $ensure_target) {
35+
if ! ($content or $source) {
11236
crit('No content, source or symlink specified')
37+
} elsif ($content and $source) {
38+
fail("Can't use 'source' and 'content' at the same time")
11339
}
11440

115-
file { "${fragdir}/fragments/${order}_${safe_name}":
116-
ensure => $safe_ensure,
117-
owner => $fragowner,
118-
group => $fraggroup,
119-
mode => $fragmode,
120-
source => $source,
41+
$safe_target_name = regsubst($target, '[/:\n\s]', '_', 'GM')
42+
43+
file_fragment { $name:
44+
tag => $safe_target_name,
45+
order => $order,
12146
content => $content,
122-
backup => $my_backup,
123-
replace => true,
124-
alias => "concat_fragment_${name}",
125-
notify => Exec["concat_${target}"]
47+
source => $source,
12648
}
12749
}

0 commit comments

Comments
 (0)