File: mount_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (169 lines) | stat: -rw-r--r-- 6,242 bytes parent folder | download
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
require 'spec_helper'

require 'puppet/provider/mount'

describe Puppet::Provider::Mount do
  before :each do
    @mounter = Object.new
    @mounter.extend(Puppet::Provider::Mount)

    @name = "/"

    @resource = double('resource')
    allow(@resource).to receive(:[]).with(:name).and_return(@name)

    allow(@mounter).to receive(:resource).and_return(@resource)
  end

  describe Puppet::Provider::Mount, " when mounting" do
    before :each do
      allow(@mounter).to receive(:get).with(:ensure).and_return(:mounted)
    end

    it "should use the 'mountcmd' method to mount" do
      allow(@mounter).to receive(:options).and_return(nil)
      expect(@mounter).to receive(:mountcmd)

      @mounter.mount
    end

    it "should add the options following '-o' on MacOS if they exist and are not set to :absent" do
      expect(Facter).to receive(:value).with(:kernel).and_return('Darwin')
      allow(@mounter).to receive(:options).and_return("ro")
      expect(@mounter).to receive(:mountcmd).with('-o', 'ro', '/')

      @mounter.mount
    end

    it "should not explicitly pass mount options on systems other than MacOS" do
      expect(Facter).to receive(:value).with(:kernel).and_return('HP-UX')
      allow(@mounter).to receive(:options).and_return("ro")
      expect(@mounter).to receive(:mountcmd).with('/')

      @mounter.mount
    end

    it "should specify the filesystem name to the mount command" do
      allow(@mounter).to receive(:options).and_return(nil)
      expect(@mounter).to receive(:mountcmd) { |*ary| expect(ary[-1]).to eq(@name) }

      @mounter.mount
    end

    it "should update the :ensure state to :mounted if it was :unmounted before" do
      expect(@mounter).to receive(:mountcmd)
      allow(@mounter).to receive(:options).and_return(nil)
      expect(@mounter).to receive(:get).with(:ensure).and_return(:unmounted)
      expect(@mounter).to receive(:set).with(:ensure => :mounted)
      @mounter.mount
    end

    it "should update the :ensure state to :ghost if it was :absent before" do
      expect(@mounter).to receive(:mountcmd)
      allow(@mounter).to receive(:options).and_return(nil)
      expect(@mounter).to receive(:get).with(:ensure).and_return(:absent)
      expect(@mounter).to receive(:set).with(:ensure => :ghost)
      @mounter.mount
    end
  end

  describe Puppet::Provider::Mount, " when remounting" do
    context "if the resource supports remounting" do
      context "given explicit options on AIX" do
        it "should combine the options with 'remount'" do
          allow(@mounter).to receive(:info)
          allow(@mounter).to receive(:options).and_return('ro')
          allow(@resource).to receive(:[]).with(:remounts).and_return(:true)
          expect(Facter).to receive(:value).with(:operatingsystem).and_return('AIX')
          expect(@mounter).to receive(:mountcmd).with("-o", "ro,remount", @name)
          @mounter.remount
        end
      end

      it "should use '-o remount'" do
        allow(@mounter).to receive(:info)
        allow(@resource).to receive(:[]).with(:remounts).and_return(:true)
        expect(@mounter).to receive(:mountcmd).with("-o", "remount", @name)
        @mounter.remount
      end
    end

    it "should mount with '-o update' on OpenBSD" do
      allow(@mounter).to receive(:info)
      allow(@mounter).to receive(:options)
      allow(@resource).to receive(:[]).with(:remounts).and_return(false)
      expect(Facter).to receive(:value).with(:operatingsystem).and_return('OpenBSD')
      expect(@mounter).to receive(:mountcmd).with("-o", "update", @name)
      @mounter.remount
    end

    it "should unmount and mount if the resource does not specify it supports remounting" do
      allow(@mounter).to receive(:info)
      allow(@mounter).to receive(:options)
      allow(@resource).to receive(:[]).with(:remounts).and_return(false)
      expect(Facter).to receive(:value).with(:operatingsystem).and_return('AIX')
      expect(@mounter).to receive(:mount)
      expect(@mounter).to receive(:unmount)
      @mounter.remount
    end

    it "should log that it is remounting" do
      allow(@resource).to receive(:[]).with(:remounts).and_return(:true)
      allow(@mounter).to receive(:mountcmd)
      expect(@mounter).to receive(:info).with("Remounting")
      @mounter.remount
    end
  end

  describe Puppet::Provider::Mount, " when unmounting" do
    before :each do
      allow(@mounter).to receive(:get).with(:ensure).and_return(:unmounted)
    end

    it "should call the :umount command with the resource name" do
      expect(@mounter).to receive(:umount).with(@name)
      @mounter.unmount
    end

    it "should update the :ensure state to :absent if it was :ghost before" do
      expect(@mounter).to receive(:umount).with(@name).and_return(true)
      expect(@mounter).to receive(:get).with(:ensure).and_return(:ghost)
      expect(@mounter).to receive(:set).with(:ensure => :absent)
      @mounter.unmount
    end

    it "should update the :ensure state to :unmounted if it was :mounted before" do
      expect(@mounter).to receive(:umount).with(@name).and_return(true)
      expect(@mounter).to receive(:get).with(:ensure).and_return(:mounted)
      expect(@mounter).to receive(:set).with(:ensure => :unmounted)
      @mounter.unmount
    end
  end

  describe Puppet::Provider::Mount, " when determining if it is mounted" do
    it "should query the property_hash" do
      expect(@mounter).to receive(:get).with(:ensure).and_return(:mounted)
      @mounter.mounted?
    end

    it "should return true if prefetched value is :mounted" do
      allow(@mounter).to receive(:get).with(:ensure).and_return(:mounted)
      @mounter.mounted? == true
    end

    it "should return true if prefetched value is :ghost" do
      allow(@mounter).to receive(:get).with(:ensure).and_return(:ghost)
      @mounter.mounted? == true
    end

    it "should return false if prefetched value is :absent" do
      allow(@mounter).to receive(:get).with(:ensure).and_return(:absent)
      @mounter.mounted? == false
    end

    it "should return false if prefetched value is :unmounted" do
      allow(@mounter).to receive(:get).with(:ensure).and_return(:unmounted)
      @mounter.mounted? == false
    end
  end
end