From 79ac9ad37e03f9121261189bcba97b0515c92139 Mon Sep 17 00:00:00 2001 From: Andrew Makousky Date: Fri, 30 Aug 2019 17:58:24 -0500 Subject: [PATCH 1/2] (POOLER-148) Fix undefined variable bug in _check_ready_vm. The host['boottime'] variable in the function _check_ready_vm no longer has its parent object in reference due to the refactoring in pull request #269. So in order to get the same information without the performance impact from duplicate object lookups, we get similar information from the time that the VM is ready. --- lib/vmpooler/pool_manager.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index f2242ff66..34a76b0e1 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -156,8 +156,14 @@ def _check_ready_vm(vm, pool_name, ttl, provider) $redis.hset('vmpooler__vm__' + vm, 'check', Time.now) # Check if the hosts TTL has expired if ttl > 0 - # host['boottime'] may be nil if host is not powered on - if ((Time.now - host['boottime']) / 60).to_s[/^\d+\.\d{1}/].to_f > ttl + # 'boottime' may be nil if host is not powered on + boottime = $redis.hget("vmpooler__vm__#{vm}", 'ready') + if boottime + boottime = Time.parse(boottime) + else + boottime = Time.at(0) + end + if ((Time.now - boottime) / 60).to_s[/^\d+\.\d{1}/].to_f > ttl $redis.smove('vmpooler__ready__' + pool_name, 'vmpooler__completed__' + pool_name, vm) $logger.log('d', "[!] [#{pool_name}] '#{vm}' reached end of TTL after #{ttl} minutes, removed from 'ready' queue") From a2548d11e8c5404f6ab728c0d59a3bcb836d406b Mon Sep 17 00:00:00 2001 From: Andrew Makousky Date: Wed, 4 Sep 2019 01:32:20 +0000 Subject: [PATCH 2/2] (POOLER-148) Improve code comment. Co-Authored-By: Samuel --- lib/vmpooler/pool_manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 34a76b0e1..3e59e4474 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -156,7 +156,7 @@ def _check_ready_vm(vm, pool_name, ttl, provider) $redis.hset('vmpooler__vm__' + vm, 'check', Time.now) # Check if the hosts TTL has expired if ttl > 0 - # 'boottime' may be nil if host is not powered on + # if 'boottime' is nil, set bootime to beginning of unix epoch, forces TTL to be assumed expired boottime = $redis.hget("vmpooler__vm__#{vm}", 'ready') if boottime boottime = Time.parse(boottime)