Yum_package seems to be broken

Hi there,
it looks for me that yum_package resource is caching the sources list and if this list changed during the execution it can't install the new packages. I've found this issue in quite complex deployment, and it cost me some time to understand what is going on, but the issue boils down to the following:

ext = 'epel'
execute "enable-extra-#{ext}" do
  command "amazon-linux-extras enable #{ext}"
end
package 'epel-release' if ext == 'epel'

The code above is working but if I use any yum_package resource before execute, it will fail:

package 'whatever'
[...]
ext = 'epel'
execute "enable-extra-#{ext}" do
  command "amazon-linux-extras enable #{ext}"
end
package 'epel-release' if ext == 'epel'

This will fail with error message that package epel-release is not available. Next run package 'whatever' already installed and everything working again. So it looks like yum_package has cached the sources list. Is there a way to refresh/drop this cache?

Have you tried using the flush_cache property on the yum_package resource? So something like:

flush_cache [ :before ]

No, because it breaks my cookbook testing pipeline:
FC009: Resource attribute not recognised: ./recipes/install.rb:38

and also in chefspec:
expected no Exception, got #<NoMethodError: undefined method flush_cache' for Chef::Resource::AptPackage> with backtrace: # /tmp/chefspec20190716-2339-15evbmcfile_cache_path/cookbooks/ul_common/recipes/install.rb:85:inblock in from_file'
# /tmp/chefspec20190716-2339-15evbmcfile_cache_path/cookbooks/ul_common/recipes/install.rb:83:in from_file' # /tmp/chefspec20190716-2339-15evbmcfile_cache_path/cookbooks/ul_common/recipes/default.rb:33:infrom_file'
# ./spec/unit/recipes/default_spec.rb:31:in block (3 levels) in <top (required)>' # ./spec/unit/recipes/default_spec.rb:35:inblock (4 levels) in <top (required)>'
# ./spec/unit/recipes/default_spec.rb:35:in `block (3 levels) in <top (required)>'

May be this option is accepted on yum_package, but I need to use general package resource, since these cookbooks are intended to work in debianish as well as redhatish distros.