blob: 1f25017650d483821deb8a9648e86299f98a2f43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet_spec/files'
require 'puppet/provider/mount'
describe Puppet::Provider::Mount do
include PuppetSpec::Files
before :each do
@name = "/"
@resource = Puppet::Type.type(:mount).new(
:name => '/',
:device => '/dev/sda1',
:target => tmpfile("mount_provider")
)
@mounter = Puppet::Type.type(:mount).defaultprovider().new(@resource)
end
describe "when calling mount!" do
it "should use the 'mountcmd' method to mount" do
@mounter.stubs(:options).returns(nil)
@mounter.expects(:mountcmd)
@mounter.mount!
end
it "should flush before mounting if a flush method exists" do
@mounter.meta_def(:flush) { }
@mounter.expects(:flush)
@mounter.stubs(:mountcmd)
@mounter.stubs(:options).returns(nil)
@mounter.mount!
end
it "should add the options following '-o' if they exist and are not set to :absent" do
@mounter.stubs(:options).returns("ro")
@mounter.expects(:mountcmd).with { |*ary| ary[0] == "-o" and ary[1] == "ro" }
@mounter.mount!
end
it "should specify the filesystem name to the mount command" do
@mounter.stubs(:options).returns(nil)
@mounter.expects(:mountcmd).with { |*ary| ary[-1] == @name }
@mounter.mount!
end
end
describe "when remounting" do
it "should use '-o remount' if the resource specifies it supports remounting" do
@mounter.stubs(:info)
@resource[:remounts] = true
@mounter.expects(:mountcmd).with("-o", "remount", @name)
@mounter.remount
end
it "should unmount and mount if the resource does not specify it supports remounting" do
@mounter.stubs(:info)
@resource[:remounts] = false
@mounter.expects(:unmount)
@mounter.expects(:mount)
@mounter.remount
end
it "should log that it is remounting" do
@resource[:remounts] = true
@mounter.stubs(:mountcmd)
@mounter.expects(:info).with("Remounting")
@mounter.remount
end
end
describe "when unmounting" do
it "should call the :umount command with the resource name" do
@mounter.expects(:umount).with(@name)
@mounter.unmount
end
end
%w{Darwin Solaris HP-UX AIX Other}.each do |platform|
describe "on #{platform}" do
before :each do
case platform
when 'Darwin'
mount_fixture = 'mount-output.darwin.txt'
@mount_device = '/dev/disk0s3'
@mount_point = '/usr'
when 'Solaris'
mount_fixture = 'mount-output.solaris.txt'
@mount_device = 'swap'
@mount_point = '/tmp'
when 'HP-UX'
mount_fixture = 'mount-output.hp-ux.txt'
@mount_device = 'swap'
@mount_point = '/tmp'
when 'AIX'
mount_fixture = 'mount-output.aix.txt'
@mount_device = '/dev/hd2'
@mount_point = '/usr'
when 'Other'
mount_fixture = 'mount-output.other.txt'
@mount_device = '/dev/sda2'
@mount_point = '/usr'
end
@mount_data = File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'unit', 'provider', 'mount', mount_fixture))
Facter.stubs(:value).with("operatingsystem").returns(platform)
end
describe "when the correct thing is mounted" do
before :each do
@mounter.expects(:mountcmd).returns(@mount_data)
@resource.stubs(:[]).with(:name).returns(@mount_point)
@resource.stubs(:[]).with(:device).returns(@mount_device)
end
it "should say anything_mounted?" do
@mounter.should be_anything_mounted
end
it "should say correctly_mounted?" do
@mounter.should be_correctly_mounted
end
end
describe "when the wrong thing is mounted" do
before :each do
@mounter.expects(:mountcmd).returns(@mount_data)
@resource.stubs(:[]).with(:name).returns(@mount_point)
@resource.stubs(:[]).with(:device).returns('/dev/bogus/thing')
end
it "should say anything_mounted?" do
@mounter.should be_anything_mounted
end
it "should not say correctly_mounted?" do
@mounter.should_not be_correctly_mounted
end
end
describe "when nothing is mounted" do
before :each do
@mounter.expects(:mountcmd).returns(@mount_data)
@resource.stubs(:[]).with(:name).returns('/bogus/location')
@resource.stubs(:[]).with(:device).returns(@mount_device)
end
it "should not say anything_mounted?" do
@mounter.should_not be_anything_mounted
end
it "should not say correctly_mounted?" do
@mounter.should_not be_correctly_mounted
end
end
end
end
describe "when mounting a device" do
it "should not mount! or unmount anything when the correct device is mounted" do
@mounter.stubs(:correctly_mounted?).returns(true)
@mounter.expects(:anything_mounted?).never
@mounter.expects(:create).once
@mounter.expects(:mount!).never
@mounter.expects(:unmount).never
FileUtils.expects(:mkdir_p).never
@mounter.mount
end
it "should mount the device when nothing is mounted at the desired point" do
@mounter.stubs(:correctly_mounted?).returns(false)
@mounter.stubs(:anything_mounted?).returns(false)
@mounter.expects(:create).once
@mounter.expects(:mount!).once
@mounter.expects(:unmount).never
FileUtils.expects(:mkdir_p).never
@mounter.mount
end
it "should unmount the incorrect device and mount the correct device" do
@mounter.stubs(:correctly_mounted?).returns(false)
@mounter.stubs(:anything_mounted?).returns(true)
@mounter.expects(:create).once
@mounter.expects(:mount!).once
@mounter.expects(:unmount).once
FileUtils.expects(:mkdir_p).with(@name).returns(true)
@mounter.mount
end
end
end
|