Erase non-root disks first
This change adjusts the order that the system block devices (disks) are erased as part erase_node MCollective action. This change queries the block devices for the system and uses lsblk to determine if the device has a partition that is currently being used for mounting /. The disks that are not used for / are erased first, followed by the root disks. This done to ensure that data disks are properly cleaned up and are not accidentally left intact on the chance that purging the root disk causes the erase script to fail. Change-Id: I17e0e88224ef781b666b100f80904e5abfecd023 Closes-Bug: 1437511
This commit is contained in:
parent
c1793f982f
commit
53aee4a491
|
@ -44,8 +44,6 @@ module MCollective
|
|||
|
||||
prevent_discover unless dry_run
|
||||
|
||||
tempfile_storage='/mnt/tempfiles'
|
||||
|
||||
begin
|
||||
reboot if !dry_run && request_reboot
|
||||
reply[:rebooted] = request_reboot
|
||||
|
@ -62,12 +60,17 @@ module MCollective
|
|||
end
|
||||
end
|
||||
|
||||
def get_boot_devices
|
||||
def get_devices(type='all')
|
||||
raise "Path /sys/block does not exist" unless File.exists?("/sys/block")
|
||||
Dir["/sys/block/*"].inject([]) do |blocks, block_device_dir|
|
||||
basename_dir = File.basename(block_device_dir)
|
||||
dev_name = basename_dir.gsub(/!/, '/')
|
||||
major = `udevadm info --query=property --name=#{dev_name} | grep MAJOR`.strip.split(/\=/)[-1]
|
||||
dev_info = {}
|
||||
# Query device info from udev
|
||||
`udevadm info --query=property --name=#{dev_name}`.strip.split.each do |line|
|
||||
key, value = line.chomp.split(/\=/)
|
||||
dev_info[key.to_sym] = value
|
||||
end
|
||||
if File.exists?("/sys/block/#{basename_dir}/removable")
|
||||
removable = File.open("/sys/block/#{basename_dir}/removable") { |f| f.read_nonblock(1024).strip }
|
||||
end
|
||||
|
@ -78,8 +81,16 @@ module MCollective
|
|||
debug_msg("Can not define device size. File /sys/block/#{basename_dir}/size not found.")
|
||||
end
|
||||
|
||||
if STORAGE_CODES.include?(major.to_i) && removable =~ /^0$/
|
||||
blocks << {:name => dev_name, :size => size}
|
||||
# Check device major number against our storage code list and exclude
|
||||
# removable devices
|
||||
if STORAGE_CODES.include?(dev_info[:MAJOR].to_i) && removable =~ /^0$/
|
||||
device_root_count = `lsblk -n -r "#{dev_info[:DEVNAME]}" | grep -c '\ /$'`.to_i
|
||||
# determine if the block device should be returned basked on the
|
||||
# requested type
|
||||
if (type.eql? 'all') or (type.eql? 'root' and device_root_count > 0) or (type.eql? 'data' and device_root_count == 0)
|
||||
debug_msg("get_devices(type=#{type}): adding #{dev_name}")
|
||||
blocks << {:name => dev_name, :size => size}
|
||||
end
|
||||
end
|
||||
blocks
|
||||
end
|
||||
|
@ -106,7 +117,9 @@ module MCollective
|
|||
end
|
||||
|
||||
begin
|
||||
get_boot_devices.each do |dev|
|
||||
# Delete data disks first, then OS drive to address bug #1437511
|
||||
(get_devices(type='data') + get_devices(type='root')).each do |dev|
|
||||
debug_msg("erasing #{dev[:name]}")
|
||||
erase_partitions(dev[:name])
|
||||
erase_data(dev[:name])
|
||||
erase_data(dev[:name], 1, dev[:size], '512')
|
||||
|
@ -121,6 +134,7 @@ module MCollective
|
|||
error_msg << msg
|
||||
end
|
||||
|
||||
# Reboot the system
|
||||
['b'].each do |req|
|
||||
File.open('/proc/sysrq-trigger','w') do |file|
|
||||
file.write("#{req}\n")
|
||||
|
|
Loading…
Reference in New Issue