hieracles 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/hc +4 -3
- data/bin/ppdb +2 -2
- data/lib/hieracles/config.rb +2 -4
- data/lib/hieracles/formats/console.rb +16 -15
- data/lib/hieracles/formats/csv.rb +6 -9
- data/lib/hieracles/formats/plain.rb +21 -13
- data/lib/hieracles/formats/yaml.rb +7 -14
- data/lib/hieracles/hiera.rb +5 -4
- data/lib/hieracles/node.rb +57 -25
- data/lib/hieracles/registry.rb +6 -3
- data/lib/hieracles/utils.rb +5 -0
- data/spec/lib/config_spec.rb +48 -32
- data/spec/lib/formats/console_spec.rb +23 -12
- data/spec/lib/formats/csv_spec.rb +24 -34
- data/spec/lib/formats/plain_spec.rb +23 -12
- data/spec/lib/formats/yaml_spec.rb +164 -96
- data/spec/lib/hiera_spec.rb +10 -12
- data/spec/lib/node_spec.rb +194 -146
- data/spec/lib/registry_spec.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40e11515e3204a93d07953d15d29185a1b1881ad
|
4
|
+
data.tar.gz: 3e3c04ef13bbdab8d989ef49ddb3182eadae3007
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1ff0c0467ec5f1d8128080e57559f2e0202cfa93b06389954fa70c25f7d887f4203bd2b5dd128e3c252e129dadfe16454a371471f49d8292fad00fb5a3dd57e
|
7
|
+
data.tar.gz: 0f1350b7fde0e2607e66ae2e3d07c416481c371fe7b91ed139023f283ec5a5c8cc6195f9cc4a9f3f36c826c95e2fcc3f4e427a2586fd54ef2d625290031ff1ca
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Hieracles Changelog
|
2
2
|
=======================
|
3
3
|
|
4
|
+
### 0.3.1 - 2015-12-28
|
5
|
+
- added some relevance to the registry class
|
6
|
+
- changed the internal way to store the nodes information
|
7
|
+
- moved Config singleton to a proper class for modularity sake
|
8
|
+
|
4
9
|
### 0.3.0 - 2015-12-16
|
5
10
|
- added json output as an option to ppdb
|
6
11
|
- added some more ppdb commands
|
data/bin/hc
CHANGED
@@ -23,15 +23,16 @@ end
|
|
23
23
|
|
24
24
|
if Hieracles::Format.method_defined? command
|
25
25
|
begin
|
26
|
-
|
26
|
+
config = Hieracles::Config.new opt.options
|
27
|
+
node = Hieracles::Node.new fqdn, config
|
27
28
|
rescue Exception => e
|
28
29
|
puts "*** Error: #{e.message}"
|
29
30
|
exit(1)
|
30
31
|
end
|
31
32
|
begin
|
32
|
-
formatter = Object.const_get("Hieracles::Formats::#{
|
33
|
+
formatter = Object.const_get("Hieracles::Formats::#{config.format}")
|
33
34
|
rescue
|
34
|
-
puts "*** Unknown format #{
|
35
|
+
puts "*** Unknown format #{config.format}"
|
35
36
|
exit(1)
|
36
37
|
end
|
37
38
|
dispatch = formatter.new node
|
data/bin/ppdb
CHANGED
@@ -31,9 +31,9 @@ else
|
|
31
31
|
exit(1)
|
32
32
|
end
|
33
33
|
|
34
|
-
Hieracles::Config.
|
34
|
+
config = Hieracles::Config.new opt.options
|
35
35
|
|
36
|
-
request = Hieracles::Puppetdb::Request.new
|
36
|
+
request = Hieracles::Puppetdb::Request.new config.puppetdb
|
37
37
|
meth = request.method(command.to_sym)
|
38
38
|
required = request.method(command.to_sym).parameters.select { |arg| arg[0] == :req }.map { |arg| arg[1] }
|
39
39
|
if args.length < required.length
|
data/lib/hieracles/config.rb
CHANGED
@@ -4,15 +4,13 @@ require 'yaml'
|
|
4
4
|
require 'hieracles/utils'
|
5
5
|
|
6
6
|
module Hieracles
|
7
|
-
|
8
|
-
module Config
|
7
|
+
class Config
|
9
8
|
include Hieracles::Utils
|
10
|
-
extend self
|
11
9
|
|
12
10
|
attr_reader :extraparams, :server, :classpath, :scope, :puppetdb, :usedb,
|
13
11
|
:modulepath, :hierafile, :basepath, :encpath, :format, :interactive
|
14
12
|
|
15
|
-
def
|
13
|
+
def initialize(options)
|
16
14
|
@options = options
|
17
15
|
@optionfile = @options[:config] || defaultconfig
|
18
16
|
@extraparams = extract_params(options[:params])
|
@@ -13,9 +13,9 @@ module Hieracles
|
|
13
13
|
"\e[33m%s\e[0m",
|
14
14
|
"\e[34m%s\e[0m",
|
15
15
|
"\e[35m%s\e[0m",
|
16
|
-
"\e[36m%s\e[0m",
|
17
16
|
"\e[37m%s\e[0m",
|
18
17
|
"\e[38m%s\e[0m",
|
18
|
+
"\e[36m%s\e[0m",
|
19
19
|
"\e[97m%s\e[0m",
|
20
20
|
"\e[35;1m%s\e[0m"
|
21
21
|
]
|
@@ -85,28 +85,29 @@ module Hieracles
|
|
85
85
|
def build_params_line(key, value, filter)
|
86
86
|
output = ''
|
87
87
|
if !filter || Regexp.new(filter).match(key)
|
88
|
-
output <<
|
89
|
-
while value.count > 0
|
90
|
-
output << build_next(key, value.pop)
|
91
|
-
end
|
88
|
+
output << build_line_item(key, value)
|
92
89
|
end
|
93
90
|
output
|
94
91
|
end
|
95
92
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
format("%s #{COLORS[5]} %s\n", "[-]", key, sanitize(first[:merged]) ) +
|
101
|
-
format(" #{COLORS[8]}\n", "[#{filecolor_index}] #{key} #{sanitize(first[:value])}" )
|
93
|
+
def build_line_item(key, value)
|
94
|
+
if value[:overriden]
|
95
|
+
format("%s #{COLORS[7]} %s\n", "[-]", key, sanitize(value[:value]) ) +
|
96
|
+
build_overriden(key, value[:found_in])
|
102
97
|
else
|
103
|
-
|
98
|
+
filecolor_index = @colors[value[:file]]
|
99
|
+
filecolor = COLORS[filecolor_index]
|
100
|
+
format("#{filecolor} #{COLORS[7]} %s\n", "[#{filecolor_index}]", key, sanitize(value[:value]) )
|
104
101
|
end
|
105
102
|
end
|
106
103
|
|
107
|
-
def
|
108
|
-
|
109
|
-
|
104
|
+
def build_overriden(key, found_in)
|
105
|
+
back = ''
|
106
|
+
found_in.each do |v|
|
107
|
+
filecolor_index = @colors[v[:file]]
|
108
|
+
back << format(" #{COLORS[8]}\n", "[#{filecolor_index}] #{key} #{v[:value]}")
|
109
|
+
end
|
110
|
+
back
|
110
111
|
end
|
111
112
|
|
112
113
|
def build_modules_line(key, value)
|
@@ -32,16 +32,13 @@ module Hieracles
|
|
32
32
|
def build_params_line(key, value, filter)
|
33
33
|
output = ''
|
34
34
|
if !filter || Regexp.new(filter).match(key)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
if value[:overriden]
|
36
|
+
output << build_line('-', key, value[:value])
|
37
|
+
value[:found_in].each do |v|
|
38
|
+
output << build_line(v[:file], key, v[:value], '1')
|
39
|
+
end
|
39
40
|
else
|
40
|
-
output << build_line(
|
41
|
-
end
|
42
|
-
while value.count > 0
|
43
|
-
overriden = value.pop
|
44
|
-
output << build_line(overriden[:file], key, overriden[:value], '1')
|
41
|
+
output << build_line(value[:file], key, value[:value])
|
45
42
|
end
|
46
43
|
end
|
47
44
|
output
|
@@ -60,23 +60,31 @@ module Hieracles
|
|
60
60
|
def build_params_line(key, value, filter)
|
61
61
|
output = ''
|
62
62
|
if !filter || Regexp.new(filter).match(key)
|
63
|
-
|
64
|
-
filecolor_index = @index[first[:file]]
|
65
|
-
if is_merged? first
|
66
|
-
output << "[-] #{key} #{first[:merged]}\n"
|
67
|
-
output << " [#{filecolor_index}] #{key} #{first[:value]}\n"
|
68
|
-
else
|
69
|
-
output << "[#{filecolor_index}] #{key} #{first[:value]}\n"
|
70
|
-
end
|
71
|
-
while value.count > 0
|
72
|
-
overriden = value.pop
|
73
|
-
filecolor_index = @index[overriden[:file]]
|
74
|
-
output << " [#{filecolor_index}] #{key} #{overriden[:value]}\n"
|
75
|
-
end
|
63
|
+
output << build_line_item(key, value)
|
76
64
|
end
|
77
65
|
output
|
78
66
|
end
|
79
67
|
|
68
|
+
def build_line_item(key, value)
|
69
|
+
if value[:overriden]
|
70
|
+
"[-] #{key} #{value[:value]}\n" +
|
71
|
+
build_overriden(key, value[:found_in])
|
72
|
+
else
|
73
|
+
filecolor_index = @index[value[:file]]
|
74
|
+
"[#{filecolor_index}] #{key} #{value[:value]}\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def build_overriden(key, found_in)
|
79
|
+
back = ''
|
80
|
+
found_in.each do |v|
|
81
|
+
filecolor_index = @index[v[:file]]
|
82
|
+
back << " [#{filecolor_index}] #{key} #{v[:value]}\n"
|
83
|
+
end
|
84
|
+
back
|
85
|
+
end
|
86
|
+
|
87
|
+
|
80
88
|
def build_modules_line(key, value)
|
81
89
|
length = max_key_length(@node.modules) + 3
|
82
90
|
format("%-#{length}s %s\n", key, value)
|
@@ -39,7 +39,7 @@ module Hieracles
|
|
39
39
|
|
40
40
|
def commented_yaml_tree(filter, without_common = true)
|
41
41
|
tree = @node.params_tree(without_common)
|
42
|
-
params =
|
42
|
+
params = @node.params(without_common)
|
43
43
|
mergetree('---', [], tree, params)
|
44
44
|
end
|
45
45
|
|
@@ -61,13 +61,8 @@ module Hieracles
|
|
61
61
|
aryaml = yaml.each_line.map do |l|
|
62
62
|
indent + l
|
63
63
|
end
|
64
|
-
|
65
|
-
|
66
|
-
params[key.join('.')].each do |f|
|
67
|
-
output += "\n" + indent + "# " + f[:file]
|
68
|
-
end
|
69
|
-
else
|
70
|
-
output += "\n" + indent + "# " + params[key.join('.')].last[:file]
|
64
|
+
params[key.join('.')][:found_in].each do |k|
|
65
|
+
output += "\n" + indent + "# " + k[:file]
|
71
66
|
end
|
72
67
|
output += "\n" + aryaml.join().chomp
|
73
68
|
output
|
@@ -101,12 +96,10 @@ module Hieracles
|
|
101
96
|
|
102
97
|
def added(output, key, leaf, params)
|
103
98
|
output += leaf.to_s
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
break
|
109
|
-
end
|
99
|
+
k = params["#{key.join('.')}"]
|
100
|
+
if k
|
101
|
+
k[:found_in].each do |i|
|
102
|
+
output += " # " + i[:file]
|
110
103
|
end
|
111
104
|
end
|
112
105
|
output
|
data/lib/hieracles/hiera.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
module Hieracles
|
2
2
|
class Hiera
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
|
6
|
-
@hierafile
|
4
|
+
def initialize(config)
|
5
|
+
@config = config
|
6
|
+
raise IOError, "Hierafile #{@config.hierafile} not found." unless File.exist? @config.hierafile
|
7
|
+
@hierafile = @config.hierafile
|
7
8
|
@loaded = YAML.load_file(@hierafile)
|
8
9
|
end
|
9
10
|
|
10
11
|
def datapath
|
11
12
|
raise TypeError, "Sorry hieracles only knows yaml backend for now." unless @loaded[:yaml]
|
12
|
-
parampath = File.expand_path(File.join(
|
13
|
+
parampath = File.expand_path(File.join(@config.basepath, datadir))
|
13
14
|
raise IOError, "Params dir #{parampath} not found." unless Dir.exist? parampath
|
14
15
|
parampath
|
15
16
|
end
|
data/lib/hieracles/node.rb
CHANGED
@@ -10,21 +10,21 @@ module Hieracles
|
|
10
10
|
|
11
11
|
attr_reader :hiera_params, :hiera, :facts, :notifications
|
12
12
|
|
13
|
-
def initialize(fqdn,
|
13
|
+
def initialize(fqdn, config)
|
14
14
|
@fqdn = fqdn
|
15
|
-
|
16
|
-
@hiera = Hieracles::Hiera.new
|
15
|
+
@config = config
|
16
|
+
@hiera = Hieracles::Hiera.new @config
|
17
17
|
@hiera_params = { fqdn: @fqdn }.
|
18
18
|
merge(get_hiera_params(@fqdn)).
|
19
|
-
merge(
|
19
|
+
merge(@config.extraparams)
|
20
20
|
@facts = deep_sort(@hiera_params.
|
21
|
-
merge(
|
21
|
+
merge(@config.scope).
|
22
22
|
merge(puppet_facts))
|
23
23
|
end
|
24
24
|
|
25
25
|
def get_hiera_params(fqdn)
|
26
|
-
@__hiera_params ||= if File.exist?(File.join(
|
27
|
-
load = YAML.load_file(File.join(
|
26
|
+
@__hiera_params ||= if File.exist?(File.join(@config.encpath, "#{fqdn}.yaml"))
|
27
|
+
load = YAML.load_file(File.join(@config.encpath, "#{fqdn}.yaml"))
|
28
28
|
sym_keys(load['parameters']).merge({ classes: load['classes']})
|
29
29
|
else
|
30
30
|
raise "Node not found"
|
@@ -33,7 +33,7 @@ module Hieracles
|
|
33
33
|
|
34
34
|
def files(without_common = true)
|
35
35
|
@__files ||= @hiera.hierarchy.reduce([]) do |a, f|
|
36
|
-
file = parse("#{f}.yaml", @facts,
|
36
|
+
file = parse("#{f}.yaml", @facts, @config.interactive)
|
37
37
|
if file &&
|
38
38
|
File.exist?(File.join(@hiera.datapath, file)) &&
|
39
39
|
(!without_common ||
|
@@ -45,25 +45,56 @@ module Hieracles
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def paths(without_common = true)
|
48
|
-
files(without_common).map { |p| File.join(
|
48
|
+
files(without_common).map { |p| File.join(@config.basepath, p) }
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
51
|
+
def params_old(without_common = true)
|
52
52
|
params = {}
|
53
53
|
files(without_common).reverse.each do |f|
|
54
|
-
data = YAML.load_file(File.join(
|
54
|
+
data = YAML.load_file(File.join(@config.basepath, f))
|
55
55
|
if data
|
56
56
|
s = to_shallow_hash(data)
|
57
57
|
s.each do |k,v|
|
58
58
|
params[k] ||= []
|
59
|
-
|
60
|
-
params[k] << { value: v, file: f, merged: merge_value(params[k], v) }
|
59
|
+
params[k] << { value: v, file: f }.merge(merge_value(params[k], v))
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
64
63
|
params.sort
|
65
64
|
end
|
66
65
|
|
66
|
+
def params(without_common = true)
|
67
|
+
params = {}
|
68
|
+
files(without_common).each do |f|
|
69
|
+
data = YAML.load_file(File.join(@config.basepath, f))
|
70
|
+
if data
|
71
|
+
s = to_shallow_hash(data)
|
72
|
+
s.each do |k,v|
|
73
|
+
if params[k]
|
74
|
+
case @hiera.merge_behavior
|
75
|
+
when :deeper
|
76
|
+
params[k] = { value: v }.deep_merge!(params[k])
|
77
|
+
when :deep
|
78
|
+
params[k].deep_merge({ value: v })
|
79
|
+
end
|
80
|
+
params[k][:file] = '-'
|
81
|
+
params[k][:overriden] = true
|
82
|
+
params[k][:found_in].push({ value: v, file: f })
|
83
|
+
else
|
84
|
+
params[k] = {
|
85
|
+
value: v,
|
86
|
+
file: f,
|
87
|
+
overriden: false,
|
88
|
+
found_in: [{ value: v, file: f }]
|
89
|
+
}
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
params.sort.to_h
|
96
|
+
end
|
97
|
+
|
67
98
|
def params_tree(without_common = true)
|
68
99
|
params = {}
|
69
100
|
paths(without_common).reverse.each do |f|
|
@@ -99,7 +130,7 @@ module Hieracles
|
|
99
130
|
|
100
131
|
def _get_info
|
101
132
|
extra = {}
|
102
|
-
if
|
133
|
+
if @config.usedb
|
103
134
|
extra = puppetdb_info
|
104
135
|
end
|
105
136
|
@hiera_params.merge extra
|
@@ -107,12 +138,12 @@ module Hieracles
|
|
107
138
|
|
108
139
|
def classfiles
|
109
140
|
@hiera_params[:classes].map do |cl|
|
110
|
-
format(
|
141
|
+
format(@config.classpath, cl)
|
111
142
|
end
|
112
143
|
end
|
113
144
|
|
114
145
|
def modulepath(path)
|
115
|
-
File.join(
|
146
|
+
File.join(@config.modulepath, path)
|
116
147
|
end
|
117
148
|
|
118
149
|
def add_modules(line, modules)
|
@@ -120,7 +151,7 @@ module Hieracles
|
|
120
151
|
mod = $1
|
121
152
|
mainmod = mod[/^[^:]*/]
|
122
153
|
if Dir.exists? modulepath(mainmod)
|
123
|
-
modules[mod] = File.join(
|
154
|
+
modules[mod] = File.join(@config.modulepath, mainmod)
|
124
155
|
else
|
125
156
|
modules[mod] = nil
|
126
157
|
end
|
@@ -133,7 +164,7 @@ module Hieracles
|
|
133
164
|
end
|
134
165
|
|
135
166
|
def puppet_facts
|
136
|
-
if
|
167
|
+
if @config.usedb
|
137
168
|
resp = request_db.node_facts(@fqdn)
|
138
169
|
@notifications = resp.notifications
|
139
170
|
if resp.total_records > 0
|
@@ -148,7 +179,7 @@ module Hieracles
|
|
148
179
|
end
|
149
180
|
|
150
181
|
def request_db
|
151
|
-
@_request ||= Hieracles::Puppetdb::Request.new
|
182
|
+
@_request ||= Hieracles::Puppetdb::Request.new @config.puppetdb
|
152
183
|
end
|
153
184
|
|
154
185
|
def merge_trees(left, right)
|
@@ -165,21 +196,22 @@ module Hieracles
|
|
165
196
|
def merge_value(previous, value)
|
166
197
|
if value.is_a? Array
|
167
198
|
if previous == []
|
168
|
-
deep_sort(value)
|
199
|
+
{ merged: deep_sort(value) }
|
169
200
|
else
|
170
|
-
left = previous.last[:merged]
|
201
|
+
left = { merged: previous.last[:merged] }
|
202
|
+
right = { merged: value }
|
171
203
|
case @hiera.merge_behavior
|
172
204
|
# TODO: handle the case where right is not an array
|
173
205
|
when :deeper
|
174
|
-
deep_sort(left
|
206
|
+
deep_sort(left.deep_merge!(right))
|
175
207
|
when :deep
|
176
|
-
deep_sort(left
|
208
|
+
deep_sort(left.deep_merge(right))
|
177
209
|
else
|
178
|
-
deep_sort(
|
210
|
+
deep_sort(right)
|
179
211
|
end
|
180
212
|
end
|
181
213
|
else
|
182
|
-
value
|
214
|
+
{ merged: value }
|
183
215
|
end
|
184
216
|
end
|
185
217
|
|
data/lib/hieracles/registry.rb
CHANGED
@@ -4,17 +4,20 @@ module Hieracles
|
|
4
4
|
extend self
|
5
5
|
|
6
6
|
def farms(config)
|
7
|
-
|
7
|
+
Dir.glob(format(config.classpath, '*')).sort.map do |f|
|
8
|
+
sub = Regexp.new(".*#{config.classpath.sub(/%s/,'([^/]*)')}")
|
9
|
+
f.sub(sub, "\\1")
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
def nodes(config)
|
11
|
-
|
14
|
+
Dir.glob(File.join(config.encpath, '*.yaml')).sort.map do |f|
|
12
15
|
File.basename(f, '.yaml')
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
19
|
def modules(config)
|
17
|
-
|
20
|
+
Dir.glob(File.join(config.modulepath, '*')).sort.map do |f|
|
18
21
|
File.basename(f)
|
19
22
|
end
|
20
23
|
end
|
data/lib/hieracles/utils.rb
CHANGED
@@ -29,6 +29,11 @@ module Hieracles
|
|
29
29
|
hash1.merge!(hash2, &merger)
|
30
30
|
end
|
31
31
|
|
32
|
+
def local_merge(hash1, hash2)
|
33
|
+
merger = proc { |key, v1, v2| v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2, &merger) : v2 }
|
34
|
+
hash1.merge(hash2, &merger)
|
35
|
+
end
|
36
|
+
|
32
37
|
def deep_sort(object)
|
33
38
|
if object.is_a?(Hash)
|
34
39
|
res = {}
|
data/spec/lib/config_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hieracles::Config do
|
4
|
-
describe '.
|
4
|
+
describe '.new' do
|
5
5
|
context 'with an existing file' do
|
6
6
|
let(:options) { { config: 'spec/files/config.yml' } }
|
7
7
|
let(:expected) do
|
@@ -11,13 +11,13 @@ describe Hieracles::Config do
|
|
11
11
|
hierafile: File.expand_path('spec/files/hiera.yaml')
|
12
12
|
}
|
13
13
|
end
|
14
|
-
|
14
|
+
let(:config) { Hieracles::Config.new options }
|
15
15
|
|
16
16
|
it 'initialize config values' do
|
17
|
-
expect(
|
18
|
-
expect(
|
19
|
-
expect(
|
20
|
-
expect(
|
17
|
+
expect(config.classpath).to eq expected[:classpath]
|
18
|
+
expect(config.modulepath).to eq expected[:modulepath]
|
19
|
+
expect(config.hierafile).to eq expected[:hierafile]
|
20
|
+
expect(config.format).to eq 'Console'
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -36,13 +36,13 @@ describe Hieracles::Config do
|
|
36
36
|
hierafile: File.expand_path('spec/files/hiera.yaml')
|
37
37
|
}
|
38
38
|
end
|
39
|
-
|
39
|
+
let(:config) { Hieracles::Config.new options }
|
40
40
|
|
41
41
|
it 'initialize config values' do
|
42
|
-
expect(
|
43
|
-
expect(
|
44
|
-
expect(
|
45
|
-
expect(
|
42
|
+
expect(config.classpath).to eq expected[:classpath]
|
43
|
+
expect(config.modulepath).to eq expected[:modulepath]
|
44
|
+
expect(config.hierafile).to eq expected[:hierafile]
|
45
|
+
expect(config.format).to eq 'Console'
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -53,8 +53,8 @@ describe Hieracles::Config do
|
|
53
53
|
config: 'spec/files/config_withdb.yml'
|
54
54
|
}
|
55
55
|
end
|
56
|
-
|
57
|
-
it { expect(
|
56
|
+
let(:config) { Hieracles::Config.new options }
|
57
|
+
it { expect(config.usedb).to be true }
|
58
58
|
end
|
59
59
|
context 'with nodb passed as param' do
|
60
60
|
let(:options) do
|
@@ -63,8 +63,8 @@ describe Hieracles::Config do
|
|
63
63
|
nodb: true
|
64
64
|
}
|
65
65
|
end
|
66
|
-
|
67
|
-
it { expect(
|
66
|
+
let(:config) { Hieracles::Config.new options }
|
67
|
+
it { expect(config.usedb).to be false }
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -76,8 +76,8 @@ describe Hieracles::Config do
|
|
76
76
|
db: true
|
77
77
|
}
|
78
78
|
end
|
79
|
-
|
80
|
-
it { expect(
|
79
|
+
let(:config) { Hieracles::Config.new options }
|
80
|
+
it { expect(config.usedb).to be true }
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -89,30 +89,40 @@ describe Hieracles::Config do
|
|
89
89
|
basepath: 'spec/files'
|
90
90
|
}
|
91
91
|
end
|
92
|
-
|
93
|
-
FileUtils.rm(options[:config]) if File.exist? options[:config]
|
94
|
-
Hieracles::Config.load options
|
95
|
-
end
|
92
|
+
let(:config) { Hieracles::Config.new options }
|
96
93
|
after { FileUtils.rm(options[:config]) if File.exist? options[:config] }
|
97
94
|
|
98
95
|
it 'creates a default config file' do
|
96
|
+
config.classpath
|
99
97
|
expect(File.exist? options[:config]).to be true
|
100
98
|
end
|
101
99
|
|
102
100
|
it 'initialize config values' do
|
103
|
-
expect(
|
101
|
+
expect(config.classpath).to eq File.expand_path('spec/files/manifests/classes/%s.pp')
|
104
102
|
end
|
105
103
|
end
|
106
104
|
end
|
107
105
|
|
108
|
-
describe '.defaultconfig' do
|
109
|
-
|
110
|
-
|
106
|
+
# describe '.defaultconfig' do
|
107
|
+
# let(:config) { Hieracles::Config.new Hash.new }
|
108
|
+
# before {
|
109
|
+
# allow(config).
|
110
|
+
# to receive(:defaultconfig).
|
111
|
+
# and_return('spec/files/config.yml')
|
112
|
+
# }
|
113
|
+
# it { expect(config.defaultconfig).not_to eq nil }
|
114
|
+
# end
|
111
115
|
|
112
116
|
describe '.extract_params' do
|
117
|
+
let(:options) do
|
118
|
+
{
|
119
|
+
config: 'spec/files/config.yml'
|
120
|
+
}
|
121
|
+
end
|
113
122
|
let(:str) { 'bla=blu;one=two' }
|
114
123
|
let(:expected) { { bla: 'blu', one: 'two' } }
|
115
|
-
|
124
|
+
let(:config) { Hieracles::Config.new options }
|
125
|
+
it { expect(config.extract_params(str)).to eq expected }
|
116
126
|
end
|
117
127
|
|
118
128
|
describe '.scope' do
|
@@ -124,9 +134,9 @@ describe Hieracles::Config do
|
|
124
134
|
}
|
125
135
|
end
|
126
136
|
let(:expected) { 'Debian' }
|
127
|
-
|
137
|
+
let(:config) { Hieracles::Config.new options }
|
128
138
|
|
129
|
-
it { expect(
|
139
|
+
it { expect(config.scope[:osfamily]).to eq expected }
|
130
140
|
end
|
131
141
|
context 'with a json file' do
|
132
142
|
let(:options) do
|
@@ -136,21 +146,27 @@ describe Hieracles::Config do
|
|
136
146
|
}
|
137
147
|
end
|
138
148
|
let(:expected) { 'Debian' }
|
139
|
-
|
149
|
+
let(:config) { Hieracles::Config.new options }
|
140
150
|
|
141
|
-
it { expect(
|
151
|
+
it { expect(config.scope[:osfamily]).to eq expected }
|
142
152
|
end
|
143
153
|
end
|
144
154
|
|
145
155
|
describe '.resolve_path' do
|
156
|
+
let(:options) do
|
157
|
+
{
|
158
|
+
config: 'spec/files/config.yml'
|
159
|
+
}
|
160
|
+
end
|
161
|
+
let(:config) { Hieracles::Config.new options }
|
146
162
|
context "when path is found" do
|
147
163
|
let(:path) { 'README.md' }
|
148
164
|
let(:expected) { File.expand_path('README.md') }
|
149
|
-
it { expect(
|
165
|
+
it { expect(config.resolve_path(path)).to eq expected }
|
150
166
|
end
|
151
167
|
context "when path is not found anywhere" do
|
152
168
|
let(:path) { 'README-NOT.md' }
|
153
|
-
it { expect {
|
169
|
+
it { expect { config.resolve_path(path) }.to raise_error(IOError) }
|
154
170
|
end
|
155
171
|
end
|
156
172
|
|