Issue #12835 has been updated by Gary Richards.

I believe that the fix suggested doesn't fix the whole problem that I was 
describing.

Assuming that I do define an interface as suggested above. parse_interface 
would be called, which would go off to the switch and try to obtain the 
configuration for the specified port on the switch. The code in 
provider_network_device.rb that I show above would match either of these lines 
of output from a Cisco switch:

<interface name> is up, line protocol is up
<interface name> is administratively down, line protocol is down

That code would set resources[:ensure] to either :present or :absent based on 
the current state of the switch port.

At that point, resources would already be populated (even if it were just with 
:ensure), the code that I show above from provider/network_device.rb (result = 
lookup(device, name)) would cause result to be the populated hash.

Therefore result (although it will could contain result[:ensure] = :absent, 
will cause the if statement surrounding it to succeed. The first thing the code 
within that if block does is set result[:ensure] = :present

Meaning that you can never detect the current state of the interface. It will 
always be considered present. Even if we add the suggested code, resources will 
always be populated and therefore we'll still have the same problem.

I'll try to submit patch that I think makes sense for this at some point today. 
Unfortunately I can't actually test it on a Cisco switch. It would be nice if 
someone with a cisco switch could test whether it actually works now or not :) 
I have a couple of technical friends that have Cisco switches that are trying 
to get me access to one for testing, but I can't guarantee anything, 

Are there any tests for this code currently? In theory (although i've written 
no test code for puppet at all) testing whether a type is correctly ensureable 
would likely be one of the first tests written? I imagine that's easier said 
than done though when the code highly depends on talking to some remote device 
and therefore would probably rely on a whole bunch of mocking... hrm!
----------------------------------------
Bug #12835: Cisco device, interface type, ensure => absent won't work 
properly.... I think
https://projects.puppetlabs.com/issues/12835#change-55900

Author: Gary Richards
Status: Accepted
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