Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8bcf748
(POOLER-73) Restructure tests to unit and integration directories
glennsarti Feb 8, 2017
a9fc1bb
(POOLER-73) Update test helpers
glennsarti Feb 13, 2017
af9ec66
(POOLER-73) Add spec tests for check_pending_vm
glennsarti Feb 9, 2017
b72275b
(POOLER-73) Add spec tests for open_socket
glennsarti Feb 9, 2017
9fdb51e
(POOLER-73) Modify spec tests for _check_pending_vm
glennsarti Feb 9, 2017
b5ec74b
(POOLER-73) Add spec tests for remove_nonexistent_vm
glennsarti Feb 9, 2017
4b2ca49
(POOLER-73) Modify spec tests for fail_pending_vm
glennsarti Feb 9, 2017
8ae6b29
(POOLER-73) Modify spec tests for move_pending_vm_to_ready
glennsarti Feb 9, 2017
2475f55
(POOLER-73) Add spec tests for check_ready_vm
glennsarti Feb 9, 2017
58175de
(POOLER-73) Add spec tests for check_running_vm
glennsarti Feb 9, 2017
cb4e140
(POOLER-73) Modify spec tests for _check_running_vm
glennsarti Feb 9, 2017
9d8b792
(POOLER-73) Add spec tests for move_vm_queue
glennsarti Feb 9, 2017
434ab54
(POOLER-73) Add spec tests for clone_vm
glennsarti Feb 9, 2017
14c0913
(POOLER-73) Add spec tests for destroy_vm
glennsarti Feb 9, 2017
e342cfe
(POOLER-73) Add spec tests for get_vm_host_info
glennsarti Feb 10, 2017
5e46ace
(POOLER-73) Add spec tests for execute!
glennsarti Feb 10, 2017
daad5c7
(POOLER-73) Add spec tests for check_pool
glennsarti Feb 10, 2017
64d2d95
(POOLER-73) Remove #move_running_to_completed tests
glennsarti Feb 13, 2017
15d4dfa
(POOLER-73) Add spec tests for _check_pool
glennsarti Feb 13, 2017
943d302
(POOLER-73) Remove #_stats_running_ready tests
glennsarti Feb 13, 2017
6f79c43
(POOLER-73) Add spec tests for create_vm_disk
glennsarti Feb 14, 2017
e6be5bf
(POOLER-73) Add spec tests for create_vm_snapshot
glennsarti Feb 14, 2017
713e202
(POOLER-73) Add spec tests for revert_vm_snapshot
glennsarti Feb 14, 2017
925071b
(POOLER-73) Add spec tests for migrate_vm
glennsarti Feb 14, 2017
a4c55d5
(POOLER-73) Add spec tests for migration_limit
glennsarti Feb 14, 2017
fb6be8e
(POOLER-73) Add spec tests for remove_vmpooler_migration_vm
glennsarti Feb 14, 2017
47d597f
(POOLER-73) Add spec tests for migrate_vm_and_record_timing
glennsarti Feb 14, 2017
4dd0c96
(POOLER-73) Add spec tests for check_disk_queue
glennsarti Feb 17, 2017
6f127d3
(POOLER-73) Add spec tests for check_snapshot_queue
glennsarti Feb 17, 2017
25ad5d5
(POOLER-73) Add spec tests for _check_snapshot_queue
glennsarti Feb 17, 2017
3083186
(POOLER-73) Add spec tests for _check_disk_queue
glennsarti Feb 17, 2017
0a6dffb
(POOLER-73) Add spec tests for _create_vm_disk
glennsarti Feb 17, 2017
b63822f
(POOLER-73) Modify spec tests for _create_vm_snapshot
glennsarti Feb 17, 2017
c69d611
(POOLER-73) Modify spec tests for _revert_vm_snapshot
glennsarti Feb 17, 2017
e783e93
(POOLER-73) Modify spec tests for _migrate_vm
glennsarti Feb 17, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions lib/vmpooler/pool_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,20 @@ def _revert_vm_snapshot(vm, snapshot_name, vsphere)
end
end

def check_disk_queue
def check_disk_queue(maxloop = 0, loop_delay = 5)
$logger.log('d', "[*] [disk_manager] starting worker thread")

$vsphere['disk_manager'] ||= Vmpooler::VsphereHelper.new $config, $metrics

$threads['disk_manager'] = Thread.new do
loop_count = 1
loop do
_check_disk_queue $vsphere['disk_manager']
sleep(5)
sleep(loop_delay)

unless maxloop.zero?
break if loop_count >= maxloop
loop_count = loop_count + 1
end
end
end
end
Expand All @@ -438,15 +443,21 @@ def _check_disk_queue(vsphere)
end
end

def check_snapshot_queue
def check_snapshot_queue(maxloop = 0, loop_delay = 5)
$logger.log('d', "[*] [snapshot_manager] starting worker thread")

$vsphere['snapshot_manager'] ||= Vmpooler::VsphereHelper.new $config, $metrics

$threads['snapshot_manager'] = Thread.new do
loop_count = 1
loop do
_check_snapshot_queue $vsphere['snapshot_manager']
sleep(5)
sleep(loop_delay)

unless maxloop.zero?
break if loop_count >= maxloop
loop_count = loop_count + 1
end
end
end
end
Expand Down Expand Up @@ -546,15 +557,21 @@ def migrate_vm_and_record_timing(vm_object, vm_name, pool, host, source_host_nam
finish
end

def check_pool(pool)
def check_pool(pool,maxloop = 0, loop_delay = 5)
$logger.log('d', "[*] [#{pool['name']}] starting worker thread")

$vsphere[pool['name']] ||= Vmpooler::VsphereHelper.new $config, $metrics

$threads[pool['name']] = Thread.new do
loop_count = 1
loop do
_check_pool(pool, $vsphere[pool['name']])
sleep(5)
sleep(loop_delay)

unless maxloop.zero?
break if loop_count >= maxloop
loop_count = loop_count + 1
end
end
end
end
Expand Down Expand Up @@ -714,14 +731,15 @@ def _check_pool(pool, vsphere)
raise
end

def execute!
def execute!(maxloop = 0, loop_delay = 1)
$logger.log('d', 'starting vmpooler')

# Clear out the tasks manager, as we don't know about any tasks at this point
$redis.set('vmpooler__tasks__clone', 0)
# Clear out vmpooler__migrations since stale entries may be left after a restart
$redis.del('vmpooler__migration')

loop_count = 1
loop do
if ! $threads['disk_manager']
check_disk_queue
Expand All @@ -746,7 +764,12 @@ def execute!
end
end

sleep(1)
sleep(loop_delay)

unless maxloop.zero?
break if loop_count >= maxloop
loop_count = loop_count + 1
end
end
end
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit messages make it sound like it should all be test changes but these look like code changes. Is this expected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Perhaps my commit title is misleading.

But in the commit msg itself:

Previously the check_pool method would execute the loop indefinitely as it did not
have a terminating condition.  This made it impossible to test.  This commit
modifies the check_pool method so that it can take a maxloop and delay parameter
so that it can be tested.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, cool. 👍

Expand Down
43 changes: 43 additions & 0 deletions spec/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@ def redis
@redis
end

# Mock an object which is result from Vmpooler::VsphereHelper.find_folder(foldername)
class MockFindFolder
attr_reader :childEntity

def initialize(vmlist = [])
# Generate an array of hashes
@childEntity = vmlist.map do |vm|
vm_object = {}
vm_object['name'] = vm

vm_object
end
end
end

# Mock an object which represents a Logger. This stops the proliferation
# of allow(logger).to .... expectations in tests.
class MockLogger
def log(_level, string)
end
end

def expect_json(ok = true, http = 200)
expect(last_response.header['Content-Type']).to eq('application/json')

Expand Down Expand Up @@ -56,6 +78,18 @@ def create_vm(name, token = nil, redis_handle = nil)
redis_db.hset("vmpooler__vm__#{name}", 'token:token', token) if token
end

def create_completed_vm(name, pool, active = false, redis_handle = nil)
redis_db = redis_handle ? redis_handle : redis
redis_db.sadd("vmpooler__completed__#{pool}", name)
redis_db.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
redis_db.hset("vmpooler__active__#{pool}", name, Time.now) if active
end

def create_discovered_vm(name, pool, redis_handle = nil)
redis_db = redis_handle ? redis_handle : redis
redis_db.sadd("vmpooler__discovered__#{pool}", name)
end

def create_migrating_vm(name, pool, redis_handle = nil)
redis_db = redis_handle ? redis_handle : redis
redis_db.hset("vmpooler__vm__#{name}", 'checkout', Time.now)
Expand All @@ -71,11 +105,20 @@ def fetch_vm(vm)
redis.hgetall("vmpooler__vm__#{vm}")
end

def snapshot_revert_vm(vm, snapshot = '12345678901234567890123456789012')
redis.sadd('vmpooler__tasks__snapshot-revert', "#{vm}:#{snapshot}")
redis.hset("vmpooler__vm__#{vm}", "snapshot:#{snapshot}", "1")
end

def snapshot_vm(vm, snapshot = '12345678901234567890123456789012')
redis.sadd('vmpooler__tasks__snapshot', "#{vm}:#{snapshot}")
redis.hset("vmpooler__vm__#{vm}", "snapshot:#{snapshot}", "1")
end

def disk_task_vm(vm, disk_size = '10')
redis.sadd('vmpooler__tasks__disk', "#{vm}:#{disk_size}")
end

def has_vm_snapshot?(vm)
redis.smembers('vmpooler__tasks__snapshot').any? do |snapshot|
instance, sha = snapshot.split(':')
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading