Skip to content

Commit

Permalink
Simplify open_socket by raising errors
Browse files Browse the repository at this point in the history
This commit updates open_socket to raise errors, and return nil when it
succeeds. This simplifies both the method, and usage when implemented.
Without this change the intent is less clear.
  • Loading branch information
mattkirby committed Nov 17, 2016
1 parent 459125c commit 48ad69d
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/vmpooler/pool_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ def open_socket(host, domain=nil, timeout=5, port=22, &block)
yield sock if block_given?
ensure
sock.close
return true
end
end
rescue SocketError
rescue Timeout::Error
end

def _check_pending_vm(vm, pool, timeout, vsphere)
Expand All @@ -49,8 +46,7 @@ def _check_pending_vm(vm, pool, timeout, vsphere)
fail_pending_vm(vm, pool, timeout, false)
return
end
socket = open_socket vm
fail_pending_vm(vm, pool, timeout) if ! socket
open_socket vm
move_pending_vm_to_ready(vm, pool, host)
rescue
fail_pending_vm(vm, pool, timeout)
Expand Down Expand Up @@ -145,8 +141,9 @@ def check_ready_vm(vm, pool, ttl, vsphere)
$logger.log('s', "[!] [#{pool}] '#{vm}' not found in vCenter inventory, removed from 'ready' queue")
end

socket = open_socket vm
if ! socket
begin
open_socket vm
rescue
if $redis.smove('vmpooler__ready__' + pool, 'vmpooler__completed__' + pool, vm)
$logger.log('d', "[!] [#{pool}] '#{vm}' is unreachable, removed from 'ready' queue")
else
Expand Down

0 comments on commit 48ad69d

Please sign in to comment.