Skip to content

Commit

Permalink
B OpenNebula#3136: timeout when using cleaunp option
Browse files Browse the repository at this point in the history
    * Increase the default timeout from 10 to 20
    * Add cleanup_timeout parameter to configure it via CLI
  • Loading branch information
Alejandro Huertas committed Mar 28, 2019
1 parent b9fd1e6 commit 0c0b10c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/cli/oneprovision
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ CommandParser::CmdParser.new(ARGV) do
'then delete the resources.'
}

CLEANUP_TIMEOUT = {
:name => 'cleanup_timeout',
:large => '--cleanup_timeout timeout',
:description => 'Change the default timeout when deleting VMs.'
}

INCREMENTAL = {
:name => 'incremental',
:large => '--incremental',
Expand Down Expand Up @@ -266,7 +272,7 @@ CommandParser::CmdParser.new(ARGV) do
command :delete,
provision_delete_desc,
:provisionid,
:options => [MODES, THREADS, CLEANUP] do
:options => [MODES, THREADS, CLEANUP, CLEANUP_TIMEOUT] do
helper.parse_options(options)

helper.delete(args[0], (options.key? :cleanup))
Expand Down
19 changes: 11 additions & 8 deletions src/oneprovision/lib/provision.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def refresh
# Deletes the PROVISION
#
# @param cleanup [Boolean] True to delete running VMs and images
def delete(cleanup = false)
# @param timeout [Integer] Timeout for deleting running VMs
def delete(cleanup = false, timeout = 20)
Utils.fail('Provision not found.') unless exists

if running_vms? && !cleanup
Expand All @@ -74,7 +75,7 @@ def delete(cleanup = false)
Utils.fail('Provision with images can\'t be deleted')
end

delete_vms if cleanup
delete_vms(timeout) if cleanup

delete_images if cleanup

Expand Down Expand Up @@ -417,7 +418,8 @@ def images?
end

# Deletes VMs from the PROVISION
def delete_vms
# @param timeout [Integer] Timeout for deleting running VMs
def delete_vms(timeout)
Driver.retry_loop 'Failed to delete running_vms' do
hosts = []

Expand All @@ -431,7 +433,7 @@ def delete_vms
vm_ids = host.retrieve_elements('VMS/ID')

vm_ids.each do |id|
delete_object('vm', id)
delete_object('vm', id, timeout)
end
end

Expand Down Expand Up @@ -470,9 +472,10 @@ def delete_images

# Deletes an object
#
# @param type [String] Type of the object (vm, image)
# @param id [String] ID of the object
def delete_object(type, id)
# @param type [String] Type of the object (vm, image)
# @param id [String] ID of the object
# @param timeout [Integer] Timeout for deleting running VMs
def delete_object(type, id, timeout)
msg = "Deleting OpenNebula #{type} #{id}"

OneProvision::OneProvisionLogger.debug(msg)
Expand All @@ -490,7 +493,7 @@ def delete_object(type, id)

Utils.exception(object.delete)

Utils.exception(object.wait_state('DONE')) if type == 'vm'
Utils.exception(object.wait_state('DONE', timeout)) if type == 'vm'
end

end
Expand Down

0 comments on commit 0c0b10c

Please sign in to comment.