1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

F #1684: Improve driver error handling

This commit is contained in:
Daniel Clavijo Coca 2018-12-12 05:41:56 -06:00 committed by Ruben S. Montero
parent 5dfc51bae0
commit 79f17288b9
11 changed files with 80 additions and 50 deletions

View File

@ -152,7 +152,7 @@ class Container
# Runs command inside container
# @param command [String] to execute through lxc exec
def exec(command)
Command.lxd_execute(name, command)
Command.lxc_execute(name, command)
end
#---------------------------------------------------------------------------
@ -186,7 +186,7 @@ class Container
nic_xml = @one.get_nic_by_mac(mac)
return unless nic_xml
raise 'Missing NIC xml' unless nic_xml
nic_config = @one.nic(nic_xml)
@ -211,7 +211,8 @@ class Container
return unless @one
@one.get_disks.each do |disk|
setup_disk(disk, operation)
status = setup_disk(disk, operation)
return nil unless status
end
return unless @one.has_context?
@ -224,7 +225,12 @@ class Container
context_path = "#{@one.lxdrc[:containers]}/#{name}/rootfs/context"
create_context_dir = "#{Mapper::COMMANDS[:su_mkdir]} #{context_path}"
Command.execute(create_context_dir, false)
rc, _o, e = Command.execute(create_context_dir, false)
if rc != 0
OpenNebula.log_error("setup_storage: #{e}")
return
end
mapper.public_send(operation, @one, context, csrc)
end
@ -238,9 +244,10 @@ class Container
context = @one.get_context_disk
mapper = FSRawMapper.new
mapper.map(@one, context, csrc)
return unless mapper.map(@one, context, csrc)
update
true
end
# Removes the context section from the LXD configuration and unmap the
@ -263,9 +270,11 @@ class Container
# Attach disk to container (ATTACH = YES) in VM description
def attach_disk(source)
disk_element = hotplug_disk
return unless disk_element
setup_disk(disk_element, 'map')
raise 'Missing hotplug info' unless disk_element
status = setup_disk(disk_element, 'map')
return unless status
source2 = source.dup
if source
@ -278,6 +287,7 @@ class Container
@lxc['devices'].update(disk_hash)
update
true
end
# Detects disk being hotplugged

View File

@ -219,15 +219,16 @@ class Mapper
partitions.sort! { |a,b|
b['mountpoint'].length <=> a['mountpoint'].length
}
umount(partitions)
do_unmap(device, one_vm, disk, real_path)
return unless umount(partitions)
return unless do_unmap(device, one_vm, disk, real_path)
true
end
private
#---------------------------------------------------------------------------
# Methods to mount/umount partitions
#---------------------------------------------------------------------------
@ -238,7 +239,7 @@ class Mapper
partitions.each { |p|
next if !p['mountpoint']
umount_dev(p['path'])
return nil unless umount_dev(p['path'])
}
end
@ -270,7 +271,8 @@ class Mapper
rc, fstab, e = Command.execute(cmd, false)
if fstab.empty?
umount_dev(p['path'])
return false unless umount_dev(p['path'])
next
end
@ -306,11 +308,12 @@ class Mapper
rc = mount_dev(p['path'], path + mount_point)
return false if !rc
break
}
end
return rc
rc
end
# --------------------------------------------------------------------------
@ -333,7 +336,12 @@ class Mapper
cmd = COMMANDS[:mkdir]
end
Command.execute("#{cmd} #{path}", false)
rc, _out, err = Command.execute("#{cmd} #{path}", false)
if rc != 0
OpenNebula.log_error("mount_dev: #{err}")
return false
end
rc, _out, err = Command.execute("#{COMMANDS[:mount]} #{dev} #{path}", true)
@ -350,7 +358,12 @@ class Mapper
def umount_dev(dev)
OpenNebula.log_info "Umounting disk mapped at #{dev}"
Command.execute("#{COMMANDS[:umount]} #{dev}", true)
rc, _o, e = Command.execute("#{COMMANDS[:umount]} #{dev}", true)
return true if rc.zero?
OpenNebula.log_error("umount_dev: #{e}")
nil
end
#---------------------------------------------------------------------------

View File

@ -35,14 +35,14 @@ class Qcow2Mapper < Mapper
ds = one_vm.lxdrc[:datastore_location] + "/#{one_vm.sysds_id}"
File.chmod(0664, dsrc) if File.symlink?(ds)
rc, _out, err = Command.execute(cmd, true)
if rc != 0
if rc != 0
OpenNebula.log_error("do_map: #{err}")
return
end
sleep 0.5 # TODO: improve settledown, lsblk -f fails
device
@ -51,9 +51,12 @@ class Qcow2Mapper < Mapper
def do_unmap(device, one_vm, disk, directory)
cmd = "#{COMMANDS[:nbd]} -d #{device}"
rc, out, err = Command.execute(cmd, true)
rc, _out, err = Command.execute(cmd, true)
OpenNebula.log_error("do_unmap: #{err}") if rc != 0
return true if rc.zero?
OpenNebula.log_error("do_unmap: #{err}")
nil
end
private

View File

@ -31,12 +31,10 @@ class FSRawMapper < Mapper
rc, out, err = Command.execute(cmd, true)
if rc != 0 || out.empty?
OpenNebula.log_error("do_map: #{err}")
return
end
return out.chomp unless rc != 0 || out.empty?
out.chomp
OpenNebula.log_error("do_map: #{err}")
nil
end
def do_unmap(device, one_vm, disk, directory)
@ -44,7 +42,10 @@ class FSRawMapper < Mapper
rc, _out, err = Command.execute(cmd, true)
return true if rc.zero?
OpenNebula.log_error("do_unmap: #{err}") if rc != 0
nil
end
end
@ -78,10 +79,11 @@ class DiskRawMapper < Mapper
dsrc = disk_source(one_vm, disk)
cmd = "#{COMMANDS[:kpartx]} -d #{dsrc}"
rc, out, err = Command.execute(cmd, true)
rc, _out, err = Command.execute(cmd, true)
if rc != 0
OpenNebula.log_error("do_unmap: #{err}")
end
return true if rc.zero?
OpenNebula.log_error("do_unmap: #{err}")
nil
end
end

View File

@ -39,12 +39,10 @@ class RBDMapper < Mapper
rc, out, err = Command.execute(cmd, false)
if rc != 0
OpenNebula.log_error("do_map: #{err}")
return
end
return out.chomp if rc.zero?
out.chomp
OpenNebula.log_error("do_map: #{err}")
nil
end
def do_unmap(device, one_vm, disk, directory)
@ -52,9 +50,9 @@ class RBDMapper < Mapper
rc, _out, err = Command.execute(cmd, false)
if rc != 0
OpenNebula.log_error("do_map: #{err}")
return
end
return true if rc.zero?
OpenNebula.log_error("do_unmap: #{err}")
nil
end
end

View File

@ -37,4 +37,4 @@ xml = STDIN.read
client = LXDClient.new
container = Container.get(vm_name, xml, client)
container.attach_disk(image_path)
raise 'failed to attach disk' unless container.attach_disk(image_path)

View File

@ -68,12 +68,15 @@ end
if container.wild?
container.start
else
container.setup_storage('map')
mapped = container.setup_storage('map')
raise 'failed to setup container storage' unless mapped
if container.start != 'Running'
OpenNebula.log_error('Container failed to start')
container.setup_storage('unmap')
deleted = container.setup_storage('unmap')
raise 'failed to dismantle container storage' unless deleted
container.delete
raise LXDError, container.status

View File

@ -35,4 +35,4 @@ xml = STDIN.read
client = LXDClient.new
container = Container.get(vm_name, xml, client)
container.detach_disk
raise 'failed to detach disk' unless container.detach_disk

View File

@ -36,4 +36,4 @@ xml = STDIN.read
client = LXDClient.new
container = Container.get(vm_name, xml, client)
container.detach_context
raise 'Failed to detach context' unless container.detach_context

View File

@ -38,6 +38,8 @@ if iso_path != ''
client = LXDClient.new
container = Container.get(vm_name, xml, client)
container.attach_context
container.exec('one-contextd local 2>/dev/null')
raise 'Failed to attach context' unless container.attach_context
rc, _out, err = container.exec('one-contextd local 2>/dev/null')
raise err unless rc.zero?
end

View File

@ -43,11 +43,10 @@ else
end
if !container.wild?
begin
container.setup_storage('unmap')
rescue StandardError => e
unmapped = container.setup_storage('unmap')
unless unmapped
container.start
raise e
raise 'Failed to dismantle container storage'
end
container.delete