mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
(POOLER-52) Modify dummy provider to use a connection pool
Previously a connection pooler class was added. This commit modifies the Dummy VM Provider to use a connection pooler. While the Dummy provider strictly speaking does not use connections, this allows testing to see what happens when connection pools are stressed or exhausted. This commit: - Modifies functions to use a connection pool object for the public API functions - Modifies the VMPooler YAML with new settings for connection pool size and timeout
This commit is contained in:
parent
888ffc4afc
commit
2f37c1e9b5
3 changed files with 222 additions and 172 deletions
|
|
@ -19,6 +19,22 @@ module Vmpooler
|
|||
# duplicate actions to put the @dummylist hashtable into a bad state, for example;
|
||||
# Deleting a VM while it's in the middle of adding a disk.
|
||||
@write_lock = Mutex.new
|
||||
|
||||
# Create a dummy connection pool
|
||||
connpool_size = provider_config['connection_pool_size'].nil? ? 1 : provider_config['connection_pool_size'].to_i
|
||||
connpool_timeout = provider_config['connection_pool_timeout'].nil? ? 10 : provider_config['connection_pool_timeout'].to_i
|
||||
logger.log('d', "[#{name}] ConnPool - Creating a connection pool of size #{connpool_size} with timeout #{connpool_timeout}")
|
||||
@connection_pool = Vmpooler::PoolManager::GenericConnectionPool.new(
|
||||
metrics: metrics,
|
||||
metric_prefix: "#{name}_provider_connection_pool",
|
||||
size: connpool_size,
|
||||
timeout: connpool_timeout
|
||||
) do
|
||||
# Create a mock connection object
|
||||
new_conn = { create_timestamp: Time.now, conn_id: rand(2048).to_s }
|
||||
logger.log('d', "[#{name}] ConnPool - Creating a connection object ID #{new_conn[:conn_id]}")
|
||||
new_conn
|
||||
end
|
||||
end
|
||||
|
||||
def name
|
||||
|
|
@ -27,21 +43,30 @@ module Vmpooler
|
|||
|
||||
def vms_in_pool(pool_name)
|
||||
vmlist = []
|
||||
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
get_dummy_pool_object(pool_name).each do |vm|
|
||||
vmlist << { 'name' => vm['name'] }
|
||||
end
|
||||
end
|
||||
|
||||
vmlist
|
||||
end
|
||||
|
||||
def get_vm_host(pool_name, vm_name)
|
||||
current_vm = nil
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
current_vm = get_dummy_vm(pool_name, vm_name)
|
||||
end
|
||||
|
||||
current_vm.nil? ? raise("VM #{vm_name} does not exist") : current_vm['vm_host']
|
||||
end
|
||||
|
||||
def find_least_used_compatible_host(pool_name, vm_name)
|
||||
current_vm = nil
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
current_vm = get_dummy_vm(pool_name, vm_name)
|
||||
end
|
||||
|
||||
# Unless migratevm_couldmove_percent is specified, don't migrate
|
||||
return current_vm['vm_host'] if provider_config['migratevm_couldmove_percent'].nil?
|
||||
|
|
@ -56,6 +81,7 @@ module Vmpooler
|
|||
end
|
||||
|
||||
def migrate_vm_to_host(pool_name, vm_name, dest_host_name)
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
current_vm = get_dummy_vm(pool_name, vm_name)
|
||||
|
||||
# Inject migration delay
|
||||
|
|
@ -74,11 +100,14 @@ module Vmpooler
|
|||
current_vm['vm_host'] = dest_host_name
|
||||
write_backing_file
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def get_vm(pool_name, vm_name)
|
||||
obj = {}
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
dummy = get_dummy_vm(pool_name, vm_name)
|
||||
return nil if dummy.nil?
|
||||
|
||||
|
|
@ -106,7 +135,6 @@ module Vmpooler
|
|||
end
|
||||
end
|
||||
|
||||
obj = {}
|
||||
obj['name'] = dummy['name']
|
||||
obj['hostname'] = dummy['hostname']
|
||||
obj['boottime'] = dummy['boottime']
|
||||
|
|
@ -114,6 +142,7 @@ module Vmpooler
|
|||
obj['poolname'] = dummy['poolname']
|
||||
obj['powerstate'] = dummy['powerstate']
|
||||
obj['snapshots'] = dummy['snapshots']
|
||||
end
|
||||
|
||||
obj
|
||||
end
|
||||
|
|
@ -150,6 +179,7 @@ module Vmpooler
|
|||
|
||||
logger.log('d', "[ ] [#{pool_name}] '#{dummy_hostname}' is being cloned from '#{template_name}'")
|
||||
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
# Inject clone time delay
|
||||
unless provider_config['createvm_max_time'].nil?
|
||||
@write_lock.synchronize do
|
||||
|
|
@ -178,11 +208,13 @@ module Vmpooler
|
|||
end
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
get_vm(pool_name, dummy_hostname)
|
||||
end
|
||||
|
||||
def create_disk(pool_name, vm_name, disk_size)
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
vm_object = get_dummy_vm(pool_name, vm_name)
|
||||
raise("VM #{vm_name} does not exist in Pool #{pool_name} for the provider #{name}") if vm_object.nil?
|
||||
|
||||
|
|
@ -202,11 +234,13 @@ module Vmpooler
|
|||
vm_object['disks'] << disk_size
|
||||
write_backing_file
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def create_snapshot(pool_name, vm_name, snapshot_name)
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
vm_object = get_dummy_vm(pool_name, vm_name)
|
||||
raise("VM #{vm_name} does not exist in Pool #{pool_name} for the provider #{name}") if vm_object.nil?
|
||||
|
||||
|
|
@ -226,11 +260,14 @@ module Vmpooler
|
|||
vm_object['snapshots'] << snapshot_name
|
||||
write_backing_file
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def revert_snapshot(pool_name, vm_name, snapshot_name)
|
||||
vm_object = nil
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
vm_object = get_dummy_vm(pool_name, vm_name)
|
||||
raise("VM #{vm_name} does not exist in Pool #{pool_name} for the provider #{name}") if vm_object.nil?
|
||||
|
||||
|
|
@ -244,11 +281,13 @@ module Vmpooler
|
|||
unless provider_config['revertsnapshot_fail_percent'].nil?
|
||||
raise('Dummy Failure for revertsnapshot_fail_percent') if 1 + rand(100) <= provider_config['revertsnapshot_fail_percent']
|
||||
end
|
||||
end
|
||||
|
||||
vm_object['snapshots'].include?(snapshot_name)
|
||||
end
|
||||
|
||||
def destroy_vm(pool_name, vm_name)
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
vm = get_dummy_vm(pool_name, vm_name)
|
||||
return false if vm.nil?
|
||||
return false if vm['poolname'] != pool_name
|
||||
|
|
@ -286,11 +325,13 @@ module Vmpooler
|
|||
remove_dummy_vm(pool_name, vm_name)
|
||||
write_backing_file
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def vm_ready?(pool_name, vm_name)
|
||||
@connection_pool.with_metrics do |_conn|
|
||||
vm_object = get_dummy_vm(pool_name, vm_name)
|
||||
return false if vm_object.nil?
|
||||
return false if vm_object['poolname'] != pool_name
|
||||
|
|
@ -317,6 +358,7 @@ module Vmpooler
|
|||
vm_object['ready'] = true
|
||||
write_backing_file
|
||||
end
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -76,11 +76,11 @@ describe 'Vmpooler::PoolManager::Provider::Dummy' do
|
|||
let(:config) { YAML.load(<<-EOT
|
||||
---
|
||||
:config:
|
||||
max_tries: 3
|
||||
retry_factor: 10
|
||||
:providers:
|
||||
:dummy:
|
||||
key1: 'value1'
|
||||
# Drop the connection pool timeout way down for spec tests so they fail fast
|
||||
connection_pool_timeout: 1
|
||||
:pools:
|
||||
- name: '#{pool_name}'
|
||||
size: 5
|
||||
|
|
|
|||
|
|
@ -50,6 +50,14 @@
|
|||
# The filename used to store the backing text file. If this is not specified the VM state is only
|
||||
# kept in memory, and is lost when the Provider is shutdown
|
||||
#
|
||||
# - connection_pool_size (Optional)
|
||||
# The size of the dummy connection pool. This can be used to simulate constrained provider resources e.g. 200 pools sharing on connection
|
||||
# (optional; default 1)
|
||||
#
|
||||
# - connection_pool_timeout (Optional)
|
||||
# The number of seconds to wait for a connection object from the pool. If the timeout is exceeded an error is raised
|
||||
# (optional; default 10 seconds)
|
||||
#
|
||||
# - migratevm_couldmove_percent
|
||||
# Percent chance that a VM could be moved to another host
|
||||
# (optional; default 0%)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue