summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-03 15:14:00 -0500
committerLuke Kanies <luke@madstop.com>2008-07-03 15:14:00 -0500
commitbe169da98d34f7305019d9e3be2a7da2bcb3e28c (patch)
treeda686ae29ae32449ff2a77b196fe074ec18ef31b
parent04ecb742f46cf8e48337c854a5ff2377caf60db1 (diff)
downloadpuppet-be169da98d34f7305019d9e3be2a7da2bcb3e28c.tar.gz
puppet-be169da98d34f7305019d9e3be2a7da2bcb3e28c.tar.xz
puppet-be169da98d34f7305019d9e3be2a7da2bcb3e28c.zip
Removing all of the code related to the interface type.
-rw-r--r--lib/puppet/provider/interface/redhat.rb261
-rw-r--r--lib/puppet/provider/interface/sunos.rb133
-rw-r--r--lib/puppet/type/interface.rb60
-rwxr-xr-xspec/integration/provider/interface/redhat.rb41
-rwxr-xr-xspec/unit/provider/interface/redhat.rb271
-rwxr-xr-xspec/unit/provider/interface/sunos.rb239
-rwxr-xr-xspec/unit/type/interface.rb95
7 files changed, 0 insertions, 1100 deletions
diff --git a/lib/puppet/provider/interface/redhat.rb b/lib/puppet/provider/interface/redhat.rb
deleted file mode 100644
index 71f2a6327..000000000
--- a/lib/puppet/provider/interface/redhat.rb
+++ /dev/null
@@ -1,261 +0,0 @@
-require 'puppet/provider/parsedfile'
-require 'erb'
-
-Puppet::Type.type(:interface).provide(:redhat) do
- desc "Manage network interfaces on Red Hat operating systems. This provider
- parses and generates configuration files in ``/etc/sysconfig/network-scripts``."
-
- INTERFACE_DIR = "/etc/sysconfig/network-scripts"
- confine :exists => INTERFACE_DIR
- defaultfor :operatingsystem => [:fedora, :centos, :redhat]
-
- # Create the setter/gettor methods to match the model.
- mk_resource_methods
-
- @templates = {}
-
- # Register a template.
- def self.register_template(name, string)
- @templates[name] = ERB.new(string)
- end
-
- # Retrieve a template by name.
- def self.template(name)
- @templates[name]
- end
-
- register_template :alias, <<-ALIAS
-DEVICE=<%= self.device %>
-ONBOOT=<%= self.on_boot %>
-BOOTPROTO=none
-IPADDR=<%= self.name %>
-NETMASK=<%= self.netmask %>
-BROADCAST=
-ALIAS
-
-
- register_template :normal, <<-LOOPBACKDUMMY
-DEVICE=<%= self.device %>
-ONBOOT=<%= self.on_boot %>
-BOOTPROTO=static
-IPADDR=<%= self.name %>
-NETMASK=<%= self.netmask %>
-BROADCAST=
-LOOPBACKDUMMY
-
- # maximum number of dummy interfaces
- @max_dummies = 10
-
- # maximum number of aliases per interface
- @max_aliases_per_iface = 10
-
- @@dummies = []
- @@aliases = Hash.new { |hash, key| hash[key] = [] }
-
- # calculate which dummy interfaces are currently already in
- # use prior to needing to call self.next_dummy later on.
- def self.instances
- # parse all of the config files at once
- Dir.glob("%s/ifcfg-*" % INTERFACE_DIR).collect do |file|
- instance = parse(file)
-
- # store the existing dummy interfaces
- @@dummies << instance.ifnum if (instance.interface_type == :dummy and ! @@dummies.include?(instance.ifnum))
-
- @@aliases[instance.interface] << instance.ifnum if instance.interface_type == :alias
-
- instance
- end
- end
-
- # return the next avaliable dummy interface number, in the case where
- # ifnum is not manually specified
- def self.next_dummy
- @max_dummies.times do |i|
- unless @@dummies.include?(i.to_s)
- @@dummies << i.to_s
- return i.to_s
- end
- end
- end
-
- # return the next available alias on a given interface, in the case
- # where ifnum if not manually specified
- def self.next_alias(interface)
- @max_aliases_per_iface.times do |i|
- unless @@aliases[interface].include?(i.to_s)
- @@aliases[interface] << i.to_s
- return i.to_s
- end
- end
- end
-
- # base the ifnum, for dummy / loopback interface in linux
- # on the last octect of the IP address
-
- # Parse the existing file.
- def self.parse(file)
- unless file =~ /-([^-]+)$/
- Puppet.warning "Could not extract interface name from %s; skipping" % file
- return nil
- end
- name = $1
- instance = new(:name => name)
- return instance unless FileTest.exist?(file)
-
- File.readlines(file).each do |line|
- if line =~ /^(\w+)=(.+)$/
- method = $1.downcase + "="
- instance.send(method, $2) if instance.respond_to?(method)
- end
- end
-
- return instance
- end
-
- # Prefetch our interface list, yo.
- def self.prefetch(resources)
- instances.each do |prov|
- if resource = resources[prov.name]
- resource.provider = prov
- end
- end
- end
-
- def create
- self.class.resource_type.validproperties.each do |property|
- if value = @resource.should(property)
- @property_hash[property] = value
- end
- end
- @property_hash[:name] = @resource.name
-
- return (@resource.class.name.to_s + "_created").intern
- end
-
- def destroy
- File.unlink(file_path)
- end
-
- def exists?
- FileTest.exist?(file_path)
- end
-
- # generate the content for the interface file, so this is dependent
- # on whether we are adding an alias to a real interface, or a loopback
- # address (also dummy) on linux. For linux it's quite involved, and we
- # will use an ERB template
- def generate
- itype = self.interface_type == :alias ? :alias : :normal
- self.class.template(itype).result(binding)
- end
-
- # Where should the file be written out?
- # This defaults to INTERFACE_DIR/ifcfg-<namevar>, but can have a
- # more symbolic name by setting interface_desc in the type.
- def file_path
- if resource and val = resource[:interface_desc]
- desc = val
- else
- desc = self.name
- end
-
- self.fail("Could not get name for interface") unless desc
-
- if self.interface_type == :alias
- return File.join(INTERFACE_DIR, "ifcfg-" + self.interface + ":" + desc)
- else
- return File.join(INTERFACE_DIR, "ifcfg-" + desc)
- end
- end
-
- # Use the device value to figure out all kinds of nifty things.
- def device=(value)
- case value
- when /:/:
- @property_hash[:interface], @property_hash[:ifnum] = value.split(":")
- @property_hash[:interface_type] = :alias
- when /^dummy/:
- @property_hash[:interface_type] = :loopback
- @property_hash[:interface] = "dummy"
-
- # take the number of the dummy interface, as this is used
- # when working out whether to call next_dummy when dynamically
- # creating these
- @property_hash[:ifnum] = value.sub("dummy",'')
-
- @@dummies << @property_hash[:ifnum].to_s unless @@dummies.include?(@property_hash[:ifnum].to_s)
- else
- @property_hash[:interface_type] = :normal
- @property_hash[:interface] = value
- end
- end
-
- # create the device name, so this based on the IP, and interface + type
- def device
- case @resource.should(:interface_type)
- when :loopback
- @property_hash[:ifnum] ||= self.class.next_dummy
- return "dummy" + @property_hash[:ifnum]
- when :alias
- @property_hash[:ifnum] ||= self.class.next_alias(@resource[:interface])
- return @resource[:interface] + ":" + @property_hash[:ifnum]
- end
- end
-
- # LAK:NOTE This method is why this resource type has been disabled.
- # The model is ridiculous -- the device name should be the interface
- # name. We're 90% of the way toward making this possible, but I'm not
- # taking the time to fix it.
- # Set the name to our ip address.
- def ipaddr=(value)
- @property_hash[:name] = value
- end
-
-
- # whether the device is to be brought up on boot or not. converts
- # the true / false of the type, into yes / no values respectively
- # writing out the ifcfg-* files
- def on_boot
- case @property_hash[:onboot].to_s
- when "true"
- return "yes"
- when "false"
- return "no"
- else
- return "neither"
- end
- end
-
- # Mark whether the interface should be started on boot.
- def on_boot=(value)
- # translate whether we come up on boot to true/false
- case value.downcase
- when "yes":
- @property_hash[:onboot] = :true
- else
- @property_hash[:onboot] = :false
- end
- end
-
- # Write the new file out.
- def flush
- # Don't flush to disk if we're removing the config.
- return if self.ensure == :absent
-
- @property_hash.each do |name, val|
- if val == :absent
- raise ArgumentError, "Propety %s must be provided" % val
- end
- end
-
- File.open(file_path, "w") do |f|
- f.puts generate()
- end
- end
-
- def prefetch
- @property_hash = self.class.parse(file_path)
- end
-end
-
diff --git a/lib/puppet/provider/interface/sunos.rb b/lib/puppet/provider/interface/sunos.rb
deleted file mode 100644
index eda21ca3d..000000000
--- a/lib/puppet/provider/interface/sunos.rb
+++ /dev/null
@@ -1,133 +0,0 @@
-require 'puppet/provider/parsedfile'
-require 'erb'
-
-Puppet::Type.type(:interface).provide(:sunos) do
- confine :kernel => "SunOS"
-
- # Add accessor/getter methods for each property/parameter; these methods
- # modify @property_hash.
- mk_resource_methods
-
- # Get a list of interface instances.
- def self.instances
- Dir.glob("/etc/hostname.*").collect do |file|
- device = File.basename(file).split(".").pop
-
- instance = new(:interface => device)
- instance.parse
- instance
- end
- end
-
- def self.match(hash)
- # see if we can match the has against an existing object
- if model.find { |obj| obj.value(:name) == hash[:name] }
- return obj
- else
- return false
- end
- end
-
- # Prefetch our interface list, yo.
- def self.prefetch(resources)
- instances.each do |prov|
- if resource = resources[prov.name]
- resource.provider = prov
- end
- end
- end
-
- def initialize(*args)
- @property_hash = {}
- super
- end
-
- def create
- self.class.resource_type.validproperties.each do |property|
- if value = resource.should(property)
- @property_hash[property] = value
- end
- end
- @property_hash[:name] = resource.name
-
- return (@resource.class.name.to_s + "_created").intern
- end
-
- def destroy
- File.unlink(file_path)
- @property_hash[:ensure] = :absent
- end
-
- def exists?
- FileTest.exist?(file_path)
- end
-
- # Where should the file be written out? Can be overridden by setting
- # :target in the model.
- def file_path
- self.fail("Could not determine interface") unless interface = @property_hash[:interface] || (resource and resource[:interface])
- return File.join("/etc", "hostname." + interface)
- end
-
- def flush
- return if self.ensure == :absent
- File.open(file_path, "w") { |f| f.print generate() + "\n" }
- end
-
- # Turn our record into a line.
- def generate
- ret = []
- if self.interface_type == :alias
- ret << "addif"
- end
- ret << self.name
-
- if self.ifopts != :absent
- if @property_hash[:ifopts].is_a?(Array)
- ret << @property_hash[:ifopts].join(" ")
- else
- ret << @property_hash[:ifopts]
- end
- end
-
- if self.onboot and ! [:absent, :false].include?(self.onboot)
- ret << "up"
- end
-
- return ret.join(" ")
- end
-
- # Parse our interface file.
- def parse
- (@property_hash = {:ensure => :absent} and return) unless FileTest.exist?(file_path)
-
- values = File.read(file_path).chomp.split(/\s+/)
-
- @property_hash[:ensure] = :present
- #@property_hash = {:ensure => :present}
-
- # Are we the primary interface?
- if values[0] == "addif"
- @property_hash[:interface_type] = :alias
- values.shift
- else
- @property_hash[:interface_type] = :normal
- end
-
- # Should the interface be up by default?
- if values[-1] == "up"
- @property_hash[:onboot] = :true
- values.pop
- else
- @property_hash[:onboot] = :false
- end
-
- # Set the interface name.
- @property_hash[:name] = values.shift
-
- # Handle any interface options
- unless values.empty?
- @property_hash[:ifopts] = values.join(" ")
- end
- end
-end
diff --git a/lib/puppet/type/interface.rb b/lib/puppet/type/interface.rb
deleted file mode 100644
index 2f6c28ad3..000000000
--- a/lib/puppet/type/interface.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-Puppet::Type.newtype(:interface) do
- require 'erb'
-
- @doc = "Create configuration for IP address aliases and loopback addresses."
-
- newparam(:name, :namevar => true) do
- desc "The ipaddress to add to alias or loopback/dummy interface"
- end
-
- ensurable
-
- newparam(:interface) do
- desc "The interface the IP should be added to"
- end
-
- newproperty(:interface_type) do
- desc "The interface type, loopback (also dummy) or alias"
-
- newvalue(:loopback)
- newvalue(:alias)
- newvalue(:normal)
-
- # Make dummy and loopback equivalent
- aliasvalue(:dummy, :loopback)
-
- defaultto :normal
- end
-
- newparam(:interface_desc) do
- desc "On Linux, the description / symbolic name you wish to refer to the
- interface by. When absent, Redhat Linux defaults to uses the namevar
- which will be either the IP address, or hostname."
- end
-
- newproperty(:onboot) do
- desc "Whether the interface should be configured to come up on boot"
- newvalue(:true)
- newvalue(:false)
- end
-
- newproperty(:ifnum) do
- desc "If not automatically configuring the dummy interface or
- and alias. This is use to force a given number to be used"
- end
-
- newproperty(:netmask) do
- desc "The netmask for the interface."
- end
-
- newproperty(:ifopts) do
- desc "Interface options."
- end
-
- newparam(:target) do
- include Puppet::Util::Warnings
- desc "The path to the file this resource creates."
-
- munge { |value| warnonce "Interface targets are deprecated and no longer have any function" }
- end
-end
diff --git a/spec/integration/provider/interface/redhat.rb b/spec/integration/provider/interface/redhat.rb
deleted file mode 100755
index 92b372dfb..000000000
--- a/spec/integration/provider/interface/redhat.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env ruby
-
-# Find and load the spec file.
-Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
-
-provider_class = Puppet::Type.type(:interface).provider(:redhat)
-
-describe provider_class do
- describe "when returning instances" do
- before do
- Dir.stubs(:glob).with("/etc/sysconfig/network-scripts/ifcfg-*").returns(%w{/etc/sysconfig/network-scripts/ifcfg-eth0
- /etc/sysconfig/network-scripts/ifcfg-lo})
- FileTest.stubs(:exist?).returns true
- File.stubs(:readlines).with("/etc/sysconfig/network-scripts/ifcfg-eth0").returns %w{DEVICE=eth0\n BOOTPROTO=dhcp\n ONBOOT=yes\n TYPE=Ethernet\n
- USERCTL=yes\n PEERDNS=yes\n IPV6INIT=no\n }
- File.stubs(:readlines).with("/etc/sysconfig/network-scripts/ifcfg-lo").returns %w{DEVICE=lo\n IPADDR=127.0.0.1\n NETMASK=255.0.0.0\n NETWORK=127.0.0.0\n
- # If you're having problems with gated making 127.0.0.0/8 a martian,\n
- # you can change this to something else (255.255.255.255, for example)\n
- BROADCAST=127.255.255.255\n ONBOOT=yes\n NAME=loopback\n }
- end
-
- it "should succeed" do
- instances = nil
- lambda { instances = provider_class.instances }.should_not raise_error
- end
-
- it "should return provider instances for each file" do
- provider_class.instances[0].should be_instance_of(provider_class)
- end
-
- it "should return provider instances for each file" do
- provider_class.instances.length.should == 2
- end
-
- it "should set the name to the interface name extracted from the file" do
- instances = provider_class.instances
- instances[0].name.should == "eth0"
- instances[1].name.should == "lo"
- end
- end
-end
diff --git a/spec/unit/provider/interface/redhat.rb b/spec/unit/provider/interface/redhat.rb
deleted file mode 100755
index 70830aab5..000000000
--- a/spec/unit/provider/interface/redhat.rb
+++ /dev/null
@@ -1,271 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-11-20.
-# Copyright (c) 2006. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-provider_class = Puppet::Type.type(:interface).provider(:redhat)
-
-describe provider_class do
- it "should not be functional on systems without a network-scripts directory" do
- FileTest.expects(:exist?).with("/etc/sysconfig/network-scripts").returns(false)
- provider_class.should_not be_suitable
- end
-
- it "should be functional on systems with a network-scripts directory" do
- FileTest.expects(:exist?).with("/etc/sysconfig/network-scripts").returns(true)
- provider_class.should be_suitable
- end
-end
-
-describe provider_class, "when determining the file path" do
- it "should always contain '/etc/sysconfig/network-scripts/ifcfg-'" do
- provider = provider_class.new(:name => "192.168.0.1")
- provider.file_path.should =~ %r{^/etc/sysconfig/network-scripts/ifcfg-}
- end
-
- it "should include the interface name and the description when the interface is an alias" do
- provider = provider_class.new(:name => "192.168.0.1", :interface => "eth0")
- provider.interface_type = :alias
- resource = stub 'resource'
- resource.stubs(:[]).with(:interface_desc).returns("blah")
- provider.resource = resource
- provider.file_path.should == "/etc/sysconfig/network-scripts/ifcfg-eth0:blah"
- end
-
- it "should just include the description when the interface is not an alias" do
- provider = provider_class.new(:name => "192.168.0.1")
- provider.interface_type = :normal
- resource = stub 'resource'
- resource.stubs(:[]).with(:interface_desc).returns("eth0")
- provider.resource = resource
- provider.file_path.should == "/etc/sysconfig/network-scripts/ifcfg-eth0"
- end
-
- it "should use the interface description if one is available" do
- provider = provider_class.new(:name => "192.168.0.1")
- provider.interface_type = :normal
- resource = stub 'resource'
- resource.stubs(:[]).with(:interface_desc).returns("eth0")
- provider.resource = resource
- provider.file_path.should == "/etc/sysconfig/network-scripts/ifcfg-eth0"
- end
-
- it "should use the name if no interface description is available" do
- provider = provider_class.new(:name => "192.168.0.1")
- provider.interface_type = :normal
- provider.file_path.should == "/etc/sysconfig/network-scripts/ifcfg-192.168.0.1"
- end
-
- it "should fail if no name or interface description can be found" do
- provider = provider_class.new()
- proc { provider.file_path }.should raise_error
- end
-end
-
-describe provider_class, "when parsing" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- end
-
- it "should return nil if the file name does not include an interface" do
- Puppet::Type::Interface::ProviderRedhat.parse("/my/file").should be_nil
- end
-
- it "should return an unmodified provider if the file does not exist" do
- FileTest.expects(:exist?).with("/my/ifcfg-eth0").returns(false)
- provider = mock 'provider'
- Puppet::Type::Interface::ProviderRedhat.expects(:new).returns(provider)
- Puppet::Type::Interface::ProviderRedhat.parse("/my/ifcfg-eth0").should equal(provider)
- end
-
- it "should set each attribute in the file on the provider" do
- FileTest.expects(:exist?).with("/my/ifcfg-eth0").returns(true)
- File.expects(:readlines).with("/my/ifcfg-eth0").returns(%w{DEVICE=foo ONBOOT=yes})
- Puppet::Type::Interface::ProviderRedhat.expects(:new).returns(@provider)
- @provider.expects(:device=).with('foo')
- @provider.expects(:onboot=).with('yes')
- Puppet::Type::Interface::ProviderRedhat.parse("/my/ifcfg-eth0").should equal(@provider)
- end
-
- it "should not try to assign parameters that the provider does not support" do
- Puppet::Type::Interface::ProviderRedhat.expects(:new).returns @provider
-
- file = "/my/file/ifcfg-eth0"
- FileTest.stubs(:exist?).returns true
- File.expects(:readlines).with(file).returns %w{BOOTPROTO=foo\n DEVICE=eth0\n}
- lambda { Puppet::Type::Interface::ProviderRedhat.parse(file) }.should_not raise_error
- end
-end
-
-describe provider_class, "when setting the device to a value containing ':'" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- @provider.device = "one:two"
- end
- it "should set the interface type to :alias" do
- @provider.interface_type.should == :alias
- end
- it "should set the interface to the string to the left of the ':'" do
- @provider.interface.should == "one"
- end
- it "should set the ifnum to the string to the right of the ':'" do
- @provider.ifnum.should == "two"
- end
-end
-
-describe provider_class, "when setting the device to a value starting with 'dummy-'" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- @provider.device = "dummy5"
- end
- it "should set the interface type to :loopback" do
- @provider.interface_type.should == :loopback
- end
- it "should set the interface to 'dummy'" do
- @provider.interface.should == "dummy"
- end
- it "should set the ifnum to remainder of value after removing 'dummy'" do
- @provider.ifnum.should == "5"
- end
-end
-
-describe provider_class, "when setting the device to a value containing neither 'dummy-' nor ':'" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- @provider.device = "whatever"
- end
- it "should set the interface type to :normal" do
- @provider.interface_type.should == :normal
- end
- it "should set the interface to the device value" do
- @provider.interface.should == "whatever"
- end
-end
-
-describe provider_class, "when setting the on_boot value" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- end
- it "should set it to :true if the value is 'yes'" do
- @provider.on_boot = "yes"
- @provider.onboot.should == :true
- end
- it "should set it to :false if the value is not 'yes'" do
- @provider.on_boot = "no"
- @provider.onboot.should == :false
- end
-end
-
-describe provider_class, "when setting the ipaddr value" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- end
-
- it "should set the name to the provided value" do
- @provider.ipaddr = "yay"
- @provider.name.should == "yay"
- end
-end
-
-describe provider_class, "when generating" do
- before do
- @provider = Puppet::Type::Interface::ProviderRedhat.new
- @provider.interface_type = :alias
- @provider.stubs(:device).returns("mydevice")
- @provider.stubs(:on_boot).returns("myboot")
- @provider.stubs(:name).returns("myname")
- @provider.stubs(:netmask).returns("mynetmask")
- @provider.interface_type = :alias
-
- @text = @provider.generate
- end
-
- it "should set the bootproto to none if the interface is an alias" do
- @text.should =~ /^BOOTPROTO=none$/
- end
-
- it "should set the bootproto to static if the interface is a loopback" do
- @provider.interface_type = :loopback
- @text = @provider.generate
- @text.should =~ /^BOOTPROTO=static$/
- end
-
- it "should set the broadcast address to nothing" do
- @text.should =~ /^BROADCAST=$/
- end
-
- it "should set the netmask to mynetmask" do
- @text.should =~ /^NETMASK=mynetmask$/
- end
-
- it "should set the device to the provider's device" do
- @text.should =~ /^DEVICE=mydevice$/
- end
-
- it "should set the onboot to the provider's on_boot value" do
- @text.should =~ /^ONBOOT=myboot$/
- end
-
- it "should set the ipaddr to the provider's name" do
- @text.should =~ /^IPADDR=myname$/
- end
-end
-
-describe provider_class, "when creating and destroying" do
- before do
- @provider = provider_class.new(:interface => "eth0", :name => "testing")
- @path = "/etc/sysconfig/network-scripts/ifcfg-testing"
- end
-
- it "should consider the interface present if the file exists" do
- FileTest.expects(:exist?).with(@path).returns(true)
- @provider.should be_exists
- end
-
- it "should consider the interface absent if the file does not exist" do
- FileTest.expects(:exist?).with(@path).returns(false)
- @provider.should_not be_exists
- end
-
- it "should remove the file if the interface is being destroyed" do
- File.expects(:unlink).with(@path)
- @provider.destroy
- end
-
- it "should mark :ensure as :absent if the interface is destroyed" do
- File.stubs(:unlink)
- @provider.destroy
- @provider.ensure.should == :absent
- end
-
- it "should mark :ensure as :present if the interface is being created" do
- resource = stub 'resource', :name => 'testing'
- resource.stubs(:should).with { |name| name == :ensure }.returns(:present)
- resource.stubs(:should).with { |name| name != :ensure }.returns(nil)
- @provider.resource = resource
- @provider.create
- @provider.ensure.should == :present
- end
-
- it "should write the generated text to disk when the interface is flushed" do
- fh = mock("filehandle")
- File.expects(:open).yields(fh)
- fh.expects(:puts).with("generated")
- resource = stub 'resource', :name => 'testing'
- resource.stubs(:[]).with(:interface_desc).returns(nil)
- resource.stubs(:should).with { |name| name == :ensure }.returns(:present)
- resource.stubs(:should).with { |name| name != :ensure }.returns(nil)
- @provider.resource = resource
- @provider.create
-
- @provider.stubs(:generate).returns("generated")
- @provider.flush
- end
-
- it "should not write the generated text to disk when the interface is flushed if :ensure == :absent" do
- @provider.ensure = :absent
- @provider.flush
- end
-end
diff --git a/spec/unit/provider/interface/sunos.rb b/spec/unit/provider/interface/sunos.rb
deleted file mode 100755
index 6a7bd19c1..000000000
--- a/spec/unit/provider/interface/sunos.rb
+++ /dev/null
@@ -1,239 +0,0 @@
-#!/usr/bin/env ruby
-#
-# Created by Luke Kanies on 2007-11-25.
-# Copyright (c) 2006. All rights reserved.
-
-require File.dirname(__FILE__) + '/../../../spec_helper'
-
-require 'puppet/provider/interface/sunos'
-
-
-provider_class = Puppet::Type.type(:interface).provider(:sunos)
-
-describe provider_class do
- it "should not be functional on non-SunOS kernels" do
- Facter.expects(:value).with(:kernel).returns("Linux")
- provider_class.should_not be_suitable
- end
-
- it "should be functional on SunOS kernels" do
- Facter.expects(:value).with(:kernel).returns("SunOS")
- provider_class.should be_suitable
- end
-
- it "should pick its file path by combining '/etc/hostname.' with the interface if one is set" do
- provider = provider_class.new(:record_type => :sunos, :interface_type => :normal, :name => "testing", :interface => 'eth0')
- provider.file_path.should == "/etc/hostname.eth0"
- end
-
- it "should pick its file path by combining '/etc/hostname.' with the resource's interface if one is not set in the provider" do
- provider = provider_class.new(:record_type => :sunos, :interface_type => :normal, :name => "testing")
- resource = mock 'resource'
- resource.stubs(:[]).with(:interface).returns("eth0")
- provider.resource = resource
- provider.file_path.should == "/etc/hostname.eth0"
- end
-
- it "should fail when picking its file path if there is no resource nor an interface set in the provider" do
- provider = provider_class.new(:record_type => :sunos, :interface_type => :normal, :name => "testing")
- proc { provider.file_path }.should raise_error(Puppet::Error)
- end
-end
-
-describe provider_class, " when listing interfaces" do
- it "should return an instance for every file matching /etc/hostname.*, created with the interface name set from the file" do
- Dir.expects(:glob).with("/etc/hostname.*").returns(%w{/etc/hostname.one /etc/hostname.two})
- one_instance = stub 'one_instance', :parse => nil
- two_instance = stub 'two_instance', :parse => nil
- provider_class.expects(:new).with(:interface => "one").returns(one_instance)
- provider_class.expects(:new).with(:interface => "two").returns(two_instance)
-
- provider_class.instances.should == [one_instance, two_instance]
- end
-
- it "should call parse on each instance being returned" do
- Dir.expects(:glob).with("/etc/hostname.*").returns(%w{/etc/hostname.one})
- one_instance = mock 'one_instance'
- provider_class.expects(:new).with(:interface => "one").returns(one_instance)
-
- one_instance.expects(:parse)
-
- provider_class.instances
- end
-
- it "should assign matching providers to any prefetched instances" do
- Dir.expects(:glob).with("/etc/hostname.*").returns(%w{one two})
- one_instance = stub 'one_instance', :name => "one", :parse => nil
- two_instance = stub 'two_instance', :name => "two", :parse => nil
- provider_class.expects(:new).with(:interface => "one").returns(one_instance)
- provider_class.expects(:new).with(:interface => "two").returns(two_instance)
-
- resources = {"one" => mock("one"), "three" => mock('three')}
- resources["one"].expects(:provider=).with(one_instance)
-
- provider_class.prefetch(resources)
- end
-end
-
-describe provider_class, " when creating and destroying" do
- before do
- @provider = provider_class.new(:interface => "eth0", :name => "testing")
- end
-
- it "should consider the interface present if the file exists" do
- FileTest.expects(:exist?).with("/etc/hostname.eth0").returns(true)
- @provider.should be_exists
- end
-
- it "should consider the interface absent if the file does not exist" do
- FileTest.expects(:exist?).with("/etc/hostname.eth0").returns(false)
- @provider.should_not be_exists
- end
-
- it "should remove the file if the interface is being destroyed" do
- File.expects(:unlink).with("/etc/hostname.eth0")
- @provider.destroy
- end
-
- it "should mark :ensure as :absent if the interface is destroyed" do
- File.stubs(:unlink)
- @provider.destroy
- @provider.ensure.should == :absent
- end
-
- it "should mark :ensure as :present if the interface is being created" do
- resource = stub 'resource', :name => 'testing'
- resource.stubs(:should).with { |name| name == :ensure }.returns(:present)
- resource.stubs(:should).with { |name| name != :ensure }.returns(nil)
- @provider.resource = resource
- @provider.create
- @provider.ensure.should == :present
- end
-
- it "should write the generated text to disk when the interface is flushed" do
- fh = mock("filehandle")
- File.expects(:open).yields(fh)
- fh.expects(:print).with("testing\n")
- resource = stub 'resource', :name => 'testing'
- resource.stubs(:should).with { |name| name == :ensure }.returns(:present)
- resource.stubs(:should).with { |name| name != :ensure }.returns(nil)
- @provider.resource = resource
- @provider.create
- @provider.flush
- end
-
- it "should not write the generated text to disk when the interface is flushed if :ensure == :absent" do
- @provider.ensure = :absent
- @provider.flush
- end
-end
-
-describe provider_class, " when parsing a non-existant file" do
- it "should mark the interface as absent" do
- @provider = provider_class.new(:interface => "eth0", :name => "testing")
- FileTest.expects(:exist?).with("/etc/hostname.eth0").returns(false)
- @provider.parse
- @provider.ensure.should == :absent
- end
-end
-
-describe provider_class, " when parsing an existing file" do
- before do
- @provider = provider_class.new(:interface => "eth0", :name => "testing")
- FileTest.stubs(:exist?).with("/etc/hostname.eth0").returns(true)
- end
-
- def set_text(text)
- File.stubs(:read).with("/etc/hostname.eth0").returns(text)
- end
-
- it "should retain the interface name" do
- set_text "testing"
- @provider.parse
- @provider.ensure.should == :present
- @provider.interface.should == "eth0"
- end
-
- it "should mark the interface as present" do
- set_text "testing"
- @provider.parse
- @provider.ensure.should == :present
- end
-
- it "should mark the interface as an alias if the first word is 'addif'" do
- set_text "addif testing"
- @provider.parse
- @provider.interface_type.should == :alias
- end
-
- it "should not mark the interface as normal if the first word is not 'addif'" do
- set_text "testing"
- @provider.parse
- @provider.interface_type.should == :normal
- end
-
- it "should start the interface on boot of the last word is 'up'" do
- set_text "testing up"
- @provider.parse
- @provider.onboot.should == :true
- end
-
- it "should not start the interface on boot of the last word is not 'up'" do
- set_text "testing"
- @provider.parse
- @provider.onboot.should == :false
- end
-
- it "should set the interface to the first non-behavioural word" do
- set_text "addif testing up"
- @provider.parse
- @provider.name.should == "testing"
- end
-
- it "should consider any remaining terms to be interface options" do
- set_text "addif testing -O up"
- @provider.parse
- @provider.ifopts.should == "-O"
- end
-end
-
-describe provider_class, " when generating" do
- before do
- @provider = provider_class.new(:interface => "eth0", :name => "testing")
- end
-
- it "should prefix the text with 'addif' if the interface is an alias" do
- @provider.interface_type = :alias
- @provider.generate.should == "addif testing"
- end
-
- it "should not prefix the text with 'addif' if the interface is not an alias" do
- @provider.generate.should == "testing"
- end
-
- it "should put the ifopts after the name if they are present" do
- @provider.ifopts = "-O"
- @provider.generate.should == "testing -O"
- end
-
- it "should mark the interface up if onboot is enabled" do
- @provider.onboot = :true
- @provider.generate.should == "testing up"
- end
-
- it "should use the resource name if no provider name is present" do
- provider = provider_class.new(:interface => "eth0")
- resource = stub 'resource', :name => "rtest"
- provider.resource = resource
- provider.generate.should == "rtest"
- end
-
- it "should use the provider name if present" do
- @provider.generate.should == "testing"
- end
-
- it "should fail if neither a resource nor the provider name is present" do
- provider = provider_class.new(:interface => "eth0")
- proc { provider.generate }.should raise_error
- end
-end
diff --git a/spec/unit/type/interface.rb b/spec/unit/type/interface.rb
deleted file mode 100755
index 27f34b7e0..000000000
--- a/spec/unit/type/interface.rb
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/usr/bin/env ruby
-
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-interface = Puppet::Type.type(:interface)
-
-describe interface do
- before do
- @class = Puppet::Type.type(:interface)
-
- @provider_class = stub 'provider_class', :name => "fake", :suitable? => true, :supports_parameter? => true
- @class.stubs(:defaultprovider).returns(@provider_class)
- @class.stubs(:provider).returns(@provider_class)
-
- @provider = stub 'provider', :class => @provider_class, :file_path => "/tmp/whatever", :clear => nil
- @provider_class.stubs(:new).returns(@provider)
- end
-
- it "should have a name parameter" do
- @class.attrtype(:name).should == :param
- end
-
- it "should have :name be its namevar" do
- @class.namevar.should == :name
- end
-
- it "should have a :provider parameter" do
- @class.attrtype(:provider).should == :param
- end
-
- it "should have an ensure property" do
- @class.attrtype(:ensure).should == :property
- end
-
- it "should support :present as a value for :ensure" do
- proc { @class.create(:name => "whev", :ensure => :present) }.should_not raise_error
- end
-
- it "should support :absent as a value for :ensure" do
- proc { @class.create(:name => "whev", :ensure => :absent) }.should_not raise_error
- end
-
- it "should have an interface_type property" do
- @class.attrtype(:interface_type).should == :property
- end
- it "should support :loopback as an interface_type value" do
- proc { @class.create(:name => "whev", :interface_type => :loopback) }.should_not raise_error
- end
- it "should support :alias as an interface_type value" do
- proc { @class.create(:name => "whev", :interface_type => :alias) }.should_not raise_error
- end
- it "should support :normal as an interface_type value" do
- proc { @class.create(:name => "whev", :interface_type => :normal) }.should_not raise_error
- end
- it "should alias :dummy to the :loopback interface_type value" do
- int = @class.create(:name => "whev", :interface_type => :dummy)
- int.should(:interface_type).should == :loopback
- end
-
- it "should not support values other than :loopback, :alias, :normal, and :dummy in the interface_type" do
- proc { @class.create(:name => "whev", :interface_type => :something) }.should raise_error(Puppet::Error)
- end
-
- it "should have an interface_desc parameter" do
- @class.attrtype(:interface_desc).should == :param
- end
-
- it "should have an onboot property" do
- @class.attrtype(:onboot).should == :property
- end
- it "should support :true as an onboot value" do
- proc { @class.create(:name => "whev", :onboot => :true) }.should_not raise_error
- end
- it "should support :false as an onboot value" do
- proc { @class.create(:name => "whev", :onboot => :false) }.should_not raise_error
- end
-
- it "should have an ifnum property" do
- @class.attrtype(:ifnum).should == :property
- end
-
- it "should have a netmask property" do
- @class.attrtype(:netmask).should == :property
- end
-
- it "should have an ifopts property" do
- @class.attrtype(:ifopts).should == :property
- end
-
- it "should have a target parameter" do
- @class.attrtype(:target).should == :param
- end
-
- after { @class.clear }
-end