linux_admin 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/linux_admin/common.rb +5 -12
- data/lib/linux_admin/disk.rb +82 -16
- data/lib/linux_admin/distro.rb +18 -7
- data/lib/linux_admin/exceptions.rb +1 -0
- data/lib/linux_admin/fstab.rb +9 -0
- data/lib/linux_admin/logical_volume.rb +65 -1
- data/lib/linux_admin/partition.rb +12 -4
- data/lib/linux_admin/physical_volume.rb +75 -0
- data/lib/linux_admin/{rhn.rb → registration_system/rhn.rb} +10 -8
- data/lib/linux_admin/registration_system/subscription_manager.rb +89 -0
- data/lib/linux_admin/registration_system.rb +45 -0
- data/lib/linux_admin/version.rb +1 -1
- data/lib/linux_admin/volume_group.rb +73 -0
- data/lib/linux_admin/yum.rb +1 -1
- data/lib/linux_admin.rb +6 -16
- data/linux_admin.gemspec +6 -2
- data/spec/common_spec.rb +39 -34
- data/spec/data/subscription_manager/output_orgs +6 -0
- data/spec/disk_spec.rb +117 -0
- data/spec/distro_spec.rb +1 -1
- data/spec/fstab_spec.rb +18 -0
- data/spec/linux_admin_spec.rb +0 -38
- data/spec/logical_volume_spec.rb +108 -0
- data/spec/partition_spec.rb +15 -0
- data/spec/physical_volume_spec.rb +110 -0
- data/spec/registration_system_spec.rb +60 -0
- data/spec/rhn_spec.rb +17 -21
- data/spec/spec_helper.rb +12 -0
- data/spec/subscription_manager_spec.rb +23 -18
- data/spec/volume_group_spec.rb +108 -0
- data/spec/yum_spec.rb +1 -1
- metadata +25 -5
- data/lib/linux_admin/subscription_manager.rb +0 -61
data/lib/linux_admin.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'more_core_extensions/all'
|
2
2
|
require 'active_support/core_ext'
|
3
3
|
|
4
|
+
require 'linux_admin/registration_system'
|
5
|
+
|
4
6
|
require 'linux_admin/common'
|
5
|
-
require 'linux_admin/
|
7
|
+
require 'linux_admin/exceptions'
|
6
8
|
require 'linux_admin/rpm'
|
7
|
-
require 'linux_admin/subscription_manager'
|
8
9
|
require 'linux_admin/version'
|
9
10
|
require 'linux_admin/yum'
|
10
11
|
|
@@ -14,22 +15,11 @@ require 'linux_admin/partition'
|
|
14
15
|
require 'linux_admin/distro'
|
15
16
|
require 'linux_admin/system'
|
16
17
|
require 'linux_admin/fstab'
|
18
|
+
require 'linux_admin/logical_volume'
|
19
|
+
require 'linux_admin/physical_volume'
|
20
|
+
require 'linux_admin/volume_group'
|
17
21
|
|
18
22
|
class LinuxAdmin
|
19
23
|
extend Common
|
20
24
|
include Common
|
21
|
-
|
22
|
-
def self.registered?
|
23
|
-
!!self.registration_type
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.registration_type
|
27
|
-
if SubscriptionManager.registered?
|
28
|
-
SubscriptionManager
|
29
|
-
elsif Rhn.registered?
|
30
|
-
Rhn
|
31
|
-
else
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
end
|
35
25
|
end
|
data/linux_admin.gemspec
CHANGED
@@ -4,10 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'linux_admin/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
# Dynamically create the authors information {name => e-mail}
|
9
|
+
authors_hash = Hash[`git log --no-merges --reverse --format='%an,%ae'`.split("\n").uniq.collect {|i| i.split(",")}]
|
10
|
+
|
7
11
|
spec.name = "linux_admin"
|
8
12
|
spec.version = LinuxAdmin::VERSION
|
9
|
-
spec.authors =
|
10
|
-
spec.email =
|
13
|
+
spec.authors = authors_hash.keys
|
14
|
+
spec.email = authors_hash.values
|
11
15
|
spec.description = %q{
|
12
16
|
LinuxAdmin is a module to simplify management of linux systems.
|
13
17
|
It should be a single place to manage various system level configurations,
|
data/spec/common_spec.rb
CHANGED
@@ -27,15 +27,9 @@ describe LinuxAdmin::Common do
|
|
27
27
|
|
28
28
|
subject { TestClass }
|
29
29
|
|
30
|
-
context ".write" do
|
31
|
-
it "no file no content" do
|
32
|
-
expect { subject.write("", "") }.to raise_error(ArgumentError)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
30
|
context ".cmd" do
|
37
31
|
it "looks up local command from id" do
|
38
|
-
d =
|
32
|
+
d = double(LinuxAdmin::Distro)
|
39
33
|
d.class::COMMANDS = { :sh => '/bin/sh' }
|
40
34
|
LinuxAdmin::Distro.should_receive(:local).and_return(d)
|
41
35
|
subject.cmd(:sh).should == '/bin/sh'
|
@@ -45,17 +39,17 @@ describe LinuxAdmin::Common do
|
|
45
39
|
context ".run" do
|
46
40
|
context "with params" do
|
47
41
|
it "sanitizes crazy params" do
|
48
|
-
subject.should_receive(:launch).once.with("true --user bob --pass P@\\$sw0\\^\\&\\ \\|\\<\\>/-\\+\\*d\\% --db --desc=Some\\ Description pkg1 some\\ pkg --pool 123 --pool 456")
|
42
|
+
subject.should_receive(:launch).once.with("true --user bob --pass P@\\$sw0\\^\\&\\ \\|\\<\\>/-\\+\\*d\\% --db --desc=Some\\ Description pkg1 some\\ pkg --pool 123 --pool 456", {})
|
49
43
|
subject.run("true", :params => modified_params, :return_exitstatus => true)
|
50
44
|
end
|
51
45
|
|
52
46
|
it "as empty hash" do
|
53
|
-
subject.should_receive(:launch).once.with("true")
|
47
|
+
subject.should_receive(:launch).once.with("true", {})
|
54
48
|
subject.run("true", :params => {}, :return_exitstatus => true)
|
55
49
|
end
|
56
50
|
|
57
51
|
it "as nil" do
|
58
|
-
subject.should_receive(:launch).once.with("true")
|
52
|
+
subject.should_receive(:launch).once.with("true", {})
|
59
53
|
subject.run("true", :params => nil, :return_exitstatus => true)
|
60
54
|
end
|
61
55
|
|
@@ -66,44 +60,55 @@ describe LinuxAdmin::Common do
|
|
66
60
|
end
|
67
61
|
end
|
68
62
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
it "command ok exit bad" do
|
74
|
-
expect { subject.run("false") }.to raise_error
|
75
|
-
end
|
76
|
-
|
77
|
-
it "command bad" do
|
78
|
-
expect { subject.run("XXXXX") }.to raise_error
|
79
|
-
end
|
63
|
+
context "with real execution" do
|
64
|
+
before do
|
65
|
+
Kernel.should_receive(:spawn).and_call_original
|
66
|
+
end
|
80
67
|
|
81
|
-
context "with :return_exitstatus => true" do
|
82
68
|
it "command ok exit ok" do
|
83
|
-
expect(subject.run("true"
|
69
|
+
expect(subject.run("true")).to be_true
|
84
70
|
end
|
85
71
|
|
86
72
|
it "command ok exit bad" do
|
87
|
-
expect
|
73
|
+
expect { subject.run("false") }.to raise_error(CommandError)
|
88
74
|
end
|
89
75
|
|
90
76
|
it "command bad" do
|
91
|
-
expect
|
77
|
+
expect { subject.run("XXXXX") }.to raise_error(Errno::ENOENT)
|
92
78
|
end
|
93
|
-
end
|
94
79
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
80
|
+
context "with :return_exitstatus => true" do
|
81
|
+
it "command ok exit ok" do
|
82
|
+
expect(subject.run("true", :return_exitstatus => true)).to eq(0)
|
83
|
+
end
|
99
84
|
|
100
|
-
|
101
|
-
|
85
|
+
it "command ok exit bad" do
|
86
|
+
expect(subject.run("false", :return_exitstatus => true)).to eq(1)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "command bad" do
|
90
|
+
expect(subject.run("XXXXX", :return_exitstatus => true)).to be_nil
|
91
|
+
end
|
102
92
|
end
|
103
93
|
|
104
|
-
|
105
|
-
|
94
|
+
context "with :return_output => true" do
|
95
|
+
it "command ok exit ok" do
|
96
|
+
expect(subject.run("echo \"Hello World\"", :return_output => true)).to eq("Hello World\n")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "command ok exit bad" do
|
100
|
+
expect { subject.run("false", :return_output => true) }.to raise_error(CommandError)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "command bad" do
|
104
|
+
expect { subject.run("XXXXX", :return_output => true) }.to raise_error(Errno::ENOENT)
|
105
|
+
end
|
106
106
|
end
|
107
107
|
end
|
108
|
+
|
109
|
+
it "supports spawn's chdir option" do
|
110
|
+
subject.should_receive(:launch).once.with("true", {:chdir => ".."})
|
111
|
+
subject.run("true", :chdir => "..", :return_exitstatus => true)
|
112
|
+
end
|
108
113
|
end
|
109
114
|
end
|
data/spec/disk_spec.rb
CHANGED
@@ -12,16 +12,56 @@ describe LinuxAdmin::Disk do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
describe "#size" do
|
16
|
+
it "uses fdisk" do
|
17
|
+
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
18
|
+
disk.should_receive(:run).
|
19
|
+
with(disk.cmd(:fdisk),
|
20
|
+
:return_output => true,
|
21
|
+
:params => {"-l" => nil}).
|
22
|
+
and_return("")
|
23
|
+
disk.size
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns disk size" do
|
27
|
+
fdisk = <<eos
|
28
|
+
Disk /dev/hda: 500.1 GB, 500107862016 bytes
|
29
|
+
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
|
30
|
+
Units = sectors of 1 * 512 = 512 bytes
|
31
|
+
Sector size (logical/physical): 512 bytes / 512 bytes
|
32
|
+
I/O size (minimum/optimal): 512 bytes / 512 bytes
|
33
|
+
Disk identifier: 0x3ddb508b
|
34
|
+
|
35
|
+
Device Boot Start End Blocks Id System
|
36
|
+
1 1259MB 81.8GB 80.5GB primary ntfs
|
37
|
+
2 81.8GB 162GB 80.5GB primary ext4
|
38
|
+
3 162GB 163GB 1074MB logical linux-swap(v1)
|
39
|
+
eos
|
40
|
+
|
41
|
+
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
42
|
+
disk.stub(:run).and_return(fdisk)
|
43
|
+
disk.size.should == 500.1.gigabytes
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
15
47
|
describe "#partitions" do
|
16
48
|
it "uses parted" do
|
17
49
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
18
50
|
disk.should_receive(:run).
|
19
51
|
with(disk.cmd(:parted),
|
52
|
+
:return_exitstatus => true,
|
20
53
|
:return_output => true,
|
21
54
|
:params => { nil => ['/dev/hda', 'print'] }).and_return ""
|
22
55
|
disk.partitions
|
23
56
|
end
|
24
57
|
|
58
|
+
it "returns [] on non-zero parted rc" do
|
59
|
+
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
60
|
+
disk.stub(:exitstatus => 1)
|
61
|
+
disk.stub(:launch)
|
62
|
+
disk.partitions.should == []
|
63
|
+
end
|
64
|
+
|
25
65
|
it "sets partitons" do
|
26
66
|
partitions = <<eos
|
27
67
|
Model: ATA TOSHIBA MK5061GS (scsi)
|
@@ -41,15 +81,92 @@ eos
|
|
41
81
|
disk.partitions[0].id.should == 1
|
42
82
|
disk.partitions[0].disk.should == disk
|
43
83
|
disk.partitions[0].size.should == 80.5.gigabytes
|
84
|
+
disk.partitions[0].start_sector.should == 1259.megabytes
|
85
|
+
disk.partitions[0].end_sector.should == 81.8.gigabytes
|
86
|
+
disk.partitions[0].partition_type.should == 'primary'
|
44
87
|
disk.partitions[0].fs_type.should == 'ntfs'
|
45
88
|
disk.partitions[1].id.should == 2
|
46
89
|
disk.partitions[1].disk.should == disk
|
47
90
|
disk.partitions[1].size.should == 80.5.gigabytes
|
91
|
+
disk.partitions[1].start_sector.should == 81.8.gigabytes
|
92
|
+
disk.partitions[1].end_sector.should == 162.gigabytes
|
93
|
+
disk.partitions[1].partition_type.should == 'primary'
|
48
94
|
disk.partitions[1].fs_type.should == 'ext4'
|
49
95
|
disk.partitions[2].id.should == 3
|
50
96
|
disk.partitions[2].disk.should == disk
|
51
97
|
disk.partitions[2].size.should == 1074.megabytes
|
98
|
+
disk.partitions[2].start_sector.should == 162.gigabytes
|
99
|
+
disk.partitions[2].end_sector.should == 163.gigabytes
|
100
|
+
disk.partitions[2].partition_type.should == 'logical'
|
52
101
|
disk.partitions[2].fs_type.should == 'linux-swap(v1)'
|
53
102
|
end
|
54
103
|
end
|
104
|
+
|
105
|
+
describe "#create_partition" do
|
106
|
+
before(:each) do
|
107
|
+
# test disk w/ existing partition
|
108
|
+
@disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
109
|
+
@disk.instance_variable_set(:@partitions,
|
110
|
+
[LinuxAdmin::Partition.new(:id => 1,
|
111
|
+
:end_sector => 1024)])
|
112
|
+
end
|
113
|
+
|
114
|
+
it "uses parted" do
|
115
|
+
@disk.should_receive(:run).
|
116
|
+
with(@disk.cmd(:parted),
|
117
|
+
:params => { nil => ['/dev/hda', 'mkpart', 'primary', 1024, 2048] })
|
118
|
+
@disk.create_partition 'primary', 1024
|
119
|
+
end
|
120
|
+
|
121
|
+
it "returns partition" do
|
122
|
+
@disk.should_receive(:run) # stub out call to parted
|
123
|
+
partition = @disk.create_partition 'primary', 1024
|
124
|
+
partition.should be_an_instance_of(LinuxAdmin::Partition)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "increments partition id" do
|
128
|
+
@disk.should_receive(:run) # stub out call to parted
|
129
|
+
partition = @disk.create_partition 'primary', 1024
|
130
|
+
partition.id.should == 2
|
131
|
+
end
|
132
|
+
|
133
|
+
it "sets partition start to first unused sector on disk" do
|
134
|
+
@disk.should_receive(:run) # stub out call to parted
|
135
|
+
partition = @disk.create_partition 'primary', 1024
|
136
|
+
partition.start_sector.should == 1024
|
137
|
+
end
|
138
|
+
|
139
|
+
it "stores new partition locally" do
|
140
|
+
@disk.should_receive(:run) # stub out call to parted
|
141
|
+
lambda {
|
142
|
+
@disk.create_partition 'primary', 1024
|
143
|
+
}.should change{@disk.partitions.size}.by(1)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#clear!" do
|
148
|
+
it "clears partitions" do
|
149
|
+
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
150
|
+
disk.stub(:run).and_return("") # stub out call to cmds
|
151
|
+
disk.partitions << LinuxAdmin::Partition.new
|
152
|
+
disk.clear!
|
153
|
+
disk.partitions.should be_empty
|
154
|
+
end
|
155
|
+
|
156
|
+
it "uses dd to clear partition table" do
|
157
|
+
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
158
|
+
disk.should_receive(:run).
|
159
|
+
with(disk.cmd(:dd),
|
160
|
+
:params => {'if=' => '/dev/zero', 'of=' => '/dev/hda',
|
161
|
+
'bs=' => 512, 'count=' => 1})
|
162
|
+
disk.clear!
|
163
|
+
end
|
164
|
+
|
165
|
+
it "returns self" do
|
166
|
+
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
167
|
+
disk.stub(:run) # stub out call to dd
|
168
|
+
disk.clear!.should == disk
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
55
172
|
end
|
data/spec/distro_spec.rb
CHANGED
data/spec/fstab_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
describe LinuxAdmin::FSTab do
|
4
5
|
it "creates FSTabEntry for each line in fstab" do
|
@@ -24,4 +25,21 @@ eos
|
|
24
25
|
entries[1].dumpable.should == 0
|
25
26
|
entries[1].fsck_order.should == 0
|
26
27
|
end
|
28
|
+
|
29
|
+
describe "#write!" do
|
30
|
+
it "writes entries to /etc/fstab" do
|
31
|
+
# maually set fstab
|
32
|
+
entry = LinuxAdmin::FSTabEntry.new
|
33
|
+
entry.device = '/dev/sda1'
|
34
|
+
entry.mount_point = '/'
|
35
|
+
entry.fs_type = 'ext4'
|
36
|
+
entry.mount_options = 'defaults'
|
37
|
+
entry.dumpable = 1
|
38
|
+
entry.fsck_order = 1
|
39
|
+
LinuxAdmin::FSTab.instance.entries = [entry]
|
40
|
+
|
41
|
+
File.should_receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1\n")
|
42
|
+
LinuxAdmin::FSTab.instance.write!
|
43
|
+
end
|
44
|
+
end
|
27
45
|
end
|
data/spec/linux_admin_spec.rb
CHANGED
@@ -1,42 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe LinuxAdmin do
|
4
|
-
context ".registered?" do
|
5
|
-
it "when registered Subscription Manager" do
|
6
|
-
stub_registered_to_system(:sm)
|
7
|
-
expect(described_class.registered?).to be_true
|
8
|
-
end
|
9
|
-
|
10
|
-
it "when registered RHN" do
|
11
|
-
stub_registered_to_system(:rhn)
|
12
|
-
expect(described_class.registered?).to be_true
|
13
|
-
end
|
14
|
-
|
15
|
-
it "when unregistered" do
|
16
|
-
stub_registered_to_system(nil)
|
17
|
-
expect(described_class.registered?).to be_false
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context ".registration_type" do
|
22
|
-
it "when registered Subscription Manager" do
|
23
|
-
stub_registered_to_system(:sm)
|
24
|
-
expect(described_class.registration_type).to eq(LinuxAdmin::SubscriptionManager)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "when registered RHN" do
|
28
|
-
stub_registered_to_system(:rhn)
|
29
|
-
expect(described_class.registration_type).to eq(LinuxAdmin::Rhn)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "when unregistered" do
|
33
|
-
stub_registered_to_system(nil)
|
34
|
-
expect(described_class.registration_type).to be_nil
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def stub_registered_to_system(system)
|
39
|
-
described_class::SubscriptionManager.stub(:registered? => (system == :sm))
|
40
|
-
described_class::Rhn.stub(:registered? => (system == :rhn))
|
41
|
-
end
|
42
4
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinuxAdmin::LogicalVolume do
|
4
|
+
before(:each) do
|
5
|
+
LinuxAdmin::Distro.stub(:local => LinuxAdmin::Distros::Test.new)
|
6
|
+
|
7
|
+
@logical_volumes = <<eos
|
8
|
+
/dev/vg_foobar/lv_swap:vg_foobar:3:1:-1:2:4128768:63:-1:0:-1:253:0
|
9
|
+
/dev/vg_foobar/lv_root:vg_foobar:3:1:-1:1:19988480:305:-1:0:-1:253:1
|
10
|
+
eos
|
11
|
+
|
12
|
+
@groups = <<eos
|
13
|
+
vg_foobar:r/w:772:-1:0:2:2:-1:0:1:1:12058624:32768:368:368:0:tILZUF-IspH-H90I-pT5j-vVFl-b76L-zWx3CW
|
14
|
+
eos
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:each) do
|
18
|
+
# reset local copies of volumes / groups
|
19
|
+
described_class.instance_variable_set(:@lvs, nil)
|
20
|
+
LinuxAdmin::PhysicalVolume.instance_variable_set(:@pvs, nil)
|
21
|
+
LinuxAdmin::VolumeGroup.instance_variable_set(:@vgs, nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#extend_with" do
|
25
|
+
it "uses lvextend" do
|
26
|
+
lv = described_class.new :name => 'lv'
|
27
|
+
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
28
|
+
lv.should_receive(:run).
|
29
|
+
with(vg.cmd(:lvextend),
|
30
|
+
:params => ['lv', 'vg'])
|
31
|
+
lv.extend_with(vg)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns self" do
|
35
|
+
lv = described_class.new :name => 'lv'
|
36
|
+
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
37
|
+
lv.stub(:run)
|
38
|
+
lv.extend_with(vg).should == lv
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#create" do
|
43
|
+
before(:each) do
|
44
|
+
@vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "uses lvcreate" do
|
48
|
+
described_class.instance_variable_set(:@lvs, [])
|
49
|
+
described_class.should_receive(:run).
|
50
|
+
with(LinuxAdmin.cmd(:lvcreate),
|
51
|
+
:params => { '-n' => 'lv',
|
52
|
+
nil => 'vg',
|
53
|
+
'-L' => '256G' })
|
54
|
+
described_class.create 'lv', @vg, '256G'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns new logical volume" do
|
58
|
+
LinuxAdmin::VolumeGroup.stub(:run => "")
|
59
|
+
described_class.stub(:run => "")
|
60
|
+
lv = described_class.create 'lv', @vg, '256G'
|
61
|
+
lv.should be_an_instance_of(described_class)
|
62
|
+
lv.name.should == 'lv'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "adds logical volume to local registry" do
|
66
|
+
LinuxAdmin::VolumeGroup.stub(:run => "")
|
67
|
+
described_class.stub(:run => "")
|
68
|
+
lv = described_class.create 'lv', @vg, '256G'
|
69
|
+
described_class.scan.should include(lv)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#scan" do
|
74
|
+
it "uses lvdisplay" do
|
75
|
+
described_class.should_receive(:run).
|
76
|
+
with(LinuxAdmin.cmd(:lvdisplay),
|
77
|
+
:return_output => true,
|
78
|
+
:params => { '-c' => nil}).
|
79
|
+
and_return(@logical_volumes)
|
80
|
+
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) # stub out call to vgdisplay
|
81
|
+
described_class.scan
|
82
|
+
end
|
83
|
+
|
84
|
+
it "returns local logical volumes" do
|
85
|
+
described_class.should_receive(:run).and_return(@logical_volumes)
|
86
|
+
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups)
|
87
|
+
lvs = described_class.scan
|
88
|
+
|
89
|
+
lvs[0].should be_an_instance_of(described_class)
|
90
|
+
lvs[0].name.should == '/dev/vg_foobar/lv_swap'
|
91
|
+
lvs[0].sectors.should == 4128768
|
92
|
+
|
93
|
+
lvs[1].should be_an_instance_of(described_class)
|
94
|
+
lvs[1].name.should == '/dev/vg_foobar/lv_root'
|
95
|
+
lvs[1].sectors.should == 19988480
|
96
|
+
end
|
97
|
+
|
98
|
+
it "resolves volume group references" do
|
99
|
+
described_class.should_receive(:run).and_return(@logical_volumes)
|
100
|
+
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups)
|
101
|
+
lvs = described_class.scan
|
102
|
+
lvs[0].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup)
|
103
|
+
lvs[0].volume_group.name.should == 'vg_foobar'
|
104
|
+
lvs[1].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup)
|
105
|
+
lvs[1].volume_group.name.should == 'vg_foobar'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/spec/partition_spec.rb
CHANGED
@@ -16,6 +16,21 @@ describe LinuxAdmin::Partition do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
describe "#format_to" do
|
20
|
+
it "uses mke2fs" do
|
21
|
+
@partition.should_receive(:run).
|
22
|
+
with(@partition.cmd(:mke2fs),
|
23
|
+
:params => { '-t' => 'ext4', nil => '/dev/sda2'})
|
24
|
+
@partition.format_to('ext4')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "sets fs type" do
|
28
|
+
@partition.should_receive(:run) # ignore actual formatting cmd
|
29
|
+
@partition.format_to('ext4')
|
30
|
+
@partition.fs_type.should == 'ext4'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
19
34
|
describe "#mount" do
|
20
35
|
it "sets mount point" do
|
21
36
|
@partition.should_receive(:run) # ignore actual mount cmd
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe LinuxAdmin::PhysicalVolume do
|
4
|
+
before(:each) do
|
5
|
+
LinuxAdmin::Distro.stub(:local => LinuxAdmin::Distros::Test.new)
|
6
|
+
|
7
|
+
@physical_volumes = <<eos
|
8
|
+
/dev/vda2:vg_foobar:24139776:-1:8:8:-1:32768:368:0:368:pxR32D-YkC2-PfHe-zOwb-eaGD-9Ar0-mAOl9u
|
9
|
+
eos
|
10
|
+
|
11
|
+
@groups = <<eos
|
12
|
+
vg_foobar:r/w:772:-1:0:2:2:-1:0:1:1:12058624:32768:368:368:0:tILZUF-IspH-H90I-pT5j-vVFl-b76L-zWx3CW
|
13
|
+
eos
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:each) do
|
17
|
+
# reset local copies of volumes / groups
|
18
|
+
LinuxAdmin::LogicalVolume.instance_variable_set(:@lvs, nil)
|
19
|
+
described_class.instance_variable_set(:@pvs, nil)
|
20
|
+
LinuxAdmin::VolumeGroup.instance_variable_set(:@vgs, nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#attach_to" do
|
24
|
+
it "uses vgextend" do
|
25
|
+
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
26
|
+
pv = described_class.new :device_name => '/dev/hda'
|
27
|
+
pv.should_receive(:run).
|
28
|
+
with(pv.cmd(:vgextend),
|
29
|
+
:params => ['vg', '/dev/hda'])
|
30
|
+
pv.attach_to(vg)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "assigns volume group to physical volume" do
|
34
|
+
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
35
|
+
pv = described_class.new :device_name => '/dev/hda'
|
36
|
+
pv.stub(:run)
|
37
|
+
pv.attach_to(vg)
|
38
|
+
pv.volume_group.should == vg
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns self" do
|
42
|
+
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
43
|
+
pv = described_class.new :device_name => '/dev/hda'
|
44
|
+
pv.stub(:run)
|
45
|
+
pv.attach_to(vg).should == pv
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#create" do
|
50
|
+
before do
|
51
|
+
@disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
52
|
+
@disk.stub(:size)
|
53
|
+
end
|
54
|
+
|
55
|
+
let(:disk) {@disk}
|
56
|
+
|
57
|
+
it "uses pvcreate" do
|
58
|
+
described_class.instance_variable_set(:@pvs, [])
|
59
|
+
described_class.should_receive(:run).
|
60
|
+
with(LinuxAdmin.cmd(:pvcreate),
|
61
|
+
:params => { nil => '/dev/hda'})
|
62
|
+
described_class.create disk
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns new physical volume" do
|
66
|
+
LinuxAdmin::VolumeGroup.stub(:run => "")
|
67
|
+
described_class.stub(:run => "")
|
68
|
+
pv = described_class.create disk
|
69
|
+
pv.should be_an_instance_of(described_class)
|
70
|
+
pv.device_name.should == '/dev/hda'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "adds physical volume to local registry" do
|
74
|
+
LinuxAdmin::VolumeGroup.stub(:run => "")
|
75
|
+
described_class.stub(:run => "")
|
76
|
+
pv = described_class.create disk
|
77
|
+
described_class.scan.should include(pv)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#scan" do
|
82
|
+
it "uses pvdisplay" do
|
83
|
+
described_class.should_receive(:run).
|
84
|
+
with(LinuxAdmin.cmd(:pvdisplay),
|
85
|
+
:return_output => true,
|
86
|
+
:params => { '-c' => nil}).
|
87
|
+
and_return(@physical_volumes)
|
88
|
+
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups) # stub out call to vgdisplay
|
89
|
+
described_class.scan
|
90
|
+
end
|
91
|
+
|
92
|
+
it "returns local physical volumes" do
|
93
|
+
described_class.should_receive(:run).and_return(@physical_volumes)
|
94
|
+
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups)
|
95
|
+
pvs = described_class.scan
|
96
|
+
|
97
|
+
pvs[0].should be_an_instance_of(described_class)
|
98
|
+
pvs[0].device_name.should == '/dev/vda2'
|
99
|
+
pvs[0].size.should == 24139776
|
100
|
+
end
|
101
|
+
|
102
|
+
it "resolves volume group references" do
|
103
|
+
described_class.should_receive(:run).and_return(@physical_volumes)
|
104
|
+
LinuxAdmin::VolumeGroup.should_receive(:run).and_return(@groups)
|
105
|
+
pvs = described_class.scan
|
106
|
+
pvs[0].volume_group.should be_an_instance_of(LinuxAdmin::VolumeGroup)
|
107
|
+
pvs[0].volume_group.name.should == 'vg_foobar'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|