Issue #12835 has been updated by Chris Price.

Linked this to a previous ticket that deals with similar code; if we end up 
merging in changes related to either of these tickets, perhaps we can combine 
them into one changeset.
----------------------------------------
Bug #12835: Cisco device, interface type, ensure => absent won't work 
properly.... I think
https://projects.puppetlabs.com/issues/12835#change-55852

Author: Gary Richards
Status: Unreviewed
Priority: Normal
Assignee: 
Category: device
Target version: 
Affected Puppet version: 2.7.10
Keywords: 
Branch: 


Hi,

I've been working on modifying the Cisco device code to work with Hp devices.

I started out fairly simple with just being able to define a vlan and the basic 
parts of an interface.

Some real simple testing suggested that defining an interface like so:
    interface { '1':
      ensure => absent
    }

Although I detect (correctly) that the interface is disabled, every time puppet 
runs it always tries to set the interface as disabled. My code isn't too much 
different to the existing cisco code. I can't test this against a cisco device, 
but I think it would fail there too for the following reason:

The parse_interface method in util/network_device/cisco/device.rb:
    def parse_interface(name)
      resource = {}
      ...
      if l =~ /#{name} is (.+), line protocol is /
        resource[:ensure] = ($1 == 'up' ? :present : :absent);
      end
      ...
      resource
    end

So whatever happens it always returns something, even if that's an empty hash.

If we look at self.prefetch(resources) in provider/network_device.rb
    def self.prefetch(resources)
      resources.each do |name, resource|
        device = Puppet::Util::NetworkDevice.current || 
device(resource[:device_url])
        if result = lookup(device, name)
          result[:ensure] = :present
          resource.provider = new(device, result)
        else
          resource.provider = new(device, :ensure => :absent)
        end
      end
    end

The line: 'if result = lookup(device, name)' is what (if you follow through the 
various classes and their methods) ends up calling the parse_interface(name) 
method I mention above. As parse_interface always returns a hash, 
result[:ensure] oh that hash always gets set to :present.

Therefore despite the code detecting whether the port is shutdown or not and 
then sets resouces[:ensure] to present or absent, the code above simply resets 
it.

Once you get into the code that compares should and is, is[:ensure] is always 
:present because of this.

This is why, with my code at least, I can't make an interface absent (and I 
think that's the same for Cisco devices too).

Thanks


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to