chef-resolver 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/chef-resolver +1 -0
- data/lib/chef/resolver/version.rb +1 -1
- data/lib/chef/resolver_server.rb +9 -1
- data/spec/resolver_server_spec.rb +18 -10
- metadata +45 -49
data/bin/chef-resolver
CHANGED
data/lib/chef/resolver_server.rb
CHANGED
@@ -96,7 +96,15 @@ class Chef
|
|
96
96
|
load_chef_config config
|
97
97
|
|
98
98
|
puts "\tLooking up role #{role}..."
|
99
|
-
|
99
|
+
|
100
|
+
# Build search string
|
101
|
+
search = "role:#{role}"
|
102
|
+
if config.key?('search_extra')
|
103
|
+
search = "(#{config['search_extra']}) AND #{search}"
|
104
|
+
end
|
105
|
+
|
106
|
+
# Find the nodes
|
107
|
+
nodes = Chef::Search::Query.new.search('node', search)[0]
|
100
108
|
if index >= nodes.length
|
101
109
|
puts "\tIndex beyond bounds: #{index} vs #{nodes.length}"
|
102
110
|
return nil
|
@@ -14,10 +14,10 @@ describe Chef::ResolverServer do
|
|
14
14
|
@server = nil
|
15
15
|
end
|
16
16
|
|
17
|
-
def stub_search
|
17
|
+
def stub_search search, nodes
|
18
18
|
query = double('Chef::Search::Query')
|
19
19
|
nodes.each_with_index {|n, i| n['name'] = "node #{i}" }
|
20
|
-
query.should_receive(:search).with('node',
|
20
|
+
query.should_receive(:search).with('node', search).and_return([nodes, 0, nodes.length])
|
21
21
|
Chef::Search::Query.should_receive(:new) { query }
|
22
22
|
end
|
23
23
|
|
@@ -45,6 +45,7 @@ describe Chef::ResolverServer do
|
|
45
45
|
@default_config = Chef::Config.configuration
|
46
46
|
@test_config = {'knife_file' => File.dirname(__FILE__)+'/files/test_knife.rb'}
|
47
47
|
@test2_config = {'knife_file' => File.dirname(__FILE__)+'/files/test2_knife.rb', 'env' => {'ENV_PROP' => 'test2'}}
|
48
|
+
@test3_config = {'knife_file' => File.dirname(__FILE__)+'/files/test_knife.rb', 'search_extra' => 'role:staging'}
|
48
49
|
end
|
49
50
|
|
50
51
|
after :each do
|
@@ -84,14 +85,21 @@ describe Chef::ResolverServer do
|
|
84
85
|
it "should resolve a name like ROLE.CONFIG.chef" do
|
85
86
|
new_server 'test' => @test_config, 'test2' => @test2_config
|
86
87
|
@server.start
|
87
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}]
|
88
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
88
89
|
getaddress('test_role.test2.chef').should == '1.1.1.1'
|
89
90
|
end
|
90
91
|
|
92
|
+
it "should use the search_extra if given for lookups" do
|
93
|
+
new_server 'test3' => @test3_config
|
94
|
+
@server.start
|
95
|
+
stub_search '(role:staging) AND role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
96
|
+
getaddress('test_role.test3.chef').should == '1.1.1.1'
|
97
|
+
end
|
98
|
+
|
91
99
|
it "should resolve a name like ROLE-INDEX.CONFIG.chef" do
|
92
100
|
new_server 'test' => @test_config
|
93
101
|
@server.start
|
94
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}, {'ipaddress' => '2.2.2.2'}, {'ipaddress' => '3.3.3.3'}, {'ipaddress' => '4.4.4.4'}]
|
102
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}, {'ipaddress' => '2.2.2.2'}, {'ipaddress' => '3.3.3.3'}, {'ipaddress' => '4.4.4.4'}]
|
95
103
|
getaddress('test_role-3.test.chef').should == '3.3.3.3'
|
96
104
|
end
|
97
105
|
|
@@ -105,7 +113,7 @@ describe Chef::ResolverServer do
|
|
105
113
|
# Should succeed with one config
|
106
114
|
new_server 'test' => @test_config
|
107
115
|
@server.start
|
108
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}]
|
116
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
109
117
|
getaddress('test_role.chef').should == '1.1.1.1'
|
110
118
|
end
|
111
119
|
|
@@ -118,7 +126,7 @@ describe Chef::ResolverServer do
|
|
118
126
|
it "should resolve ec2 node public ip addresses properly" do
|
119
127
|
new_server 'test' => @test_config
|
120
128
|
@server.start
|
121
|
-
stub_search 'test_role', [{'ec2' => {'public_ipv4' => '1.1.1.1'}, 'ipaddress' => '0.0.0.0'}]
|
129
|
+
stub_search 'role:test_role', [{'ec2' => {'public_ipv4' => '1.1.1.1'}, 'ipaddress' => '0.0.0.0'}]
|
122
130
|
getaddress('test_role.chef').should == '1.1.1.1'
|
123
131
|
end
|
124
132
|
|
@@ -127,7 +135,7 @@ describe Chef::ResolverServer do
|
|
127
135
|
File.open(path, 'w') {|f| f.write({'test' => @test_config}.to_yaml)}
|
128
136
|
new_server path
|
129
137
|
@server.start
|
130
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}]
|
138
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
131
139
|
getaddress('test_role.chef').should == '1.1.1.1'
|
132
140
|
end
|
133
141
|
|
@@ -142,7 +150,7 @@ describe Chef::ResolverServer do
|
|
142
150
|
sleep 2
|
143
151
|
|
144
152
|
expect { getaddress('test_role.test.chef') }.to raise_error(Resolv::ResolvError)
|
145
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}]
|
153
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
146
154
|
getaddress('test_role.test2.chef').should == '1.1.1.1'
|
147
155
|
end
|
148
156
|
|
@@ -154,7 +162,7 @@ describe Chef::ResolverServer do
|
|
154
162
|
new_server config_path, true
|
155
163
|
@server.start
|
156
164
|
|
157
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}]
|
165
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
158
166
|
getaddress('test_role.changing.chef').should == '1.1.1.1'
|
159
167
|
Chef::Config.test_prop.should == true
|
160
168
|
|
@@ -162,7 +170,7 @@ describe Chef::ResolverServer do
|
|
162
170
|
File.open(knife_path, 'w') {|f| f.write("test_prop false\n")}
|
163
171
|
sleep 2
|
164
172
|
|
165
|
-
stub_search 'test_role', [{'ipaddress' => '1.1.1.1'}]
|
173
|
+
stub_search 'role:test_role', [{'ipaddress' => '1.1.1.1'}]
|
166
174
|
getaddress('test_role.changing.chef').should == '1.1.1.1'
|
167
175
|
Chef::Config.test_prop.should == false
|
168
176
|
end
|
metadata
CHANGED
@@ -1,45 +1,40 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-resolver
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 10
|
8
|
-
- 0
|
9
|
-
version: 0.10.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.11.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Stephen Augenstein
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
type: :runtime
|
22
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
segments:
|
27
|
-
- 11
|
28
|
-
- 6
|
29
|
-
version: "11.6"
|
12
|
+
date: 2014-03-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
30
15
|
name: chef
|
31
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '11.6'
|
22
|
+
type: :runtime
|
32
23
|
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '11.6'
|
33
30
|
description: A DNS resolver for Mac OS X that does role queries to resolve hostnames
|
34
|
-
email:
|
31
|
+
email:
|
35
32
|
- perl.programmer@gmail.com
|
36
|
-
executables:
|
33
|
+
executables:
|
37
34
|
- chef-resolver
|
38
35
|
extensions: []
|
39
|
-
|
40
36
|
extra_rdoc_files: []
|
41
|
-
|
42
|
-
files:
|
37
|
+
files:
|
43
38
|
- .gitignore
|
44
39
|
- Gemfile
|
45
40
|
- LICENSE.txt
|
@@ -54,37 +49,38 @@ files:
|
|
54
49
|
- spec/files/test_knife.rb
|
55
50
|
- spec/resolver_server_spec.rb
|
56
51
|
- spec/spec_helper.rb
|
57
|
-
has_rdoc: true
|
58
52
|
homepage: https://github.com/warhammerkid/chef-resolver
|
59
53
|
licenses: []
|
60
|
-
|
61
54
|
post_install_message:
|
62
55
|
rdoc_options: []
|
63
|
-
|
64
|
-
require_paths:
|
56
|
+
require_paths:
|
65
57
|
- lib
|
66
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
segments:
|
71
65
|
- 0
|
72
|
-
|
73
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
66
|
+
hash: 160828053575409919
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
78
74
|
- 0
|
79
|
-
|
75
|
+
hash: 160828053575409919
|
80
76
|
requirements: []
|
81
|
-
|
82
77
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.
|
78
|
+
rubygems_version: 1.8.23
|
84
79
|
signing_key:
|
85
80
|
specification_version: 3
|
86
|
-
summary: Instead of doing knife search node role every time you want to look up a
|
87
|
-
|
81
|
+
summary: Instead of doing knife search node role every time you want to look up a
|
82
|
+
server, simply ssh into ROLE_NAME-##.chef
|
83
|
+
test_files:
|
88
84
|
- spec/files/test2_knife.rb
|
89
85
|
- spec/files/test_knife.rb
|
90
86
|
- spec/resolver_server_spec.rb
|