Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facts > 2.5 not working as expected #61

Closed
cdenneen opened this issue Sep 5, 2017 · 8 comments
Closed

facts > 2.5 not working as expected #61

cdenneen opened this issue Sep 5, 2017 · 8 comments

Comments

@cdenneen
Copy link

cdenneen commented Sep 5, 2017

In doing some testing if you lookup %{::memory.system.total_bytes} it returns null and I believe that is because puppet requires facter and the latest version if 2.5.1 and in that facts set there is no fact for that even though for example 4.10.1 ships with 3.6.4 and it is available in facterdb under 3.6 folder.

I think there either needs to be a facter gem published to support later than 2.5 or some way for rspec-puppet-facts to use the 3.x facts from facterdb

@DavidS
Copy link
Contributor

DavidS commented Sep 6, 2017

Please try specifying the facter version you want to test through setting facterversion on on_supported_os (see https://github.com/mcanevet/rspec-puppet-facts/blob/fe21de12108fbab0123bdc4db2365a29ea62f171/lib/rspec-puppet-facts.rb#L34) . This could use a sentence or two in the README to make it discoverable.

Related, there is talk on getting cfacter (that is, facter 3) into gems for testing: https://tickets.puppetlabs.com/browse/FACT-1542 . please vote there to help prioritise this issue.

@cdenneen
Copy link
Author

cdenneen commented Sep 6, 2017

@DavidS any good way to get this in the spec_helper.rb so I don't have to specify in the array of the spec test?

@cdenneen
Copy link
Author

cdenneen commented Sep 6, 2017

@DavidS tried the following but didn't work (you can see the commented out stubbed fact I had to use before):

  on_supported_os({
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => [
          '7'
        ],
        'facterversion' => '3.6.4'
      }
    ]
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          puppetversion: Puppet.version,
          sudoversion: '1.7.10p9',
          ap_env: 'dev',
          role: 'mapi',
          awsregion: 'us-east-1'
#          memory: {
#            system: {
#              total_bytes: '1111'
#            }
#          }
        })
      end

Even tried:

  on_supported_os({
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => [
          '7'
        ]
      }
    ]
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          facterversion: '3.6.4',
          puppetversion: Puppet.version,
          sudoversion: '1.7.10p9',
          ap_env: 'dev',
          role: 'mapi',
          awsregion: 'us-east-1'
#          memory: {
#            system: {
#              total_bytes: '1111'
#            }
#          }
        })
      end

@cdenneen
Copy link
Author

cdenneen commented Sep 6, 2017

I even tried to move this to spec_helper.rb with no luck:

RSpec.configure do |c|
  c.tty = true
  c.mock_framework = :rspec
  c.mock_with(:rspec)
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!(95)
  end
  c.hiera_config = File.expand_path(
    File.join(__FILE__, '../fixtures/hiera.yaml')
  )
  default_facts = {
    puppetversion: Puppet.version,
    facterversion: '3.6.4'
  }
  c.default_facts = default_facts
end

But oddly if I do this in my own script it will return just fine ( facterversion > 2.5.1 ):

require 'facterdb'
require 'rspec-puppet-facts'

facterversion = ARGV[0]
facter_version_filter = RspecPuppetFacts.facter_version_to_filter(facterversion)
db = FacterDB.get_facts({ :facterversion => facter_version_filter })

version = facterversion

filter = []

filter << {
  :facterversion => facter_version_filter,
  :operatingsystem => 'CentOS',
  :operatingsystemmajrelease => '7',
  :hardwaremodel => 'x86_64',
}

received_facts = FacterDB::get_facts(filter)

puts received_facts[0].to_h[:memory]['system']['total_bytes']
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.6.1
512798720
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.7
6089424896
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.4
6089424896
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 3.0
514228224
gitlab/test-puppet - [modulesync-a4c2046a●] » be ruby mytest.rb 2.5
mytest.rb:21:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)

@cdenneen
Copy link
Author

cdenneen commented Sep 6, 2017

I found a way to do it within the individual spec ... the facterversion has to be on the same level as supported_os:

  on_supported_os({
   facterversion: '3.7',
    supported_os: [
      {
        'operatingsystem' => 'CentOS',
        'operatingsystemrelease' => [
          '7'
        ]
      }
    ]
  }).each do |os, facts|
    context "on #{os}" do
      let(:facts) do
        facts.merge({
          puppetversion: Puppet.version,
          sudoversion: '1.7.10p9',
          ap_env: 'dev',
          role: 'mapi',
          awsregion: 'us-east-1'
#          memory: {
#            system: {
#              total_bytes: '1111'
#            }
#          }
        })
      end

Does anyone know how to get that to work from the spec_helper.rb example above... doesn't appear to be reading default_facts.

@cyberious
Copy link

Any update on this, fighting with the same issue.

@cyberious
Copy link

Ugly as it is the way I worked around this in my spec_helper file was to do something like this

require 'facter'

module Facter
  def self.version
    ENV['FACTER_VERSION'] || '3.8.0'
  end
end

@ghoneycutt
Copy link
Member

Facter 2.5.1 appears to be working. If someone would like to send a patch to allow for cfacter, I would be happy to add it to the test matrix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants