puppet-debugger 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +54 -0
  4. data/.gitlab-ci.yml +129 -0
  5. data/.rspec +3 -0
  6. data/CHANGELOG.md +61 -0
  7. data/Gemfile +18 -0
  8. data/Gemfile.lock +67 -0
  9. data/LICENSE.txt +20 -0
  10. data/README.md +276 -0
  11. data/Rakefile +32 -0
  12. data/bin/pdb +4 -0
  13. data/lib/awesome_print/ext/awesome_puppet.rb +40 -0
  14. data/lib/puppet-debugger/cli.rb +247 -0
  15. data/lib/puppet-debugger/code/code_file.rb +98 -0
  16. data/lib/puppet-debugger/code/code_range.rb +69 -0
  17. data/lib/puppet-debugger/code/loc.rb +80 -0
  18. data/lib/puppet-debugger/debugger_code.rb +318 -0
  19. data/lib/puppet-debugger/support/compiler.rb +20 -0
  20. data/lib/puppet-debugger/support/environment.rb +38 -0
  21. data/lib/puppet-debugger/support/errors.rb +75 -0
  22. data/lib/puppet-debugger/support/facts.rb +78 -0
  23. data/lib/puppet-debugger/support/functions.rb +72 -0
  24. data/lib/puppet-debugger/support/input_responders.rb +136 -0
  25. data/lib/puppet-debugger/support/node.rb +90 -0
  26. data/lib/puppet-debugger/support/play.rb +91 -0
  27. data/lib/puppet-debugger/support/scope.rb +42 -0
  28. data/lib/puppet-debugger/support.rb +176 -0
  29. data/lib/puppet-debugger.rb +55 -0
  30. data/lib/trollop.rb +861 -0
  31. data/lib/version.rb +3 -0
  32. data/puppet-debugger.gemspec +36 -0
  33. data/run_container_test.sh +12 -0
  34. data/spec/facts_spec.rb +86 -0
  35. data/spec/fixtures/environments/production/manifests/site.pp +1 -0
  36. data/spec/fixtures/invalid_node_obj.yaml +8 -0
  37. data/spec/fixtures/node_obj.yaml +298 -0
  38. data/spec/fixtures/sample_manifest.pp +2 -0
  39. data/spec/fixtures/sample_start_debugger.pp +13 -0
  40. data/spec/pdb_spec.rb +50 -0
  41. data/spec/puppet-debugger_spec.rb +492 -0
  42. data/spec/remote_node_spec.rb +170 -0
  43. data/spec/spec_helper.rb +57 -0
  44. data/spec/support_spec.rb +190 -0
  45. data/test_matrix.rb +42 -0
  46. metadata +148 -0
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module PuppetDebugger
2
+ VERSION = '0.4.0'
3
+ end
@@ -0,0 +1,36 @@
1
+
2
+ require './lib/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "puppet-debugger"
6
+ s.version = PuppetDebugger::VERSION
7
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|resources|local_test_results|pec)/}) }
8
+ s.bindir = "bin"
9
+ s.executables = ["pdb"]
10
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
11
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
12
+ if s.respond_to?(:metadata)
13
+ s.metadata['allowed_push_host'] = 'https://rubygems.org'
14
+ else
15
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
16
+ end
17
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
18
+ s.require_paths = ["lib"]
19
+ s.authors = ["Corey Osman"]
20
+ s.date = "2016-07-03"
21
+ s.description = "A interactive command line tool for evaluating the puppet language"
22
+ s.email = "corey@nwops.io"
23
+ s.extra_rdoc_files = [
24
+ "CHANGELOG.md",
25
+ "LICENSE.txt",
26
+ "README.md"
27
+ ]
28
+ s.homepage = "http://github.com/nwops/puppet-debugger"
29
+ s.licenses = ["MIT"]
30
+ s.rubygems_version = "2.4.5.1"
31
+ s.summary = "A repl for the puppet language"
32
+ s.add_runtime_dependency(%q<puppet>, [">= 3.8"])
33
+ s.add_runtime_dependency(%q<facterdb>, ["~> 0.3"])
34
+ s.add_runtime_dependency(%q<awesome_print>, ["~> 1.6"])
35
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
36
+ end
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+ export PATH=$PATH:/usr/local/bundle
3
+ gem install bundler > /dev/null
4
+ gem update --system > /dev/null
5
+ bundle install --no-color --without development
6
+ bundle exec puppet module install puppetlabs-stdlib
7
+ echo "Running tests, output to ${OUT_DIR}/results.txt"
8
+ bundle exec rspec --out "${OUT_DIR}/results.txt" --format documentation
9
+ # due to concurrency issues we can't build this in parallel
10
+ #gem build puppet-debugger.gemspec
11
+
12
+ # docker run -e RUBY_VERSION='ruby:1.9.3' -e PUPPET_GEM_VERSION='~> 3.8' --rm -ti -v ${PWD}:/module --workdir /module ruby:1.9.3 /bin/bash run_container_test.sh
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'facts' do
4
+ let(:debugger) do
5
+ PuppetDebugger::Cli.new(:out_buffer => output)
6
+ end
7
+
8
+ let(:puppet_version) do
9
+ '4.5.3'
10
+ end
11
+
12
+ let(:facter_version) do
13
+ debugger.default_facter_version
14
+ end
15
+
16
+ before(:each) do
17
+ allow(Puppet).to receive(:version).and_return(puppet_version)
18
+ end
19
+
20
+ describe '2.4' do
21
+ before(:each) do
22
+ ENV['REPL_FACTERDB_FILTER'] = nil
23
+ end
24
+ let(:puppet_version) do
25
+ '4.2.0'
26
+ end
27
+ it 'returns 2.4' do
28
+ expect(facter_version).to eq('/^2\.4/')
29
+ end
30
+ it 'return default filter' do
31
+ expect(debugger.dynamic_facterdb_filter).to eq("operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^2\\.4/")
32
+ end
33
+ it 'get node_facts' do
34
+ expect(debugger.node_facts).to be_instance_of(Hash)
35
+ end
36
+ it 'has fqdn' do
37
+ expect(debugger.node_facts[:fqdn]).to eq('foo.example.com')
38
+ end
39
+ end
40
+
41
+ describe '3.1' do
42
+ before(:each) do
43
+ ENV['REPL_FACTERDB_FILTER'] = nil
44
+ end
45
+ let(:puppet_version) do
46
+ '4.5.3'
47
+ end
48
+ it 'get node_facts' do
49
+ expect(debugger.node_facts).to be_instance_of(Hash)
50
+ end
51
+ it 'has networking fqdn' do
52
+ expect(debugger.node_facts[:networking]['fqdn']).to eq('foo.example.com')
53
+ end
54
+ it 'has fqdn' do
55
+ expect(debugger.node_facts[:fqdn]).to eq('foo.example.com')
56
+ end
57
+ it 'returns 3.1' do
58
+ expect(facter_version).to eq('/^3\.1/')
59
+ end
60
+ it 'return default filter' do
61
+ expect(debugger.dynamic_facterdb_filter).to eq("operatingsystem=Fedora and operatingsystemrelease=23 and architecture=x86_64 and facterversion=/^3\\.1/")
62
+ end
63
+ end
64
+
65
+ describe 'default facts' do
66
+ describe 'bad filter' do
67
+ before(:each) do
68
+ ENV['REPL_FACTERDB_FILTER'] = 'facterversion=/^6\.5/'
69
+ end
70
+ it 'return filter' do
71
+ expect(debugger.dynamic_facterdb_filter).to eq("facterversion=/^6\\.5/")
72
+ end
73
+ it 'throws error' do
74
+ expect{debugger.default_facts}.to raise_error(PuppetDebugger::Exception::BadFilter)
75
+ end
76
+ end
77
+ describe 'good filter' do
78
+ before(:each) do
79
+ ENV['REPL_FACTERDB_FILTER'] = 'facterversion=/^3\.1/'
80
+ end
81
+ it 'return filter' do
82
+ expect(debugger.dynamic_facterdb_filter).to eq("facterversion=/^3\\.1/")
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1 @@
1
+ fail('test_error')
@@ -0,0 +1,8 @@
1
+ --- !ruby/object:Puppet::Node
2
+ name: invalid
3
+ classes: []
4
+ parameters: []
5
+ facts:
6
+ time: 2016-05-10 16:28:21.502653 -07:00
7
+ environment_name: production
8
+ expiration: 2016-05-10 16:58:21.502660 -07:00
@@ -0,0 +1,298 @@
1
+ --- !ruby/object:Puppet::Node
2
+ name: puppetdev.localdomain
3
+ classes:
4
+ stdlib:
5
+ parameters:
6
+ kernel: Linux
7
+ ipaddress6_lo: "::1"
8
+ network6_lo: "::1"
9
+ custom_auth_conf: false
10
+ puppet_files_dir_present: false
11
+ selinux: false
12
+ clientnoop: false
13
+ is_pe: false
14
+ hardwareisa: x86_64
15
+ hardwaremodel: x86_64
16
+ architecture: x86_64
17
+ platform_tag: el-7-x86_64
18
+ rubysitedir: /opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0
19
+ productname: "VMware Virtual Platform"
20
+ blockdevice_sr0_vendor: NECVMWar
21
+ facterversion: "3.1.6"
22
+ processorcount: 1
23
+ physicalprocessorcount: 1
24
+ netmask6_eth0: "ffff:ffff:ffff:ffff::"
25
+ netmask6: "ffff:ffff:ffff:ffff::"
26
+ pe_concat_basedir: /opt/puppetlabs/puppet/cache/pe_concat
27
+ chassisassettag: "No Asset Tag"
28
+ pe_razor_server_version: "package pe-razor-server is not installed"
29
+ rubyversion: "2.1.8"
30
+ boardmanufacturer: "Intel Corporation"
31
+ timezone: UTC
32
+ bios_vendor: "Phoenix Technologies LTD"
33
+ os:
34
+ architecture: x86_64
35
+ family: RedHat
36
+ hardware: x86_64
37
+ name: CentOS
38
+ release:
39
+ full: "7.2.1511"
40
+ major: "7"
41
+ minor: "2"
42
+ selinux:
43
+ enabled: false
44
+ osfamily: RedHat
45
+ operatingsystem: CentOS
46
+ operatingsystemrelease: "7.2.1511"
47
+ operatingsystemmajrelease: "7"
48
+ augeasversion: "1.4.0"
49
+ ipaddress_lo: "127.0.0.1"
50
+ swapsize_mb: 1108.51953125
51
+ swapfree_mb: 1108.51953125
52
+ manufacturer: "VMware, Inc."
53
+ domain: localdomain
54
+ bios_version: "6.00"
55
+ network_lo: "127.0.0.0"
56
+ gid: root
57
+ id: root
58
+ aio_agent_version: "1.4.2"
59
+ aio_agent_build: "1.4.2"
60
+ ipaddress6_eth0: "fe80::42:acff:fe11:2"
61
+ ipaddress6: "fe80::42:acff:fe11:2"
62
+ netmask_lo: "255.0.0.0"
63
+ network6: "fe80::"
64
+ network6_eth0: "fe80::"
65
+ processor0: "Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz"
66
+ staging_http_get: curl
67
+ blockdevice_fd0_size: 0
68
+ uptime_days: 0
69
+ uptime_hours: 0
70
+ platform_symlink_writable: true
71
+ is_virtual: true
72
+ boardserialnumber: None
73
+ bios_release_date: "05/20/2014"
74
+ swapfree: "1.08 GiB"
75
+ swapsize: "1.08 GiB"
76
+ uptime: "0:34 hours"
77
+ mtu_eth0: 1500
78
+ identity:
79
+ gid: 0
80
+ group: root
81
+ uid: 0
82
+ user: root
83
+ puppetversion: "4.4.2"
84
+ clientversion: "4.4.2"
85
+ rubyplatform: x86_64-linux
86
+ chassistype: Other
87
+ ipaddress_eth0: "172.17.0.2"
88
+ ipaddress: "172.17.0.2"
89
+ mtu_lo: 65536
90
+ macaddress: "02:42:ac:11:00:02"
91
+ macaddress_eth0: "02:42:ac:11:00:02"
92
+ augeas:
93
+ version: "1.4.0"
94
+ netmask6_lo: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
95
+ ruby:
96
+ platform: x86_64-linux
97
+ sitedir: /opt/puppetlabs/puppet/lib/ruby/site_ruby/2.1.0
98
+ version: "2.1.8"
99
+ blockdevice_sda_model: "VMware Virtual S"
100
+ blockdevice_sda_vendor: "VMware,"
101
+ processors:
102
+ count: 1
103
+ isa: x86_64
104
+ models:
105
+ - "Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz"
106
+ physicalcount: 1
107
+ blockdevices: "fd0,sda,sr0"
108
+ boardproductname: "440BX Desktop Reference Platform"
109
+ networking:
110
+ mac: "02:42:ac:11:00:02"
111
+ ip6: "fe80::42:acff:fe11:2"
112
+ hostname: puppetdev
113
+ netmask6: "ffff:ffff:ffff:ffff::"
114
+ interfaces:
115
+ eth0:
116
+ mac: "02:42:ac:11:00:02"
117
+ ip6: "fe80::42:acff:fe11:2"
118
+ bindings:
119
+ - address: "172.17.0.2"
120
+ netmask: "255.255.0.0"
121
+ network: "172.17.0.0"
122
+ netmask6: "ffff:ffff:ffff:ffff::"
123
+ netmask: "255.255.0.0"
124
+ network: "172.17.0.0"
125
+ mtu: 1500
126
+ ip: "172.17.0.2"
127
+ bindings6:
128
+ - address: "fe80::42:acff:fe11:2"
129
+ netmask: "ffff:ffff:ffff:ffff::"
130
+ network: "fe80::"
131
+ network6: "fe80::"
132
+ lo:
133
+ ip6: "::1"
134
+ bindings:
135
+ - address: "127.0.0.1"
136
+ netmask: "255.0.0.0"
137
+ network: "127.0.0.0"
138
+ netmask6: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
139
+ netmask: "255.0.0.0"
140
+ network: "127.0.0.0"
141
+ mtu: 65536
142
+ ip: "127.0.0.1"
143
+ bindings6:
144
+ - address: "::1"
145
+ netmask: "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
146
+ network: "::1"
147
+ network6: "::1"
148
+ fqdn: puppetdev.localdomain
149
+ netmask: "255.255.0.0"
150
+ network: "172.17.0.0"
151
+ mtu: 1500
152
+ primary: eth0
153
+ ip: "172.17.0.2"
154
+ domain: localdomain
155
+ network6: "fe80::"
156
+ memoryfree: "788.06 MiB"
157
+ system_uptime:
158
+ days: 0
159
+ hours: 0
160
+ seconds: 2069
161
+ uptime: "0:34 hours"
162
+ uptime_seconds: 2069
163
+ memoryfree_mb: 788.0625
164
+ memory:
165
+ swap:
166
+ available: "1.08 GiB"
167
+ available_bytes: 1162366976
168
+ capacity: "0%"
169
+ total: "1.08 GiB"
170
+ total_bytes: 1162366976
171
+ used: "0 bytes"
172
+ used_bytes: 0
173
+ system:
174
+ available: "788.06 MiB"
175
+ available_bytes: 826343424
176
+ capacity: "20.89%"
177
+ total: "996.13 MiB"
178
+ total_bytes: 1044512768
179
+ used: "208.06 MiB"
180
+ used_bytes: 218169344
181
+ kernelrelease: "4.1.13-boot2docker"
182
+ memorysize_mb: 996.125
183
+ memorysize: "996.13 MiB"
184
+ hostname: puppetdev
185
+ virtual: docker
186
+ interfaces: "eth0,lo"
187
+ blockdevice_sr0_model: "VMware SATA CD01"
188
+ netmask: "255.255.0.0"
189
+ netmask_eth0: "255.255.0.0"
190
+ trusted:
191
+ authenticated: remote
192
+ certname: puppetdev.localdomain
193
+ domain: localdomain
194
+ extensions: {}
195
+ hostname: puppetdev
196
+ clientcert: puppetdev.localdomain
197
+ fqdn: puppetdev.localdomain
198
+ path: "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
199
+ blockdevice_sr0_size: 31457280
200
+ kernelversion: "4.1.13"
201
+ uuid: "564D25BB-6B40-EBBF-38B3-07CCD4455918"
202
+ network_eth0: "172.17.0.0"
203
+ network: "172.17.0.0"
204
+ blockdevice_sda_size: 20971520000
205
+ kernelmajversion: "4.1"
206
+ filesystems: "cramfs,ext2,ext3,ext4,iso9660,squashfs,vfat"
207
+ mountpoints:
208
+ /etc/hostname:
209
+ filesystem: ext4
210
+ device: /dev/sda1
211
+ used_bytes: 5667684352
212
+ available_bytes: 13854396416
213
+ used: "5.28 GiB"
214
+ size: "18.18 GiB"
215
+ options:
216
+ - rw
217
+ - relatime
218
+ - "data=ordered"
219
+ size_bytes: 19522080768
220
+ available: "12.90 GiB"
221
+ capacity: "29.03%"
222
+ /etc/hosts:
223
+ filesystem: ext4
224
+ device: /dev/sda1
225
+ used_bytes: 5667684352
226
+ available_bytes: 13854396416
227
+ used: "5.28 GiB"
228
+ size: "18.18 GiB"
229
+ options:
230
+ - rw
231
+ - relatime
232
+ - "data=ordered"
233
+ size_bytes: 19522080768
234
+ available: "12.90 GiB"
235
+ capacity: "29.03%"
236
+ /etc/resolv.conf:
237
+ filesystem: ext4
238
+ device: /dev/sda1
239
+ used_bytes: 5667684352
240
+ available_bytes: 13854396416
241
+ used: "5.28 GiB"
242
+ size: "18.18 GiB"
243
+ options:
244
+ - rw
245
+ - relatime
246
+ - "data=ordered"
247
+ size_bytes: 19522080768
248
+ available: "12.90 GiB"
249
+ capacity: "29.03%"
250
+ partitions:
251
+ /dev/sda1:
252
+ mount: /etc/resolv.conf
253
+ size: "18.60 GiB"
254
+ size_bytes: 19970129920
255
+ /dev/sda2:
256
+ size: "954.98 MiB"
257
+ size_bytes: 1001373696
258
+ load_averages:
259
+ "15m": 0.06
260
+ "1m": 0.06
261
+ "5m": 0.05
262
+ disks:
263
+ fd0:
264
+ size: "0 bytes"
265
+ size_bytes: 0
266
+ sda:
267
+ model: "VMware Virtual S"
268
+ size: "19.53 GiB"
269
+ size_bytes: 20971520000
270
+ vendor: "VMware,"
271
+ sr0:
272
+ model: "VMware SATA CD01"
273
+ size: "30.00 MiB"
274
+ size_bytes: 31457280
275
+ vendor: NECVMWar
276
+ dmi:
277
+ bios:
278
+ release_date: "05/20/2014"
279
+ vendor: "Phoenix Technologies LTD"
280
+ version: "6.00"
281
+ board:
282
+ manufacturer: "Intel Corporation"
283
+ product: "440BX Desktop Reference Platform"
284
+ serial_number: None
285
+ chassis:
286
+ asset_tag: "No Asset Tag"
287
+ type: Other
288
+ manufacturer: "VMware, Inc."
289
+ product:
290
+ name: "VMware Virtual Platform"
291
+ serial_number: "VMware-56 4d 25 bb 6b 40 eb bf-38 b3 07 cc d4 45 59 18"
292
+ uuid: "564D25BB-6B40-EBBF-38B3-07CCD4455918"
293
+ serialnumber: "VMware-56 4d 25 bb 6b 40 eb bf-38 b3 07 cc d4 45 59 18"
294
+ environment: production
295
+ facts:
296
+ time: 2016-05-10 13:14:57.080352 -07:00
297
+ environment_name: production
298
+ expiration: 2016-05-10 13:44:57.080364 -07:00
@@ -0,0 +1,2 @@
1
+ $var1 = 'test'
2
+ file{"/tmp/${var1}.txt": ensure => present, mode => '0755'}
@@ -0,0 +1,13 @@
1
+ class sample_test_breakpoint(
2
+
3
+ ) {
4
+
5
+ include stdlib
6
+ file{'/tmp/test':
7
+ ensure => present,
8
+ }
9
+ range(1,5).map | $num | {
10
+ start_repl()
11
+ }
12
+ }
13
+ include sample_test_breakpoint
data/spec/pdb_spec.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'pdb' do
4
+ let(:fixtures_file) do
5
+ File.join(fixtures_dir, 'sample_manifest.pp')
6
+ end
7
+
8
+ before(:each) do
9
+ allow(PuppetDebugger).to receive(:fetch_url_data).with(file_url).and_return(File.read(fixtures_file))
10
+ end
11
+
12
+ let(:file_url) do
13
+ 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'
14
+ end
15
+
16
+ it do
17
+ expect(`echo 'file{"/tmp/test":}'| bundle exec bin/pdb`)
18
+ .to match(/Puppet::Type::File/)
19
+ end
20
+
21
+ it do
22
+ expect(`bundle exec bin/pdb #{fixtures_file} --run-once`)
23
+ .to match(/Puppet::Type::File/)
24
+ end
25
+ it do
26
+ expect(`bundle exec bin/pdb --play #{fixtures_file} --run-once`)
27
+ .to match(/Puppet::Type::File/)
28
+ end
29
+ # xit do
30
+ # # this test does not work without internet, and I am at 30K feet right now
31
+ # expect(`bundle exec bin/pdb --play #{file_url} --run-once`)
32
+ # .to match(/Puppet::Type::File/)
33
+ # end
34
+
35
+ describe 'remote_node' do
36
+ let(:node_obj) do
37
+ YAML.load_file(File.join(fixtures_dir, 'node_obj.yaml'))
38
+ end
39
+ let(:node_name) do
40
+ 'puppetdev.localdomain'
41
+ end
42
+ before :each do
43
+ allow(PuppetDebugger).to receive(:get_remote_node).with(node_name).and_return(node_obj)
44
+ end
45
+ # xit do
46
+ # expect(`echo 'vars'| bundle exec bin/pdb -n #{node_name}`)
47
+ # .to match(/server_facts/)
48
+ # end
49
+ end
50
+ end