puppet-debugger 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +12 -8
- data/CHANGELOG.md +5 -2
- data/lib/puppet-debugger/cli.rb +3 -3
- data/lib/puppet-debugger/support/environment.rb +2 -2
- data/lib/puppet-debugger/support/functions.rb +12 -0
- data/lib/puppet-debugger/support/input_responders.rb +33 -4
- data/lib/puppet-debugger/support/loader.rb +37 -10
- data/lib/puppet-debugger/support/node.rb +4 -6
- data/lib/puppet-debugger/support/scope.rb +0 -1
- data/lib/version.rb +1 -1
- data/spec/puppet/application/debugger_spec.rb +0 -4
- data/spec/puppet_debugger_spec.rb +25 -1
- metadata +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 857afe5c153e6dbdce56459291318d984689a28f
|
4
|
+
data.tar.gz: c8c80c82ef553716ac98bf59c6a3175f8a11235a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fd7ebb96bef948c27045478ff96f872e22bcd98b2bcf4c8c2b44087eb7d75efaa1760327c9becdc8be2eb6b62ba1e6cf6bc5f147b00d98db1135410e0af27ed
|
7
|
+
data.tar.gz: d2440f621ba7b0fe0111fa7735fd7cd8a53f1e6832cf7c1eba073149ebb8bd8c7d1bd15d6d5559766f1a2303194155be35d2edbdfd40d23201ac1ba50fb478d0
|
data/.gitlab-ci.yml
CHANGED
@@ -13,6 +13,8 @@ stages:
|
|
13
13
|
- bundle install --without development validate
|
14
14
|
- bundle exec puppet module install puppetlabs-stdlib
|
15
15
|
- bundle exec rake spec
|
16
|
+
tags:
|
17
|
+
- ruby
|
16
18
|
|
17
19
|
web_trigger_staging:
|
18
20
|
type: web_deploy
|
@@ -45,14 +47,16 @@ bump_and_tag:
|
|
45
47
|
- gem install release_me
|
46
48
|
- bump_and_tag
|
47
49
|
|
48
|
-
web_trigger_production:
|
49
|
-
type: web_deploy
|
50
|
-
variables:
|
51
|
-
REF: production
|
52
|
-
only:
|
53
|
-
- tags
|
54
|
-
|
55
|
-
-
|
50
|
+
#web_trigger_production:
|
51
|
+
# type: web_deploy
|
52
|
+
# variables:
|
53
|
+
# REF: production
|
54
|
+
# only:
|
55
|
+
# - tags
|
56
|
+
# tags:
|
57
|
+
# - ruby
|
58
|
+
# script:
|
59
|
+
# - "curl -X POST -F token=$PREPL_BUILD_TRIGGER_TOKEN -F ref=$REF https://gitlab.com/api/v3/projects/1146764/trigger/builds"
|
56
60
|
|
57
61
|
.ruby_193: &ruby193
|
58
62
|
image: ruby:1.9.3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
##
|
2
|
-
|
1
|
+
## 0.6.0
|
2
|
+
* Adds ability to list puppet types
|
3
|
+
* Adds ability to list puppet datatypes
|
4
|
+
## 0.5.1
|
5
|
+
* accidently bump
|
3
6
|
## 0.5.0
|
4
7
|
* Fixes #gh-49 - puppet 4 functions don't seem to work
|
5
8
|
* Disables trying to set trusted_node_data for puppet versions that do not support it
|
data/lib/puppet-debugger/cli.rb
CHANGED
@@ -45,7 +45,7 @@ module PuppetDebugger
|
|
45
45
|
scoped_vars = variables.map { |k, _v| scope.compiler.topscope.exist?(k) ? "$::#{k}" : "$#{k}" }
|
46
46
|
# append a () to functions so we know they are functions
|
47
47
|
funcs = function_map.keys.map { |k| "#{k.split('::').last}()" }
|
48
|
-
(scoped_vars + funcs + static_responder_list).uniq.sort
|
48
|
+
(scoped_vars + funcs + static_responder_list + all_data_types).uniq.sort
|
49
49
|
end
|
50
50
|
|
51
51
|
# looks up the type in the catalog by using the type and title
|
@@ -97,7 +97,7 @@ module PuppetDebugger
|
|
97
97
|
begin
|
98
98
|
output = ''
|
99
99
|
case input
|
100
|
-
when /^play|^classification|^whereami|^facterdb_filter|^facts|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/
|
100
|
+
when /^play|^classification|^whereami|^facterdb_filter|^facts|^datatypes|^types|^vars|^functions|^classes|^resources|^krt|^environment|^reset|^help/
|
101
101
|
args = input.split(' ')
|
102
102
|
command = args.shift.to_sym
|
103
103
|
output = send(command, args) if respond_to?(command)
|
@@ -150,7 +150,7 @@ Puppet Version: #{Puppet.version}
|
|
150
150
|
Puppet Debugger Version: #{PuppetDebugger::VERSION}
|
151
151
|
Created by: NWOps <corey@nwops.io>
|
152
152
|
Type "exit", "functions", "vars", "krt", "whereami", "facts", "resources", "classes",
|
153
|
-
"play", "classification", "reset", or "help" for more information.
|
153
|
+
"play", "classification", "types", "datatypes", "reset", or "help" for more information.
|
154
154
|
|
155
155
|
EOT
|
156
156
|
output
|
@@ -34,8 +34,8 @@ module PuppetDebugger
|
|
34
34
|
# returns the environment
|
35
35
|
def create_environment
|
36
36
|
Puppet::Node::Environment.create(Puppet[:environment],
|
37
|
-
|
38
|
-
|
37
|
+
default_modules_paths,
|
38
|
+
default_manifests_dir)
|
39
39
|
end
|
40
40
|
|
41
41
|
def create_node_environment(manifest = nil)
|
@@ -17,6 +17,18 @@ module PuppetDebugger
|
|
17
17
|
Dir.glob(search_dirs.flatten)
|
18
18
|
end
|
19
19
|
|
20
|
+
def data_type_files
|
21
|
+
search_dirs = lib_dirs.map do |lib_dir|
|
22
|
+
[File.join(lib_dir, 'puppet', 'functions', '**', '*.rb'),
|
23
|
+
File.join(lib_dir, 'functions', '**', '*.rb'),
|
24
|
+
File.join(lib_dir, 'puppet', 'parser', 'functions', '*.rb')]
|
25
|
+
end
|
26
|
+
# add puppet lib directories
|
27
|
+
search_dirs << [File.join(puppet_lib_dir, 'puppet', 'functions', '**', '*.rb'),
|
28
|
+
File.join(puppet_lib_dir, 'puppet', 'parser', 'functions', '*.rb')]
|
29
|
+
Dir.glob(search_dirs.flatten)
|
30
|
+
end
|
31
|
+
|
20
32
|
# returns either the module name or puppet version
|
21
33
|
def mod_finder
|
22
34
|
@mod_finder ||= Regexp.new('\/([\w\-\.]+)\/lib')
|
@@ -3,13 +3,20 @@ module PuppetDebugger
|
|
3
3
|
module Support
|
4
4
|
module InputResponders
|
5
5
|
def static_responder_list
|
6
|
-
%w(exit functions classification vars facterdb_filter krt facts
|
7
|
-
resources classes whereami play reset help)
|
6
|
+
%w(exit functions classification vars facterdb_filter krt facts types
|
7
|
+
resources classes whereami datatypes play reset help)
|
8
|
+
end
|
9
|
+
|
10
|
+
def datatypes(_args = [])
|
11
|
+
types = all_data_types
|
12
|
+
return types.sort.ai if types.instance_of?(Array)
|
13
|
+
types
|
8
14
|
end
|
9
15
|
|
10
16
|
# @source_file and @source_line_num instance variables must be set for this
|
11
17
|
# method to show the surrounding code
|
12
|
-
# @return [String] - string output of the code surrounded by the breakpoint or nil if file
|
18
|
+
# @return [String] - string output of the code surrounded by the breakpoint or nil if file
|
19
|
+
# or line_num do not exist
|
13
20
|
def whereami(_command = nil, _args = nil)
|
14
21
|
file = @source_file
|
15
22
|
line_num = @source_line_num
|
@@ -20,7 +27,29 @@ module PuppetDebugger
|
|
20
27
|
else
|
21
28
|
code = DebuggerCode.from_file(file, :puppet)
|
22
29
|
end
|
23
|
-
return code.with_marker(line_num).around(line_num, 5)
|
30
|
+
return code.with_marker(line_num).around(line_num, 5)
|
31
|
+
.with_line_numbers.with_indentation(5).with_file_reference.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @return - returns a list of types available to the environment
|
36
|
+
# if a error occurs we we run the types function again
|
37
|
+
def types(_args = [])
|
38
|
+
loaded_types = []
|
39
|
+
begin
|
40
|
+
# this loads all the types, if already loaded the file is skipped
|
41
|
+
Puppet::Type.loadall
|
42
|
+
Puppet::Type.eachtype do |t|
|
43
|
+
next if t.name == :component
|
44
|
+
loaded_types << t.name.to_s
|
45
|
+
end
|
46
|
+
loaded_types.ai
|
47
|
+
rescue Puppet::Error => e
|
48
|
+
puts e.message.red
|
49
|
+
Puppet.info(e.message)
|
50
|
+
# prevent more than two calls and recursive loop
|
51
|
+
return if caller_locations(1,10).find_all{|f| f.label == 'types' }.count > 2
|
52
|
+
types
|
24
53
|
end
|
25
54
|
end
|
26
55
|
|
@@ -1,15 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module PuppetDebugger
|
2
3
|
module Support
|
3
4
|
module Loader
|
4
|
-
|
5
5
|
def create_loader(environment)
|
6
6
|
Puppet::Pops::Loaders.new(environment)
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
# @return [Array[String]] - returns a list of all the custom data types found in all the modules in the environment
|
10
|
+
def environment_data_types
|
11
|
+
files = Dir.glob(puppet_environment.modulepath.map { |m| File.join(m, '**', 'types', '**', '*.pp') })
|
12
|
+
files.map do |f|
|
13
|
+
m = File.read(f).match(/type\s([a-z\d\:_]+)/i)
|
14
|
+
next if m =~ /type|alias/ # can't figure out the best way to filter type and alias out
|
15
|
+
m[1] if m && m[1] =~ /::/
|
16
|
+
end.uniq.compact
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Array[String]] - a list of core data types
|
20
|
+
def core_datatypes
|
21
|
+
loaders.implementation_registry
|
22
|
+
.instance_variable_get(:'@implementations_per_type_name')
|
23
|
+
.keys.find_all { |t| t !~ /::/ }
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Array[String]] - combined list of core data types and environment data types
|
27
|
+
def all_data_types
|
28
|
+
unless loaders.respond_to?(:implementation_registry)
|
29
|
+
Puppet.info("Data Types Not Available in Puppet: #{Puppet.version}")
|
30
|
+
return []
|
31
|
+
end
|
32
|
+
core_datatypes + environment_data_types
|
13
33
|
end
|
14
34
|
|
15
35
|
def loaders
|
@@ -19,16 +39,23 @@ module PuppetDebugger
|
|
19
39
|
# returns an array of module loaders that we may need to use in the future
|
20
40
|
# in order to parse all types of code (ie. functions) For now this is not
|
21
41
|
# being used.
|
22
|
-
def resolve_paths(loaders)
|
23
|
-
|
24
|
-
|
25
|
-
|
42
|
+
# def resolve_paths(loaders)
|
43
|
+
# mod_resolver = loaders.instance_variable_get(:@module_resolver)
|
44
|
+
# all_mods = mod_resolver.instance_variable_get(:@all_module_loaders)
|
45
|
+
# all_mods.last.get_contents
|
46
|
+
# end
|
26
47
|
|
27
48
|
# def functions
|
28
49
|
# @functions = []
|
29
50
|
# @functions << compiler.loaders.static_loader.loaded.keys.find_all {|l| l.type == :function}
|
51
|
+
# returns all the type names, athough we cannot determine the difference between datatype and resource type
|
52
|
+
# loaders.static_loader.loaded.map { |item| item.first.name}
|
53
|
+
# loaders.implementation_registry.
|
54
|
+
# instance_variable_get(:'@implementations_per_type_name').
|
55
|
+
# keys.find_all { |t| t !~ /::/ }
|
56
|
+
# Puppet::Pops::Types::TypeFactory.type_map.keys.map(&:capatilize)
|
30
57
|
# end
|
31
|
-
|
58
|
+
# Puppet::Pops::Adapters::LoaderAdapter.loader_for_model_object(generate_ast(''))
|
32
59
|
end
|
33
60
|
end
|
34
61
|
end
|
@@ -31,17 +31,15 @@ module PuppetDebugger
|
|
31
31
|
node = nil
|
32
32
|
unless Puppet[:node_name_fact].empty?
|
33
33
|
# Collect our facts.
|
34
|
-
|
35
|
-
|
36
|
-
end
|
34
|
+
facts = Puppet::Node::Facts.indirection.find(Puppet[:node_name_value])
|
35
|
+
raise "Could not find facts for #{Puppet[:node_name_value]}" unless facts
|
37
36
|
Puppet[:node_name_value] = facts.values[Puppet[:node_name_fact]]
|
38
37
|
facts.name = Puppet[:node_name_value]
|
39
38
|
end
|
40
39
|
Puppet.override({ current_environment: environment }, 'For puppet debugger') do
|
41
40
|
# Find our Node
|
42
|
-
|
43
|
-
|
44
|
-
end
|
41
|
+
node = Puppet::Node.indirection.find(Puppet[:node_name_value])
|
42
|
+
raise "Could not find node #{Puppet[:node_name_value]}" unless node
|
45
43
|
# Merge in the facts.
|
46
44
|
node.merge(facts.values) if facts
|
47
45
|
end
|
data/lib/version.rb
CHANGED
@@ -78,7 +78,6 @@ $var1
|
|
78
78
|
EOF
|
79
79
|
end
|
80
80
|
|
81
|
-
|
82
81
|
it 'assign variable' do
|
83
82
|
allow(debugger).to receive(:options).and_return(code: input, quiet: true, run_once: true, use_facterdb: true)
|
84
83
|
expect { debugger.run_command }.to output(/\"111111\"/).to_stdout
|
@@ -109,13 +108,10 @@ $var1
|
|
109
108
|
EOF
|
110
109
|
end
|
111
110
|
|
112
|
-
|
113
111
|
it 'assign variable' do
|
114
112
|
allow(debugger).to receive(:options).and_return(code: input, quiet: true, run_once: true, use_facterdb: false)
|
115
113
|
expect { debugger.run_command }.to output(/\"111111\"/).to_stdout
|
116
114
|
end
|
117
115
|
end
|
118
116
|
end
|
119
|
-
|
120
|
-
|
121
117
|
end
|
@@ -180,7 +180,7 @@ describe 'PuppetDebugger' do
|
|
180
180
|
'help'
|
181
181
|
end
|
182
182
|
it 'can show the help screen' do
|
183
|
-
expected_debugger_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"whereami\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"reset\", or \"help\" for more information.\n\n/
|
183
|
+
expected_debugger_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"whereami\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"types\", \"datatypes\", \"reset\", or \"help\" for more information.\n\n/
|
184
184
|
debugger.handle_input(input)
|
185
185
|
expect(output.string).to match(/Ruby Version: #{RUBY_VERSION}\n/)
|
186
186
|
expect(output.string).to match(/Puppet Version: \d.\d.\d\n/)
|
@@ -446,6 +446,20 @@ describe 'PuppetDebugger' do
|
|
446
446
|
end
|
447
447
|
end
|
448
448
|
|
449
|
+
describe 'datatypes' do
|
450
|
+
let(:input) do
|
451
|
+
'datatypes'
|
452
|
+
end
|
453
|
+
it 'handle datatypes' do
|
454
|
+
debugger.handle_input(input)
|
455
|
+
if Puppet.version < '4.3.0'
|
456
|
+
expect(output.string).to eq("\n[]\n")
|
457
|
+
else
|
458
|
+
expect(output.string).to match(/.*Array.*/)
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
449
463
|
describe 'whereami' do
|
450
464
|
let(:input) do
|
451
465
|
File.expand_path File.join(fixtures_dir, 'sample_start_debugger.pp')
|
@@ -465,6 +479,16 @@ describe 'PuppetDebugger' do
|
|
465
479
|
end
|
466
480
|
end
|
467
481
|
|
482
|
+
describe 'types' do
|
483
|
+
let(:input) do
|
484
|
+
'types'
|
485
|
+
end
|
486
|
+
it 'runs' do
|
487
|
+
debugger.handle_input(input)
|
488
|
+
expect(output.string).to match(/service/)
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
468
492
|
describe 'error message' do
|
469
493
|
let(:input) do
|
470
494
|
"file{'/tmp/test': ensure => present, contact => 'blah'}"
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-debugger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Osman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.8'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.8'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: facterdb
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.3.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.3.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: awesome_print
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.6'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rdoc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.12'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.12'
|
69
69
|
description: A interactive command line tool for evaluating and debugging the puppet
|
@@ -77,15 +77,15 @@ extra_rdoc_files:
|
|
77
77
|
- LICENSE.txt
|
78
78
|
- README.md
|
79
79
|
files:
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
80
|
+
- .dockerignore
|
81
|
+
- .document
|
82
|
+
- .gitignore
|
83
|
+
- .gitlab-ci.yml
|
84
|
+
- .release_me.yaml
|
85
|
+
- .rspec
|
86
|
+
- .rubocop.yml
|
87
|
+
- .rubocop_todo.yml
|
88
|
+
- .ruby-version
|
89
89
|
- CHANGELOG.md
|
90
90
|
- DEVELOPMENT.md
|
91
91
|
- Gemfile
|
@@ -142,17 +142,17 @@ require_paths:
|
|
142
142
|
- lib
|
143
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - '>='
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
155
|
+
rubygems_version: 2.0.14.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: A repl based debugger for the puppet language
|