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
2 changes: 1 addition & 1 deletion lib/linux_admin/hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ def build_line(address, hosts, comment)
line.flatten.join(" ").strip
end
end
end
end
21 changes: 18 additions & 3 deletions lib/linux_admin/logical_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

class LinuxAdmin
class LogicalVolume < Volume
DEVICE_PATH = Pathname.new('/dev/')

# path to logical volume
attr_accessor :path

# logical volume name
attr_accessor :name

Expand All @@ -26,10 +31,19 @@ class LogicalVolume < Volume
# major device number of logical volume
# minor device number of logical volume

def path=(value)
@path = value.include?(File::SEPARATOR) ? value : DEVICE_PATH.join(@volume_group.name, value)
end

def name=(value)
@name = value.include?(File::SEPARATOR) ? value.split(File::SEPARATOR).last : value
end

def initialize(args = {})
@name = args[:name]
@volume_group = args[:volume_group]
@sectors = args[:sectors]
self.path = args[:name]
self.name = args[:name]
end

def extend_with(vg)
Expand Down Expand Up @@ -66,9 +80,10 @@ def self.create(name, vg, value)
params.merge!({'-L' => bytes_to_string(size)})
end
run!(cmd(:lvcreate), :params => params)
lv = LogicalVolume.new :name => name,

lv = LogicalVolume.new(:name => name,
:volume_group => vg,
:sectors => size
:sectors => size)
@lvs << lv
lv
end
Expand Down
28 changes: 24 additions & 4 deletions spec/logical_volume_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

describe "#extend_with" do
it "uses lvextend" do
lv = described_class.new :name => 'lv'
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
lv = described_class.new :name => 'lv', :volume_group => vg
lv.should_receive(:run!).
with(vg.cmd(:lvextend),
:params => ['lv', 'vg'])
lv.extend_with(vg)
end

it "returns self" do
lv = described_class.new :name => 'lv'
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
lv = described_class.new :name => 'lv', :volume_group => vg
lv.stub(:run!)
lv.extend_with(vg).should == lv
end
Expand Down Expand Up @@ -86,6 +86,24 @@
lv.name.should == 'lv'
end

context "name is specified" do
it "sets path under volume group" do
LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
described_class.stub(:run! => double(:output => ""))
lv = described_class.create 'lv', @vg, 256.gigabytes
lv.path.to_s.should == "#{described_class::DEVICE_PATH}#{@vg.name}/lv"
end
end

context "path is specified" do
it "sets name" do
LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
described_class.stub(:run! => double(:output => ""))
lv = described_class.create '/dev/lv', @vg, 256.gigabytes
lv.name.should == "lv"
end
end

it "adds logical volume to local registry" do
LinuxAdmin::VolumeGroup.stub(:run! => double(:output => ""))
described_class.stub(:run! => double(:output => ""))
Expand All @@ -110,11 +128,13 @@
lvs = described_class.scan

lvs[0].should be_an_instance_of(described_class)
lvs[0].name.should == '/dev/vg_foobar/lv_swap'
lvs[0].path.should == '/dev/vg_foobar/lv_swap'
lvs[0].name.should == 'lv_swap'
lvs[0].sectors.should == 4128768

lvs[1].should be_an_instance_of(described_class)
lvs[1].name.should == '/dev/vg_foobar/lv_root'
lvs[1].path.should == '/dev/vg_foobar/lv_root'
lvs[1].name.should == 'lv_root'
lvs[1].sectors.should == 19988480
end

Expand Down
4 changes: 2 additions & 2 deletions spec/volume_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

describe "#attach_to" do
it "uses lvextend" do
lv = LinuxAdmin::LogicalVolume.new :name => 'lv'
vg = described_class.new :name => 'vg'
lv = LinuxAdmin::LogicalVolume.new :name => 'lv', :volume_group => vg
vg.should_receive(:run!).
with(vg.cmd(:lvextend),
:params => ['lv', 'vg'])
vg.attach_to(lv)
end

it "returns self" do
lv = LinuxAdmin::LogicalVolume.new :name => 'lv'
vg = described_class.new :name => 'vg'
lv = LinuxAdmin::LogicalVolume.new :name => 'lv', :volume_group => vg
vg.stub(:run!)
vg.attach_to(lv).should == vg
end
Expand Down