describe LinuxAdmin::PhysicalVolume do before(:each) do @physical_volumes = < 'vg' pv = described_class.new :device_name => '/dev/hda' expect(LinuxAdmin::Common).to receive(:run!) .with(LinuxAdmin::Common.cmd(:vgextend), :params => ['vg', '/dev/hda']) pv.attach_to(vg) end it "assigns volume group to physical volume" do vg = LinuxAdmin::VolumeGroup.new :name => 'vg' pv = described_class.new :device_name => '/dev/hda' allow(LinuxAdmin::Common).to receive(:run!) pv.attach_to(vg) expect(pv.volume_group).to eq(vg) end it "returns self" do vg = LinuxAdmin::VolumeGroup.new :name => 'vg' pv = described_class.new :device_name => '/dev/hda' allow(LinuxAdmin::Common).to receive(:run!) expect(pv.attach_to(vg)).to eq(pv) end end describe "#create" do before do @disk = LinuxAdmin::Disk.new :path => '/dev/hda' allow(@disk).to receive(:size) end let(:disk) {@disk} it "uses pvcreate" do described_class.instance_variable_set(:@pvs, []) expect(LinuxAdmin::Common).to receive(:run!) .with(LinuxAdmin::Common.cmd(:pvcreate), :params => {nil => '/dev/hda'}) described_class.create disk end it "returns new physical volume" do allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => "")) pv = described_class.create disk expect(pv).to be_an_instance_of(described_class) expect(pv.device_name).to eq('/dev/hda') end it "adds physical volume to local registry" do allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => "")) pv = described_class.create disk expect(described_class.scan).to include(pv) end end describe "#scan" do it "uses pvdisplay" do expect(LinuxAdmin::Common).to receive(:run!) .with(LinuxAdmin::Common.cmd(:pvdisplay), :params => {'-c' => nil}) .and_return(double(:output => @physical_volumes)) expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @groups)) # stub out call to vgdisplay described_class.scan end it "returns local physical volumes" do expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @physical_volumes), double(:output => @groups)) pvs = described_class.scan expect(pvs[0]).to be_an_instance_of(described_class) expect(pvs[0].device_name).to eq('/dev/vda2') expect(pvs[0].size).to eq(24139776) end it "resolves volume group references" do expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @physical_volumes), double(:output => @groups)) pvs = described_class.scan expect(pvs[0].volume_group).to be_an_instance_of(LinuxAdmin::VolumeGroup) expect(pvs[0].volume_group.name).to eq('vg_foobar') end end end