0001-type-augeas-add-incl-and-lens-parameters.patch

David Lutterkort, 10/06/2009 06:44 pm

Download (4.7 kB)

b/lib/puppet/provider/augeas/augeas.rb
133 133
        unless @aug
134 134
            flags = Augeas::NONE
135 135
            flags = Augeas::TYPE_CHECK if resource[:type_check] == :true
136
            flags |= Augeas::NO_MODL_AUTOLOAD if resource[:incl]
136 137
            root = resource[:root]
137 138
            load_path = resource[:load_path]
138 139
            debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
......
141 142
            if get_augeas_version >= "0.3.6"
142 143
                debug("Augeas version #{get_augeas_version} is installed")
143 144
            end
145

  
146
            if resource[:incl]
147
                aug.set("/augeas/load/Xfm/lens", resource[:lens])
148
                aug.set("/augeas/load/Xfm/incl", resource[:incl])
149
                aug.load
150
            end
144 151
        end
145 152
        @aug
146 153
    end
b/lib/puppet/type/augeas.rb
58 58
    end
59 59

  
60 60
    newparam (:context) do
61
        desc "Optional context path. This value is pre-pended to the paths of all changes if the
62
              path is relative. So a path specified as /files/foo will not be prepended with the
63
              context whild files/foo will be prepended"
61
        desc "Optional context path. This value is prepended to the paths of all changes if the path is relative. If INCL is set, defaults to '/files' + INCL, otherwise the empty string"
64 62
        defaultto ""
63
        munge do |value|
64
            if value.empty? and resource[:incl]
65
                "/files" + resource[:incl]
66
            else
67
                value
68
            end
69
        end
65 70
    end
66 71

  
67 72
    newparam (:onlyif) do
......
129 134
        defaultto :false
130 135
    end
131 136

  
137
    newparam(:lens) do
138
        desc "Use a specific lens, e.g. 'Hosts.lns'. When this parameter is set, you must also set the incl parameter to indicate which file to load. Only that file will be loaded, which greatly speeds up execution of the type"
139
    end
140

  
141
    newparam(:incl) do
142
        desc "Load only a specific file, e.g. '/etc/hosts'.  When this parameter is set, you must also set the lens parameter to indicate which lens to use."
143
    end
144

  
145
    validate do
146
        has_lens = !self[:lens].nil?
147
        has_incl = !self[:incl].nil?
148
        if has_lens != has_incl
149
            self.fail "You must specify both the lens and incl parameters, or neither"
150
        end
151
    end
152

  
132 153
    # This is the acutal meat of the code. It forces
133 154
    # augeas to be run and fails or not based on the augeas return
134 155
    # code.
b/spec/unit/type/augeas.rb
103 103
            changes.retrieve.should == :need_to_run
104 104
        end
105 105
    end
106

  
107
    describe "loading specific files" do
108
        it "should require lens when incl is used" do
109
            lambda { augeas.new(:name => :no_lens, :incl => "/etc/hosts")}.should raise_error(Puppet::Error)
110
        end
111

  
112
        it "should require incl when lens is used" do
113
            lambda { augeas.new(:name => :no_incl, :lens => "Hosts.lns") }.should raise_error(Puppet::Error)
114
        end
115

  
116
        it "should set the context when a specific file is used" do
117
            augeas.new(:name => :no_incl, :lens => "Hosts.lns", :incl => "/etc/hosts")[:context].should == "/files/etc/hosts"
118
        end
119
    end
106 120
end
107
-