puppet-repl 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +53 -0
- data/.gitlab-ci.yml +28 -32
- data/.rspec +2 -1
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +4 -46
- data/README.md +5 -3
- data/Rakefile +4 -24
- data/lib/puppet-repl/cli.rb +5 -7
- data/lib/puppet-repl/support/input_responders.rb +1 -0
- data/lib/puppet-repl/support.rb +42 -2
- data/lib/version.rb +1 -1
- data/puppet-repl.gemspec +18 -76
- data/run_container_test.sh +12 -0
- data/spec/fixtures/invalid_node_obj.yaml +2 -2
- data/spec/fixtures/node_obj.yaml +45 -62
- data/spec/prepl_spec.rb +9 -9
- data/spec/puppet-repl_spec.rb +122 -178
- data/spec/remote_node_spec.rb +170 -0
- data/spec/spec_helper.rb +24 -16
- data/test_matrix.rb +42 -0
- metadata +9 -13
- data/VERSION +0 -1
- data/resources/classes.png +0 -0
- data/resources/classification.png +0 -0
- data/resources/command_line_node.png +0 -0
- data/resources/functions.png +0 -0
- data/resources/hiera.png +0 -0
- data/resources/set_node.png +0 -0
- data/resources/tab_complete.png +0 -0
- data/resources/variables.png +0 -0
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
describe "PuppetRepl" do
|
4
|
+
|
5
|
+
let(:resource) do
|
6
|
+
"service{'httpd': ensure => running}"
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
repl.handle_input('reset')
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:output) do
|
14
|
+
StringIO.new('', 'w')
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:repl) do
|
18
|
+
PuppetRepl::Cli.new(:out_buffer => output)
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:input) do
|
22
|
+
"file{'/tmp/test2.txt': ensure => present, mode => '0755'}"
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:resource_types) do
|
26
|
+
repl.parser.evaluate_string(repl.scope, input)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'remote node' do
|
30
|
+
let(:node_obj) do
|
31
|
+
YAML.load_file(File.join(fixtures_dir, 'node_obj.yaml'))
|
32
|
+
end
|
33
|
+
let(:node_name) do
|
34
|
+
'puppetdev.localdomain'
|
35
|
+
end
|
36
|
+
before :each do
|
37
|
+
allow(repl).to receive(:get_remote_node).with(node_name).and_return(node_obj)
|
38
|
+
repl.handle_input(":set node #{node_name}")
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'set' do
|
42
|
+
it 'sends message about resetting' do
|
43
|
+
expect(output.string).to eq("\n => Resetting to use node puppetdev.localdomain\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "return node name" do
|
47
|
+
output.reopen # removes previous message
|
48
|
+
repl.handle_input('$::hostname')
|
49
|
+
expect(output.string).to match(/puppetdev.localdomain/)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "return classification" do
|
53
|
+
output.reopen # removes previous message
|
54
|
+
repl.handle_input('classification')
|
55
|
+
expect(output.string).to match(/stdlib/)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'facts' do
|
60
|
+
let(:input) do
|
61
|
+
"$::facts['os']['family'].downcase == 'debian'"
|
62
|
+
end
|
63
|
+
it 'fact evaulation should return false' do
|
64
|
+
repl_output = /false/
|
65
|
+
repl.handle_input(input)
|
66
|
+
expect(output.string).to match(repl_output)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
describe 'use defaults when invalid' do
|
71
|
+
let(:node_obj) do
|
72
|
+
YAML.load_file(File.join(fixtures_dir, 'invalid_node_obj.yaml'))
|
73
|
+
end
|
74
|
+
let(:node_name) do
|
75
|
+
'invalid.localdomain'
|
76
|
+
end
|
77
|
+
it 'name' do
|
78
|
+
expect{repl.node.name}.to raise_error(PuppetRepl::Exception::UndefinedNode)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'set node name' do
|
83
|
+
expect(repl.remote_node_name = 'puppetdev.localdomain').to eq("puppetdev.localdomain")
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'print classes' do
|
87
|
+
let(:input) do
|
88
|
+
'resources'
|
89
|
+
end
|
90
|
+
it 'should be able to print classes' do
|
91
|
+
repl_output = /Settings/
|
92
|
+
repl.handle_input(input)
|
93
|
+
expect(output.string).to match(repl_output)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe 'vars' do
|
98
|
+
let(:input) do
|
99
|
+
"vars"
|
100
|
+
end
|
101
|
+
it 'display facts variable' do
|
102
|
+
repl_output = /facts/
|
103
|
+
repl.handle_input(input)
|
104
|
+
expect(output.string).to match(repl_output)
|
105
|
+
end
|
106
|
+
it 'display server facts variable' do
|
107
|
+
repl_output = /server_facts/
|
108
|
+
repl.handle_input(input)
|
109
|
+
expect(output.string).to match(repl_output) if Puppet.version.to_f >= 4.1
|
110
|
+
end
|
111
|
+
it 'display server facts variable' do
|
112
|
+
repl_output = /server_facts/
|
113
|
+
repl.handle_input(input)
|
114
|
+
expect(output.string).to match(repl_output) if Puppet.version.to_f >= 4.1
|
115
|
+
end
|
116
|
+
it 'display local variable' do
|
117
|
+
repl.handle_input("$var1 = 'value1'")
|
118
|
+
expect(output.string).to match(/value1/)
|
119
|
+
repl.handle_input("$var1")
|
120
|
+
expect(output.string).to match(/value1/)
|
121
|
+
end
|
122
|
+
it 'display productname variable' do
|
123
|
+
repl.handle_input("$productname")
|
124
|
+
expect(output.string).to match(/VMware Virtual Platform/)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe 'execute functions' do
|
129
|
+
let(:input) do
|
130
|
+
"md5('hello')"
|
131
|
+
end
|
132
|
+
it 'execute md5' do
|
133
|
+
repl_output = /5d41402abc4b2a76b9719d911017c592/
|
134
|
+
repl.handle_input(input)
|
135
|
+
expect(output.string).to match(repl_output)
|
136
|
+
end
|
137
|
+
it 'execute swapcase' do
|
138
|
+
repl_output = /HELLO/
|
139
|
+
repl.handle_input("swapcase('hello')")
|
140
|
+
expect(output.string).to match(repl_output)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'reset' do
|
145
|
+
let(:input) do
|
146
|
+
"file{'/tmp/reset': ensure => present}"
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'can process a file' do
|
150
|
+
repl_output = /Puppet::Type::File/
|
151
|
+
repl.handle_input(input)
|
152
|
+
expect(output.string).to match(repl_output)
|
153
|
+
repl.handle_input('reset')
|
154
|
+
repl.handle_input(input)
|
155
|
+
expect(output.string).to match(repl_output)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe 'classification' do
|
160
|
+
let(:input) do
|
161
|
+
"classification"
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'shows certificate_authority_host' do
|
165
|
+
repl.handle_input(input)
|
166
|
+
expect(output.string).to match(/stdlib/)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,22 +1,25 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require_relative '../lib/puppet-repl'
|
3
3
|
require 'yaml'
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
4
|
+
ENV['COVERAGE'] = "true"
|
5
|
+
|
6
|
+
module SimpleCov::Configuration
|
7
|
+
def clean_filters
|
8
|
+
@filters = []
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
SimpleCov.configure do
|
13
|
+
clean_filters
|
14
|
+
load_profile 'test_frameworks'
|
15
|
+
end
|
16
|
+
|
17
|
+
SimpleCov.start do
|
18
|
+
add_filter "/.rvm/"
|
19
|
+
add_filter "vendor"
|
20
|
+
add_filter "bundler"
|
21
|
+
end
|
22
|
+
|
20
23
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
21
24
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
22
25
|
|
@@ -45,5 +48,10 @@ def environments_dir
|
|
45
48
|
File.join(fixtures_dir, 'environments')
|
46
49
|
end
|
47
50
|
|
51
|
+
def supports_native_functions?
|
52
|
+
Gem::Version.new(Puppet.version) >= Gem::Version.new('4.3')
|
53
|
+
end
|
54
|
+
|
48
55
|
RSpec.configure do |config|
|
56
|
+
config.filter_run_excluding :native_functions => ! supports_native_functions?
|
49
57
|
end
|
data/test_matrix.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
@threads = {}
|
4
|
+
|
5
|
+
def run_container(image, puppet_version)
|
6
|
+
pversion = puppet_version.match(/([\d\.]+)/)[0]
|
7
|
+
ruby_version = image.split(':').last
|
8
|
+
dir = File.join('.','local_test_results', pversion, ruby_version)
|
9
|
+
real_dir = File.expand_path(dir)
|
10
|
+
FileUtils.rm_rf(real_dir)
|
11
|
+
FileUtils.mkdir_p(real_dir)
|
12
|
+
cmd = "docker run -e OUT_DIR='#{dir}' -e RUBY_VERSION='#{ruby_version}' -e PUPPET_GEM_VERSION='#{puppet_version}' --rm -ti -v ${PWD}:/module --workdir /module #{image} /bin/bash run_container_test.sh"
|
13
|
+
File.write(File.join(real_dir, 'command.txt'), cmd)
|
14
|
+
output = `#{cmd}`
|
15
|
+
if $?.success?
|
16
|
+
File.write(File.join(dir, 'success.txt'), output)
|
17
|
+
else
|
18
|
+
File.write(File.join(dir, 'error.txt'), output)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def ci_data
|
23
|
+
@ci_data ||= YAML.load_file(File.expand_path('.gitlab-ci.yml'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def matrix
|
27
|
+
unless @matrix
|
28
|
+
@matrix = {}
|
29
|
+
ci_data.each do |id, data|
|
30
|
+
@matrix[id] = data if id =~ /^puppet/
|
31
|
+
end
|
32
|
+
end
|
33
|
+
@matrix
|
34
|
+
end
|
35
|
+
|
36
|
+
matrix.each do |id, item|
|
37
|
+
@threads[id] = Thread.new do
|
38
|
+
run_container(item['image'], item['variables']['PUPPET_GEM_VERSION'])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@threads.each {|id, thr| thr.join } # wait on thread to finish
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2016-
|
11
|
+
date: 2016-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -77,6 +77,7 @@ extra_rdoc_files:
|
|
77
77
|
- README.md
|
78
78
|
files:
|
79
79
|
- ".document"
|
80
|
+
- ".gitignore"
|
80
81
|
- ".gitlab-ci.yml"
|
81
82
|
- ".rspec"
|
82
83
|
- CHANGELOG.md
|
@@ -85,7 +86,6 @@ files:
|
|
85
86
|
- LICENSE.txt
|
86
87
|
- README.md
|
87
88
|
- Rakefile
|
88
|
-
- VERSION
|
89
89
|
- bin/prepl
|
90
90
|
- lib/awesome_print/ext/awesome_puppet.rb
|
91
91
|
- lib/puppet-repl.rb
|
@@ -103,26 +103,22 @@ files:
|
|
103
103
|
- lib/trollop.rb
|
104
104
|
- lib/version.rb
|
105
105
|
- puppet-repl.gemspec
|
106
|
-
-
|
107
|
-
- resources/classification.png
|
108
|
-
- resources/command_line_node.png
|
109
|
-
- resources/functions.png
|
110
|
-
- resources/hiera.png
|
111
|
-
- resources/set_node.png
|
112
|
-
- resources/tab_complete.png
|
113
|
-
- resources/variables.png
|
106
|
+
- run_container_test.sh
|
114
107
|
- spec/fixtures/environments/production/manifests/site.pp
|
115
108
|
- spec/fixtures/invalid_node_obj.yaml
|
116
109
|
- spec/fixtures/node_obj.yaml
|
117
110
|
- spec/fixtures/sample_manifest.pp
|
118
111
|
- spec/prepl_spec.rb
|
119
112
|
- spec/puppet-repl_spec.rb
|
113
|
+
- spec/remote_node_spec.rb
|
120
114
|
- spec/spec_helper.rb
|
121
115
|
- spec/support_spec.rb
|
116
|
+
- test_matrix.rb
|
122
117
|
homepage: http://github.com/nwops/puppet-repl
|
123
118
|
licenses:
|
124
119
|
- MIT
|
125
|
-
metadata:
|
120
|
+
metadata:
|
121
|
+
allowed_push_host: "'http://mygemserver.com'"
|
126
122
|
post_install_message:
|
127
123
|
rdoc_options: []
|
128
124
|
require_paths:
|
@@ -139,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
135
|
version: '0'
|
140
136
|
requirements: []
|
141
137
|
rubyforge_project:
|
142
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.6.6
|
143
139
|
signing_key:
|
144
140
|
specification_version: 4
|
145
141
|
summary: A repl for the puppet language
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.3
|
data/resources/classes.png
DELETED
Binary file
|
Binary file
|
Binary file
|
data/resources/functions.png
DELETED
Binary file
|
data/resources/hiera.png
DELETED
Binary file
|
data/resources/set_node.png
DELETED
Binary file
|
data/resources/tab_complete.png
DELETED
Binary file
|
data/resources/variables.png
DELETED
Binary file
|