ruby-puppetdb 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ed96d47f9a2eae2e54dccea8d9961cd185d0631
4
- data.tar.gz: dc1ba65a4259f59d583dda883957b3bc5127df4a
3
+ metadata.gz: 9f199ac32e1da71ed00c19f6b157660787d08a86
4
+ data.tar.gz: 53c9970cb340bc587b2b3cdec6aaeda8133c5e40
5
5
  SHA512:
6
- metadata.gz: 15f7ae9d9c39d487f772ea24d46229dfced946265d9fd52e5b7603a319eeb420c335d57ce618ab45344b47cfa10728645ddacf9a79d3b02ab6f6cb39ec961e94
7
- data.tar.gz: 79e0500fd751c24e7ca74d5df6342d4eb76b8b2f1721672472d2d99832d6d4a87a654c49cd3c3a375aa327919f535bd3099d926b925171ccf5559d8159b95f85
6
+ metadata.gz: 385d225ca591427dde487a9d9a3232cc016b936c7c9014394361bee489109c6b963a5ab141e3dd3f76b5c0819ad04b3dea8edaae093b93236fd9c584f459d8f1
7
+ data.tar.gz: afbb1e20ae8091011201d092aadfb6a7696b680cac65a7d3cc49800b986d37d88398655c382ae7266b63f3b5b0e81507eebe292afca72dad29430e2f70792fc9
@@ -0,0 +1,38 @@
1
+ # Accepts two arguments, a query used to discover nodes, and a list of facts
2
+ # that should be returned from those hosts.
3
+ #
4
+ # The query specified should conform to the following format:
5
+ # (Type[title] and fact_name<operator>fact_value) or ...
6
+ # Package[mysql-server] and cluster_id=my_first_cluster
7
+ #
8
+ # The facts list provided should be an array of fact names.
9
+ #
10
+ # The result is a hash that maps the name of the nodes to a hash of facts that
11
+ # contains the facts specified.
12
+ Puppet::Functions.create_function('query_facts') do
13
+ require 'puppet/util/puppetdb'
14
+
15
+ # This is needed if the puppetdb library isn't pluginsynced to the master
16
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
17
+ begin
18
+ require 'puppetdb/connection'
19
+ ensure
20
+ $LOAD_PATH.shift
21
+ end
22
+
23
+ dispatch :query_facts do
24
+ param 'Variant[String, Array]', :query
25
+ param 'Array[String, 1]', :facts
26
+ end
27
+
28
+ def query_facts(query, facts)
29
+ facts = facts.map { |fact| fact.match(/\./) ? fact.split('.') : fact }
30
+ facts_for_query = facts.map { |fact| fact.is_a?(Array) ? fact.first : fact }
31
+
32
+ uri = URI(Puppet::Util::Puppetdb.config.server_urls.first)
33
+ puppetdb = PuppetDB::Connection.new(uri.host, uri.port, uri.scheme == 'https')
34
+ parser = PuppetDB::Parser.new
35
+ query = parser.facts_query query, facts_for_query if query.is_a? String
36
+ parser.facts_hash(puppetdb.query(:facts, query, :extract => [:certname, :name, :value]), facts)
37
+ end
38
+ end
@@ -0,0 +1,62 @@
1
+ # Accepts two arguments, a query used to discover nodes, and an optional
2
+ # fact that should be returned.
3
+ #
4
+ # The query specified should conform to the following format:
5
+ # (Type[title] and fact_name<operator>fact_value) or ...
6
+ # Package["mysql-server"] and cluster_id=my_first_cluster
7
+ #
8
+ # The second argument should be single fact or series of keys joined on periods
9
+ # (this argument is optional)
10
+ Puppet::Functions.create_function('query_nodes') do
11
+ require 'puppet/util/puppetdb'
12
+
13
+ # This is needed if the puppetdb library isn't pluginsynced to the master
14
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
15
+ begin
16
+ require 'puppetdb/connection'
17
+ ensure
18
+ $LOAD_PATH.shift
19
+ end
20
+
21
+ dispatch :query_nodes do
22
+ param 'Variant[String, Array]', :query
23
+ end
24
+
25
+ dispatch :query_nodes_fact do
26
+ param 'Variant[String, Array]', :query
27
+ param 'String', :fact
28
+ end
29
+
30
+ def parser
31
+ @parser ||= PuppetDB::Parser.new
32
+ end
33
+
34
+ def puppetdb
35
+ @uri ||= URI(Puppet::Util::Puppetdb.config.server_urls.first)
36
+ @puppetdb ||= PuppetDB::Connection.new(
37
+ @uri.host,
38
+ @uri.port,
39
+ @uri.scheme == 'https'
40
+ )
41
+ end
42
+
43
+ def query_nodes(query)
44
+ query = parser.parse(query, :nodes) if query.is_a? String
45
+ puppetdb.query(:nodes, query, :extract => :certname).collect do |n|
46
+ n['certname']
47
+ end
48
+ end
49
+
50
+ def query_nodes_fact(query, fact)
51
+ fact_for_query = fact.split('.').first
52
+
53
+ query = parser.facts_query(query, [fact_for_query])
54
+ response = puppetdb.query(:facts, query, :extract => :value)
55
+
56
+ if fact.split('.').size > 1
57
+ parser.extract_nested_fact(response, fact.split('.')[1..-1])
58
+ else
59
+ response.collect { |f| f['value'] }
60
+ end
61
+ end
62
+ end
@@ -1,4 +1,4 @@
1
1
  module PuppetDB
2
2
  # Current version of this module
3
- VERSION ||= [2, 2, 0]
3
+ VERSION ||= [2, 3, 0].freeze
4
4
  end
@@ -7,11 +7,11 @@ describe PuppetDB::Parser do
7
7
  context 'Query parsing' do
8
8
  let(:parser) { PuppetDB::Parser.new }
9
9
  it 'should handle empty queries' do
10
- parser.parse('').should be_nil
10
+ expect(parser.parse('')).to be_nil
11
11
  end
12
12
 
13
13
  it 'should handle double quoted strings' do
14
- parser.parse('foo="bar"').should eq \
14
+ expect(parser.parse('foo="bar"')).to eq \
15
15
  ['in', 'certname',
16
16
  ['extract', 'certname',
17
17
  ['select_fact_contents',
@@ -21,7 +21,7 @@ describe PuppetDB::Parser do
21
21
  end
22
22
 
23
23
  it 'should handle single quoted strings' do
24
- parser.parse('foo=\'bar\'').should eq \
24
+ expect(parser.parse('foo=\'bar\'')).to eq \
25
25
  ['in', 'certname',
26
26
  ['extract', 'certname',
27
27
  ['select_fact_contents',
@@ -31,7 +31,7 @@ describe PuppetDB::Parser do
31
31
  end
32
32
 
33
33
  it 'should handle = operator' do
34
- parser.parse('foo=bar').should eq \
34
+ expect(parser.parse('foo=bar')).to eq \
35
35
  ['in', 'certname',
36
36
  ['extract', 'certname',
37
37
  ['select_fact_contents',
@@ -41,7 +41,7 @@ describe PuppetDB::Parser do
41
41
  end
42
42
 
43
43
  it 'should handle != operator' do
44
- parser.parse('foo!=bar').should eq \
44
+ expect(parser.parse('foo!=bar')).to eq \
45
45
  ['in', 'certname',
46
46
  ['extract', 'certname',
47
47
  ['select_fact_contents',
@@ -51,7 +51,7 @@ describe PuppetDB::Parser do
51
51
  end
52
52
 
53
53
  it 'should handle ~ operator' do
54
- parser.parse('foo~bar').should eq \
54
+ expect(parser.parse('foo~bar')).to eq \
55
55
  ['in', 'certname',
56
56
  ['extract', 'certname',
57
57
  ['select_fact_contents',
@@ -61,7 +61,7 @@ describe PuppetDB::Parser do
61
61
  end
62
62
 
63
63
  it 'should handle !~ operator' do
64
- parser.parse('foo!~bar').should eq \
64
+ expect(parser.parse('foo!~bar')).to eq \
65
65
  ['in', 'certname',
66
66
  ['extract', 'certname',
67
67
  ['select_fact_contents',
@@ -71,7 +71,7 @@ describe PuppetDB::Parser do
71
71
  end
72
72
 
73
73
  it 'should handle >= operator' do
74
- parser.parse('foo>=1').should eq \
74
+ expect(parser.parse('foo>=1')).to eq \
75
75
  ['in', 'certname',
76
76
  ['extract', 'certname',
77
77
  ['select_fact_contents',
@@ -81,7 +81,7 @@ describe PuppetDB::Parser do
81
81
  end
82
82
 
83
83
  it 'should handle <= operator' do
84
- parser.parse('foo<=1').should eq \
84
+ expect(parser.parse('foo<=1')).to eq \
85
85
  ['in', 'certname',
86
86
  ['extract', 'certname',
87
87
  ['select_fact_contents',
@@ -91,7 +91,7 @@ describe PuppetDB::Parser do
91
91
  end
92
92
 
93
93
  it 'should handle > operator' do
94
- parser.parse('foo>1').should eq \
94
+ expect(parser.parse('foo>1')).to eq \
95
95
  ['in', 'certname',
96
96
  ['extract', 'certname',
97
97
  ['select_fact_contents',
@@ -101,7 +101,7 @@ describe PuppetDB::Parser do
101
101
  end
102
102
 
103
103
  it 'should handle < operator' do
104
- parser.parse('foo<1').should eq \
104
+ expect(parser.parse('foo<1')).to eq \
105
105
  ['in', 'certname',
106
106
  ['extract', 'certname',
107
107
  ['select_fact_contents',
@@ -111,111 +111,111 @@ describe PuppetDB::Parser do
111
111
  end
112
112
 
113
113
  it 'should handle precedence' do
114
- parser.parse('foo=1 or bar=2 and baz=3').should eq ['or', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 1]]]]], ['and', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['bar']], ['=', 'value', 2]]]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['baz']], ['=', 'value', 3]]]]]]]
115
- parser.parse('(foo=1 or bar=2) and baz=3').should eq ['and', ['or', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 1]]]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['bar']], ['=', 'value', 2]]]]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['baz']], ['=', 'value', 3]]]]]]
114
+ expect(parser.parse 'foo=1 or bar=2 and baz=3').to eq ['or', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 1]]]]], ['and', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['bar']], ['=', 'value', 2]]]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['baz']], ['=', 'value', 3]]]]]]]
115
+ expect(parser.parse '(foo=1 or bar=2) and baz=3').to eq ['and', ['or', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 1]]]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['bar']], ['=', 'value', 2]]]]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['baz']], ['=', 'value', 3]]]]]]
116
116
  end
117
117
 
118
118
  it 'should parse resource queries for exported resources' do
119
- parser.parse('@@file[foo]').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', true]]]]]
119
+ expect(parser.parse '@@file[foo]').to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', true]]]]]
120
120
  end
121
121
 
122
122
  it 'should parse resource queries with type, title and parameters' do
123
- parser.parse('file[foo]{bar=baz}').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['=', %w(parameter bar), 'baz']]]]]
123
+ expect(parser.parse('file[foo]{bar=baz}')).to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['=', %w(parameter bar), 'baz']]]]]
124
124
  end
125
125
 
126
126
  it 'should parse resource queries with tags' do
127
- parser.parse('file[foo]{tag=baz}').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['=', 'tag', 'baz']]]]]
127
+ expect(parser.parse('file[foo]{tag=baz}')).to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['=', 'tag', 'baz']]]]]
128
128
  end
129
129
 
130
130
  it 'should handle precedence within resource parameter queries' do
131
- parser.parse('file[foo]{foo=1 or bar=2 and baz=3}').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['or', ['=', %w(parameter foo), 1], ['and', ['=', %w(parameter bar), 2], ['=', %w(parameter baz), 3]]]]]]]
132
- parser.parse('file[foo]{(foo=1 or bar=2) and baz=3}').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['and', ['or', ['=', %w(parameter foo), 1], ['=', %w(parameter bar), 2]], ['=', %w(parameter baz), 3]]]]]]
131
+ expect(parser.parse('file[foo]{foo=1 or bar=2 and baz=3}')).to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['or', ['=', %w(parameter foo), 1], ['and', ['=', %w(parameter bar), 2], ['=', %w(parameter baz), 3]]]]]]]
132
+ expect(parser.parse('file[foo]{(foo=1 or bar=2) and baz=3}')).to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'File'], ['=', 'title', 'foo'], ['=', 'exported', false], ['and', ['or', ['=', %w(parameter foo), 1], ['=', %w(parameter bar), 2]], ['=', %w(parameter baz), 3]]]]]]
133
133
  end
134
134
 
135
135
  it 'should capitalize class names' do
136
- parser.parse('class[foo::bar]').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'Class'], ['=', 'title', 'Foo::Bar'], ['=', 'exported', false]]]]]
136
+ expect(parser.parse('class[foo::bar]')).to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'Class'], ['=', 'title', 'Foo::Bar'], ['=', 'exported', false]]]]]
137
137
  end
138
138
 
139
139
  it 'should parse resource queries with regeexp title matching' do
140
- parser.parse('class[~foo]').should eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'Class'], ['~', 'title', 'foo'], ['=', 'exported', false]]]]]
140
+ expect(parser.parse('class[~foo]')).to eq ['in', 'certname', ['extract', 'certname', ['select_resources', ['and', ['=', 'type', 'Class'], ['~', 'title', 'foo'], ['=', 'exported', false]]]]]
141
141
  end
142
142
 
143
143
  it 'should be able to negate expressions' do
144
- parser.parse('not foo=bar').should eq ['not', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 'bar']]]]]]
144
+ expect(parser.parse('not foo=bar')).to eq ['not', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 'bar']]]]]]
145
145
  end
146
146
 
147
147
  it 'should handle single string expressions' do
148
- parser.parse('foo.bar.com').should eq ['~', 'certname', 'foo\\.bar\\.com']
148
+ expect(parser.parse('foo.bar.com')).to eq ['~', 'certname', 'foo\\.bar\\.com']
149
149
  end
150
150
 
151
151
  it 'should handle structured facts' do
152
- parser.parse('foo.bar=baz').should eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', %w(foo bar)], ['=', 'value', 'baz']]]]]
152
+ expect(parser.parse('foo.bar=baz')).to eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', %w(foo bar)], ['=', 'value', 'baz']]]]]
153
153
  end
154
154
 
155
155
  it 'should handle structured facts with array component' do
156
- parser.parse('foo.bar.0=baz').should eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo', 'bar', 0]], ['=', 'value', 'baz']]]]]
156
+ expect(parser.parse('foo.bar.0=baz')).to eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo', 'bar', 0]], ['=', 'value', 'baz']]]]]
157
157
  end
158
158
 
159
159
  it 'should handle structured facts with match operator' do
160
- parser.parse('foo.bar.~".*"=baz').should eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['~>', 'path', ['foo', 'bar', '.*']], ['=', 'value', 'baz']]]]]
160
+ expect(parser.parse('foo.bar.~".*"=baz')).to eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['~>', 'path', ['foo', 'bar', '.*']], ['=', 'value', 'baz']]]]]
161
161
  end
162
162
 
163
163
  it 'should handle structured facts with wildcard operator' do
164
- parser.parse('foo.bar.*=baz').should eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['~>', 'path', ['foo', 'bar', '.*']], ['=', 'value', 'baz']]]]]
164
+ expect(parser.parse('foo.bar.*=baz')).to eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['~>', 'path', ['foo', 'bar', '.*']], ['=', 'value', 'baz']]]]]
165
165
  end
166
166
 
167
167
  it 'should handle #node subqueries' do
168
- parser.parse('#node.catalog_environment=production').should eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['=', 'catalog_environment', 'production']]]]
168
+ expect(parser.parse('#node.catalog_environment=production')).to eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['=', 'catalog_environment', 'production']]]]
169
169
  end
170
170
 
171
171
  it 'should handle #node subqueries with block of conditions' do
172
- parser.parse('#node { catalog_environment=production }').should eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['=', 'catalog_environment', 'production']]]]
172
+ expect(parser.parse('#node { catalog_environment=production }')).to eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['=', 'catalog_environment', 'production']]]]
173
173
  end
174
174
 
175
175
  it 'should handle #node subquery combined with fact query' do
176
- parser.parse('#node.catalog_environment=production and foo=bar').should eq ['and', ['in', 'certname', ['extract', 'certname', ['select_nodes', ['=', 'catalog_environment', 'production']]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 'bar']]]]]]
176
+ expect(parser.parse('#node.catalog_environment=production and foo=bar')).to eq ['and', ['in', 'certname', ['extract', 'certname', ['select_nodes', ['=', 'catalog_environment', 'production']]]], ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['foo']], ['=', 'value', 'bar']]]]]]
177
177
  end
178
178
 
179
179
  it 'should escape non match parts on structured facts with match operator' do
180
- parser.parse('"foo.bar".~".*"=baz').should eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['~>', 'path', ['foo\\.bar', '.*']], ['=', 'value', 'baz']]]]]
180
+ expect(parser.parse('"foo.bar".~".*"=baz')).to eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['~>', 'path', ['foo\\.bar', '.*']], ['=', 'value', 'baz']]]]]
181
181
  end
182
182
 
183
183
  it 'should parse dates in queries' do
184
184
  date = Time.new(2014, 9, 9).utc.strftime('%FT%TZ')
185
- parser.parse('#node.report_timestamp<@"Sep 9, 2014"').should eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['<', 'report_timestamp', date]]]]
185
+ expect(parser.parse('#node.report_timestamp<@"Sep 9, 2014"')).to eq ['in', 'certname', ['extract', 'certname', ['select_nodes', ['<', 'report_timestamp', date]]]]
186
186
  end
187
187
 
188
188
  it 'should not wrap it in a subquery if mode is :none' do
189
- parser.parse('class[apache]', :none).should eq ["and", ["=", "type", "Class"], ["=", "title", "Apache"], ["=", "exported", false]]
189
+ expect(parser.parse 'class[apache]', :none).to eq ["and", ["=", "type", "Class"], ["=", "title", "Apache"], ["=", "exported", false]]
190
190
  end
191
191
  end
192
192
 
193
193
  context 'facts_query' do
194
194
  let(:parser) { PuppetDB::Parser.new }
195
195
  it 'should return a query for all if no facts are specified' do
196
- parser.facts_query('kernel=Linux').should eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['kernel']], ['=', 'value', 'Linux']]]]]
196
+ expect(parser.facts_query 'kernel=Linux').to eq ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['kernel']], ['=', 'value', 'Linux']]]]]
197
197
  end
198
198
 
199
199
  it 'should return a query for specific facts if they are specified' do
200
- parser.facts_query('kernel=Linux', ['ipaddress']). should eq ['and', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['kernel']], ['=', 'value', 'Linux']]]]], ['or', ['=', 'name', 'ipaddress']]]
200
+ expect(parser.facts_query 'kernel=Linux', ['ipaddress']).to eq ['and', ['in', 'certname', ['extract', 'certname', ['select_fact_contents', ['and', ['=', 'path', ['kernel']], ['=', 'value', 'Linux']]]]], ['or', ['=', 'name', 'ipaddress']]]
201
201
  end
202
202
 
203
203
  it 'should return a query for matching facts on all nodes if query is missing' do
204
- parser.facts_query('', ['ipaddress']).should eq ['or', ['=', 'name', 'ipaddress']]
204
+ expect(parser.facts_query('', ['ipaddress'])).to eq ['or', ['=', 'name', 'ipaddress']]
205
205
  end
206
206
  end
207
207
 
208
208
  context 'facts_hash' do
209
209
  let(:parser) { PuppetDB::Parser.new }
210
210
  it 'should merge facts into a nested hash' do
211
- parser.facts_hash([
211
+ expect(parser.facts_hash([
212
212
  { 'certname' => 'ip-172-31-45-32.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'kernel', 'value' => 'Linux' },
213
213
  { 'certname' => 'ip-172-31-33-234.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'kernel', 'value' => 'Linux' },
214
214
  { 'certname' => 'ip-172-31-5-147.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'kernel', 'value' => 'Linux' },
215
215
  { 'certname' => 'ip-172-31-45-32.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'fqdn', 'value' => 'ip-172-31-45-32.eu-west-1.compute.internal' },
216
216
  { 'certname' => 'ip-172-31-33-234.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'fqdn', 'value' => 'ip-172-31-33-234.eu-west-1.compute.internal' },
217
217
  { 'certname' => 'ip-172-31-5-147.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'fqdn', 'value' => 'ip-172-31-5-147.eu-west-1.compute.internal' }
218
- ], ['kernel', 'fqdn']).should eq(
218
+ ], ['kernel', 'fqdn'])).to eq(
219
219
  'ip-172-31-45-32.eu-west-1.compute.internal' => { 'kernel' => 'Linux', 'fqdn' => 'ip-172-31-45-32.eu-west-1.compute.internal' },
220
220
  'ip-172-31-33-234.eu-west-1.compute.internal' => { 'kernel' => 'Linux', 'fqdn' => 'ip-172-31-33-234.eu-west-1.compute.internal' },
221
221
  'ip-172-31-5-147.eu-west-1.compute.internal' => { 'kernel' => 'Linux', 'fqdn' => 'ip-172-31-5-147.eu-west-1.compute.internal' }
@@ -223,12 +223,12 @@ describe PuppetDB::Parser do
223
223
  end
224
224
 
225
225
  it 'should handle nested facts' do
226
- parser.facts_hash([
226
+ expect(parser.facts_hash([
227
227
  { 'certname' => 'ip-172-31-45-32.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'kernel', 'value' => 'Linux' },
228
228
  { 'certname' => 'ip-172-31-33-234.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'kernel', 'value' => 'Linux' },
229
229
  { 'certname' => 'ip-172-31-45-32.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'networking', 'value' => { 'interfaces' => { 'eth0' => { 'ip' => '172.31.45.32' } } } },
230
230
  { 'certname' => 'ip-172-31-33-234.eu-west-1.compute.internal', 'environment' => 'production', 'name' => 'networking', 'value' => { 'interfaces' => { 'eth0' => { 'ip' => '172.31.33.234' } } } },
231
- ], ['kernel', ['networking', 'interfaces', 'eth0', 'ip']]).should eq(
231
+ ], ['kernel', ['networking', 'interfaces', 'eth0', 'ip']])).to eq(
232
232
  'ip-172-31-45-32.eu-west-1.compute.internal' => { 'kernel' => 'Linux', 'networking_interfaces_eth0_ip' => '172.31.45.32' },
233
233
  'ip-172-31-33-234.eu-west-1.compute.internal' => { 'kernel' => 'Linux', 'networking_interfaces_eth0_ip' => '172.31.33.234' },
234
234
  )
@@ -237,7 +237,7 @@ describe PuppetDB::Parser do
237
237
 
238
238
  context 'extract' do
239
239
  it 'should create an extract query' do
240
- PuppetDB::ParserHelper.extract(:certname, :name, ['=', 'certname', 'foo.example.com']).should eq(
240
+ expect(PuppetDB::ParserHelper.extract(:certname, :name, ['=', 'certname', 'foo.example.com'])).to eq(
241
241
  ['extract', ['certname', 'name'], ['=', 'certname', 'foo.example.com']]
242
242
  )
243
243
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-puppetdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Dalen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-14 00:00:00.000000000 Z
11
+ date: 2017-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -64,56 +64,56 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '2.13'
67
+ version: '3.5'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '2.13'
74
+ version: '3.5'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rspec-expectations
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: '3.5'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: '3.5'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: rspec-puppet
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">="
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0'
95
+ version: '2.4'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ">="
100
+ - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0'
102
+ version: '2.4'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rake
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - ">="
107
+ - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: '11.2'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - ">="
114
+ - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '0'
116
+ version: '11.2'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: puppetlabs_spec_helper
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -146,16 +146,16 @@ dependencies:
146
146
  name: rexical
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - ">="
149
+ - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '0'
151
+ version: '1.0'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - ">="
156
+ - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: '1.0'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: puppet-blacksmith
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +185,8 @@ files:
185
185
  - lib/hiera/backend/puppetdb_backend.rb
186
186
  - lib/puppet/application/query.rb
187
187
  - lib/puppet/face/query.rb
188
+ - lib/puppet/functions/query_facts.rb
189
+ - lib/puppet/functions/query_nodes.rb
188
190
  - lib/puppet/parser/functions/query_facts.rb
189
191
  - lib/puppet/parser/functions/query_nodes.rb
190
192
  - lib/puppet/parser/functions/query_resources.rb
@@ -227,12 +229,12 @@ signing_key:
227
229
  specification_version: 4
228
230
  summary: Query functions for PuppetDB
229
231
  test_files:
232
+ - spec/puppet/util/puppetdb.rb
230
233
  - spec/spec_helper.rb
234
+ - spec/unit/puppetdb/parser_spec.rb
231
235
  - spec/functions/query_facts_spec.rb
232
236
  - spec/functions/query_nodes_spec.rb
233
237
  - spec/functions/query_resources_spec.rb
234
- - spec/unit/puppetdb/parser_spec.rb
235
- - spec/puppet/util/puppetdb.rb
236
238
  - examples/nova_functions.pp
237
- - examples/query_node_examples.pp
238
239
  - examples/query_resource_examples.pp
240
+ - examples/query_node_examples.pp