mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-19 06:50:07 +03:00
B#3098: Fix LXD storage errors on deploy start action error handling (#3100)
(cherry picked from commit a07c2014da389eeb2213de4ffd6e3d32e815d2a1)
This commit is contained in:
parent
6f95aa9e8a
commit
5fb69330f3
@ -94,7 +94,7 @@ class LXDClient
|
||||
def wait(response, timeout)
|
||||
operation_id = response['operation'].split('/').last
|
||||
|
||||
timeout = "?timeout=#{timeout}" if timeout
|
||||
timeout = "?timeout=#{timeout}" if [nil, ''].include?(timeout)
|
||||
|
||||
response = get("operations/#{operation_id}/wait#{timeout}")
|
||||
|
||||
@ -142,13 +142,17 @@ end
|
||||
# Error used for raising LXDClient exception when response is error return value
|
||||
class LXDError < StandardError
|
||||
|
||||
attr_reader :body, :error, :error_code, :type
|
||||
attr_reader :body, :error, :code, :type
|
||||
|
||||
def initialize(msg = 'LXD API error')
|
||||
@body = msg
|
||||
def initialize(response)
|
||||
raise "Got wrong argument class: #{response.class}, expecting Hash" \
|
||||
unless response.class == Hash
|
||||
|
||||
@body = response
|
||||
@code = @body['error_code']
|
||||
@type = @body['type']
|
||||
@error = @body['error']
|
||||
@error_code = @body['error_code']
|
||||
@type = @body['type']
|
||||
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -88,8 +88,6 @@ class Container
|
||||
one = OpenNebulaVM.new(one_xml) if one_xml
|
||||
|
||||
Container.new(info, one, client)
|
||||
rescue LXDError => exception
|
||||
raise exception
|
||||
end
|
||||
|
||||
# Creates container from a OpenNebula VM xml description
|
||||
@ -112,12 +110,12 @@ class Container
|
||||
containers
|
||||
end
|
||||
|
||||
# Returns boolean indicating if the container exists(true) or not (false)
|
||||
# Returns boolean indicating the container exists(true) or not (false)
|
||||
def exist?(name, client)
|
||||
client.get("#{CONTAINERS}/#{name}")
|
||||
true
|
||||
rescue LXDError => exception
|
||||
raise exception if exception.body['error_code'] != 404
|
||||
rescue LXDError => e
|
||||
raise e if e.code != 404
|
||||
|
||||
false
|
||||
end
|
||||
@ -234,7 +232,7 @@ class Container
|
||||
return nil unless status
|
||||
end
|
||||
|
||||
return 'no context' unless @one.has_context?
|
||||
return true unless @one.has_context?
|
||||
|
||||
csrc = @lxc['devices']['context']['source'].clone
|
||||
|
||||
@ -271,7 +269,7 @@ class Container
|
||||
# Removes the context section from the LXD configuration and unmap the
|
||||
# context device
|
||||
def detach_context
|
||||
return 'no context' unless @one.has_context?
|
||||
return true unless @one.has_context?
|
||||
|
||||
csrc = @lxc['devices']['context']['source'].clone
|
||||
|
||||
|
@ -357,7 +357,7 @@ class OpenNebulaVM
|
||||
begin
|
||||
LXDClient.new.get("profiles/#{profile}")
|
||||
rescue LXDError => e
|
||||
raise e unless e.error_code == 404
|
||||
raise e unless e.code == 404
|
||||
|
||||
OpenNebula.log_error "Profile \"#{profile}\" not found\n#{e}"
|
||||
profile = 'default'
|
||||
|
@ -51,7 +51,7 @@ if Container.exist?(container.name, client)
|
||||
container.get_metadata
|
||||
|
||||
err_msg = 'A container with the same ID is already running'
|
||||
raise LXDError, err_msg if container.status == 'Running'
|
||||
raise err_msg if container.status == 'Running'
|
||||
|
||||
container.config = config
|
||||
|
||||
@ -74,7 +74,9 @@ else
|
||||
begin
|
||||
operation = container.start
|
||||
raise operation if container.status != 'Running'
|
||||
rescue LXDError => exception
|
||||
rescue StandardError => exception
|
||||
# TODO: Improve wait condition
|
||||
sleep 5 # Wait for LXD to revert non-rootfs disks mountpoint
|
||||
storage_deleted = container.setup_storage('unmap')
|
||||
|
||||
if storage_deleted
|
||||
@ -83,7 +85,7 @@ else
|
||||
OpenNebula.log_error 'failed to dismantle container storage'
|
||||
end
|
||||
|
||||
raise LXDError, exception
|
||||
raise exception
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user