voxpupuli / puppet-network

Types and providers to manage network interfaces
https://forge.puppet.com/puppet/network
Apache License 2.0
66 stars 107 forks source link

Double initialisation of "interfaces" provider causes exception (aka can't purge unmanaged config) #258

Open LadyNamedLaura opened 4 years ago

LadyNamedLaura commented 4 years ago

Due to some autoloading behaviour when using resources{'network_config': purge => true} or crayfishx/purge 2 instances of the provider get created.

This creates a problem because FileMapper calls parse_file('/etc/network/interfaces') twice, resulting in it detecting duplicate interfaces since the parse state gets kept globally between runs in the Instance class.

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

  resources { 'network_config':
    purge => true,
  }

What are you seeing

Error: Could not prefetch network_config provider 'interfaces': Malformed debian interfaces file; cannot instantiate network_config resources
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:39:in `raise_malformed'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:181:in `block (2 levels) in parse_file'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:174:in `match'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:174:in `block in parse_file'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:130:in `each'
/opt/puppetlabs/puppet/cache/lib/puppet/provider/network_config/interfaces.rb:130:in `parse_file'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:172:in `block in load_all_providers_from_disk'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:166:in `each_pair'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:166:in `load_all_providers_from_disk'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:102:in `instances'
/opt/puppetlabs/puppet/cache/lib/puppetx/filemapper.rb:192:in `prefetch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:364:in `prefetch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:256:in `prefetch_if_necessary'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/transaction.rb:111:in `block in evaluate'

What behaviour did you expect instead

No exceptions and removal of unmanaged config

Possible fixes:

Which one would you like me to take a look at for a PR?

Related issues:

This is likely to be the root issue behind stuff like #60 and #44

LadyNamedLaura commented 4 years ago

also

   Network_config {
    ensure => purged
  }

as sugested in #78 does not work for this and even if it did it still wouldn't fix the crayfishx/purge usecase.