deprecate NetInfo providers and examples, remove all NetInfo references and tests.

This commit is contained in:
Nigel Kersten 2009-07-13 16:18:51 -07:00
Родитель 22f56327e7
Коммит a42e8788b1
21 изменённых файлов: 17 добавлений и 608 удалений

Просмотреть файл

@ -64,7 +64,7 @@ The server can also function as a certificate authority and file server.
%build
# Fix some rpmlint complaints
for f in mac_dscl.pp mac_dscl_revert.pp \
mac_netinfo.pp mac_pkgdmg.pp ; do
mac_pkgdmg.pp ; do
sed -i -e'1d' examples/$f
chmod a-x examples/$f
done

Просмотреть файл

@ -1,5 +0,0 @@
#!/usr/bin/env puppet --debug
user {
"jmccune": provider => "netinfo", ensure => present;
}

Просмотреть файл

@ -1,15 +0,0 @@
# Manage NetInfo POSIX objects.
#
# This provider has been deprecated. You should be using the directoryservice
# nameservice provider instead.
require 'puppet/provider/nameservice/netinfo'
Puppet::Type.type(:group).provide :netinfo, :parent => Puppet::Provider::NameService::NetInfo do
desc "Group management using NetInfo.
"
commands :nireport => "nireport", :niutil => "niutil"
end

Просмотреть файл

@ -1,19 +0,0 @@
# Manage NetInfo POSIX objects. Probably only used on OS X, but I suppose
# it could be used elsewhere.
require 'puppet/provider/nameservice/netinfo'
Puppet::Type.type(:host).provide :netinfo, :parent => Puppet::Provider::NameService::NetInfo,
:netinfodir => "machines" do
desc "Host 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 :ip, :key => "ip_address"
defaultfor :operatingsystem => :darwin
end

Просмотреть файл

@ -1,37 +0,0 @@
# 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(resource)
# warning "The NetInfo mount provider is highly experimental. Use at your own risk."
# super
# end
#
# def mount
# cmd = []
# if opts = @resource.should(:options)
# cmd << opts
# end
# cmd << @resource.should(:device)
# cmd << @resource[:name]
# mountcmd cmd
# end
# end

Просмотреть файл

@ -130,7 +130,7 @@ class Puppet::Provider::NameService < Puppet::Provider
end
# Autogenerate a value. Mostly used for uid/gid, but also used heavily
# with netinfo, because netinfo is stupid.
# with DirectoryServices, because DirectoryServices is stupid.
def autogen(field)
field = symbolize(field)
id_generators = {:user => :uid, :group => :gid}

Просмотреть файл

@ -30,14 +30,6 @@ class DirectoryService < Puppet::Provider::NameService
attr_writer :macosx_version_major
end
# JJM 2007-07-24: Not yet sure what initvars() does. I saw it in netinfo.rb
# I do know, however, that it makes methods "work" =)
# e.g. addcmd isn't available if this method call isn't present.
#
# JJM: Also, where this method is defined seems to impact the visibility
# of methods. If I put initvars after commands, confine and defaultfor,
# then getinfo is called from the parent class, not this class.
initvars()
commands :dscl => "/usr/bin/dscl"
@ -333,10 +325,9 @@ class DirectoryService < Puppet::Provider::NameService
def ensure=(ensure_value)
super
# JJM: Modeled after nameservice/netinfo.rb, we need to
# loop over all valid properties for the type we're managing
# and call the method which sets that property value
# Like netinfo, dscl can't create everything at once, afaik.
# We need to loop over all valid properties for the type we're
# managing and call the method which sets that property value
# dscl can't create everything at once unfortunately.
if ensure_value == :present
@resource.class.validproperties.each do |name|
next if name == :ensure
@ -491,12 +482,7 @@ class DirectoryService < Puppet::Provider::NameService
def getinfo(refresh = false)
# JJM 2007-07-24:
# Override the getinfo method, which is also defined in nameservice.rb
# This method returns and sets @infohash, which looks like:
# (NetInfo provider, user type...)
# @infohash = {:comment=>"Jeff McCune", :home=>"/Users/mccune",
# :shell=>"/bin/zsh", :password=>"********", :uid=>502, :gid=>502,
# :name=>"mccune"}
#
# This method returns and sets @infohash
# I'm not re-factoring the name "getinfo" because this method will be
# most likely called by nameservice.rb, which I didn't write.
if refresh or (! defined?(@property_value_cache_hash) or ! @property_value_cache_hash)

Просмотреть файл

@ -1,224 +0,0 @@
# Manage NetInfo POSIX objects.
#
# This provider has been deprecated. You should be using the directoryservice
# nameservice provider instead.
require 'puppet'
require 'puppet/provider/nameservice'
class Puppet::Provider::NameService
class NetInfo < Puppet::Provider::NameService
class << self
attr_writer :netinfodir
end
# We have to initialize manually because we're not using
# classgen() here.
initvars()
commands :lookupd => "/usr/sbin/lookupd"
# Attempt to flush the database, but this doesn't seem to work at all.
def self.flush
begin
lookupd "-flushcache"
rescue Puppet::ExecutionFailure
# Don't throw an error; it's just a failed cache flush
Puppet.err "Could not flush lookupd cache: %s" % output
end
end
# Similar to posixmethod, what key do we use to get data? Defaults
# to being the object name.
def self.netinfodir
if defined? @netinfodir
return @netinfodir
else
return @resource_type.name.to_s + "s"
end
end
def self.finish
case self.name
when :uid
noautogen
when :gid
noautogen
end
end
def self.instances
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
report(@resource_type.validproperties).collect do |hash|
self.new(hash)
end
end
# Convert a NetInfo line into a hash of data.
def self.line2hash(line, params)
values = line.split(/\t/)
hash = {}
params.zip(values).each do |param, value|
next if value == '#NoValue#'
hash[param] = if value =~ /^[-0-9]+$/
Integer(value)
else
value
end
end
hash
end
# What field the value is stored under.
def self.netinfokey(name)
name = symbolize(name)
self.option(name, :key) || name
end
# Retrieve the data, yo.
# FIXME This should retrieve as much information as possible,
# rather than retrieving it one at a time.
def self.report(*params)
dir = self.netinfodir()
cmd = [command(:nireport), "/", "/%s" % dir]
params.flatten!
# We require the name in order to know if we match. There's no
# way to just report on our individual object, we have to get the
# whole list.
params.unshift :name unless params.include? :name
params.each do |param|
if key = netinfokey(param)
cmd << key.to_s
else
raise Puppet::DevError,
"Could not find netinfokey for property %s" %
self.class.name
end
end
begin
output = execute(cmd)
rescue Puppet::ExecutionFailure => detail
Puppet.err "Failed to call nireport: %s" % detail
return nil
end
return output.split("\n").collect { |line|
line2hash(line, params)
}
end
# How to add an object.
def addcmd
creatorcmd("-create")
end
def creatorcmd(arg)
cmd = [command(:niutil)]
cmd << arg
cmd << "/" << "/%s/%s" % [self.class.netinfodir(), @resource[:name]]
return cmd
end
def deletecmd
creatorcmd("-destroy")
end
def destroy
delete()
end
def ensure=(arg)
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
super
# Because our stupid type can't create the whole thing at once,
# we have to do this hackishness. Yay.
if arg == :present
@resource.class.validproperties.each do |name|
next if name == :ensure
# LAK: We use property.sync here rather than directly calling
# the settor method because the properties might do some kind
# of conversion. In particular, the user gid property might
# have a string and need to convert it to a number
if @resource.should(name)
@resource.property(name).sync
elsif value = autogen(name)
self.send(name.to_s + "=", value)
else
next
end
end
end
end
# Retrieve a specific value by name.
def get(param)
hash = getinfo(false)
if hash
return hash[param]
else
return :absent
end
end
# Retrieve everything about this object at once, instead of separately.
def getinfo(refresh = false)
if refresh or (! defined? @infohash or ! @infohash)
properties = [:name] + self.class.resource_type.validproperties
properties.delete(:ensure) if properties.include? :ensure
@infohash = single_report(*properties)
end
return @infohash
end
def modifycmd(param, value)
cmd = [command(:niutil)]
# if value.is_a?(Array)
# warning "Netinfo providers cannot currently handle multiple values"
# end
cmd << "-createprop" << "/" << "/%s/%s" % [self.class.netinfodir, @resource[:name]]
value = [value] unless value.is_a?(Array)
if key = netinfokey(param)
cmd << key
cmd += value
else
raise Puppet::DevError,
"Could not find netinfokey for property %s" %
self.class.name
end
cmd
end
# Determine the flag to pass to our command.
def netinfokey(name)
self.class.netinfokey(name)
end
# Get a report for a single resource, not the whole table
def single_report(*properties)
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
self.class.report(*properties).find do |hash| hash[:name] == self.name end
end
def setuserlist(group, list)
cmd = [command(:niutil), "-createprop", "/", "/groups/%s" % group, "users", list.join(",")]
begin
output = execute(cmd)
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Failed to set user list on %s: %s" %
[group, detail]
end
end
end
end

Просмотреть файл

@ -43,27 +43,10 @@ Puppet::Type.type(:user).provide :directoryservice, :parent => Puppet::Provider:
return @resource[:name].capitalize
end
# The list of all groups the user is a member of. Different
# user mgmt systems will need to override this method.
# The list of all groups the user is a member of.
# JJM: FIXME: Override this method...
def groups
groups = []
# user = @resource[:name]
# # Retrieve them all from netinfo
# open("| #{command(:nireport)} / /groups name users") do |file|
# file.each do |line|
# name, members = line.split(/\s+/)
# next unless members
# next if members =~ /NoValue/
# members = members.split(",")
#
# if members.include? user
# groups << name
# end
# end
# end
groups.join(",")
end

Просмотреть файл

@ -1,111 +0,0 @@
# Manage NetInfo POSIX objects.
#
# This provider has been deprecated. You should be using the directoryservice
# nameservice provider instead.
require 'puppet/provider/nameservice/netinfo'
Puppet::Type.type(:user).provide :netinfo, :parent => Puppet::Provider::NameService::NetInfo do
desc "User management in NetInfo. Note that NetInfo is not smart enough to fill in default information
for users, so this provider will use default settings for home (``/var/empty``), shell (``/usr/bin/false``),
comment (the user name, capitalized), and password ('********'). These defaults are only used when the user is created.
Note that password management probably does not really work -- OS X does not store the password in NetInfo itself,
yet we cannot figure out how to store the encrypted password where OS X will look for it. The main reason the password
support is even there is so that a default password is created, which effectively locks people out, even if it does not
enable us to set a password."
commands :nireport => "nireport", :niutil => "niutil"
options :comment, :key => "realname"
options :password, :key => "passwd"
autogen_defaults :home => "/var/empty", :shell => "/usr/bin/false", :password => '********'
has_feature :manages_passwords
verify :gid, "GID must be an integer" do |value|
value.is_a? Integer
end
verify :uid, "UID must be an integer" do |value|
value.is_a? Integer
end
def autogen_comment
return @resource[:name].capitalize
end
# The list of all groups the user is a member of. Different
# user mgmt systems will need to override this method.
def groups
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
groups = []
user = @resource[:name]
# Retrieve them all from netinfo
open("| #{command(:nireport)} / /groups name users") do |file|
file.each do |line|
name, members = line.split(/\s+/)
next unless members
next if members =~ /NoValue/
members = members.split(",")
if members.include? user
groups << name
end
end
end
groups.join(",")
end
# This is really lame. We have to iterate over each
# of the groups and add us to them.
def groups=(groups)
warnonce "The NetInfo provider is deprecated; use directoryservice instead"
case groups
when Fixnum
groups = [groups.to_s]
when String
groups = groups.split(/\s*,\s*/)
else
raise Puppet::DevError, "got invalid groups value %s of type %s" % [groups.class, groups]
end
# Get just the groups we need to modify
diff = groups - (@is || [])
data = {}
open("| #{command(:nireport)} / /groups name users") do |file|
file.each do |line|
name, members = line.split(/\s+/)
if members.nil? or members =~ /NoValue/
data[name] = []
else
# Add each diff group's current members
data[name] = members.split(/,/)
end
end
end
user = @resource[:name]
data.each do |name, members|
if members.include? user and groups.include? name
# I'm in the group and should be
next
elsif members.include? user
# I'm in the group and shouldn't be
setuserlist(name, members - [user])
elsif groups.include? name
# I'm not in the group and should be
setuserlist(name, members + [user])
else
# I'm not in the group and shouldn't be
next
end
end
end
end

Просмотреть файл

@ -71,7 +71,7 @@ module Puppet
newproperty(:target) do
desc "The file in which to store service information. Only used by
those providers that write to disk (i.e., not NetInfo)."
those providers that write to disk."
defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@resource.class.defaultprovider.default_target

Просмотреть файл

@ -35,7 +35,7 @@ module Puppet
newproperty(:target) do
desc "The file in which to store the aliases. Only used by
those providers that write to disk (i.e., not NetInfo)."
those providers that write to disk."
defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@resource.class.defaultprovider.default_target

Просмотреть файл

@ -154,7 +154,7 @@ module Puppet
newproperty(:target) do
desc "The file in which to store the mount table. Only used by
those providers that write to disk (i.e., not NetInfo)."
those providers that write to disk."
defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
@resource.class.defaultprovider.default_target

Просмотреть файл

@ -98,7 +98,7 @@
#
# newproperty(:target) do
# desc "The file in which to store service information. Only used by
# those providers that write to disk (i.e., not NetInfo)."
# those providers that write to disk."
#
# defaultto { if @resource.class.defaultprovider.ancestors.include?(Puppet::Provider::ParsedFile)
# @resource.class.defaultprovider.default_target

Просмотреть файл

@ -1,56 +0,0 @@
#!/usr/bin/env ruby
#
# Created by Luke Kanies on 2006-11-12.
# Copyright (c) 2006. All rights reserved.
require File.dirname(__FILE__) + '/../../../lib/puppettest'
require 'puppettest'
if Puppet::Type.type(:host).provider(:netinfo).suitable?
class TestNetinfoHostProvider < Test::Unit::TestCase
include PuppetTest
def setup
super
@host = Puppet::Type.type(:host)
@provider = @host.provider(:netinfo)
end
def test_list
list = nil
assert_nothing_raised do
list = @provider.instances
end
assert(list.length > 0)
list.each do |prov|
assert_instance_of(@provider, prov)
assert(prov.name, "objects do not have names")
assert(prov.ip, "Did not get value for device in %s" % prov.ip)
end
assert(list.detect { |provider| provider.name == "localhost"}, "Could not find localhost")
end
if Process.uid == 0
def test_simple
localhost = nil
assert_nothing_raised do
localhost = @host.create :name => "localhost", :check => [:ip], :provider => :netinfo
end
assert_nothing_raised do
localhost.retrieve
end
prov = localhost.provider
assert_nothing_raised do
assert(prov.ip, "Did not find value for ip")
assert(prov.ip != :absent, "Netinfo thinks the localhost is missing")
end
end
end
end
end

Просмотреть файл

@ -1,79 +0,0 @@
#!/usr/bin/env ruby
#
# Created by Luke Kanies on 2006-11-12.
# Copyright (c) 2006. All rights reserved.
require File.dirname(__FILE__) + '/../../../lib/puppettest'
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.validproperties
# 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

Просмотреть файл

@ -52,7 +52,6 @@ class TestUserProvider < Test::Unit::TestCase
prov = Puppet::Type.type(:user).defaultprovider
output = prov.report(param)
# output = %x{nireport / /users name #{prov.netinfokey(param)}}
output.each { |hash|
if hash[:name] == user.name
val = hash[param]
@ -307,7 +306,7 @@ class TestUserProvider < Test::Unit::TestCase
return
end
# Stupid netinfo
# Stupid DirectoryServices
if Facter.value(:operatingsystem) == "Darwin"
assert_raise(ArgumentError, "gid allowed a non-integer value") do
user.gid = group.name

Просмотреть файл

@ -15,7 +15,7 @@ class TestHost < Test::Unit::TestCase
@provider = @hosttype.defaultprovider
# Make sure they aren't using something funky like netinfo
# Make sure they are using the parsed provider
unless @provider.name == :parsed
@hosttype.defaultprovider = @hosttype.provider(:parsed)
end
@ -63,14 +63,9 @@ class TestHost < Test::Unit::TestCase
assert_equal(0, list.length, "Found hosts in empty file somehow")
end
# Darwin will actually write to netinfo here.
if Facter.value(:operatingsystem) != "Darwin" or Process.uid == 0
def test_simplehost
host = nil
# We want to actually use the netinfo provider on darwin
if Facter.value(:operatingsystem) == "Darwin"
Puppet::Type.type(:host).defaultprovider = nil
end
assert_nothing_raised {
host = Puppet::Type.type(:host).new(
@ -97,14 +92,7 @@ class TestHost < Test::Unit::TestCase
end
def test_moddinghost
# We want to actually use the netinfo provider on darwin
if Facter.value(:operatingsystem) == "Darwin"
Puppet::Type.type(:host).defaultprovider = nil
end
host = mkhost()
if Facter.value(:operatingsystem) == "Darwin"
assert_equal(:netinfo, host[:provider], "Got incorrect provider")
end
cleanup do
host[:ensure] = :absent
assert_apply(host)
@ -195,7 +183,6 @@ class TestHost < Test::Unit::TestCase
}
end
end
def test_aliasisproperty
assert_equal(:property, @hosttype.attrtype(:alias))
end

Просмотреть файл

@ -14,7 +14,7 @@ class TestMailAlias < Test::Unit::TestCase
@provider = @type.defaultprovider
# Make sure they aren't using something funky like netinfo
# Make sure they are using the parsed provider
unless @provider.name == :aliases
@type.defaultprovider = @type.provider(:aliases)
end

Просмотреть файл

@ -15,7 +15,7 @@ require 'puppettest'
#
# @provider = @porttype.defaultprovider
#
# # Make sure they aren't using something funky like netinfo
# # Make sure they are using the parsed provider
# unless @provider.name == :parsed
# @porttype.defaultprovider = @porttype.provider(:parsed)
# end

Просмотреть файл

@ -14,7 +14,7 @@ class TestSSHKey < Test::Unit::TestCase
@provider = @sshkeytype.defaultprovider
# Make sure they aren't using something funky like netinfo
# Make sure they are using the parsed provider
unless @provider.name == :parsed
@sshkeytype.defaultprovider = @sshkeytype.provider(:parsed)
end