From 48ad69d4af8de6281ae90bda9887d13f8a5a2689 Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Thu, 17 Nov 2016 14:44:25 -0800 Subject: [PATCH] Simplify open_socket by raising errors 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. --- lib/vmpooler/pool_manager.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 20231ef3d..939d7bc54 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -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) @@ -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) @@ -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