diff options
| -rw-r--r-- | lib/puppet/metatype/providers.rb | 11 | ||||
| -rw-r--r-- | lib/puppet/provider/mount.rb | 39 | ||||
| -rw-r--r-- | lib/puppet/provider/mount/netinfo.rb | 37 | ||||
| -rwxr-xr-x | lib/puppet/provider/mount/parsed.rb | 32 | ||||
| -rw-r--r-- | lib/puppet/provider/nameservice.rb | 4 | ||||
| -rw-r--r-- | lib/puppet/provider/nameservice/netinfo.rb | 5 | ||||
| -rwxr-xr-x | lib/puppet/type/group.rb | 2 | ||||
| -rwxr-xr-x | lib/puppet/type/mount.rb | 7 | ||||
| -rwxr-xr-x | test/providers/netinfo_mount.rb | 80 |
9 files changed, 177 insertions, 40 deletions
diff --git a/lib/puppet/metatype/providers.rb b/lib/puppet/metatype/providers.rb index 0165da83e..04de20732 100644 --- a/lib/puppet/metatype/providers.rb +++ b/lib/puppet/metatype/providers.rb @@ -44,7 +44,7 @@ class Puppet::Type # Convert a hash, as provided by, um, a provider, into an instance of self. def self.hash2obj(hash) obj = nil - + namevar = self.namevar unless hash.include?(namevar) and hash[namevar] raise Puppet::DevError, "Hash was not passed with namevar" @@ -93,7 +93,14 @@ class Puppet::Type suitableprovider.find_all { |p| p.respond_to?(:list) }.collect { |prov| prov.list.each { |h| h[:provider] = prov.name } }.flatten.collect do |hash| - hash2obj(hash) + if hash.is_a?(Hash) + hash2obj(hash) + elsif hash.is_a?(self) + hash + else + raise Puppet::DevError, "Provider %s returned object of type %s in list" % + [prov.name, hash.class] + end end end end diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb new file mode 100644 index 000000000..d3597ef15 --- /dev/null +++ b/lib/puppet/provider/mount.rb @@ -0,0 +1,39 @@ +# Created by Luke Kanies on 2006-11-12. +# Copyright (c) 2006. All rights reserved. + +require 'puppet' + +# A module just to store the mount/unmount methods. Individual providers +# still need to add the mount commands manually. +module Puppet::Provider::Mount + # This only works when the mount point is synced to the fstab. + def mount + mountcmd @model[:name] + end + + # This only works when the mount point is synced to the fstab. + def unmount + umount @model[:name] + end + + # Is the mount currently mounted? + def mounted? + platform = Facter["operatingsystem"].value + df = command(:df) + case Facter["operatingsystem"].value + # Solaris's df prints in a very weird format + when "Solaris": df = "#{command(:df)} -k" + end + %x{#{df}}.split("\n").find do |line| + fs = line.split(/\s+/)[-1] + if platform == "Darwin" + fs == "/private/var/automount" + @model[:name] or + fs == @model[:name] + else + fs == @model[:name] + end + end + end +end + +# $Id$
\ No newline at end of file diff --git a/lib/puppet/provider/mount/netinfo.rb b/lib/puppet/provider/mount/netinfo.rb new file mode 100644 index 000000000..4f39dfbdf --- /dev/null +++ b/lib/puppet/provider/mount/netinfo.rb @@ -0,0 +1,37 @@ +# Manage NetInfo POSIX objects. Probably only used on OS X, but I suppose +# it could be used elsewhere. +require 'puppet/provider/nameservice/netinfo' +require 'puppet/provider/mount' + +Puppet::Type.type(:mount).provide :netinfo, :parent => Puppet::Provider::NameService::NetInfo do + include Puppet::Provider::Mount + desc "Mount management in NetInfo. This provider is highly experimental and is known + not to work currently." + commands :nireport => "nireport", :niutil => "niutil" + commands :mountcmd => "mount", :umount => "umount", :df => "df" + + options :device, :key => "name" + options :name, :key => "dir" + options :dump, :key => "dump_freq" + options :pass, :key => "passno" + options :fstype, :key => "vfstype" + options :options, :key => "opts" + + defaultfor :operatingsystem => :darwin + + def initialize(model) + warning "The NetInfo mount provider is highly experimental. Use at your own risk." + end + + def mount + cmd = [] + if opts = @model.should(:options) + cmd << opts + end + cmd << @model.should(:device) + cmd << @model[:name] + mountcmd cmd.join(" ") + end +end + +# $Id$ diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb index af67ca6ff..106d624bf 100755 --- a/lib/puppet/provider/mount/parsed.rb +++ b/lib/puppet/provider/mount/parsed.rb @@ -1,4 +1,5 @@ require 'puppet/provider/parsedfile' +require 'puppet/provider/mount' fstab = nil case Facter.value(:operatingsystem) @@ -12,6 +13,8 @@ Puppet::Type.type(:mount).provide(:parsed, :default_target => fstab, :filetype => :flat ) do + include Puppet::Provider::Mount + confine :exists => fstab commands :mountcmd => "mount", :umount => "umount", :df => "df" @@ -29,35 +32,6 @@ Puppet::Type.type(:mount).provide(:parsed, text_line :blank, :match => /^\s*$/ record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t" - - # This only works when the mount point is synced to the fstab. - def mount - mountcmd @model[:name] - end - - # This only works when the mount point is synced to the fstab. - def unmount - umount @model[:name] - end - - # Is the mount currently mounted? - def mounted? - platform = Facter["operatingsystem"].value - df = command(:df) - case Facter["operatingsystem"].value - # Solaris's df prints in a very weird format - when "Solaris": df = "#{command(:df)} -k" - end - %x{#{df}}.split("\n").find do |line| - fs = line.split(/\s+/)[-1] - if platform == "Darwin" - fs == "/private/var/automount" + @model[:name] or - fs == @model[:name] - else - fs == @model[:name] - end - end - end end # $Id$ diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb index 5565de23a..d33ab1936 100644 --- a/lib/puppet/provider/nameservice.rb +++ b/lib/puppet/provider/nameservice.rb @@ -37,8 +37,8 @@ class Puppet::Provider::NameService < Puppet::Provider end def options(name, hash) - unless model.validstate?(name) - raise Puppet::DevError, "%s is not a valid state for %s" % + unless model.validattr?(name) + raise Puppet::DevError, "%s is not a valid attribute for %s" % [name, model.name] end @options ||= {} diff --git a/lib/puppet/provider/nameservice/netinfo.rb b/lib/puppet/provider/nameservice/netinfo.rb index f6822b087..00d1e4478 100644 --- a/lib/puppet/provider/nameservice/netinfo.rb +++ b/lib/puppet/provider/nameservice/netinfo.rb @@ -184,11 +184,6 @@ class NetInfo < Puppet::Provider::NameService return nil end - def retrieve - raise "wtf?" - @is = report() || :absent - end - def setuserlist(group, list) cmd = "#{command(:niutil)} -createprop / /groups/%s users %s" % [group, list.join(",")] diff --git a/lib/puppet/type/group.rb b/lib/puppet/type/group.rb index aa982c247..d68d03515 100755 --- a/lib/puppet/type/group.rb +++ b/lib/puppet/type/group.rb @@ -89,7 +89,7 @@ module Puppet end # Set ourselves to whatever our should value is. - self.set + self.set(self.should) end end diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb index a6be65ae6..517f52632 100755 --- a/lib/puppet/type/mount.rb +++ b/lib/puppet/type/mount.rb @@ -116,7 +116,12 @@ module Puppet desc "The file in which to store the mount table. Only used by those providers that write to disk (i.e., not NetInfo)." - defaultto { @parent.class.defaultprovider.default_target } + defaultto { if @parent.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile) + @parent.class.defaultprovider.default_target + else + nil + end + } end newparam(:name) do diff --git a/test/providers/netinfo_mount.rb b/test/providers/netinfo_mount.rb new file mode 100755 index 000000000..fcd814264 --- /dev/null +++ b/test/providers/netinfo_mount.rb @@ -0,0 +1,80 @@ +#!/usr/bin/env ruby +# +# Created by Luke Kanies on 2006-11-12. +# Copyright (c) 2006. All rights reserved. + +$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/ + +require 'puppettest' +# +# if Puppet::Type.type(:mount).provider(:netinfo).suitable? +# class TestNetinfoMountProvider < Test::Unit::TestCase +# include PuppetTest +# +# def setup +# super +# @mount = Puppet::Type.type(:mount) +# end +# +# if Process.uid == 0 and Facter.value(:hostname) == "midden" +# def test_mount_nfs +# culain = nil +# assert_nothing_raised do +# culain = @mount.create :name => "/mnt", :device => "culain:/home/luke", :options => "-o -P", :ensure => :present, +# :fstype => "nfs" +# end +# +# assert(culain, "Did not create fs") +# +# assert_apply(culain) +# +# assert_nothing_raised do +# culain.provider.mount +# end +# +# assert(culain.provider.mounted?, "fs is not considered mounted") +# assert_nothing_raised() { culain.provider.unmount } +# +# culain[:ensure] = :absent +# +# assert_apply(culain) +# end +# end +# +# def test_simple +# root = nil +# assert_nothing_raised do +# root = @mount.create :name => "/", :check => @mount.validstates +# end +# +# assert_nothing_raised do +# root.retrieve +# end +# +# prov = root.provider +# +# assert_nothing_raised do +# assert(prov.device, "Did not value for device") +# assert(prov.device != :absent, "Netinfo thinks the root device is missing") +# end +# end +# +# def test_list +# list = nil +# assert_nothing_raised do +# list = @mount.list +# end +# assert(list.length > 0) +# list.each do |obj| +# assert_instance_of(@mount, obj) +# assert(obj[:name], "objects do not have names") +# p obj +# assert(obj.is(:device), "Did not get value for device in %s" % obj[:name]) +# end +# +# assert(list.detect { |m| m[:name] == "/"}, "Could not find root fs") +# end +# end +# end + +# $Id$
\ No newline at end of file |
