puppet-debugger 0.4.0 → 0.4.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 +3 -0
- data/DEVELOPMENT.md +8 -0
- data/README.md +3 -1
- data/lib/puppet/application/debugger.rb +306 -0
- data/lib/puppet-debugger/cli.rb +2 -5
- data/lib/puppet-debugger/debugger_code.rb +20 -4
- data/lib/puppet-debugger/support/facts.rb +4 -4
- data/lib/puppet-debugger/support/input_responders.rb +1 -1
- data/lib/puppet-debugger/support.rb +2 -2
- data/lib/version.rb +1 -1
- data/spec/facts_spec.rb +4 -4
- data/spec/puppet/application/debugger_spec.rb +67 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5495b2df7d84d06cb7871e2201f78c0bfca4240a
|
4
|
+
data.tar.gz: b98315db3c5862050e0afc147868fb48e6306875
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 516bb93a8fef0e35e9b100f0f73b604c74acc2449984d0370127f242dd66226e1e894c051b39547eb5273ebc62d8cb713850d534a1b12443c45276a179520695
|
7
|
+
data.tar.gz: b2597ecda5402fe9659ab5d3d54b5b0c08e0c96960db30a4fe9453329257352c3813ef4cc25440e5749873f7798b7d8c4b97965fbeb871b83340b6aa6f5509a1
|
data/CHANGELOG.md
CHANGED
data/DEVELOPMENT.md
ADDED
data/README.md
CHANGED
@@ -61,7 +61,7 @@ There is a web version of the [puppet-debugger](https://www.puppet-debugger.com)
|
|
61
61
|
limited at this time. In the future we will be adding lots of awesome features to the web repl.
|
62
62
|
|
63
63
|
## Usage
|
64
|
-
puppet-debugger will only parse and
|
64
|
+
puppet-debugger will only parse and evaluate your code. It will not build a catalog
|
65
65
|
and try to enforce the catalog. This has a few side affects.
|
66
66
|
|
67
67
|
1. Type and provider code will not get run.
|
@@ -87,6 +87,8 @@ Type "exit", "functions", "vars", "krt", "facts", "reset", "help" for more infor
|
|
87
87
|
|
88
88
|
```
|
89
89
|
|
90
|
+
You can also use the debugger from the puppet command via `puppet debugger`
|
91
|
+
|
90
92
|
## Using Variables
|
91
93
|
|
92
94
|
```
|
@@ -0,0 +1,306 @@
|
|
1
|
+
require 'puppet/application'
|
2
|
+
require 'optparse'
|
3
|
+
require 'puppet/util/command_line'
|
4
|
+
|
5
|
+
class Puppet::Application::Debugger < Puppet::Application
|
6
|
+
attr_reader :use_facterdb, :use_stdin
|
7
|
+
|
8
|
+
option("--execute EXECUTE","-e") do |arg|
|
9
|
+
options[:code] = arg
|
10
|
+
end
|
11
|
+
|
12
|
+
option("--facterdb-filter FILTER") do |arg|
|
13
|
+
@use_facterdb = true unless options[:node_name]
|
14
|
+
ENV['DEBUGGER_FACTERDB_FILTER'] = arg if arg
|
15
|
+
end
|
16
|
+
|
17
|
+
option("--test") do |_arg|
|
18
|
+
options[:quiet] = true
|
19
|
+
options[:run_once] = true
|
20
|
+
@use_stdin = true
|
21
|
+
end
|
22
|
+
|
23
|
+
option("--no-facterdb") { |_arg| @use_facterdb = false }
|
24
|
+
|
25
|
+
option("--log-level LEVEL","-l") do |arg|
|
26
|
+
Puppet::Util::Log.level = arg.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
option("--quiet", "-q") { |_arg| options[:quiet] = true }
|
30
|
+
|
31
|
+
option("--play URL", "-p") do |arg|
|
32
|
+
options[:play] = arg
|
33
|
+
end
|
34
|
+
|
35
|
+
option("--stdin", "-s") { |_arg| @use_stdin = true }
|
36
|
+
|
37
|
+
option("--run-once", '-r') { |_arg| options[:run_once] = true }
|
38
|
+
|
39
|
+
option("--node-name CERTNAME", '-n') do |arg|
|
40
|
+
@use_facterdb = false
|
41
|
+
options[:node_name] = arg
|
42
|
+
end
|
43
|
+
|
44
|
+
def help
|
45
|
+
<<-HELP
|
46
|
+
|
47
|
+
puppet-debugger(8) -- Starts a debugger session using the puppet-debugger tool
|
48
|
+
========
|
49
|
+
|
50
|
+
SYNOPSIS
|
51
|
+
--------
|
52
|
+
A interactive command line tool for evaluating the puppet language and debugging
|
53
|
+
puppet code.
|
54
|
+
|
55
|
+
USAGE
|
56
|
+
-----
|
57
|
+
puppet debugger [--help] [--version] [-e|--execute CODE] [--facterdb-filter FILTER]
|
58
|
+
[--test] [--no-facterdb] [-q|--quiet] [-p|--play URL] [-s|--stdin]
|
59
|
+
[-r|--run-once] [-n|--node-name CERTNAME]
|
60
|
+
|
61
|
+
|
62
|
+
DESCRIPTION
|
63
|
+
-----------
|
64
|
+
A interactive command line tool for evaluating the puppet language and debugging
|
65
|
+
puppet code.
|
66
|
+
|
67
|
+
USAGE WITH DEBUG MODULE
|
68
|
+
-----------------------
|
69
|
+
Use the puppet debugger in conjunction with the debug::break() puppet function
|
70
|
+
to pry into your code during compilation. Get immediate insight in how the puppet4
|
71
|
+
languge works during the execution of your code.
|
72
|
+
|
73
|
+
To use the break function install the module via: puppet module install nwops/debug
|
74
|
+
|
75
|
+
Now place the debug::break() function anywhere in your code to
|
76
|
+
|
77
|
+
Example:
|
78
|
+
puppet debugger -e '$abs_vars = [-11,-22,-33].map | Integer $num | { debug::break() ; notice($num) }'
|
79
|
+
|
80
|
+
See: https://github.com/nwops/puppet-debug
|
81
|
+
OPTIONS
|
82
|
+
-------
|
83
|
+
Note that any setting that's valid in the configuration
|
84
|
+
file is also a valid long argument. For example, 'server' is a valid
|
85
|
+
setting, so you can specify '--server <servername>' as
|
86
|
+
an argument.
|
87
|
+
|
88
|
+
See the configuration file documentation at
|
89
|
+
http://docs.puppetlabs.com/references/stable/configuration.html for the
|
90
|
+
full list of acceptable parameters. A commented list of all
|
91
|
+
configuration options can also be generated by running puppet debugger with
|
92
|
+
'--genconfig'.
|
93
|
+
|
94
|
+
* --help:
|
95
|
+
Print this help message
|
96
|
+
|
97
|
+
* --version:
|
98
|
+
Print the puppet version number and exit.
|
99
|
+
|
100
|
+
* --execute:
|
101
|
+
Execute a specific piece of Puppet code
|
102
|
+
|
103
|
+
* --facterdb-filter
|
104
|
+
Disables the usage of the current node level facts and uses cached facts
|
105
|
+
from facterdb. Specifying a filter will override the default facterdb filter.
|
106
|
+
Not specifiying a filter will use the default CentOS based filter.
|
107
|
+
This will greatly speed up the start time of the debugger since
|
108
|
+
you are using cached facts. Additionally, using facterdb also allows you
|
109
|
+
to play with many other operating system facts that you might not have access
|
110
|
+
to. For example filters please see the facterdb docs.
|
111
|
+
|
112
|
+
See https://github.com/camptocamp/facterdb for more info
|
113
|
+
|
114
|
+
* --no-facterdb
|
115
|
+
Use the facts found on this node instead of cached facts from facterdb.
|
116
|
+
|
117
|
+
* --log-level
|
118
|
+
Set the Puppet log level which can be very useful with using the debugger.
|
119
|
+
|
120
|
+
* --quiet
|
121
|
+
Do not display the debugger help script upon startup.
|
122
|
+
|
123
|
+
* --play
|
124
|
+
Plays back the code file supplied into the debugger. Can also supply
|
125
|
+
any http based url.
|
126
|
+
|
127
|
+
* --run-once
|
128
|
+
Return the result from the debugger and exit
|
129
|
+
|
130
|
+
* --stdin
|
131
|
+
Read from stdin instead of starting the debugger right away. Useful when piping code into the debugger.
|
132
|
+
|
133
|
+
* --node-name
|
134
|
+
Retrieves the node information remotely via the puppet server given the node name.
|
135
|
+
This is extremely useful when trying to debug classification issues, as this can show
|
136
|
+
classes and parameters retrieved from the ENC. You can also play around with the real facts
|
137
|
+
of the remote node as well.
|
138
|
+
|
139
|
+
Note: this requires special permission in your puppet server's auth.conf file to allow
|
140
|
+
access to make remote calls from this node: #{Puppet[:certname]}
|
141
|
+
|
142
|
+
You must also have a signed cert and be able to connect to the server from this system.
|
143
|
+
|
144
|
+
Mutually exclusive with --facterdb-filter
|
145
|
+
|
146
|
+
* --test
|
147
|
+
Runs the code in the debugger and exit without showing the help screen ( --quiet --run-once, --stdin)
|
148
|
+
|
149
|
+
EXAMPLE
|
150
|
+
-------
|
151
|
+
$ puppet debugger
|
152
|
+
$ echo "notice('hello, can you hear me?')" | puppet debugger --test
|
153
|
+
$ echo "notice('hello, can you hear me?')" | puppet debugger --stdin
|
154
|
+
$ puppet debugger --execute "notice('hello')"
|
155
|
+
$ puppet debugger --facterdb-filter 'facterversion=/^2.4\./ and operatingsystem=Debian'
|
156
|
+
$ puppet debugger --play https://gist.github.com/logicminds/4f6bcfd723c92aad1f01f6a800319fa4
|
157
|
+
$ puppet debugger --facterdb-filter 'facterversion=/^2.4\./ and operatingsystem=Debian' \\
|
158
|
+
--play https://gist.github.com/logicminds/4f6bcfd723c92aad1f01f6a800319fa4
|
159
|
+
$ puppet debugger --node-name
|
160
|
+
|
161
|
+
|
162
|
+
AUTHOR
|
163
|
+
------
|
164
|
+
Corey Osman <corey@nwops.io>
|
165
|
+
|
166
|
+
|
167
|
+
COPYRIGHT
|
168
|
+
---------
|
169
|
+
Copyright (c) 2016 NWOps
|
170
|
+
|
171
|
+
HELP
|
172
|
+
end
|
173
|
+
|
174
|
+
def app_defaults
|
175
|
+
Puppet::Settings.app_defaults_for_run_mode(self.class.run_mode).merge(
|
176
|
+
:name => name
|
177
|
+
)
|
178
|
+
end
|
179
|
+
|
180
|
+
def initialize_app_defaults
|
181
|
+
Puppet.settings.initialize_app_defaults(app_defaults)
|
182
|
+
end
|
183
|
+
|
184
|
+
def initialize(command_line = Puppet::Util::CommandLine.new)
|
185
|
+
@command_line = CommandLineArgs.new(command_line.subcommand_name, command_line.args.dup)
|
186
|
+
@options = {}
|
187
|
+
@use_facterdb = true
|
188
|
+
@use_stdin = false
|
189
|
+
begin
|
190
|
+
require 'puppet-debugger'
|
191
|
+
unless ::PuppetDebugger::VERSION >= '0.4.0'
|
192
|
+
Puppet.err('You must install the puppet-debugger gem version >= 0.4.0')
|
193
|
+
end
|
194
|
+
rescue LoadError => e
|
195
|
+
Puppet.err('You must install the puppet-debugger: gem install puppet-debugger')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def main
|
200
|
+
# if this is a file we don't play back since its part of the environment
|
201
|
+
# if just the code we put in a file and use the play feature of the debugger
|
202
|
+
# we could do the same thing with the passed in manifest file but that might be too much code to show
|
203
|
+
manifest = nil
|
204
|
+
if options[:code]
|
205
|
+
code_input = options.delete(:code)
|
206
|
+
file = Tempfile.new(['puppet_repl_input', '.pp'])
|
207
|
+
File.open(file, 'w') do |f|
|
208
|
+
f.write(code_input)
|
209
|
+
end
|
210
|
+
options[:play] = file
|
211
|
+
elsif command_line.args.length == 0 and use_stdin
|
212
|
+
code_input = STDIN.read
|
213
|
+
file = Tempfile.new(['puppet_repl_input', '.pp'])
|
214
|
+
File.open(file, 'w') do |f|
|
215
|
+
f.write(code_input)
|
216
|
+
end
|
217
|
+
options[:play] = file
|
218
|
+
elsif command_line.args.length > 0
|
219
|
+
manifest = command_line.args.shift
|
220
|
+
raise "Could not find file #{manifest}" unless Puppet::FileSystem.exist?(manifest)
|
221
|
+
Puppet.warning("Only one file can be used per run. Skipping #{command_line.args.join(', ')}") if command_line.args.size > 0
|
222
|
+
options[:play] = file
|
223
|
+
end
|
224
|
+
if ! use_facterdb and options[:node_name].nil?
|
225
|
+
debug_environment = create_environment(nil)
|
226
|
+
Puppet.notice('Gathering node facts...')
|
227
|
+
node = create_node(debug_environment)
|
228
|
+
scope = create_scope(node)
|
229
|
+
# start_debugger(scope)
|
230
|
+
options.merge!({:scope => scope})
|
231
|
+
end
|
232
|
+
::PuppetDebugger::Cli.start_without_stdin(options)
|
233
|
+
end
|
234
|
+
|
235
|
+
def create_environment(manifest)
|
236
|
+
configured_environment = Puppet.lookup(:current_environment)
|
237
|
+
manifest ?
|
238
|
+
configured_environment.override_with(:manifest => manifest) :
|
239
|
+
configured_environment
|
240
|
+
end
|
241
|
+
|
242
|
+
def create_node(environment)
|
243
|
+
node = nil
|
244
|
+
unless Puppet[:node_name_fact].empty?
|
245
|
+
# Collect our facts.
|
246
|
+
unless facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
|
247
|
+
raise "Could not find facts for #{Puppet[:node_name_value]}"
|
248
|
+
end
|
249
|
+
Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
|
250
|
+
facts.name = Puppet[:node_name_value]
|
251
|
+
end
|
252
|
+
|
253
|
+
Puppet.override({:current_environment => environment}, "For puppet debugger") do
|
254
|
+
# Find our Node
|
255
|
+
unless node = Puppet::Node.indirection.find(Puppet[:node_name_value])
|
256
|
+
raise "Could not find node #{Puppet[:node_name_value]}"
|
257
|
+
end
|
258
|
+
# Merge in the facts.
|
259
|
+
node.merge(facts.values) if facts
|
260
|
+
end
|
261
|
+
node
|
262
|
+
end
|
263
|
+
|
264
|
+
def create_scope(node)
|
265
|
+
compiler = Puppet::Parser::Compiler.new(node) # creates a new compiler for each scope
|
266
|
+
scope = Puppet::Parser::Scope.new(compiler)
|
267
|
+
# creates a node class
|
268
|
+
scope.source = Puppet::Resource::Type.new(:node, node.name)
|
269
|
+
scope.parent = compiler.topscope
|
270
|
+
# compiling will load all the facts into the scope
|
271
|
+
# without this step facts will not get resolved
|
272
|
+
scope.compiler.compile # this will load everything into the scope
|
273
|
+
scope
|
274
|
+
end
|
275
|
+
|
276
|
+
def start_debugger(scope, options = {})
|
277
|
+
if $stdout.isatty
|
278
|
+
options = options.merge({:scope => scope})
|
279
|
+
# required in order to use convert puppet hash into ruby hash with symbols
|
280
|
+
options = options.inject({}){|data,(k,v)| data[k.to_sym] = v; data}
|
281
|
+
#options[:source_file], options[:source_line] = stacktrace.last
|
282
|
+
::PuppetRepl::Cli.start(options)
|
283
|
+
else
|
284
|
+
Puppet.info 'puppet debug: refusing to start the debugger without a tty'
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
# returns a stacktrace of called puppet code
|
289
|
+
# @return [String] - file path to source code
|
290
|
+
# @return [Integer] - line number of called function
|
291
|
+
# This method originally came from the puppet 4.6 codebase and was backported here
|
292
|
+
# for compatibility with older puppet versions
|
293
|
+
# The basics behind this are to find the `.pp` file in the list of loaded code
|
294
|
+
def stacktrace
|
295
|
+
result = caller().reduce([]) do |memo, loc|
|
296
|
+
if loc =~ /\A(.*\.pp)?:([0-9]+):in\s(.*)/
|
297
|
+
# if the file is not found we set to code
|
298
|
+
# and read from Puppet[:code]
|
299
|
+
# $3 is reserved for the stacktrace type
|
300
|
+
memo << [$1.nil? ? :code : $1, $2.to_i]
|
301
|
+
end
|
302
|
+
memo
|
303
|
+
end.reverse
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
data/lib/puppet-debugger/cli.rb
CHANGED
@@ -204,11 +204,8 @@ Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "clas
|
|
204
204
|
repl_obj.remote_node_name = options[:node_name] if options[:node_name]
|
205
205
|
repl_obj.initialize_from_scope(options[:scope])
|
206
206
|
puts repl_obj.whereami if options[:source_file] and options[:source_line]
|
207
|
-
if options[:play]
|
208
|
-
|
209
|
-
elsif ! options[:run_once]
|
210
|
-
repl_obj.read_loop
|
211
|
-
end
|
207
|
+
repl_obj.play_back(options) if options[:play]
|
208
|
+
repl_obj.read_loop unless options[:run_once]
|
212
209
|
end
|
213
210
|
|
214
211
|
# start reads from stdin or from a file
|
@@ -22,7 +22,7 @@ require_relative 'code/code_file'
|
|
22
22
|
# @return [Code]
|
23
23
|
def from_file(filename, code_type = nil)
|
24
24
|
code_file = CodeFile.new(filename, code_type)
|
25
|
-
new(code_file.code, 1, code_file.code_type)
|
25
|
+
new(code_file.code, 1, code_file.code_type, filename)
|
26
26
|
end
|
27
27
|
|
28
28
|
# Instantiate a `Code` object containing code loaded from a file or
|
@@ -37,7 +37,7 @@ require_relative 'code/code_file'
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# @return [Symbol] The type of code stored in this wrapper.
|
40
|
-
attr_accessor :code_type
|
40
|
+
attr_accessor :code_type, :filename
|
41
41
|
|
42
42
|
# Instantiate a `Code` object containing code from the given `Array`,
|
43
43
|
# `String`, or `IO`. The first line will be line 1 unless specified
|
@@ -47,14 +47,15 @@ require_relative 'code/code_file'
|
|
47
47
|
# @param [Array<String>, String, IO] lines
|
48
48
|
# @param [Integer?] start_line
|
49
49
|
# @param [Symbol?] code_type
|
50
|
-
def initialize(lines = [], start_line = 1, code_type = :ruby)
|
50
|
+
def initialize(lines = [], start_line = 1, code_type = :ruby, filename=nil)
|
51
51
|
if lines.is_a? String
|
52
52
|
lines = lines.lines
|
53
53
|
end
|
54
54
|
@lines = lines.each_with_index.map { |line, lineno|
|
55
55
|
LOC.new(line, lineno + start_line.to_i) }
|
56
56
|
@code_type = code_type
|
57
|
-
|
57
|
+
@filename = filename
|
58
|
+
@with_file_reference = nil
|
58
59
|
@with_marker = @with_indentation = nil
|
59
60
|
end
|
60
61
|
|
@@ -181,6 +182,16 @@ require_relative 'code/code_file'
|
|
181
182
|
end
|
182
183
|
end
|
183
184
|
|
185
|
+
# Format output with line numbers next to it, unless `y_n` is falsy.
|
186
|
+
#
|
187
|
+
# @param [Boolean?] y_n
|
188
|
+
# @return [Code]
|
189
|
+
def with_file_reference(y_n = true)
|
190
|
+
alter do
|
191
|
+
@with_file_reference = y_n
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
184
195
|
# Format output with a marker next to the given +lineno+, unless +lineno+ is
|
185
196
|
# falsy.
|
186
197
|
#
|
@@ -226,9 +237,14 @@ require_relative 'code/code_file'
|
|
226
237
|
print_to_output("", true)
|
227
238
|
end
|
228
239
|
|
240
|
+
def add_file_reference
|
241
|
+
"From file: #{File.basename(filename)}\n"
|
242
|
+
end
|
243
|
+
|
229
244
|
# Writes a formatted representation (based on the configuration of the
|
230
245
|
# object) to the given output, which must respond to `#<<`.
|
231
246
|
def print_to_output(output, color=false)
|
247
|
+
output << add_file_reference if @with_file_reference
|
232
248
|
@lines.each do |loc|
|
233
249
|
loc = loc.dup
|
234
250
|
loc.add_line_number(max_lineno_width) if @with_line_numbers
|
@@ -6,7 +6,7 @@ module PuppetDebugger
|
|
6
6
|
|
7
7
|
# allow the user to specify the facterdb filter
|
8
8
|
def dynamic_facterdb_filter
|
9
|
-
ENV['
|
9
|
+
ENV['DEBUGGER_FACTERDB_FILTER'] || default_facterdb_filter
|
10
10
|
end
|
11
11
|
|
12
12
|
def default_facterdb_filter
|
@@ -14,7 +14,7 @@ module PuppetDebugger
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def facter_version
|
17
|
-
ENV['
|
17
|
+
ENV['DEBUGGER_FACTER_VERSION'] || default_facter_version
|
18
18
|
end
|
19
19
|
|
20
20
|
# return the correct supported version of facter facts
|
@@ -27,11 +27,11 @@ module PuppetDebugger
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def facter_os_name
|
30
|
-
ENV['
|
30
|
+
ENV['DEBUGGER_FACTER_OS_NAME'] || 'Fedora'
|
31
31
|
end
|
32
32
|
|
33
33
|
def facter_os_version
|
34
|
-
ENV['
|
34
|
+
ENV['DEBUGGER_FACTER_OS_VERSION'] || '23'
|
35
35
|
end
|
36
36
|
|
37
37
|
def set_facts(value)
|
@@ -21,7 +21,7 @@ module PuppetDebugger
|
|
21
21
|
else
|
22
22
|
code = DebuggerCode.from_file(file, :puppet)
|
23
23
|
end
|
24
|
-
return code.with_marker(line_num).around(line_num, 5).with_line_numbers.with_indentation(5).to_s
|
24
|
+
return code.with_marker(line_num).around(line_num, 5).with_line_numbers.with_indentation(5).with_file_reference.to_s
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -76,7 +76,7 @@ module PuppetDebugger
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def keyword_expression
|
79
|
-
@keyword_expression ||= Regexp.new(/^exit|^:set|^play|^classification|^facts|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/)
|
79
|
+
@keyword_expression ||= Regexp.new(/^exit|^:set|^play|^classification|^facts|^vars|^functions|^whereami|^classes|^resources|^krt|^environment|^reset|^help/)
|
80
80
|
end
|
81
81
|
|
82
82
|
def known_resource_types
|
@@ -142,7 +142,7 @@ module PuppetDebugger
|
|
142
142
|
# in order to call native functions we need to set the global_scope
|
143
143
|
ast = generate_ast(input)
|
144
144
|
# record the input for puppet to retrieve and reference later
|
145
|
-
file = Tempfile.new(['
|
145
|
+
file = Tempfile.new(['puppet_debugger_input', '.pp'])
|
146
146
|
File.open(file, 'w') do |f|
|
147
147
|
f.write(input)
|
148
148
|
end
|
data/lib/version.rb
CHANGED
data/spec/facts_spec.rb
CHANGED
@@ -19,7 +19,7 @@ describe 'facts' do
|
|
19
19
|
|
20
20
|
describe '2.4' do
|
21
21
|
before(:each) do
|
22
|
-
ENV['
|
22
|
+
ENV['DEBUGGER_FACTERDB_FILTER'] = nil
|
23
23
|
end
|
24
24
|
let(:puppet_version) do
|
25
25
|
'4.2.0'
|
@@ -40,7 +40,7 @@ describe 'facts' do
|
|
40
40
|
|
41
41
|
describe '3.1' do
|
42
42
|
before(:each) do
|
43
|
-
ENV['
|
43
|
+
ENV['DEBUGGER_FACTERDB_FILTER'] = nil
|
44
44
|
end
|
45
45
|
let(:puppet_version) do
|
46
46
|
'4.5.3'
|
@@ -65,7 +65,7 @@ describe 'facts' do
|
|
65
65
|
describe 'default facts' do
|
66
66
|
describe 'bad filter' do
|
67
67
|
before(:each) do
|
68
|
-
ENV['
|
68
|
+
ENV['DEBUGGER_FACTERDB_FILTER'] = 'facterversion=/^6\.5/'
|
69
69
|
end
|
70
70
|
it 'return filter' do
|
71
71
|
expect(debugger.dynamic_facterdb_filter).to eq("facterversion=/^6\\.5/")
|
@@ -76,7 +76,7 @@ describe 'facts' do
|
|
76
76
|
end
|
77
77
|
describe 'good filter' do
|
78
78
|
before(:each) do
|
79
|
-
ENV['
|
79
|
+
ENV['DEBUGGER_FACTERDB_FILTER'] = 'facterversion=/^3\.1/'
|
80
80
|
end
|
81
81
|
it 'return filter' do
|
82
82
|
expect(debugger.dynamic_facterdb_filter).to eq("facterversion=/^3\\.1/")
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
require 'puppet/application/debugger'
|
5
|
+
|
6
|
+
describe Puppet::Application::Debugger do
|
7
|
+
let(:debugger) do
|
8
|
+
Puppet::Application[:debugger]
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:environment) do
|
12
|
+
debugger.create_environment(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:node) do
|
16
|
+
debugger.create_node(environment)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:scope) do
|
20
|
+
debugger.create_node(node)
|
21
|
+
end
|
22
|
+
|
23
|
+
before :each do
|
24
|
+
debugger.initialize_app_defaults
|
25
|
+
end
|
26
|
+
|
27
|
+
it "declare a main command" do
|
28
|
+
expect(debugger).to respond_to(:main)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'start the debugger' do
|
32
|
+
expect(PuppetDebugger::Cli).to receive(:start_without_stdin)
|
33
|
+
debugger.run_command
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'start the debugger' do
|
37
|
+
expect(PuppetDebugger::Cli).to receive(:start_without_stdin)
|
38
|
+
debugger.run_command
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'create an environment' do
|
42
|
+
expect(environment).to be_a(Puppet::Node::Environment)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'shows describtion' do
|
46
|
+
expect(debugger.help).to match(/^puppet-debugger\([^\)]+\) -- (.*)$/)
|
47
|
+
end
|
48
|
+
|
49
|
+
# use --stdin
|
50
|
+
# use facterdb
|
51
|
+
# not use facterdb
|
52
|
+
# use execute
|
53
|
+
# play
|
54
|
+
# runonce
|
55
|
+
# test
|
56
|
+
|
57
|
+
|
58
|
+
# it 'create a node' do
|
59
|
+
# require 'pry'; binding.pry
|
60
|
+
# expect(node).to be_a(Puppet::Node::Environment)
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# it 'create a scope' do
|
64
|
+
# expect(scope).to be_a(Puppet::Node::Environment)
|
65
|
+
# end
|
66
|
+
|
67
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-debugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
@@ -81,6 +81,7 @@ files:
|
|
81
81
|
- ".gitlab-ci.yml"
|
82
82
|
- ".rspec"
|
83
83
|
- CHANGELOG.md
|
84
|
+
- DEVELOPMENT.md
|
84
85
|
- Gemfile
|
85
86
|
- Gemfile.lock
|
86
87
|
- LICENSE.txt
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- lib/puppet-debugger/support/node.rb
|
105
106
|
- lib/puppet-debugger/support/play.rb
|
106
107
|
- lib/puppet-debugger/support/scope.rb
|
108
|
+
- lib/puppet/application/debugger.rb
|
107
109
|
- lib/trollop.rb
|
108
110
|
- lib/version.rb
|
109
111
|
- puppet-debugger.gemspec
|
@@ -116,6 +118,7 @@ files:
|
|
116
118
|
- spec/fixtures/sample_start_debugger.pp
|
117
119
|
- spec/pdb_spec.rb
|
118
120
|
- spec/puppet-debugger_spec.rb
|
121
|
+
- spec/puppet/application/debugger_spec.rb
|
119
122
|
- spec/remote_node_spec.rb
|
120
123
|
- spec/spec_helper.rb
|
121
124
|
- spec/support_spec.rb
|