chef-zero 2.1.5 → 2.2
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/Rakefile +6 -0
- data/bin/chef-zero +16 -2
- data/lib/chef_zero/server.rb +45 -6
- data/lib/chef_zero/version.rb +1 -1
- data/spec/server_spec.rb +28 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e812fceafd51d3dbba1d43446f13c67c12dfbee
|
4
|
+
data.tar.gz: e6ec4a6756763c7fc69d10e4e76c309e91ad469e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdb9632a016a53427b3d1a977d7fa8ddb6a50f1e02c73001bfbdc192ef0b368798dda5beca6cb18e81394e63fc8132c5db125e08f5b4bb45155fca5dbf839f10
|
7
|
+
data.tar.gz: 3b01505e14cefdee548abf5324d742742159a3d66ceaa604d2463095eed7b96c8f1eb5ae9c8ad93a90eea082e91b19d5008074b053926062a2ad42f48ad07874
|
data/Rakefile
CHANGED
data/bin/chef-zero
CHANGED
@@ -10,6 +10,19 @@ require 'chef_zero/version'
|
|
10
10
|
require 'chef_zero/server'
|
11
11
|
require 'optparse'
|
12
12
|
|
13
|
+
def parse_port(port)
|
14
|
+
array = []
|
15
|
+
port.split(',').each do |part|
|
16
|
+
a,b = part.split('-',2)
|
17
|
+
if b
|
18
|
+
array = array.concat(a.to_i.upto(b.to_i).to_a)
|
19
|
+
else
|
20
|
+
array = array.concat([a.to_i])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
array
|
24
|
+
end
|
25
|
+
|
13
26
|
options = {}
|
14
27
|
|
15
28
|
OptionParser.new do |opts|
|
@@ -19,8 +32,9 @@ OptionParser.new do |opts|
|
|
19
32
|
options[:host] = value
|
20
33
|
end
|
21
34
|
|
22
|
-
opts.on("-p", "--port PORT",
|
23
|
-
options[:port]
|
35
|
+
opts.on("-p", "--port PORT", "Port to listen on (e.g. 8889, or 8500-8600 or 8885,8888)") do |value|
|
36
|
+
options[:port] ||= []
|
37
|
+
options[:port] += parse_port(value)
|
24
38
|
end
|
25
39
|
|
26
40
|
opts.on("--[no-]generate-keys", "Whether to generate actual keys or fake it (faster). Default: false.") do |value|
|
data/lib/chef_zero/server.rb
CHANGED
@@ -80,6 +80,17 @@ module ChefZero
|
|
80
80
|
# @return [Hash]
|
81
81
|
attr_reader :options
|
82
82
|
|
83
|
+
# @return [Integer]
|
84
|
+
def port
|
85
|
+
if @port
|
86
|
+
@port
|
87
|
+
elsif !options[:port].respond_to?(:each)
|
88
|
+
options[:port]
|
89
|
+
else
|
90
|
+
raise "port cannot be determined until server is started"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
83
94
|
# @return [WEBrick::HTTPServer]
|
84
95
|
attr_reader :server
|
85
96
|
|
@@ -95,9 +106,9 @@ module ChefZero
|
|
95
106
|
#
|
96
107
|
def url
|
97
108
|
@url ||= if @options[:host].include?(':')
|
98
|
-
URI("http://[#{@options[:host]}]:#{
|
109
|
+
URI("http://[#{@options[:host]}]:#{port}").to_s
|
99
110
|
else
|
100
|
-
URI("http://#{@options[:host]}:#{
|
111
|
+
URI("http://#{@options[:host]}:#{port}").to_s
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
@@ -153,14 +164,20 @@ module ChefZero
|
|
153
164
|
output = publish.respond_to?(:puts) ? publish : STDOUT
|
154
165
|
output.puts <<-EOH.gsub(/^ {10}/, '')
|
155
166
|
>> Starting Chef Zero (v#{ChefZero::VERSION})...
|
167
|
+
EOH
|
168
|
+
end
|
169
|
+
|
170
|
+
thread = start_background
|
171
|
+
|
172
|
+
if publish
|
173
|
+
output = publish.respond_to?(:puts) ? publish : STDOUT
|
174
|
+
output.puts <<-EOH.gsub(/^ {10}/, '')
|
156
175
|
>> WEBrick (v#{WEBrick::VERSION}) on Rack (v#{Rack.release}) is listening at #{url}
|
157
176
|
>> Press CTRL+C to stop
|
158
177
|
|
159
178
|
EOH
|
160
179
|
end
|
161
180
|
|
162
|
-
thread = start_background
|
163
|
-
|
164
181
|
%w[INT TERM].each do |signal|
|
165
182
|
Signal.trap(signal) do
|
166
183
|
puts "\n>> Stopping Chef Zero..."
|
@@ -185,8 +202,7 @@ module ChefZero
|
|
185
202
|
#
|
186
203
|
def start_background(wait = 5)
|
187
204
|
@server = WEBrick::HTTPServer.new(
|
188
|
-
:
|
189
|
-
:Port => @options[:port],
|
205
|
+
:DoNotListen => true,
|
190
206
|
:AccessLog => [],
|
191
207
|
:Logger => WEBrick::Log.new(StringIO.new, 7),
|
192
208
|
:StartCallback => proc {
|
@@ -195,18 +211,41 @@ module ChefZero
|
|
195
211
|
)
|
196
212
|
@server.mount('/', Rack::Handler::WEBrick, app)
|
197
213
|
|
214
|
+
# Pick a port
|
215
|
+
if options[:port].respond_to?(:each)
|
216
|
+
options[:port].each do |port|
|
217
|
+
begin
|
218
|
+
@server.listen(options[:host], port)
|
219
|
+
@port = port
|
220
|
+
break
|
221
|
+
rescue Errno::EADDRINUSE
|
222
|
+
ChefZero::Log.info("Port #{port} in use: #{$!}")
|
223
|
+
end
|
224
|
+
end
|
225
|
+
if !@port
|
226
|
+
raise Errno::EADDRINUSE, "No port in :port range #{options[:port]} is available"
|
227
|
+
end
|
228
|
+
else
|
229
|
+
@server.listen(options[:host], options[:port])
|
230
|
+
@port = options[:port]
|
231
|
+
end
|
232
|
+
|
233
|
+
# Start the server in the background
|
198
234
|
@thread = Thread.new do
|
199
235
|
begin
|
200
236
|
Thread.current.abort_on_exception = true
|
201
237
|
@server.start
|
202
238
|
ensure
|
239
|
+
@port = nil
|
203
240
|
@running = false
|
204
241
|
end
|
205
242
|
end
|
243
|
+
|
206
244
|
# Do not return until the web server is genuinely started.
|
207
245
|
while !@running && @thread.alive?
|
208
246
|
sleep(0.01)
|
209
247
|
end
|
248
|
+
|
210
249
|
@thread
|
211
250
|
end
|
212
251
|
|
data/lib/chef_zero/version.rb
CHANGED
data/spec/server_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'chef_zero/server'
|
2
|
+
|
3
|
+
describe ChefZero::Server do
|
4
|
+
context 'with a server bound to port 8889' do
|
5
|
+
before :each do
|
6
|
+
@server = ChefZero::Server.new(:port => 8889)
|
7
|
+
@server.start_background
|
8
|
+
end
|
9
|
+
after :each do
|
10
|
+
@server.stop
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'a second server bound to port 8889 throws EADDRINUSE' do
|
14
|
+
expect { ChefZero::Server.new(:port => 8889).start }.to raise_error Errno::EADDRINUSE
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'a server bound to range 8889-9999 binds to a port > 8889' do
|
18
|
+
server = ChefZero::Server.new(:port => 8889.upto(9999))
|
19
|
+
server.start_background
|
20
|
+
expect(server.port).to be > 8889
|
21
|
+
expect(URI(server.url).port).to be > 8889
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'a server bound to range 8889-8889 throws an exception' do
|
25
|
+
expect { ChefZero::Server.new(:port => 8889.upto(8889)).start_background }.to raise_error Errno::EADDRINUSE
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-zero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: '2.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-log
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/chef_zero/version.rb
|
167
167
|
- spec/run.rb
|
168
168
|
- spec/search_spec.rb
|
169
|
+
- spec/server_spec.rb
|
169
170
|
- spec/support/pedant.rb
|
170
171
|
- spec/support/stickywicket.pem
|
171
172
|
homepage: http://www.opscode.com
|