mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 10:28:41 -05:00
(MOB) cleared up some tests
helped some repopulate tests, needed refactoring for the clone_vm method which broke its own tests. Yay
This commit is contained in:
parent
6449f1aab1
commit
1c8728b9b2
2 changed files with 12 additions and 17 deletions
|
|
@ -210,20 +210,18 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clone a VM
|
# Clone a VM
|
||||||
def clone_vm(pool, provider)
|
def clone_vm(pool_name, provider)
|
||||||
Thread.new do
|
Thread.new do
|
||||||
begin
|
begin
|
||||||
_clone_vm(pool, provider)
|
_clone_vm(pool_name, provider)
|
||||||
rescue => err
|
rescue => err
|
||||||
$logger.log('s', "[!] [#{pool['name']}] failed while cloning VM with an error: #{err}")
|
$logger.log('s', "[!] [#{pool_name}] failed while cloning VM with an error: #{err}")
|
||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def _clone_vm(pool, provider)
|
def _clone_vm(pool_name, provider)
|
||||||
pool_name = pool['name']
|
|
||||||
|
|
||||||
# Generate a randomized hostname
|
# Generate a randomized hostname
|
||||||
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
|
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
|
||||||
new_vmname = $config[:config]['prefix'] + o[rand(25)] + (0...14).map { o[rand(o.length)] }.join
|
new_vmname = $config[:config]['prefix'] + o[rand(25)] + (0...14).map { o[rand(o.length)] }.join
|
||||||
|
|
@ -842,7 +840,7 @@ module Vmpooler
|
||||||
begin
|
begin
|
||||||
$redis.incr('vmpooler__tasks__clone')
|
$redis.incr('vmpooler__tasks__clone')
|
||||||
pool_check_response[:cloned_vms] += 1
|
pool_check_response[:cloned_vms] += 1
|
||||||
clone_vm(pool, provider)
|
clone_vm(pool_name, provider)
|
||||||
rescue => err
|
rescue => err
|
||||||
$logger.log('s', "[!] [#{pool_name}] clone failed during check_pool with an error: #{err}")
|
$logger.log('s', "[!] [#{pool_name}] clone failed during check_pool with an error: #{err}")
|
||||||
$redis.decr('vmpooler__tasks__clone')
|
$redis.decr('vmpooler__tasks__clone')
|
||||||
|
|
|
||||||
|
|
@ -3090,9 +3090,6 @@ EOT
|
||||||
---
|
---
|
||||||
:config:
|
:config:
|
||||||
task_limit: 10
|
task_limit: 10
|
||||||
:pools:
|
|
||||||
- name: #{pool}
|
|
||||||
size: #{pool_size}
|
|
||||||
EOT
|
EOT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -3113,28 +3110,28 @@ EOT
|
||||||
create_ready_vm(pool,vm,token)
|
create_ready_vm(pool,vm,token)
|
||||||
expect(subject).to receive(:clone_vm).exactly(0).times
|
expect(subject).to receive(:clone_vm).exactly(0).times
|
||||||
|
|
||||||
subject._check_pool(pool_object,provider)
|
subject.repopulate_pool_vms(pool, provider, pool_check_response, pool_size)
|
||||||
end
|
end
|
||||||
|
|
||||||
['ready','pending'].each do |queue_name|
|
['ready','pending'].each do |queue_name|
|
||||||
it "should use VMs in #{queue_name} queue to caculate pool size" do
|
it "should use VMs in #{queue_name} queue to calculate pool size" do
|
||||||
expect(subject).to receive(:clone_vm).exactly(0).times
|
expect(subject).to receive(:clone_vm).exactly(0).times
|
||||||
# Modify the pool size to 1 and add a VM in the queue
|
# Modify the pool size to 1 and add a VM in the queue
|
||||||
redis.sadd("vmpooler__#{queue_name}__#{pool}",vm)
|
redis.sadd("vmpooler__#{queue_name}__#{pool}",vm)
|
||||||
config[:pools][0]['size'] = 1
|
pool_size = 1
|
||||||
|
|
||||||
subject._check_pool(pool_object,provider)
|
subject.repopulate_pool_vms(pool, provider, pool_check_response, pool_size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
['running','completed','discovered','migrating'].each do |queue_name|
|
['running','completed','discovered','migrating'].each do |queue_name|
|
||||||
it "should not use VMs in #{queue_name} queue to caculate pool size" do
|
it "should not use VMs in #{queue_name} queue to calculate pool size" do
|
||||||
expect(subject).to receive(:clone_vm)
|
expect(subject).to receive(:clone_vm)
|
||||||
# Modify the pool size to 1 and add a VM in the queue
|
# Modify the pool size to 1 and add a VM in the queue
|
||||||
redis.sadd("vmpooler__#{queue_name}__#{pool}",vm)
|
redis.sadd("vmpooler__#{queue_name}__#{pool}",vm)
|
||||||
config[:pools][0]['size'] = 1
|
pool_size = 1
|
||||||
|
|
||||||
subject._check_pool(pool_object,provider)
|
subject.repopulate_pool_vms(pool, provider, pool_check_response, pool_size)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue