From 6810cbe78e41d26f165c8d5e81e98d496354b9cc Mon Sep 17 00:00:00 2001 From: "kirby@puppetlabs.com" Date: Fri, 29 Jun 2018 00:46:03 -0700 Subject: [PATCH] Check if a hostname return is empty string This commit checks whether a hostname returned is an empty string. Without this change a VM that returns a hostname with a empty string will report as having a hostname mismatch, which may happen before all VM data is updated. --- lib/vmpooler/pool_manager.rb | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 1f6b5f5..b3a69c7 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -134,23 +134,28 @@ module Vmpooler end end - check_hostname = pool['check_hostname_for_mismatch'] - check_hostname = $config[:config]['check_ready_vm_hostname_for_mismatch'] if check_hostname.nil? - check_hostname = true if check_hostname.nil? - if check_hostname - # Check if the hostname has magically changed from underneath Pooler - host = provider.get_vm(pool['name'], vm) - if host['hostname'] != vm - $redis.smove('vmpooler__ready__' + pool['name'], 'vmpooler__completed__' + pool['name'], vm) - $logger.log('d', "[!] [#{pool['name']}] '#{vm}' has mismatched hostname, removed from 'ready' queue") - return - end - end + return if has_mismatched_hostname?(vm, pool, provider) vm_still_ready?(pool['name'], vm, provider) end end + def has_mismatched_hostname?(vm, pool, provider) + check_hostname = pool['check_hostname_for_mismatch'] + check_hostname = $config[:config]['check_ready_vm_hostname_for_mismatch'] if check_hostname.nil? + return if check_hostname == false + + # Check if the hostname has magically changed from underneath Pooler + vm_hash = provider.get_vm(pool['name'], vm) + hostname = vm_hash['hostname'] + + return if hostname.empty? + return if hostname == vm + $redis.smove('vmpooler__ready__' + pool['name'], 'vmpooler__completed__' + pool['name'], vm) + $logger.log('d', "[!] [#{pool['name']}] '#{vm}' has mismatched hostname, removed from 'ready' queue") + return true + end + def check_running_vm(vm, pool, ttl, provider) Thread.new do begin