Remove unnecessary rescue

This commit removes an unnecessary rescue that results in duplicate clone error messages. Without this change clone failures due to unavailable host resources are logged twice. A log message is added to specify the host the VM is running on when migration_limit is not set and migration is disabled. Lastly, when a migration fails it reports the host the VM is running on in addition to the reason for the failed migration.
This commit is contained in:
kirby@puppetlabs.com 2017-11-06 11:24:35 -08:00 committed by mattkirby
parent 82b9033e83
commit 048ab4433a
2 changed files with 26 additions and 23 deletions

View file

@ -224,10 +224,9 @@ module Vmpooler
$logger.log('s', "[+] [#{pool_name}] '#{new_vmname}' cloned in #{finish} seconds") $logger.log('s', "[+] [#{pool_name}] '#{new_vmname}' cloned in #{finish} seconds")
$metrics.timing("clone.#{pool_name}", finish) $metrics.timing("clone.#{pool_name}", finish)
rescue => err rescue => _err
$logger.log('s', "[!] [#{pool_name}] '#{new_vmname}' clone failed with an error: #{err}")
$redis.srem('vmpooler__pending__' + pool_name, new_vmname) $redis.srem('vmpooler__pending__' + pool_name, new_vmname)
raise raise _err
ensure ensure
$redis.decr('vmpooler__tasks__clone') $redis.decr('vmpooler__tasks__clone')
end end
@ -712,9 +711,6 @@ module Vmpooler
end end
pool_check_response pool_check_response
rescue => err
$logger.log('d', "[!] [#{pool['name']}] _check_pool failed with an error: #{err}")
raise
end end
# Create a provider object, usually based on the providers/*.rb class, that implements providers/base.rb # Create a provider object, usually based on the providers/*.rb class, that implements providers/base.rb

View file

@ -122,7 +122,7 @@ module Vmpooler
dc = "#{datacenter}_#{cluster}" dc = "#{datacenter}_#{cluster}"
@provider_hosts_lock.synchronize do @provider_hosts_lock.synchronize do
if architecture if architecture
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('architectures') raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('architectures')
host = target[dc]['architectures'][architecture].shift host = target[dc]['architectures'][architecture].shift
target[dc]['architectures'][architecture] << host target[dc]['architectures'][architecture] << host
if target[dc]['hosts'].include?(host) if target[dc]['hosts'].include?(host)
@ -131,7 +131,7 @@ module Vmpooler
end end
return host return host
else else
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts') raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts')
host = target[dc]['hosts'].shift host = target[dc]['hosts'].shift
target[dc]['hosts'] << host target[dc]['hosts'] << host
target[dc]['architectures'].each do |arch| target[dc]['architectures'].each do |arch|
@ -150,7 +150,7 @@ module Vmpooler
raise("cluster for pool #{pool_name} cannot be identified") if cluster.nil? raise("cluster for pool #{pool_name} cannot be identified") if cluster.nil?
raise("datacenter for pool #{pool_name} cannot be identified") if datacenter.nil? raise("datacenter for pool #{pool_name} cannot be identified") if datacenter.nil?
dc = "#{datacenter}_#{cluster}" dc = "#{datacenter}_#{cluster}"
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts') raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory") unless target[dc].key?('hosts')
return true if target[dc]['architectures'][architecture].include?(parent_host) return true if target[dc]['architectures'][architecture].include?(parent_host)
return false return false
end end
@ -699,7 +699,7 @@ module Vmpooler
cluster_object = find_cluster(cluster, connection, datacentername) cluster_object = find_cluster(cluster, connection, datacentername)
raise("Cluster #{cluster} cannot be found") if cluster_object.nil? raise("Cluster #{cluster} cannot be found") if cluster_object.nil?
target_hosts = get_cluster_host_utilization(cluster_object) target_hosts = get_cluster_host_utilization(cluster_object)
raise("there is no candidate in vcenter that meets all the required conditions, that that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory'") if target_hosts.nil? raise("there is no candidate in vcenter that meets all the required conditions, that the cluster has available hosts in a 'green' status, not in maintenance mode and not overloaded CPU and memory'") if target_hosts.empty?
architectures = build_compatible_hosts_lists(target_hosts, percentage) architectures = build_compatible_hosts_lists(target_hosts, percentage)
least_used_hosts = select_least_used_hosts(target_hosts, percentage) least_used_hosts = select_least_used_hosts(target_hosts, percentage)
{ {
@ -892,21 +892,28 @@ module Vmpooler
def migrate_vm(pool_name, vm_name) def migrate_vm(pool_name, vm_name)
@connection_pool.with_metrics do |pool_object| @connection_pool.with_metrics do |pool_object|
connection = ensured_vsphere_connection(pool_object) begin
vm_hash = get_vm_details(vm_name, connection) connection = ensured_vsphere_connection(pool_object)
migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit') vm_hash = get_vm_details(vm_name, connection)
migration_count = $redis.scard('vmpooler__migration') migration_limit = @config[:config]['migration_limit'] if @config[:config].key?('migration_limit')
if migration_enabled? @config migration_count = $redis.scard('vmpooler__migration')
if migration_count >= migration_limit if migration_enabled? @config
logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}. No migration will be evaluated since the migration_limit has been reached") if migration_count >= migration_limit
return logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}. No migration will be evaluated since the migration_limit has been reached")
end return
run_select_hosts(pool_name, @provider_hosts) end
if vm_in_target?(pool_name, vm_hash['host_name'], vm_hash['architecture'], @provider_hosts) run_select_hosts(pool_name, @provider_hosts)
logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{vm_hash['host_name']}") if vm_in_target?(pool_name, vm_hash['host_name'], vm_hash['architecture'], @provider_hosts)
logger.log('s', "[ ] [#{pool_name}] No migration required for '#{vm_name}' running on #{vm_hash['host_name']}")
else
migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection)
end
else else
migrate_vm_to_new_host(pool_name, vm_name, vm_hash, connection) logger.log('s', "[ ] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}")
end end
rescue => _err
logger.log('s', "[!] [#{pool_name}] '#{vm_name}' is running on #{vm_hash['host_name']}")
raise _err
end end
end end
end end