Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-3362

Cisco device, interface type, ensure => absent won't work properly.... I think

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
    • Template:

      Description

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              redmine.exporter redmine.exporter
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Zendesk Support