|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'logical_volumes fact' do |
| 4 | + before :each do |
| 5 | + Facter.clear |
| 6 | + end |
| 7 | + |
| 8 | + context 'when not on Linux' do |
| 9 | + it 'should be set to nil' do |
| 10 | + Facter.fact(:kernel).expects(:value).at_least(1).returns('SunOs') |
| 11 | + Facter.value(:logical_volumes).should be_nil |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + context 'when on Linux' do |
| 16 | + before :each do |
| 17 | + Facter.fact(:kernel).expects(:value).at_least(1).returns('Linux') |
| 18 | + end |
| 19 | + |
| 20 | + context 'when lvs is absent' do |
| 21 | + before :each do |
| 22 | + Facter::Core::Execution.stubs('exec') # All other calls |
| 23 | + Facter::Core::Execution.expects('which').with('lvs').at_least(1).returns(nil) |
| 24 | + end |
| 25 | + |
| 26 | + it 'should be set to nil' do |
| 27 | + Facter.value(:logical_volumes).should be_nil |
| 28 | + end |
| 29 | + end |
| 30 | + |
| 31 | + context 'when lvs is present' do |
| 32 | + before :each do |
| 33 | + Facter::Core::Execution.stubs('exec') # All other calls |
| 34 | + Facter::Core::Execution.expects('which').with('lvs').returns('/sbin/lvs') |
| 35 | + end |
| 36 | + |
| 37 | + it 'should be able to resolve VGs' do |
| 38 | + lvs_output = <<~OUTPUT |
| 39 | + E7qan8-4NGf-jq2P-l11v-6fFe-MPHK-T6IGzl root centos/root /dev/centos/root /dev/mapper/centos-root -wi-ao---- linear public active 18.46g writeable |
| 40 | + buUXDX-GDUh-rN2t-y80n-vtCt-xhhu-XSZ5kA swap centos/swap /dev/centos/swap /dev/mapper/centos-swap -wi-ao---- linear public active 1.00g writeable |
| 41 | + uedsry-OTVv-wGW4-vaFf-c7IY-oH6Z-ig6IXB cool_tasks tasks/cool_tasks /dev/tasks/cool_tasks /dev/mapper/tasks-cool_tasks -wi-a----- linear public active 800.00m writeable |
| 42 | + gmNS3G-cAhA-vRj0-2Uf0-21yO-QVdy-LNXfBv lame_tasks tasks/lame_tasks /dev/tasks/lame_tasks /dev/mapper/tasks-lame_tasks -wi-a----- linear public active 400.00m writeable |
| 43 | + OUTPUT |
| 44 | + Facter::Core::Execution.expects(:exec).at_least(1).returns(lvs_output) |
| 45 | + Facter.value(:logical_volumes).should include({ |
| 46 | + "cool_tasks" => { |
| 47 | + "uuid" => "uedsry-OTVv-wGW4-vaFf-c7IY-oH6Z-ig6IXB", |
| 48 | + "full_name" => "tasks/cool_tasks", |
| 49 | + "path" => "/dev/tasks/cool_tasks", |
| 50 | + "dm_path" => "/dev/mapper/tasks-cool_tasks", |
| 51 | + "attr" => "-wi-a-----", |
| 52 | + "layout" => "linear", |
| 53 | + "role" => "public", |
| 54 | + "active" => "active", |
| 55 | + "size" => "800.00m", |
| 56 | + "permissions" => "writeable" |
| 57 | + }, |
| 58 | + "lame_tasks" => { |
| 59 | + "uuid" => "gmNS3G-cAhA-vRj0-2Uf0-21yO-QVdy-LNXfBv", |
| 60 | + "full_name" => "tasks/lame_tasks", |
| 61 | + "path" => "/dev/tasks/lame_tasks", |
| 62 | + "dm_path" => "/dev/mapper/tasks-lame_tasks", |
| 63 | + "attr" => "-wi-a-----", |
| 64 | + "layout" => "linear", |
| 65 | + "role" => "public", |
| 66 | + "active" => "active", |
| 67 | + "size" => "400.00m", |
| 68 | + "permissions" => "writeable" |
| 69 | + }, |
| 70 | + "root" => { |
| 71 | + "uuid" => "E7qan8-4NGf-jq2P-l11v-6fFe-MPHK-T6IGzl", |
| 72 | + "full_name" => "centos/root", |
| 73 | + "path" => "/dev/centos/root", |
| 74 | + "dm_path" => "/dev/mapper/centos-root", |
| 75 | + "attr" => "-wi-ao----", |
| 76 | + "layout" => "linear", |
| 77 | + "role" => "public", |
| 78 | + "active" => "active", |
| 79 | + "size" => "18.46g", |
| 80 | + "permissions" => "writeable" |
| 81 | + }, |
| 82 | + "swap" => { |
| 83 | + "uuid" => "buUXDX-GDUh-rN2t-y80n-vtCt-xhhu-XSZ5kA", |
| 84 | + "full_name" => "centos/swap", |
| 85 | + "path" => "/dev/centos/swap", |
| 86 | + "dm_path" => "/dev/mapper/centos-swap", |
| 87 | + "attr" => "-wi-ao----", |
| 88 | + "layout" => "linear", |
| 89 | + "role" => "public", |
| 90 | + "active" => "active", |
| 91 | + "size" => "1.00g", |
| 92 | + "permissions" => "writeable" |
| 93 | + }, |
| 94 | + }) |
| 95 | + end |
| 96 | + end |
| 97 | + end |
| 98 | +end |
0 commit comments