puppetdb_rundeck 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/CHANGELOG +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/puppetdb_rundeck +45 -0
- data/lib/app.rb +41 -0
- data/lib/helpers/process.rb +69 -0
- data/lib/helpers/puppetdb.rb +46 -0
- data/lib/model/endpoint.rb +5 -0
- data/lib/model/xml.rb +37 -0
- data/lib/model/yaml.rb +31 -0
- data/lib/views/api.haml +15 -0
- data/puppetdb_rundeck.gemspec +31 -0
- data/spec/app_spec.rb +29 -0
- data/spec/helpers/puppetdb_spec.rb +53 -0
- data/spec/model/xml_spec.rb +18 -0
- data/spec/model/yaml_spec.rb +18 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/support/fake_puppetdb.rb +12 -0
- metadata +92 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3b9ec50bf9c3da53dbd20eafcc0b237626377b6
|
4
|
+
data.tar.gz: 75eb0f1ffa84b54c49efd46c1e1be2755f992aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fbe3e54a78d1c595ab7beb74e330709bd0341173b4ff17b3d98c5e7041e2cb847856d6295be0cff0fda80dc9882b3ea6569df2b6ed9fce7784f4c1b6378c4f6
|
7
|
+
data.tar.gz: 7ecee81c7c6bf23e80ffa87d7a79fcd495fc0c2225bf9d251a6d4b1ae5bfeeaee48bc4f786a0de30fa0f2d90fda03cb9cf137b5b5017fb62a40400dbe7e5093f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 OpenTable, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# PuppetDBRundeck
|
2
|
+
|
3
|
+
puppetdb_rundeck is a sinatra based application to provide integration between [PuppetDB](https://docs.puppetlabs.com/puppetdb/latest/) and [Rundeck](http://rundeck.org/).
|
4
|
+
It provides an api in either xml or yaml that allows the node and fact data with puppetdb to use used as a resource
|
5
|
+
with rundeck.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install it yourself as:
|
10
|
+
|
11
|
+
$ gem install puppetdb_rundeck
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Start the application:
|
16
|
+
|
17
|
+
$ puppetdb_rundeck --pdbhost <puppetdb hostname> --pdbport <puppetdb port> --port <application port>
|
18
|
+
|
19
|
+
Then go to the following endpoint in your browser:
|
20
|
+
|
21
|
+
http://localhost:<port>/api
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/opentable/puppetdb_rundeck/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
4
|
+
|
5
|
+
require 'app'
|
6
|
+
require 'optparse'
|
7
|
+
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: puppetdb_rundeck [options]"
|
12
|
+
|
13
|
+
opts.on("--port PORT", String, "The port on which to run the appllication") do |p|
|
14
|
+
options[:port] = p
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("--pdbhost HOSTNAME", String, "The hostname of the PuppetDB instance") do |ph|
|
18
|
+
options[:pdbhost] = ph
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("--pdbport PORT", String, "The port of the PuppetDB instance") do |pp|
|
22
|
+
options[:pdbport] = pp
|
23
|
+
end
|
24
|
+
end.parse!
|
25
|
+
|
26
|
+
if options[:pdbhost].nil? or options[:pdbhost].eql?('')
|
27
|
+
puts 'The --pdbhost option must be specified'
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
if options[:pdbport].nil? or options[:pdbport].eql?('')
|
32
|
+
puts 'The --pdbport option must be specified'
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
PuppetDBRunDeck.set :puppetdb_host, options[:pdbhost]
|
37
|
+
PuppetDBRunDeck.set :puppetdb_port, options[:pdbport]
|
38
|
+
|
39
|
+
if options[:port].nil? or options[:port].eql?('')
|
40
|
+
PuppetDBRunDeck.set :port, '4567'
|
41
|
+
else
|
42
|
+
PuppetDBRunDeck.set :port, options[:port]
|
43
|
+
end
|
44
|
+
|
45
|
+
PuppetDBRunDeck.run!
|
data/lib/app.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yaml'
|
3
|
+
require 'sinatra'
|
4
|
+
require 'haml'
|
5
|
+
|
6
|
+
require_relative 'helpers/puppetdb'
|
7
|
+
require_relative 'helpers/process'
|
8
|
+
|
9
|
+
require_relative 'model/endpoint'
|
10
|
+
require_relative 'model/xml'
|
11
|
+
require_relative 'model/yaml'
|
12
|
+
|
13
|
+
class PuppetDBRunDeck < Sinatra::Base
|
14
|
+
get '/' do
|
15
|
+
redirect to('/api')
|
16
|
+
end
|
17
|
+
|
18
|
+
get '/api' do
|
19
|
+
haml :api
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/api/yaml' do
|
23
|
+
content_type 'text/yaml'
|
24
|
+
puppetdb_helper = Helpers::PuppetDB.new(settings.puppetdb_host, settings.puppetdb_port)
|
25
|
+
output = YAMLOutput.new(puppetdb_helper)
|
26
|
+
Helpers::Process.new().endpoint_processor(output)
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/api/xml' do
|
30
|
+
content_type 'application/xml'
|
31
|
+
puppetdb_helper = Helpers::PuppetDB.new(settings.puppetdb_host, settings.puppetdb_port)
|
32
|
+
output = XMLOutput.new(puppetdb_helper)
|
33
|
+
Helpers::Process.new().endpoint_processor(output)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# This allows app.rb to be run in isolation without the need for the executable
|
38
|
+
if (!defined? settings.puppetdb_host) and (!defined? settings.puppetdb_port)
|
39
|
+
PuppetDBRunDeck.set :puppetdb_host, 'localhost'
|
40
|
+
PuppetDBRunDeck.set :puppetdb_port, '8080'
|
41
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
class Helpers::Process
|
3
|
+
|
4
|
+
def add_facts(facts, host, collection)
|
5
|
+
facts.each{|f|
|
6
|
+
if f['certname'].eql?(host)
|
7
|
+
fact_name = f['name']
|
8
|
+
fact_value = f['value']
|
9
|
+
|
10
|
+
if fact_name.include?('processor')
|
11
|
+
fact_name = number_to_name(fact_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
if fact_name.include?('path')
|
15
|
+
fact_value = fact_value.gsub!('"','')
|
16
|
+
end
|
17
|
+
|
18
|
+
if collection.instance_of?(Hash)
|
19
|
+
collection[host][fact_name] = fact_value
|
20
|
+
elsif collection.instance_of?(Array)
|
21
|
+
collection << "#{fact_name}=\"#{fact_value}\" "
|
22
|
+
else
|
23
|
+
end
|
24
|
+
end
|
25
|
+
}
|
26
|
+
return collection
|
27
|
+
end
|
28
|
+
|
29
|
+
def endpoint_processor(output)
|
30
|
+
file_name = output.tmp_file
|
31
|
+
content = ''
|
32
|
+
if File.exist?(file_name)
|
33
|
+
file = File.new(file_name)
|
34
|
+
t_now = Time.at(Time.now.to_i)
|
35
|
+
t_file = Time.at(file.mtime.to_i)
|
36
|
+
|
37
|
+
if t_now < (t_file + 300)
|
38
|
+
content = File.new(file_name, 'r').read
|
39
|
+
else
|
40
|
+
p "#{t_now} #{t_file}"
|
41
|
+
endpoint = EndPoint.new()
|
42
|
+
content = endpoint.parse(output)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
endpoint = EndPoint.new()
|
46
|
+
content = endpoint.parse(output)
|
47
|
+
end
|
48
|
+
|
49
|
+
return content
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def number_to_name(name)
|
54
|
+
lookup = {
|
55
|
+
'1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five',
|
56
|
+
'6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten',
|
57
|
+
'11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen',
|
58
|
+
'15' => 'fifteen', '16' => 'sixteen'
|
59
|
+
}
|
60
|
+
|
61
|
+
lookup.each { |k,v|
|
62
|
+
if name.include?(k)
|
63
|
+
name.gsub!(k,"_#{v}")
|
64
|
+
end
|
65
|
+
}
|
66
|
+
return name
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Helpers
|
6
|
+
class PuppetDB
|
7
|
+
|
8
|
+
def initialize(host, port)
|
9
|
+
@puppetdb_host = host
|
10
|
+
@puppetdb_port = port
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_nodes
|
14
|
+
uri = URI.parse( "http://#{@puppetdb_host}:#{@puppetdb_port}/v3/nodes" )
|
15
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
request = Net::HTTP::Get.new(uri.path)
|
17
|
+
request.add_field('Accept', 'application/json')
|
18
|
+
response = http.request(request)
|
19
|
+
response['Content-Type'] = 'application/yaml'
|
20
|
+
if response.code == '200'
|
21
|
+
nodes = JSON.parse(response.body)
|
22
|
+
else
|
23
|
+
nodes = []
|
24
|
+
end
|
25
|
+
|
26
|
+
return nodes
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_facts
|
30
|
+
uri = URI.parse( "http://#{@puppetdb_host}:#{@puppetdb_port}/v3/facts" )
|
31
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
request = Net::HTTP::Get.new(uri.path)
|
33
|
+
request.add_field('Accept', 'application/json')
|
34
|
+
response = http.request(request)
|
35
|
+
response['Content-Type'] = 'application/yaml'
|
36
|
+
if response.code == '200'
|
37
|
+
facts = JSON.parse(response.body)
|
38
|
+
else
|
39
|
+
facts = []
|
40
|
+
end
|
41
|
+
|
42
|
+
return facts
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/lib/model/xml.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative '../helpers/process'
|
2
|
+
|
3
|
+
class XMLOutput
|
4
|
+
attr_accessor :tmp_file
|
5
|
+
attr_accessor :db_helper
|
6
|
+
|
7
|
+
def initialize(puppetdb_helper)
|
8
|
+
@tmp_file = '/tmp/puppetdb-resource.xml'
|
9
|
+
@db_helper = puppetdb_helper
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
nodes = @db_helper.get_nodes
|
14
|
+
facts = @db_helper.get_facts
|
15
|
+
helper = Helpers::Process.new
|
16
|
+
|
17
|
+
rundeck_data = Array.new
|
18
|
+
rundeck_data << "<project>\n"
|
19
|
+
|
20
|
+
nodes.each{|n|
|
21
|
+
host = n['name']
|
22
|
+
|
23
|
+
rundeck_data << "<node name=\"#{host}\""
|
24
|
+
|
25
|
+
rundeck_data = helper.add_facts(facts, host, rundeck_data)
|
26
|
+
|
27
|
+
rundeck_data << "/>\n"
|
28
|
+
}
|
29
|
+
|
30
|
+
rundeck_data << "</project>"
|
31
|
+
xml = rundeck_data.join(" ")
|
32
|
+
|
33
|
+
File.open(@tmp_file, 'w') { |file| file.write(xml) }
|
34
|
+
|
35
|
+
return xml
|
36
|
+
end
|
37
|
+
end
|
data/lib/model/yaml.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../helpers/process'
|
2
|
+
|
3
|
+
class YAMLOutput
|
4
|
+
attr_accessor :tmp_file
|
5
|
+
|
6
|
+
def initialize(puppetdb_helper)
|
7
|
+
@tmp_file = '/tmp/puppetdb-resource.yaml'
|
8
|
+
@db_helper = puppetdb_helper
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse
|
12
|
+
nodes = @db_helper.get_nodes
|
13
|
+
facts = @db_helper.get_facts
|
14
|
+
helper = Helpers::Process.new
|
15
|
+
|
16
|
+
rundeck_data = Hash.new
|
17
|
+
nodes.each{|d|
|
18
|
+
host = d['name']
|
19
|
+
|
20
|
+
rundeck_data[host] = Hash.new if not rundeck_data.key?(host)
|
21
|
+
|
22
|
+
rundeck_data = helper.add_facts(facts, host, rundeck_data)
|
23
|
+
}
|
24
|
+
|
25
|
+
yaml = rundeck_data.to_yaml
|
26
|
+
|
27
|
+
File.open(@tmp_file, 'w') { |file| file.write(yaml) }
|
28
|
+
|
29
|
+
return yaml
|
30
|
+
end
|
31
|
+
end
|
data/lib/views/api.haml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title PuppetDB-Rundeck
|
5
|
+
%body
|
6
|
+
%h1 PuppetDB-Rundeck
|
7
|
+
%p
|
8
|
+
The puppetdb-rundeck application allows Rundeck to make use of the node and fact information stored in PuppetDB.
|
9
|
+
%p
|
10
|
+
Two API endpoints are provided which you can point Rundeck to:
|
11
|
+
%ul
|
12
|
+
%li
|
13
|
+
%a(href="/api/xml") XML
|
14
|
+
%li
|
15
|
+
%a(href="/api/yaml") YAML
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'puppetdb_rundeck'
|
6
|
+
spec.version = '0.2.0'
|
7
|
+
spec.authors = ['liamjbennett']
|
8
|
+
spec.email = ['lbennett@opentable.com']
|
9
|
+
spec.summary = %q{A sinatra based application to provide integration between PuppetDB and Rundeck}
|
10
|
+
spec.description = %q{puppetdb_rundeck is a sinatra based application to provide integration between PuppetDB and Rundeck.
|
11
|
+
It provides an api in either xml or yaml that allows the node and fact data with puppetdb to use used as a resource
|
12
|
+
with rundeck}
|
13
|
+
spec.homepage = 'https://github.com/opentable/puppetdb_rundeck'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split("\n")
|
17
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.2'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'rack-test'
|
25
|
+
spec.add_development_dependency 'webmock'
|
26
|
+
spec.add_development_dependency 'rspec-mocks'
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'json_pure', '~> 1.8'
|
29
|
+
spec.add_runtime_dependency 'sinatra', '~> 1.4'
|
30
|
+
spec.add_runtime_dependency 'haml', '~> 4.0'
|
31
|
+
end
|
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path '../spec_helper.rb', __FILE__
|
2
|
+
require File.expand_path '../../lib/app.rb', __FILE__
|
3
|
+
|
4
|
+
describe 'puppetdb_rundeck Application' do
|
5
|
+
it 'homepage should redirect to api page' do
|
6
|
+
get '/'
|
7
|
+
last_response.should be_redirect
|
8
|
+
follow_redirect!
|
9
|
+
last_request.url.should == 'http://example.org/api'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should allow access to the main api page' do
|
13
|
+
get '/api'
|
14
|
+
last_response.should be_ok
|
15
|
+
last_response.body.should include('Two API endpoints are provided')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should allow access to the xml endpoint' do
|
19
|
+
stub_request(:any, /puppetdb/).to_rack(FakePuppetDB)
|
20
|
+
get '/api/xml'
|
21
|
+
last_response.should be_ok
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should allow access to the yaml endpoint' do
|
25
|
+
stub_request(:any, /puppetdb/).to_rack(FakePuppetDB)
|
26
|
+
get '/api/yaml'
|
27
|
+
last_response.should be_ok
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path '../../spec_helper.rb', __FILE__
|
2
|
+
require File.expand_path '../../../lib/helpers/puppetdb.rb', __FILE__
|
3
|
+
|
4
|
+
describe Helpers::PuppetDB, '#get_nodes' do
|
5
|
+
|
6
|
+
it 'should return json when puppetdb details are valid' do
|
7
|
+
|
8
|
+
stub_request(:get, 'http://localhost:8080/v3/nodes').
|
9
|
+
with(:headers => {'Accept'=>['*/*', 'application/json'], 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
10
|
+
to_return(:status => 200, :body => '{ "name" : "test.internal" }', :headers => {})
|
11
|
+
|
12
|
+
puppetdb = Helpers::PuppetDB.new('localhost', '8080')
|
13
|
+
nodes = puppetdb.get_nodes
|
14
|
+
nodes.should_not be_empty
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return an empty collection when the details are invalid' do
|
18
|
+
|
19
|
+
stub_request(:get, 'http://fubar:8080/v3/nodes').
|
20
|
+
with(:headers => {'Accept'=>['*/*', 'application/json'], 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
21
|
+
to_return(:status => 404, :body => '', :headers => {})
|
22
|
+
|
23
|
+
puppetdb = Helpers::PuppetDB.new('fubar', '8080')
|
24
|
+
nodes = puppetdb.get_nodes
|
25
|
+
nodes.should be_empty
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Helpers::PuppetDB, '#get_facts' do
|
31
|
+
|
32
|
+
it 'should return json when puppetdb details are valid' do
|
33
|
+
|
34
|
+
stub_request(:get, 'http://localhost:8080/v3/facts').
|
35
|
+
with(:headers => {'Accept'=>['*/*', 'application/json'], 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
36
|
+
to_return(:status => 200, :body => '{ "name" : "osfamily" }', :headers => {})
|
37
|
+
|
38
|
+
puppetdb = Helpers::PuppetDB.new('localhost', '8080')
|
39
|
+
nodes = puppetdb.get_facts
|
40
|
+
nodes.should_not be_empty
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should return an empty collection when the details are invalid' do
|
44
|
+
|
45
|
+
stub_request(:get, 'http://fubar:8080/v3/facts').
|
46
|
+
with(:headers => {'Accept'=>['*/*', 'application/json'], 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
47
|
+
to_return(:status => 404, :body => '', :headers => {})
|
48
|
+
|
49
|
+
puppetdb = Helpers::PuppetDB.new('fubar', '8080')
|
50
|
+
nodes = puppetdb.get_facts
|
51
|
+
nodes.should be_empty
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path '../../spec_helper.rb', __FILE__
|
2
|
+
require File.expand_path '../../../lib/helpers/puppetdb', __FILE__
|
3
|
+
require File.expand_path '../../../lib/model/xml', __FILE__
|
4
|
+
|
5
|
+
describe XMLOutput, '#parse' do
|
6
|
+
|
7
|
+
it 'should return valid xml containing the node name' do
|
8
|
+
helper = Helpers::PuppetDB.new('fubar', '80')
|
9
|
+
allow(helper).to receive(:get_nodes).and_return([{'name' => 'test.internal'}])
|
10
|
+
allow(helper).to receive(:get_facts).and_return([{'certname' => 'test.internal', 'name' => 'osfamily', 'value' => 'Debian'}])
|
11
|
+
|
12
|
+
xml_output = XMLOutput.new(helper)
|
13
|
+
|
14
|
+
expectation = "<project>\n <node name=\"test.internal\" osfamily=\"Debian\" />\n </project>"
|
15
|
+
|
16
|
+
xml_output.parse.should == expectation
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path '../../spec_helper.rb', __FILE__
|
2
|
+
require File.expand_path '../../../lib/helpers/puppetdb', __FILE__
|
3
|
+
require File.expand_path '../../../lib/model/yaml', __FILE__
|
4
|
+
|
5
|
+
describe YAMLOutput, '#parse' do
|
6
|
+
|
7
|
+
it 'should return valid yaml containing the node name' do
|
8
|
+
helper = Helpers::PuppetDB.new('fubar', '80')
|
9
|
+
allow(helper).to receive(:get_nodes).and_return([{'name' => 'test.internal'}])
|
10
|
+
allow(helper).to receive(:get_facts).and_return([{'certname' => 'test.internal', 'name' => 'osfamily', 'value' => 'Debian'}])
|
11
|
+
|
12
|
+
yaml_output = YAMLOutput.new(helper)
|
13
|
+
|
14
|
+
expectation = "---\ntest.internal:\n osfamily: Debian\n"
|
15
|
+
|
16
|
+
yaml_output.parse.should == expectation
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'rspec/mocks'
|
5
|
+
|
6
|
+
require_relative '../spec/support/fake_puppetdb'
|
7
|
+
|
8
|
+
WebMock.disable_net_connect!(:allow_localhost => true)
|
9
|
+
|
10
|
+
# setup test environment
|
11
|
+
set :environment, :test
|
12
|
+
set :run, false
|
13
|
+
set :raise_errors, true
|
14
|
+
set :logging, false
|
15
|
+
|
16
|
+
def app
|
17
|
+
PuppetDBRunDeck.set :puppetdb_host, 'puppetdb'
|
18
|
+
PuppetDBRunDeck.set :puppetdb_port, '8080'
|
19
|
+
PuppetDBRunDeck
|
20
|
+
end
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
config.include Rack::Test::Methods
|
24
|
+
config.mock_with :rspec
|
25
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppetdb_rundeck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liamjbennett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,7 +39,63 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-mocks
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: json_pure
|
43
99
|
requirement: !ruby/object:Gem::Requirement
|
44
100
|
requirements:
|
45
101
|
- - ~>
|
@@ -86,10 +142,33 @@ description: |-
|
|
86
142
|
with rundeck
|
87
143
|
email:
|
88
144
|
- lbennett@opentable.com
|
89
|
-
executables:
|
145
|
+
executables:
|
146
|
+
- puppetdb_rundeck
|
90
147
|
extensions: []
|
91
148
|
extra_rdoc_files: []
|
92
|
-
files:
|
149
|
+
files:
|
150
|
+
- .gitignore
|
151
|
+
- .rspec
|
152
|
+
- CHANGELOG
|
153
|
+
- Gemfile
|
154
|
+
- LICENSE.txt
|
155
|
+
- README.md
|
156
|
+
- Rakefile
|
157
|
+
- bin/puppetdb_rundeck
|
158
|
+
- lib/app.rb
|
159
|
+
- lib/helpers/process.rb
|
160
|
+
- lib/helpers/puppetdb.rb
|
161
|
+
- lib/model/endpoint.rb
|
162
|
+
- lib/model/xml.rb
|
163
|
+
- lib/model/yaml.rb
|
164
|
+
- lib/views/api.haml
|
165
|
+
- puppetdb_rundeck.gemspec
|
166
|
+
- spec/app_spec.rb
|
167
|
+
- spec/helpers/puppetdb_spec.rb
|
168
|
+
- spec/model/xml_spec.rb
|
169
|
+
- spec/model/yaml_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
- spec/support/fake_puppetdb.rb
|
93
172
|
homepage: https://github.com/opentable/puppetdb_rundeck
|
94
173
|
licenses:
|
95
174
|
- MIT
|
@@ -110,8 +189,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
189
|
version: '0'
|
111
190
|
requirements: []
|
112
191
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
192
|
+
rubygems_version: 2.2.2
|
114
193
|
signing_key:
|
115
194
|
specification_version: 4
|
116
195
|
summary: A sinatra based application to provide integration between PuppetDB and Rundeck
|
117
|
-
test_files:
|
196
|
+
test_files:
|
197
|
+
- spec/app_spec.rb
|
198
|
+
- spec/helpers/puppetdb_spec.rb
|
199
|
+
- spec/model/xml_spec.rb
|
200
|
+
- spec/model/yaml_spec.rb
|
201
|
+
- spec/spec_helper.rb
|
202
|
+
- spec/support/fake_puppetdb.rb
|