linux_admin 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/linux_admin/common.rb +4 -4
- data/lib/linux_admin/deb.rb +1 -1
- data/lib/linux_admin/disk.rb +6 -8
- data/lib/linux_admin/hosts.rb +4 -6
- data/lib/linux_admin/ip_address.rb +4 -6
- data/lib/linux_admin/logical_volume.rb +3 -3
- data/lib/linux_admin/mountable.rb +5 -8
- data/lib/linux_admin/network_interface.rb +4 -6
- data/lib/linux_admin/package.rb +0 -1
- data/lib/linux_admin/physical_volume.rb +3 -6
- data/lib/linux_admin/registration_system/rhn.rb +5 -5
- data/lib/linux_admin/registration_system/subscription_manager.rb +2 -2
- data/lib/linux_admin/registration_system.rb +1 -2
- data/lib/linux_admin/rpm.rb +7 -5
- data/lib/linux_admin/service/sys_v_init_service.rb +12 -12
- data/lib/linux_admin/service/systemd_service.rb +12 -12
- data/lib/linux_admin/service.rb +1 -3
- data/lib/linux_admin/system.rb +2 -4
- data/lib/linux_admin/time_date.rb +3 -4
- data/lib/linux_admin/version.rb +1 -1
- data/lib/linux_admin/volume.rb +1 -1
- data/lib/linux_admin/volume_group.rb +7 -10
- data/lib/linux_admin/yum.rb +6 -8
- data/lib/linux_admin.rb +0 -2
- data/spec/common_spec.rb +6 -8
- data/spec/deb_spec.rb +3 -3
- data/spec/disk_spec.rb +27 -27
- data/spec/hosts_spec.rb +5 -5
- data/spec/ip_address_spec.rb +4 -4
- data/spec/logical_volume_spec.rb +38 -38
- data/spec/mountable_spec.rb +22 -20
- data/spec/network_interface/network_interface_rh_spec.rb +13 -9
- data/spec/network_interface_spec.rb +4 -6
- data/spec/partition_spec.rb +1 -1
- data/spec/physical_volume_spec.rb +16 -20
- data/spec/rhn_spec.rb +22 -9
- data/spec/rpm_spec.rb +6 -4
- data/spec/service/sys_v_init_service_spec.rb +27 -28
- data/spec/service/systemd_service_spec.rb +20 -20
- data/spec/service_spec.rb +1 -1
- data/spec/subscription_manager_spec.rb +27 -15
- data/spec/system_spec.rb +2 -6
- data/spec/time_date_spec.rb +1 -1
- data/spec/volume_group_spec.rb +15 -19
- data/spec/yum_spec.rb +27 -15
- metadata +8 -6
@@ -1,38 +1,38 @@
|
|
1
1
|
module LinuxAdmin
|
2
2
|
class SysVInitService < Service
|
3
3
|
def running?
|
4
|
-
run(cmd(:service),
|
5
|
-
|
4
|
+
Common.run(Common.cmd(:service),
|
5
|
+
:params => {nil => [name, "status"]}).exit_status == 0
|
6
6
|
end
|
7
7
|
|
8
8
|
def enable
|
9
|
-
run!(cmd(:chkconfig),
|
10
|
-
|
9
|
+
Common.run!(Common.cmd(:chkconfig),
|
10
|
+
:params => {nil => [name, "on"]})
|
11
11
|
self
|
12
12
|
end
|
13
13
|
|
14
14
|
def disable
|
15
|
-
run!(cmd(:chkconfig),
|
16
|
-
|
15
|
+
Common.run!(Common.cmd(:chkconfig),
|
16
|
+
:params => {nil => [name, "off"]})
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
20
|
def start
|
21
|
-
run!(cmd(:service),
|
22
|
-
|
21
|
+
Common.run!(Common.cmd(:service),
|
22
|
+
:params => {nil => [name, "start"]})
|
23
23
|
self
|
24
24
|
end
|
25
25
|
|
26
26
|
def stop
|
27
|
-
run!(cmd(:service),
|
28
|
-
|
27
|
+
Common.run!(Common.cmd(:service),
|
28
|
+
:params => {nil => [name, "stop"]})
|
29
29
|
self
|
30
30
|
end
|
31
31
|
|
32
32
|
def restart
|
33
33
|
status =
|
34
|
-
run(cmd(:service),
|
35
|
-
|
34
|
+
Common.run(Common.cmd(:service),
|
35
|
+
:params => {nil => [name, "restart"]}).exit_status
|
36
36
|
|
37
37
|
# attempt to manually stop/start if restart fails
|
38
38
|
if status != 0
|
@@ -1,38 +1,38 @@
|
|
1
1
|
module LinuxAdmin
|
2
2
|
class SystemdService < Service
|
3
3
|
def running?
|
4
|
-
run(cmd(:systemctl),
|
5
|
-
|
4
|
+
Common.run(Common.cmd(:systemctl),
|
5
|
+
:params => {nil => ["status", name]}).exit_status == 0
|
6
6
|
end
|
7
7
|
|
8
8
|
def enable
|
9
|
-
run!(cmd(:systemctl),
|
10
|
-
|
9
|
+
Common.run!(Common.cmd(:systemctl),
|
10
|
+
:params => {nil => ["enable", name]})
|
11
11
|
self
|
12
12
|
end
|
13
13
|
|
14
14
|
def disable
|
15
|
-
run!(cmd(:systemctl),
|
16
|
-
|
15
|
+
Common.run!(Common.cmd(:systemctl),
|
16
|
+
:params => {nil => ["disable", name]})
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
20
|
def start
|
21
|
-
run!(cmd(:systemctl),
|
22
|
-
|
21
|
+
Common.run!(Common.cmd(:systemctl),
|
22
|
+
:params => {nil => ["start", name]})
|
23
23
|
self
|
24
24
|
end
|
25
25
|
|
26
26
|
def stop
|
27
|
-
run!(cmd(:systemctl),
|
28
|
-
|
27
|
+
Common.run!(Common.cmd(:systemctl),
|
28
|
+
:params => {nil => ["stop", name]})
|
29
29
|
self
|
30
30
|
end
|
31
31
|
|
32
32
|
def restart
|
33
33
|
status =
|
34
|
-
run(cmd(:systemctl),
|
35
|
-
|
34
|
+
Common.run(Common.cmd(:systemctl),
|
35
|
+
:params => {nil => ["restart", name]}).exit_status
|
36
36
|
|
37
37
|
# attempt to manually stop/start if restart fails
|
38
38
|
if status != 0
|
data/lib/linux_admin/service.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
module LinuxAdmin
|
2
2
|
class Service
|
3
|
-
extend Common
|
4
|
-
include Common
|
5
3
|
include Logging
|
6
4
|
|
7
5
|
def self.service_type(reload = false)
|
@@ -34,7 +32,7 @@ module LinuxAdmin
|
|
34
32
|
private
|
35
33
|
|
36
34
|
def self.service_type_uncached
|
37
|
-
cmd?(:systemctl) ? SystemdService : SysVInitService
|
35
|
+
Common.cmd?(:systemctl) ? SystemdService : SysVInitService
|
38
36
|
end
|
39
37
|
private_class_method :service_type_uncached
|
40
38
|
end
|
data/lib/linux_admin/system.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
module LinuxAdmin
|
2
2
|
class System
|
3
|
-
extend Common
|
4
|
-
|
5
3
|
def self.reboot!
|
6
|
-
run!(cmd(:shutdown),
|
4
|
+
Common.run!(Common.cmd(:shutdown),
|
7
5
|
:params => { "-r" => "now" })
|
8
6
|
end
|
9
7
|
|
10
8
|
def self.shutdown!
|
11
|
-
run!(cmd(:shutdown),
|
9
|
+
Common.run!(Common.cmd(:shutdown),
|
12
10
|
:params => { "-h" => "0" })
|
13
11
|
end
|
14
12
|
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
module LinuxAdmin
|
2
2
|
class TimeDate
|
3
|
-
extend Common
|
4
3
|
COMMAND = 'timedatectl'
|
5
4
|
|
6
5
|
TimeCommandError = Class.new(StandardError)
|
7
6
|
|
8
7
|
def self.system_timezone_detailed
|
9
|
-
result = run(cmd(COMMAND), :params => ["status"])
|
8
|
+
result = Common.run(Common.cmd(COMMAND), :params => ["status"])
|
10
9
|
result.output.split("\n").each do |l|
|
11
10
|
return l.split(':')[1].strip if l =~ /Time.*zone/
|
12
11
|
end
|
@@ -17,13 +16,13 @@ module LinuxAdmin
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def self.system_time=(time)
|
20
|
-
run!(cmd(COMMAND), :params => ["set-time", "#{time.strftime("%F %T")}", :adjust_system_clock])
|
19
|
+
Common.run!(Common.cmd(COMMAND), :params => ["set-time", "#{time.strftime("%F %T")}", :adjust_system_clock])
|
21
20
|
rescue AwesomeSpawn::CommandResultError => e
|
22
21
|
raise TimeCommandError, e.message
|
23
22
|
end
|
24
23
|
|
25
24
|
def self.system_timezone=(zone)
|
26
|
-
run!(cmd(COMMAND), :params => ["set-timezone", zone])
|
25
|
+
Common.run!(Common.cmd(COMMAND), :params => ["set-timezone", zone])
|
27
26
|
rescue AwesomeSpawn::CommandResultError => e
|
28
27
|
raise TimeCommandError, e.message
|
29
28
|
end
|
data/lib/linux_admin/version.rb
CHANGED
data/lib/linux_admin/volume.rb
CHANGED
@@ -15,7 +15,7 @@ module LinuxAdmin
|
|
15
15
|
def self.scan_volumes(cmd)
|
16
16
|
volumes = []
|
17
17
|
|
18
|
-
out = run!(cmd, :params => {
|
18
|
+
out = Common.run!(cmd, :params => {'-c' => nil}).output
|
19
19
|
|
20
20
|
out.each_line do |line|
|
21
21
|
fields, vg = process_volume_display_line(line.lstrip)
|
@@ -1,8 +1,5 @@
|
|
1
1
|
module LinuxAdmin
|
2
2
|
class VolumeGroup
|
3
|
-
include Common
|
4
|
-
extend Common
|
5
|
-
|
6
3
|
# volume group name
|
7
4
|
attr_accessor :name
|
8
5
|
|
@@ -29,22 +26,22 @@ module LinuxAdmin
|
|
29
26
|
end
|
30
27
|
|
31
28
|
def attach_to(lv)
|
32
|
-
run!(cmd(:lvextend),
|
33
|
-
|
29
|
+
Common.run!(Common.cmd(:lvextend),
|
30
|
+
:params => [lv.name, name])
|
34
31
|
self
|
35
32
|
end
|
36
33
|
|
37
34
|
def extend_with(pv)
|
38
|
-
run!(cmd(:vgextend),
|
39
|
-
|
35
|
+
Common.run!(Common.cmd(:vgextend),
|
36
|
+
:params => [@name, pv.device_name])
|
40
37
|
pv.volume_group = self
|
41
38
|
self
|
42
39
|
end
|
43
40
|
|
44
41
|
def self.create(name, pv)
|
45
42
|
self.scan # initialize local volume groups
|
46
|
-
run!(cmd(:vgcreate),
|
47
|
-
|
43
|
+
Common.run!(Common.cmd(:vgcreate),
|
44
|
+
:params => [name, pv.device_name])
|
48
45
|
vg = VolumeGroup.new :name => name
|
49
46
|
pv.volume_group = vg
|
50
47
|
@vgs << vg
|
@@ -55,7 +52,7 @@ module LinuxAdmin
|
|
55
52
|
@vgs ||= begin
|
56
53
|
vgs = []
|
57
54
|
|
58
|
-
out = run!(cmd(:vgdisplay), :params => {
|
55
|
+
out = Common.run!(Common.cmd(:vgdisplay), :params => {'-c' => nil}).output
|
59
56
|
|
60
57
|
out.each_line do |line|
|
61
58
|
fields = line.lstrip.split(':')
|
data/lib/linux_admin/yum.rb
CHANGED
@@ -3,8 +3,6 @@ require 'inifile'
|
|
3
3
|
|
4
4
|
module LinuxAdmin
|
5
5
|
class Yum
|
6
|
-
extend Common
|
7
|
-
|
8
6
|
def self.create_repo(path, options = {})
|
9
7
|
raise ArgumentError, "path is required" unless path
|
10
8
|
options = options.reverse_merge(:database => true, :unique_file_names => true)
|
@@ -16,7 +14,7 @@ module LinuxAdmin
|
|
16
14
|
params["--database"] = nil if options[:database]
|
17
15
|
params["--unique-md-filenames"] = nil if options[:unique_file_names]
|
18
16
|
|
19
|
-
run!(cmd, :params => params)
|
17
|
+
Common.run!(cmd, :params => params)
|
20
18
|
end
|
21
19
|
|
22
20
|
def self.download_packages(path, packages, options = {})
|
@@ -34,7 +32,7 @@ module LinuxAdmin
|
|
34
32
|
params["-a"] = options[:arch] if options[:arch]
|
35
33
|
params[nil] = packages
|
36
34
|
|
37
|
-
run!(cmd, :params => params)
|
35
|
+
Common.run!(cmd, :params => params)
|
38
36
|
end
|
39
37
|
|
40
38
|
def self.repo_settings
|
@@ -45,7 +43,7 @@ module LinuxAdmin
|
|
45
43
|
cmd = "yum check-update"
|
46
44
|
params = {nil => packages} unless packages.blank?
|
47
45
|
|
48
|
-
exitstatus = run(cmd, :params => params).exit_status
|
46
|
+
exitstatus = Common.run(cmd, :params => params).exit_status
|
49
47
|
case exitstatus
|
50
48
|
when 0; false
|
51
49
|
when 100; true
|
@@ -57,7 +55,7 @@ module LinuxAdmin
|
|
57
55
|
cmd = "yum -y update"
|
58
56
|
params = {nil => packages} unless packages.blank?
|
59
57
|
|
60
|
-
out = run!(cmd, :params => params)
|
58
|
+
out = Common.run!(cmd, :params => params)
|
61
59
|
|
62
60
|
# Handle errors that exit 0 https://bugzilla.redhat.com/show_bug.cgi?id=1141318
|
63
61
|
raise AwesomeSpawn::CommandResultError.new(out.error, out) if out.error.include?("No Match for argument")
|
@@ -71,7 +69,7 @@ module LinuxAdmin
|
|
71
69
|
cmd = "repoquery --qf=\"%{name} %{version}\""
|
72
70
|
params = {nil => packages}
|
73
71
|
|
74
|
-
out = run!(cmd, :params => params).output
|
72
|
+
out = Common.run!(cmd, :params => params).output
|
75
73
|
|
76
74
|
out.split("\n").each_with_object({}) do |i, versions|
|
77
75
|
name, version = i.split(" ", 2)
|
@@ -84,7 +82,7 @@ module LinuxAdmin
|
|
84
82
|
|
85
83
|
cmd = "yum repolist"
|
86
84
|
params = {nil => scope}
|
87
|
-
output = run!(cmd, :params => params).output
|
85
|
+
output = Common.run!(cmd, :params => params).output
|
88
86
|
|
89
87
|
parse_repo_list_output(output)
|
90
88
|
end
|
data/lib/linux_admin.rb
CHANGED
data/spec/common_spec.rb
CHANGED
@@ -1,37 +1,35 @@
|
|
1
1
|
describe LinuxAdmin::Common do
|
2
|
-
subject { Class.new { include LinuxAdmin::Common }.new }
|
3
|
-
|
4
2
|
describe "#cmd" do
|
5
3
|
it "looks up local command from id" do
|
6
|
-
expect(
|
4
|
+
expect(described_class.cmd(:dd)).to match(%r{bin/dd})
|
7
5
|
end
|
8
6
|
|
9
7
|
it "returns nil when it can't find the command" do
|
10
|
-
expect(
|
8
|
+
expect(described_class.cmd(:kasgbdlcvjhals)).to be_nil
|
11
9
|
end
|
12
10
|
end
|
13
11
|
|
14
12
|
describe "#cmd?" do
|
15
13
|
it "returns true when the command exists" do
|
16
|
-
expect(
|
14
|
+
expect(described_class.cmd?(:dd)).to be true
|
17
15
|
end
|
18
16
|
|
19
17
|
it "returns false when the command doesn't exist" do
|
20
|
-
expect(
|
18
|
+
expect(described_class.cmd?(:kasgbdlcvjhals)).to be false
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
24
22
|
describe "#run" do
|
25
23
|
it "runs a command with AwesomeSpawn.run" do
|
26
24
|
expect(AwesomeSpawn).to receive(:run).with("echo", nil => "test")
|
27
|
-
|
25
|
+
described_class.run("echo", nil => "test")
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
29
|
describe "#run!" do
|
32
30
|
it "runs a command with AwesomeSpawn.run!" do
|
33
31
|
expect(AwesomeSpawn).to receive(:run!).with("echo", nil => "test")
|
34
|
-
|
32
|
+
described_class.run!("echo", nil => "test")
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
data/spec/deb_spec.rb
CHANGED
@@ -37,9 +37,9 @@ Origin: Ubuntu
|
|
37
37
|
Supported: 9m
|
38
38
|
Task: kubuntu-desktop, kubuntu-full, kubuntu-active, kubuntu-active-desktop, kubuntu-active-full, kubuntu-active, edubuntu-desktop-gnome, ubuntustudio-font-meta
|
39
39
|
EOS
|
40
|
-
expect(
|
41
|
-
|
42
|
-
|
40
|
+
expect(LinuxAdmin::Common).to receive(:run!)
|
41
|
+
.with(described_class::APT_CACHE_CMD, :params => %w(show ruby))
|
42
|
+
.and_return(double(:output => data))
|
43
43
|
metadata = described_class.info("ruby")
|
44
44
|
expect(metadata['package']).to eq('ruby')
|
45
45
|
expect(metadata['priority']).to eq('optional')
|
data/spec/disk_spec.rb
CHANGED
@@ -13,10 +13,10 @@ describe LinuxAdmin::Disk do
|
|
13
13
|
describe "#size" do
|
14
14
|
it "uses fdisk" do
|
15
15
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
16
|
-
expect(
|
17
|
-
with(
|
18
|
-
|
19
|
-
and_return(double(:output => ""))
|
16
|
+
expect(LinuxAdmin::Common).to receive(:run!)
|
17
|
+
.with(LinuxAdmin::Common.cmd(:fdisk),
|
18
|
+
:params => {"-l" => nil})
|
19
|
+
.and_return(double(:output => ""))
|
20
20
|
disk.size
|
21
21
|
end
|
22
22
|
|
@@ -36,7 +36,7 @@ Disk identifier: 0x3ddb508b
|
|
36
36
|
eos
|
37
37
|
|
38
38
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
39
|
-
allow(
|
39
|
+
allow(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => fdisk))
|
40
40
|
expect(disk.size).to eq(500_107_862_016)
|
41
41
|
end
|
42
42
|
end
|
@@ -44,15 +44,15 @@ eos
|
|
44
44
|
describe "#partitions" do
|
45
45
|
it "uses parted" do
|
46
46
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
47
|
-
expect(
|
48
|
-
with(
|
49
|
-
|
47
|
+
expect(LinuxAdmin::Common).to receive(:run)
|
48
|
+
.with(LinuxAdmin::Common.cmd(:parted),
|
49
|
+
:params => {nil => %w(--script /dev/hda print)}).and_return(double(:output => ""))
|
50
50
|
disk.partitions
|
51
51
|
end
|
52
52
|
|
53
53
|
it "returns [] on non-zero parted rc" do
|
54
54
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
55
|
-
expect(
|
55
|
+
expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => "", :exit_status => 1))
|
56
56
|
expect(disk.partitions).to eq([])
|
57
57
|
end
|
58
58
|
|
@@ -70,7 +70,7 @@ Number Start End Size Type File system Flags
|
|
70
70
|
3 162GB 163GB 1074MB logical linux-swap(v1)
|
71
71
|
eos
|
72
72
|
disk = LinuxAdmin::Disk.new
|
73
|
-
expect(
|
73
|
+
expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => partitions))
|
74
74
|
|
75
75
|
expect(disk.partitions[0].id).to eq(1)
|
76
76
|
expect(disk.partitions[0].disk).to eq(disk)
|
@@ -137,13 +137,13 @@ eos
|
|
137
137
|
|
138
138
|
it "uses parted" do
|
139
139
|
params = ['--script', '/dev/hda', 'mkpart', '-a', 'opt', 'primary', 1024, 2048]
|
140
|
-
expect(
|
140
|
+
expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:parted), :params => {nil => params})
|
141
141
|
@disk.create_partition 'primary', 1024
|
142
142
|
end
|
143
143
|
|
144
144
|
it "accepts start/end params" do
|
145
145
|
params = ['--script', '/dev/hda', 'mkpart', '-a', 'opt', 'primary', "0%", "50%"]
|
146
|
-
expect(
|
146
|
+
expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:parted), :params => {nil => params})
|
147
147
|
@disk.create_partition 'primary', "0%", "50%"
|
148
148
|
end
|
149
149
|
|
@@ -160,25 +160,25 @@ eos
|
|
160
160
|
end
|
161
161
|
|
162
162
|
it "returns partition" do
|
163
|
-
expect(
|
163
|
+
expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
|
164
164
|
partition = @disk.create_partition 'primary', 1024
|
165
165
|
expect(partition).to be_an_instance_of(LinuxAdmin::Partition)
|
166
166
|
end
|
167
167
|
|
168
168
|
it "increments partition id" do
|
169
|
-
expect(
|
169
|
+
expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
|
170
170
|
partition = @disk.create_partition 'primary', 1024
|
171
171
|
expect(partition.id).to eq(2)
|
172
172
|
end
|
173
173
|
|
174
174
|
it "sets partition start to first unused sector on disk" do
|
175
|
-
expect(
|
175
|
+
expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
|
176
176
|
partition = @disk.create_partition 'primary', 1024
|
177
177
|
expect(partition.start_sector).to eq(1024)
|
178
178
|
end
|
179
179
|
|
180
180
|
it "stores new partition locally" do
|
181
|
-
expect(
|
181
|
+
expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
|
182
182
|
expect {
|
183
183
|
@disk.create_partition 'primary', 1024
|
184
184
|
}.to change{@disk.partitions.size}.by(1)
|
@@ -187,7 +187,7 @@ eos
|
|
187
187
|
it "creates partition table if missing" do
|
188
188
|
allow(@disk).to receive_messages(:has_partition_table? => false)
|
189
189
|
expect(@disk).to receive(:create_partition_table)
|
190
|
-
expect(
|
190
|
+
expect(LinuxAdmin::Common).to receive(:run!)
|
191
191
|
@disk.create_partition 'primary', 1024
|
192
192
|
end
|
193
193
|
end
|
@@ -195,14 +195,14 @@ eos
|
|
195
195
|
describe "#has_partition_table?" do
|
196
196
|
it "positive case" do
|
197
197
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
198
|
-
expect(
|
198
|
+
expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => "", :exit_status => 0))
|
199
199
|
expect(disk).to have_partition_table
|
200
200
|
end
|
201
201
|
|
202
202
|
it "negative case" do
|
203
203
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
204
204
|
output = "\e[?1034h\r\rError: /dev/sdb: unrecognised disk label\n"
|
205
|
-
expect(
|
205
|
+
expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => output, :exit_status => 1))
|
206
206
|
expect(disk).not_to have_partition_table
|
207
207
|
end
|
208
208
|
end
|
@@ -210,33 +210,33 @@ eos
|
|
210
210
|
it "#create_partition_table" do
|
211
211
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
212
212
|
options = {:params => {nil => %w(--script /dev/hda mklabel msdos)}}
|
213
|
-
expect(
|
213
|
+
expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:parted), options)
|
214
214
|
disk.create_partition_table
|
215
215
|
end
|
216
216
|
|
217
217
|
describe "#clear!" do
|
218
218
|
it "clears partitions" do
|
219
219
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
220
|
-
expect(
|
220
|
+
expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => "")) # stub out call to cmds
|
221
221
|
disk.partitions << LinuxAdmin::Partition.new
|
222
222
|
|
223
|
-
expect(
|
223
|
+
expect(LinuxAdmin::Common).to receive(:run!)
|
224
224
|
disk.clear!
|
225
225
|
expect(disk.partitions).to be_empty
|
226
226
|
end
|
227
227
|
|
228
228
|
it "uses dd to clear partition table" do
|
229
229
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
230
|
-
expect(
|
231
|
-
|
232
|
-
|
233
|
-
|
230
|
+
expect(LinuxAdmin::Common).to receive(:run!)
|
231
|
+
.with(LinuxAdmin::Common.cmd(:dd),
|
232
|
+
:params => {'if=' => '/dev/zero', 'of=' => '/dev/hda',
|
233
|
+
'bs=' => 512, 'count=' => 1})
|
234
234
|
disk.clear!
|
235
235
|
end
|
236
236
|
|
237
237
|
it "returns self" do
|
238
238
|
disk = LinuxAdmin::Disk.new :path => '/dev/hda'
|
239
|
-
allow(
|
239
|
+
allow(LinuxAdmin::Common).to receive(:run!) # stub out call to dd
|
240
240
|
expect(disk.clear!).to eq(disk)
|
241
241
|
end
|
242
242
|
end
|