linux_admin 1.2.4 → 2.0.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.rb +0 -8
- data/lib/linux_admin/disk.rb +12 -5
- data/lib/linux_admin/registration_system.rb +8 -4
- data/lib/linux_admin/scap.rb +1 -1
- data/lib/linux_admin/service/sys_v_init_service.rb +2 -1
- data/lib/linux_admin/service/systemd_service.rb +6 -2
- data/lib/linux_admin/version.rb +1 -1
- metadata +8 -100
- data/lib/linux_admin/registration_system/rhn.rb +0 -111
- data/spec/chrony_spec.rb +0 -64
- data/spec/common_spec.rb +0 -37
- data/spec/data/rhn/output_rhn-channel_list +0 -2
- data/spec/data/rhn/output_rhn-channel_list_available +0 -4
- data/spec/data/rhn/systemid +0 -57
- data/spec/data/rhn/systemid.missing_system_id +0 -57
- data/spec/data/rpm/cmd_output_for_list_installed +0 -20
- data/spec/data/subscription_manager/output_list_all_available +0 -42
- data/spec/data/subscription_manager/output_list_installed_not_subscribed +0 -19
- data/spec/data/subscription_manager/output_list_installed_subscribed +0 -19
- data/spec/data/subscription_manager/output_orgs +0 -6
- data/spec/data/subscription_manager/output_repos +0 -18
- data/spec/data/time_date/timedatectl_output +0 -14
- data/spec/data/yum/first.repo +0 -19
- data/spec/data/yum/output_repo_list +0 -13
- data/spec/data/yum/output_repoquery_multiple +0 -3
- data/spec/data/yum/output_repoquery_single +0 -1
- data/spec/data/yum/second.repo +0 -9
- data/spec/deb_spec.rb +0 -52
- data/spec/disk_spec.rb +0 -307
- data/spec/distro_spec.rb +0 -77
- data/spec/dns_spec.rb +0 -105
- data/spec/etc_issue_spec.rb +0 -37
- data/spec/fstab_spec.rb +0 -132
- data/spec/hardware_spec.rb +0 -46
- data/spec/hosts_spec.rb +0 -150
- data/spec/ip_address_spec.rb +0 -148
- data/spec/logical_volume_spec.rb +0 -166
- data/spec/mountable_spec.rb +0 -182
- data/spec/network_interface/network_interface_rh_spec.rb +0 -291
- data/spec/network_interface_spec.rb +0 -284
- data/spec/partition_spec.rb +0 -24
- data/spec/physical_volume_spec.rb +0 -101
- data/spec/registration_system_spec.rb +0 -85
- data/spec/rhn_spec.rb +0 -144
- data/spec/rpm_spec.rb +0 -85
- data/spec/scap_spec.rb +0 -48
- data/spec/service/sys_v_init_service_spec.rb +0 -127
- data/spec/service/systemd_service_spec.rb +0 -133
- data/spec/service_spec.rb +0 -54
- data/spec/spec_helper.rb +0 -116
- data/spec/ssh_spec.rb +0 -53
- data/spec/subscription_manager_spec.rb +0 -228
- data/spec/system_spec.rb +0 -15
- data/spec/time_date_spec.rb +0 -106
- data/spec/volume_group_spec.rb +0 -99
- data/spec/yum_spec.rb +0 -155
data/spec/ip_address_spec.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
describe LinuxAdmin::IpAddress do
|
2
|
-
let(:ip) { described_class.new }
|
3
|
-
|
4
|
-
ADDR_SPAWN_ARGS = [
|
5
|
-
LinuxAdmin::Common.cmd("hostname"),
|
6
|
-
:params => ["-I"]
|
7
|
-
]
|
8
|
-
|
9
|
-
MAC_SPAWN_ARGS = [
|
10
|
-
LinuxAdmin::Common.cmd("ip"),
|
11
|
-
:params => %w(addr show eth0)
|
12
|
-
]
|
13
|
-
|
14
|
-
MASK_SPAWN_ARGS = [
|
15
|
-
LinuxAdmin::Common.cmd("ifconfig"),
|
16
|
-
:params => %w(eth0)
|
17
|
-
]
|
18
|
-
|
19
|
-
GW_SPAWN_ARGS = [
|
20
|
-
LinuxAdmin::Common.cmd("ip"),
|
21
|
-
:params => %w(route)
|
22
|
-
]
|
23
|
-
|
24
|
-
IP_ADDR_SHOW_ETH0 = <<-IP_OUT
|
25
|
-
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
26
|
-
link/ether 00:0c:29:ed:0e:8b brd ff:ff:ff:ff:ff:ff
|
27
|
-
inet 192.168.1.9/24 brd 192.168.1.255 scope global dynamic eth0
|
28
|
-
valid_lft 1297sec preferred_lft 1297sec
|
29
|
-
inet6 fe80::20c:29ff:feed:e8b/64 scope link
|
30
|
-
valid_lft forever preferred_lft forever
|
31
|
-
|
32
|
-
IP_OUT
|
33
|
-
|
34
|
-
IFCFG = <<-IP_OUT
|
35
|
-
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
|
36
|
-
inet 192.168.1.9 netmask 255.255.255.0 broadcast 192.168.1.255
|
37
|
-
inet6 fe80::20c:29ff:feed:e8b prefixlen 64 scopeid 0x20<link>
|
38
|
-
ether 00:0c:29:ed:0e:8b txqueuelen 1000 (Ethernet)
|
39
|
-
RX packets 10171 bytes 8163955 (7.7 MiB)
|
40
|
-
RX errors 0 dropped 0 overruns 0 frame 0
|
41
|
-
TX packets 2871 bytes 321915 (314.3 KiB)
|
42
|
-
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
43
|
-
|
44
|
-
IP_OUT
|
45
|
-
|
46
|
-
IP_ROUTE = <<-IP_OUT
|
47
|
-
default via 192.168.1.1 dev eth0 proto static metric 100
|
48
|
-
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.9 metric 100
|
49
|
-
IP_OUT
|
50
|
-
|
51
|
-
def result(output, exit_status)
|
52
|
-
AwesomeSpawn::CommandResult.new("", output, "", exit_status)
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#address" do
|
56
|
-
it "returns an address" do
|
57
|
-
ip_addr = "192.168.1.2"
|
58
|
-
expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
|
59
|
-
expect(ip.address).to eq(ip_addr)
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns nil when no address is found" do
|
63
|
-
ip_addr = ""
|
64
|
-
expect(AwesomeSpawn).to receive(:run).at_least(5).times.with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 1))
|
65
|
-
expect(ip.address).to be_nil
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns only IPv4 addresses" do
|
69
|
-
ip_addr = "fd12:3456:789a:1::1 192.168.1.2"
|
70
|
-
expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
|
71
|
-
expect(ip.address).to eq("192.168.1.2")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe "#address6" do
|
76
|
-
it "returns an address" do
|
77
|
-
ip_addr = "fd12:3456:789a:1::1"
|
78
|
-
expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
|
79
|
-
expect(ip.address6).to eq(ip_addr)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "returns nil when no address is found" do
|
83
|
-
ip_addr = ""
|
84
|
-
expect(AwesomeSpawn).to receive(:run).at_least(5).times.with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 1))
|
85
|
-
expect(ip.address6).to be_nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it "returns only IPv6 addresses" do
|
89
|
-
ip_addr = "192.168.1.2 fd12:3456:789a:1::1"
|
90
|
-
expect(AwesomeSpawn).to receive(:run).with(*ADDR_SPAWN_ARGS).and_return(result(ip_addr, 0))
|
91
|
-
expect(ip.address6).to eq("fd12:3456:789a:1::1")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
describe "#mac_address" do
|
96
|
-
it "returns the correct MAC address" do
|
97
|
-
expect(AwesomeSpawn).to receive(:run).with(*MAC_SPAWN_ARGS).and_return(result(IP_ADDR_SHOW_ETH0, 0))
|
98
|
-
expect(ip.mac_address("eth0")).to eq("00:0c:29:ed:0e:8b")
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns nil when the command fails" do
|
102
|
-
expect(AwesomeSpawn).to receive(:run).with(*MAC_SPAWN_ARGS).and_return(result("", 1))
|
103
|
-
expect(ip.mac_address("eth0")).to be_nil
|
104
|
-
end
|
105
|
-
|
106
|
-
it "returns nil if the link/ether line is not present" do
|
107
|
-
bad_output = IP_ADDR_SHOW_ETH0.gsub(%r{link/ether}, "")
|
108
|
-
expect(AwesomeSpawn).to receive(:run).with(*MAC_SPAWN_ARGS).and_return(result(bad_output, 0))
|
109
|
-
expect(ip.mac_address("eth0")).to be_nil
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
describe "#netmask" do
|
114
|
-
it "returns the correct netmask" do
|
115
|
-
expect(AwesomeSpawn).to receive(:run).with(*MASK_SPAWN_ARGS).and_return(result(IFCFG, 0))
|
116
|
-
expect(ip.netmask("eth0")).to eq("255.255.255.0")
|
117
|
-
end
|
118
|
-
|
119
|
-
it "returns nil when the command fails" do
|
120
|
-
expect(AwesomeSpawn).to receive(:run).with(*MASK_SPAWN_ARGS).and_return(result("", 1))
|
121
|
-
expect(ip.netmask("eth0")).to be_nil
|
122
|
-
end
|
123
|
-
|
124
|
-
it "returns nil if the netmask line is not present" do
|
125
|
-
bad_output = IFCFG.gsub(/netmask/, "")
|
126
|
-
expect(AwesomeSpawn).to receive(:run).with(*MASK_SPAWN_ARGS).and_return(result(bad_output, 0))
|
127
|
-
expect(ip.netmask("eth0")).to be_nil
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
describe "#gateway" do
|
132
|
-
it "returns the correct gateway address" do
|
133
|
-
expect(AwesomeSpawn).to receive(:run).with(*GW_SPAWN_ARGS).and_return(result(IP_ROUTE, 0))
|
134
|
-
expect(ip.gateway).to eq("192.168.1.1")
|
135
|
-
end
|
136
|
-
|
137
|
-
it "returns nil when the command fails" do
|
138
|
-
expect(AwesomeSpawn).to receive(:run).with(*GW_SPAWN_ARGS).and_return(result("", 1))
|
139
|
-
expect(ip.gateway).to be_nil
|
140
|
-
end
|
141
|
-
|
142
|
-
it "returns nil if the default line is not present" do
|
143
|
-
bad_output = IP_ROUTE.gsub(/default/, "")
|
144
|
-
expect(AwesomeSpawn).to receive(:run).with(*GW_SPAWN_ARGS).and_return(result(bad_output, 0))
|
145
|
-
expect(ip.gateway).to be_nil
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
data/spec/logical_volume_spec.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
describe LinuxAdmin::LogicalVolume do
|
2
|
-
before(:each) do
|
3
|
-
@logical_volumes = <<eos
|
4
|
-
/dev/vg_foobar/lv_swap:vg_foobar:3:1:-1:2:4128768:63:-1:0:-1:253:0
|
5
|
-
/dev/vg_foobar/lv_root:vg_foobar:3:1:-1:1:19988480:305:-1:0:-1:253:1
|
6
|
-
eos
|
7
|
-
|
8
|
-
@groups = <<eos
|
9
|
-
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
|
10
|
-
eos
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:each) do
|
14
|
-
# reset local copies of volumes / groups
|
15
|
-
described_class.instance_variable_set(:@lvs, nil)
|
16
|
-
LinuxAdmin::PhysicalVolume.instance_variable_set(:@pvs, nil)
|
17
|
-
LinuxAdmin::VolumeGroup.instance_variable_set(:@vgs, nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "#extend_with" do
|
21
|
-
it "uses lvextend" do
|
22
|
-
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
23
|
-
lv = described_class.new :name => 'lv', :volume_group => vg
|
24
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
25
|
-
.with(LinuxAdmin::Common.cmd(:lvextend),
|
26
|
-
:params => %w(lv vg))
|
27
|
-
lv.extend_with(vg)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns self" do
|
31
|
-
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
32
|
-
lv = described_class.new :name => 'lv', :volume_group => vg
|
33
|
-
allow(LinuxAdmin::Common).to receive(:run!)
|
34
|
-
expect(lv.extend_with(vg)).to eq(lv)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#path" do
|
39
|
-
it "returns /dev/vgname/lvname" do
|
40
|
-
vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
41
|
-
lv = described_class.new :name => 'lv', :volume_group => vg
|
42
|
-
expect(lv.path).to eq('/dev/vg/lv')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#create" do
|
47
|
-
before(:each) do
|
48
|
-
@vg = LinuxAdmin::VolumeGroup.new :name => 'vg'
|
49
|
-
end
|
50
|
-
|
51
|
-
it "uses lvcreate" do
|
52
|
-
described_class.instance_variable_set(:@lvs, [])
|
53
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
54
|
-
.with(LinuxAdmin::Common.cmd(:lvcreate),
|
55
|
-
:params => {'-n' => 'lv',
|
56
|
-
nil => 'vg',
|
57
|
-
'-L' => '256G'})
|
58
|
-
described_class.create 'lv', @vg, 274_877_906_944 # 256.gigabytes
|
59
|
-
end
|
60
|
-
|
61
|
-
context "size is specified" do
|
62
|
-
it "passes -L option to lvcreate" do
|
63
|
-
described_class.instance_variable_set(:@lvs, [])
|
64
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
65
|
-
.with(LinuxAdmin::Common.cmd(:lvcreate),
|
66
|
-
:params => {'-n' => 'lv',
|
67
|
-
nil => 'vg',
|
68
|
-
'-L' => '256G'})
|
69
|
-
described_class.create 'lv', @vg, 274_877_906_944 # 256.gigabytes
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "extents is specified" do
|
74
|
-
it "passes -l option to lvcreate" do
|
75
|
-
described_class.instance_variable_set(:@lvs, [])
|
76
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
77
|
-
.with(LinuxAdmin::Common.cmd(:lvcreate),
|
78
|
-
:params => {'-n' => 'lv',
|
79
|
-
nil => 'vg',
|
80
|
-
'-l' => '100%FREE'})
|
81
|
-
described_class.create 'lv', @vg, 100
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it "returns new logical volume" do
|
86
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
87
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
88
|
-
lv = described_class.create 'lv', @vg, 274_877_906_944 # 256.gigabytes
|
89
|
-
expect(lv).to be_an_instance_of(described_class)
|
90
|
-
expect(lv.name).to eq('lv')
|
91
|
-
end
|
92
|
-
|
93
|
-
context "name is specified" do
|
94
|
-
it "sets path under volume group" do
|
95
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
96
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
97
|
-
lv = described_class.create 'lv', @vg, 274_877_906_944 # 256.gigabytes
|
98
|
-
expect(lv.path.to_s).to eq("#{described_class::DEVICE_PATH}#{@vg.name}/lv")
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "path is specified" do
|
103
|
-
it "sets name" do
|
104
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
105
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
106
|
-
lv = described_class.create '/dev/lv', @vg, 274_877_906_944 # 256.gigabytes
|
107
|
-
expect(lv.name).to eq("lv")
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "path is specified as Pathname" do
|
112
|
-
it "sets name" do
|
113
|
-
require 'pathname'
|
114
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
115
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
116
|
-
lv = described_class.create Pathname.new("/dev/#{@vg.name}/lv"), @vg, 274_877_906_944 # 256.gigabytes
|
117
|
-
expect(lv.name).to eq("lv")
|
118
|
-
expect(lv.path).to eq("/dev/vg/lv")
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it "adds logical volume to local registry" do
|
123
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
124
|
-
allow(LinuxAdmin::Common).to receive_messages(:run! => double(:output => ""))
|
125
|
-
lv = described_class.create 'lv', @vg, 274_877_906_944 # 256.gigabytes
|
126
|
-
expect(described_class.scan).to include(lv)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "#scan" do
|
131
|
-
it "uses lvdisplay" do
|
132
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
133
|
-
.with(LinuxAdmin::Common.cmd(:lvdisplay),
|
134
|
-
:params => {'-c' => nil})
|
135
|
-
.and_return(double(:output => @logical_volumes))
|
136
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @groups)) # stub out call to vgdisplay
|
137
|
-
described_class.scan
|
138
|
-
end
|
139
|
-
|
140
|
-
it "returns local logical volumes" do
|
141
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @logical_volumes))
|
142
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @groups))
|
143
|
-
lvs = described_class.scan
|
144
|
-
|
145
|
-
expect(lvs[0]).to be_an_instance_of(described_class)
|
146
|
-
expect(lvs[0].path).to eq('/dev/vg_foobar/lv_swap')
|
147
|
-
expect(lvs[0].name).to eq('lv_swap')
|
148
|
-
expect(lvs[0].sectors).to eq(4128768)
|
149
|
-
|
150
|
-
expect(lvs[1]).to be_an_instance_of(described_class)
|
151
|
-
expect(lvs[1].path).to eq('/dev/vg_foobar/lv_root')
|
152
|
-
expect(lvs[1].name).to eq('lv_root')
|
153
|
-
expect(lvs[1].sectors).to eq(19988480)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "resolves volume group references" do
|
157
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @logical_volumes))
|
158
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @groups))
|
159
|
-
lvs = described_class.scan
|
160
|
-
expect(lvs[0].volume_group).to be_an_instance_of(LinuxAdmin::VolumeGroup)
|
161
|
-
expect(lvs[0].volume_group.name).to eq('vg_foobar')
|
162
|
-
expect(lvs[1].volume_group).to be_an_instance_of(LinuxAdmin::VolumeGroup)
|
163
|
-
expect(lvs[1].volume_group.name).to eq('vg_foobar')
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
data/spec/mountable_spec.rb
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
class TestMountable
|
2
|
-
include LinuxAdmin::Mountable
|
3
|
-
|
4
|
-
def path
|
5
|
-
"/dev/foo"
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
describe LinuxAdmin::Mountable do
|
10
|
-
before(:each) do
|
11
|
-
@mountable = TestMountable.new
|
12
|
-
|
13
|
-
# stub out calls that modify system
|
14
|
-
allow(FileUtils).to receive(:mkdir)
|
15
|
-
allow(LinuxAdmin::Common).to receive(:run!)
|
16
|
-
|
17
|
-
@mount_out1 = <<eos
|
18
|
-
/dev/sda on /mnt/usb type vfat (rw)
|
19
|
-
eos
|
20
|
-
@mount_out2 = <<eos
|
21
|
-
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
|
22
|
-
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
|
23
|
-
eos
|
24
|
-
|
25
|
-
@mount_out3 = <<eos
|
26
|
-
/dev/mapper/vg_data-lv_pg on /var/opt/rh/rh-postgresql95/lib/pgsql type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
|
27
|
-
/dev/foo on /tmp type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
|
28
|
-
/dev/foo on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
|
29
|
-
eos
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#mount_point_exists?" do
|
33
|
-
it "uses mount" do
|
34
|
-
expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:mount))
|
35
|
-
.and_return(double(:output => ""))
|
36
|
-
TestMountable.mount_point_exists?('/mnt/usb')
|
37
|
-
end
|
38
|
-
|
39
|
-
context "disk mounted at specified location" do
|
40
|
-
before do
|
41
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out1))
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns true" do
|
45
|
-
expect(TestMountable.mount_point_exists?('/mnt/usb')).to be_truthy
|
46
|
-
end
|
47
|
-
|
48
|
-
it "returns true when using a pathname" do
|
49
|
-
path = Pathname.new("/mnt/usb")
|
50
|
-
expect(TestMountable.mount_point_exists?(path)).to be_truthy
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "no disk mounted at specified location" do
|
55
|
-
before do
|
56
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out2))
|
57
|
-
end
|
58
|
-
|
59
|
-
it "returns false" do
|
60
|
-
expect(TestMountable.mount_point_exists?('/mnt/usb')).to be_falsey
|
61
|
-
end
|
62
|
-
|
63
|
-
it "returns false when using a pathname" do
|
64
|
-
path = Pathname.new("/mnt/usb")
|
65
|
-
expect(TestMountable.mount_point_exists?(path)).to be_falsey
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "#mount_point_available?" do
|
71
|
-
it "uses mount" do
|
72
|
-
expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:mount))
|
73
|
-
.and_return(double(:output => ""))
|
74
|
-
TestMountable.mount_point_available?('/mnt/usb')
|
75
|
-
end
|
76
|
-
|
77
|
-
context "disk mounted at specified location" do
|
78
|
-
before do
|
79
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out1))
|
80
|
-
end
|
81
|
-
|
82
|
-
it "returns false" do
|
83
|
-
expect(TestMountable.mount_point_available?('/mnt/usb')).to be_falsey
|
84
|
-
end
|
85
|
-
|
86
|
-
it "returns false when using a pathname" do
|
87
|
-
path = Pathname.new("/mnt/usb")
|
88
|
-
expect(TestMountable.mount_point_available?(path)).to be_falsey
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
context "no disk mounted at specified location" do
|
93
|
-
before do
|
94
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out2))
|
95
|
-
end
|
96
|
-
|
97
|
-
it "returns true" do
|
98
|
-
expect(TestMountable.mount_point_available?('/mnt/usb')).to be_truthy
|
99
|
-
end
|
100
|
-
|
101
|
-
it "returns true when using a pathname" do
|
102
|
-
path = Pathname.new("/mnt/usb")
|
103
|
-
expect(TestMountable.mount_point_available?(path)).to be_truthy
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
describe "#discover_mount_point" do
|
109
|
-
it "sets the correct mountpoint when the path is mounted" do
|
110
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out3))
|
111
|
-
@mountable.discover_mount_point
|
112
|
-
expect(@mountable.mount_point).to eq("/tmp")
|
113
|
-
end
|
114
|
-
|
115
|
-
it "sets mount_point to nil when the path is not mounted" do
|
116
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out1))
|
117
|
-
@mountable.discover_mount_point
|
118
|
-
expect(@mountable.mount_point).to be_nil
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "#format_to" do
|
123
|
-
it "uses mke2fs" do
|
124
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
125
|
-
.with(LinuxAdmin::Common.cmd(:mke2fs),
|
126
|
-
:params => {'-t' => 'ext4', nil => '/dev/foo'})
|
127
|
-
@mountable.format_to('ext4')
|
128
|
-
end
|
129
|
-
|
130
|
-
it "sets fs type" do
|
131
|
-
expect(LinuxAdmin::Common).to receive(:run!) # ignore actual formatting cmd
|
132
|
-
@mountable.format_to('ext4')
|
133
|
-
expect(@mountable.fs_type).to eq('ext4')
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe "#mount" do
|
138
|
-
it "sets mount point" do
|
139
|
-
# ignore actual mount cmds
|
140
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => ""))
|
141
|
-
expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => ""))
|
142
|
-
|
143
|
-
expect(@mountable.mount('/mnt/sda2')).to eq('/mnt/sda2')
|
144
|
-
expect(@mountable.mount_point).to eq('/mnt/sda2')
|
145
|
-
end
|
146
|
-
|
147
|
-
context "mountpoint does not exist" do
|
148
|
-
it "creates mountpoint" do
|
149
|
-
expect(TestMountable).to receive(:mount_point_exists?).and_return(false)
|
150
|
-
expect(File).to receive(:directory?).with('/mnt/sda2').and_return(false)
|
151
|
-
expect(FileUtils).to receive(:mkdir).with('/mnt/sda2')
|
152
|
-
expect(LinuxAdmin::Common).to receive(:run!) # ignore actual mount cmd
|
153
|
-
@mountable.mount '/mnt/sda2'
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context "disk mounted at mountpoint" do
|
158
|
-
it "raises argument error" do
|
159
|
-
expect(TestMountable).to receive(:mount_point_exists?).and_return(true)
|
160
|
-
expect(File).to receive(:directory?).with('/mnt/sda2').and_return(true)
|
161
|
-
expect { @mountable.mount '/mnt/sda2' }.to raise_error(ArgumentError, "disk already mounted at /mnt/sda2")
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
it "mounts partition" do
|
166
|
-
expect(TestMountable).to receive(:mount_point_exists?).and_return(false)
|
167
|
-
expect(LinuxAdmin::Common).to receive(:run!)
|
168
|
-
.with(LinuxAdmin::Common.cmd(:mount),
|
169
|
-
:params => {nil => ['/dev/foo', '/mnt/sda2']})
|
170
|
-
@mountable.mount '/mnt/sda2'
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe "#umount" do
|
175
|
-
it "unmounts partition" do
|
176
|
-
@mountable.mount_point = '/mnt/sda2'
|
177
|
-
expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:umount),
|
178
|
-
:params => {nil => ['/mnt/sda2']})
|
179
|
-
@mountable.umount
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|