Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/linux_admin/disk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ def partitions

# requires sudo
out = run(cmd(:parted),
:return_exitstatus => true,
:return_output => true,
:params => { nil => [@path, 'print'] })

return [] if out.kind_of?(Fixnum)

out.each_line do |l|
if l =~ /^ [0-9].*/
p = l.split
Expand Down
8 changes: 8 additions & 0 deletions spec/disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
disk.should_receive(:run).
with(disk.cmd(:parted),
:return_exitstatus => true,
:return_output => true,
:params => { nil => ['/dev/hda', 'print'] }).and_return ""
disk.partitions
end

it "returns [] on non-zero parted rc" do
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
disk.stub(:exitstatus => 1)
disk.stub(:launch)
disk.partitions.should == []
end

it "sets partitons" do
partitions = <<eos
Model: ATA TOSHIBA MK5061GS (scsi)
Expand Down