Skip to content

Commit

Permalink
Impliment error reporting with debug information using fpaste URL
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkasun committed Jun 23, 2014
1 parent c4bf804 commit cecf652
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 44 deletions.
13 changes: 10 additions & 3 deletions app/models/disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ def unmount

# Delete all excisting partitions and create one partition from entire device/disk
def full_format fstype, label = nil
DebugLogger.info "class = #{self.class.name}, method = #{__method__}"
delete_all_partitions unless partitions.blank?
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Creating partition #{self.kname}"
Diskwz.create_partition self, 1, -1
new_partition = Disk.find self.kname + "1"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Find partition #{@kname}"
new_partition = Disk.find @kname + "1"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Formating #{@kname} to #{fstype}"
new_partition.format fstype
end

Expand All @@ -148,20 +152,23 @@ def format_to filesystem_type
end

def format_job params_hash
puts "DEBUG:********** format_job params_hash #{params_hash}"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Params_hash #{params_hash}"
new_fstype = params_hash[:fs_type]
Disk.progress = 10
puts "DEBUG:*********** umount @path umount #{self.path}"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Create partition_table #{partition_table}"
#TODO: check the disk size and pass the relevent partition table type (i.e. if device size >= 3TB create GPT table else MSDOS(MBR))
create_partition_table unless partition_table
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Full format label #{params_hash['label']}"
full_format new_fstype, params_hash['label']
Disk.progress = 40
end

def mount_job params_hash
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Params_hash #{params_hash}"
Disk.progress = 60
kname = @kname
label = params_hash['label'] || kname
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:New partition Label #{label}"
new_partition = Disk.find kname + "1"
new_partition.mount label
Disk.progress = 80
Expand Down
8 changes: 5 additions & 3 deletions app/models/job_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ def reset
def process_queue disk
while(not self.empty?)
job = self.dequeue
puts "DEBUG:******* job[:job_name] = #{job[:job_name]} job[:job_para] = $ #{job[:job_para]}"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:job[:job_name] = #{job[:job_name]} job[:job_para] = #{job[:job_para]}"
begin
disk.send(job[:job_name],job[:job_para])
rescue => exception
puts "DEBUG:*** JOB FAILS #{exception.inspect}"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:JOB FAILS #{exception.inspect}"
if DiskCommand.debug_mode
DiskCommand.operations_log << {name: 'exception', message: exception.inspect}
last_command = @@operations_log.last
last_command[:exception] = exception.inspect
DebugLogger.info "Exception: #{exception.inspect}"
next
else
return exception
Expand Down
4 changes: 2 additions & 2 deletions app/models/partition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def partition_number
# Return the `Disk` object of which this Partition belongs to
def get_disk
#Strip partition number
#puts "@kname = #{@kname}"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:@Kname = #{@kname}"
disk_kname = @kname.gsub(/[0-9]/, "")
#puts "disk_kname = #{disk_kname}"
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Disk_kname = #{disk_kname}"
disk = Disk.find disk_kname
return disk
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/disk_wizards/confirmation.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
$(function() {
$('#debug').tooltip()
$('#debug').tooltip();
});
</script>
<%= render 'shared/header' %>
Expand Down
68 changes: 66 additions & 2 deletions app/views/disk_wizards/done.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
<%= render 'shared/header' %>
<script>

function getDebugURL() {
$.getJSON("<%= defined?(disk_wizards_engine) ? disk_wizards_engine.debug_info_path : debug_info_path %>",function(data) {
if(data["error"]){
alert("An error occourd while generating debug_info paste:\n\n"+data['error']);
return 0
}
$("#fpaste_url").attr("value",data['url']);
$('#debug_info').slideDown();
});
}
$(function() {
$('#fpaste_url').tooltip();
var $loading = $('#fpaste_loading').hide();
$(document).ajaxStart(function() {
$loading.show();
}).ajaxStop(function() {
$loading.hide();
});
});
</script>
<style>
/*
* Fix for conflicts with platform CSS
*/
input[type="text"]{
border: 1px solid #d0cece;
height: auto;
width: 100%;
padding: auto;
background: white;
font-size: large;
</style>
<div class="row">
<br />
<% if user_selections['debug'] %>
Expand Down Expand Up @@ -78,9 +112,39 @@
</tbody>
</table>
<% end %>
<div class="col-md-6 col-md-offset-3 well well-sm">
<div class="col-md-8 col-md-offset-2 well well-sm">
<a href="/tab/disks/disk_wizards" class="btn btn-success"> Continue with another device </a>
<button onclick="getDebugURL();" id="get_debug_info" class="btn btn-warning">
Get Debug infomation
</button>
</div>
</div>
<div id="fpaste_loading" class="col-md-8 col-md-offset-2">
<%= image_tag "disk_wizard/progress.gif"%>
<p class="text-primary"><span class="glyphicon glyphicon-time"></span> Please wait.Generating fpaste URL.......</p>
</div>
<div id="debug_info" style="display: none;" class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<form class="form-inline" role="form">
<div class="form-group has-success has-feedback">
<label class="control-label" for="fpaste_url">URL: <span class="glyphicon glyphicon-globe"></span></label>
<input id="fpaste_url" style="width: 500px;" onclick="$(this).select();" data-toggle="tooltip" data-placement="top" title="Press Ctrl+c to coppy URL to clipboard" class="form-control" id="focusedInput" type="text" placeholder="Generating URL.." autocomplete="off">
<span class="glyphicon glyphicon-ok form-control-feedback"></span>
</div>
</form>
<div class="panel-body text-left">
<p class="text-primary">
After generating your paste, copy the generated url below.
</p>
<p class="text-primary">
Head over to the Amahi IRC channel, and share your link with one of the helpful folks there.
</p>
<p class="text-info">
Good Luck! Thanks for choosing Amahi.
</p>
</div>
</div>
</div>
</div>
<%= render 'shared/footer' %>
</div>
<%= render 'shared/footer' %>
6 changes: 2 additions & 4 deletions app/views/disk_wizards/manage_disk.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= form_tag(defined?(disk_wizards_engine) ? disk_wizards_engine.confirmation_path : confirmation_path ,{method: "POST",id:"options"}) %>
<%= hidden_field_tag 'device', user_selections['kname'] %>
<div class="row">
<% "*****************#{user_selections}"%>
<% "*#{user_selections}"%>
<div class="col-md-5 col-md-offset-3 well">
<ul class="list-group">
<li class="list-group-item list-group-item-success">
Expand All @@ -14,9 +14,7 @@
<div class="checkbox">
<label> <%= check_box_tag('option[]',1,!!((user_selections['option'].include? '1') rescue false)) %>
<div class="alert alert-info">
Mount this drive automatically, Your drive will be available in /var/hda/files/drives/drive#
You will then be able to <a href="#" class="alert-link">create new share</a> in this directory to use this drive

Mount this drive automatically.
</div> </label>
</div>
</li>
Expand Down
4 changes: 2 additions & 2 deletions app/views/disk_wizards/select_device.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<% "*****************#{@new_disks}"%>

<div class="row">
<table class="table-bordered table table-hover">
<table class="settings table-bordered table table-hover">
<thead>
<tr data-toggle="collapse" data-target="#demo1" class="active accordion-toggle" style="cursor: pointer" >
<tr data-toggle="collapse" data-target="#demo1" class="accordion-toggle" style="cursor: pointer" >
<th class="text-center">Select</th>
<th class="text-center">Model</th>
<th class="text-center">Path</th>
Expand Down
4 changes: 2 additions & 2 deletions app/views/disk_wizards/select_fs.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ chart.draw(data, options);
border-radius: 5px;
}
</style>
<table class="table-bordered table table-hover">
<table class="settings table-bordered table table-hover">
<thead>
<tr class="active">
<tr>
<%
device = @selected_disk
unless device.partitions.blank? %>
Expand Down
9 changes: 6 additions & 3 deletions lib/disk_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# DiskCommand class which act as a bridge between system level dsk-wzd.sh bash script and rails
# Named as 'DiskCommand' to prevent class name conflicts('Command' library), when intergrating disk-wizard as Amahi plugin app
class DiskCommand
attr_reader :stdin, :stdout, :stderr
attr_reader :stdin, :stdout, :stderr, :success

# `debug_mode` class variable which hold the current executing mode of the commands,if true, commands will not be executed on the system level instead command(operation) will be loged(in @@operations_log) for future use
@@debug_mode = false
Expand Down Expand Up @@ -59,10 +59,13 @@ def execute blocking = false, debug = @@debug_mode
#If user select debug mode
#1. push current command(command name and parameters) to `operations_log` array, where it will be used to list all the operations took place during the debug mode
#2. Return from the method immediately,to prevent executing further
if debug
self.success = -1
if @@debug_mode
command = {name: @command, parameters: @parameters}
@@operations_log.push command
end

if debug
self.success = -1
return
end

Expand Down
4 changes: 2 additions & 2 deletions lib/disk_tools/fstab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def add_entry(opts = {})
raise ArgumentError.new("Missing :mount_point, :type, :opts, :dump or :pass options")
end

if @safe_mode
if @safe_mode and not DiskCommand.debug_mode
if label
raise ArgumentError.new("Invalid device label #{label}") unless \
File.blockdev?("/dev/disk/by-label/#{opts[:label]}")
Expand Down Expand Up @@ -236,7 +236,7 @@ def has_device?(dev)
# All the attributes except dev may be nil at any given time since
# device may not have a valid filesystem or label.
def self.get_blkdev_fs_attrs(dev)
raise ArgumentError.new("Invalid device path #{dev}") unless File.blockdev?(dev)
raise ArgumentError.new("Invalid device path #{dev}") unless File.blockdev?(dev) and not DiskCommand.debug_mode
blkid = `/sbin/blkid #{dev}`
attrs = {}
attrs[:uuid] = blkid.match(/UUID="(.*?)"/)[1] rescue nil
Expand Down
2 changes: 1 addition & 1 deletion lib/disk_wizards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "chartkick.rb"
require "disk_command.rb"
require "diskwz.rb"

require "debug_logger.rb"
module DiskWizard
class Lib
# the code for your plugin library here
Expand Down
17 changes: 13 additions & 4 deletions lib/diskwz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def all_devices
params = "-b -P -o MODEL,TYPE,SIZE,KNAME,UUID,LABEL,MOUNTPOINT,FSTYPE,RM"
end
lsblk = DiskCommand.new command, params
lsblk.execute false, false # None blocking and not debug mode
lsblk.execute
raise "Command execution error: #{lsblk.stderr.read}" if not lsblk.success?

lsblk.result.each_line do |line|
Expand Down Expand Up @@ -81,8 +81,13 @@ def find kname
params = "/dev/#{kname} -bPo MODEL,TYPE,SIZE,KNAME,UUID,LABEL,MOUNTPOINT,FSTYPE,RM"
end
lsblk = DiskCommand.new command, params
lsblk.execute false, false # None blocking and not debug mode
lsblk.execute
raise "Command execution error: #{lsblk.stderr.read}" if not lsblk.success?
if lsblk.success == -1
disk = {"model"=>"N/A", "type"=>"disk", "size"=>nil, "kname"=>"#{kname}", "rm"=>nil, "partitions"=>[]}
partition = {"type"=>"part", "size"=>nil, "kname"=>"#{kname}", "uuid"=>"N/A", "label"=>nil, "mountpoint"=>nil, "fstype"=>nil, "rm"=>nil, "used"=>nil, "available"=>nil}
return partition ? partition : disk
end
partitions = []
disk = nil
lsblk.result.each_line do |line|
Expand Down Expand Up @@ -142,25 +147,29 @@ def umount disk
end

def mount mount_point, disk
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Init Fstab disk.path = #{disk.path}"
fstab = Fstab.new
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Add_fs mount_point #{mount_point}"
fstab.add_fs(disk.path,mount_point,'auto','auto,rw,exec',0,0)

DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Create directory mount_point = #{mount_point}"
create_directory mount_point unless File.directory?(mount_point)

#remount all
command = "mount"
params = "#{disk.path} #{mount_point}"
mount = DiskCommand.new command,params
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Mount executing"
mount.execute
raise "Command execution error: #{mount.stderr.read}" if not mount.success?
end

def format disk, fstype
DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Disk.kname = #{disk.kname}, fstype = #{fstype}"
fstype = "vfat" if fstype == "fat32" #TODO: mkfs.vfat: invalid option -- 'q'
quick_format = (fstype == "ntfs") ? "-f" : nil
command = "mkfs.#{fstype} "
params = "-q #{quick_format} -F #{disk.path}" #-F parameter to ignore warning and -q for quiet execution

DebugLogger.info "|#{self.class.name}|>|#{__method__}|:Format params = #{params}"
mkfs = DiskCommand.new command, params
mkfs.execute
raise "Command execution error: #{mkfs.stderr.read}" if not mkfs.success?
Expand Down
41 changes: 26 additions & 15 deletions vendor/bash/debug_info.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
#!/bin/bash

echo "Disk-Wizard Debug information fetcher"

printf "\n/*===*dsw.log wrapper script log ===*/\n" >> /var/log/debug_info.tmp
tail -n 50 /var/hda/apps/520ut3lo6w/elevated/dsw.log >> /var/log/debug_info.tmp
echo -e "\n------------This Debug Information was Generated on $(date +"%B-%d-%Y %r")------------\n" > /var/log/debug_info.tmp

printf "\n/*=== *Current mounted partitions ===*/\n" >> /var/log/debug_info.tmp
sudo mount -l >> /var/log/debug_info.tmp 2>&1
printf "\n/*===*dsw.log wrapper script log (tail -n 50)===*/\n" >> /var/log/debug_info.tmp
if [ ! -f /var/hda/apps/520ut3lo6w/elevated/dsw.log ]; then
echo "File not found!" >> /var/log/debug_info.tmp
else
tail -n 50 /var/hda/apps/520ut3lo6w/elevated/dsw.log >> /var/log/debug_info.tmp
fi

printf "\n/*=== *list disk/partitions details with parted ===*/\n" >> /var/log/debug_info.tmp
parted -sl print all >> /var/log/debug_info.tmp 2>&1
printf "\n/*=== *Current mounted partitions ===*/\n" >> /var/log/debug_info.tmp
sudo mount -l >> /var/log/debug_info.tmp 2>&1

printf "\n/*=== *List all logical volumes ===*/\n" >> /var/log/debug_info.tmp
lvdisplay -av >> /var/log/debug_info.tmp 2>&1
printf "\n/*=== *list disk/partitions details with parted ===*/\n" >> /var/log/debug_info.tmp
parted -sl print all >> /var/log/debug_info.tmp 2>&1

printf "\n/*=== *dsk-wz.sh script ===*/\n" >> /var/log/debug_info.tmp
cat /var/hda/apps/520ut3lo6w/elevated/dsk-wz.sh >> /var/log/debug_info.tmp
printf "\n/*=== *List all logical volumes ===*/\n" >> /var/log/debug_info.tmp
lvdisplay -av >> /var/log/debug_info.tmp 2>&1

printf "\n/*=== *dsk-wz.sh wrapper script ===*/\n" >> /var/log/debug_info.tmp
if [ ! -f /var/hda/apps/520ut3lo6w/elevated/dsk-wz.sh ]; then
echo "File not found!" >> /var/log/debug_info.tmp
else
cat /var/hda/apps/520ut3lo6w/elevated/dsk-wz.sh >> /var/log/debug_info.tmp
fi

printf "\n/*=== *disk-wizard log file===*/\n" >> /var/log/debug_info.tmp
tail -n 50 /var/hda/platform/html/log/dw_debug.log >> /var/log/debug_info.tmp
printf "\n/*=== *disk-wizard rails log file(tail -n 50)===*/\n" >> /var/log/debug_info.tmp
if [ ! -f /var/hda/platform/html/log/dw_debug.log ]; then
echo "File not found!" >> /var/log/debug_info.tmp
else
tail -n 50 /var/hda/platform/html/log/dw_debug.log >> /var/log/debug_info.tmp
fi

fpaste -l bash /var/log/debug_info.tmp
rm /var/log/debug_info.tmp
fpaste -l bash /var/log/debug_info.tmp

0 comments on commit cecf652

Please sign in to comment.