Bug #14674

Facter processor fact executes commands on platforms that it shouldn't

Added by Josh Cooper about 1 year ago. Updated 8 months ago.

Status:Merged - Pending ReleaseStart date:05/23/2012
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:library
Target version:1.6.14
Keywords: Affected Facter version:
Branch:https://github.com/puppetlabs/facter/pull/332

Description

When evaluating the processor fact, it calls the following on all platforms:

## We have to enumerate these outside a Facter.add block to get the processorN descriptions iteratively
## (but we need them inside the Facter.add block above for tests on processorcount to work)
processor_list = Facter::Util::Processor.enum_cpuinfo
processor_list_aix = Facter::Util::Processor.enum_lsdev
processor_list_sunos = Facter::Util::Processor.enum_kstat

It should only call these methods on the appropriate platform, and it should only call them when needed (if processor_list is empty).

This is causing build failures when running Windows specific processor spec test on a Linux host. Because although we stub the kernel fact, the processor fact sees that /proc/cpuinfo exists, and tries to load the architecture fact, which tries to load the hardwaremodel fact, which on Windows was recently changed to use WMI instead of using RbConfig.

This appears to be new behavior as a result of https://github.com/puppetlabs/facter/commit/328ff7584e0353a609cba6d9fa08c0b6a26be664, which used to conditionally execute the commands depending on the value of the kernel fact.

This is the build failure:

1) Processor facts on Windows 2003 should count 2 processors
    Failure/Error: Facter.collection.loader.load(:processor)
    Mocha::ExpectationError:
      unexpected invocation: Facter::Util::WMI.execquery('select Architecture, Level from Win32_Processor')
      satisfied expectations:
      - allowed any number of times, not yet invoked: #.load_all(any_parameters)
      - allowed any number of times, invoked 7 times: #.value(any_parameters)
      - allowed any number of times, not yet invoked: #.proc(any_parameters)
      - allowed any number of times, not yet invoked: allowed any number of times, not yet invoked: #.proc(any_parameters).Name(any_parameters)
      - allowed any number of times, not yet invoked: allowed any number of times, not yet invoked: #.proc(any_parameters).NumberOfLogicalProcessors(any_parameters)
      - allowed any number of times, not yet invoked: Facter::Util::WMI.execquery('select * from Win32_Processor')
    # ./spec/../lib/facter/hardwaremodel.rb:39
    # ./spec/../lib/facter/util/resolution.rb:162:in `call'
    # ./spec/../lib/facter/util/resolution.rb:162:in `value'
    # ./spec/../lib/facter/util/resolution.rb:160:in `value'
    # ./spec/../lib/facter/util/fact.rb:78:in `value'
    # ./spec/../lib/facter/util/loader.rb:81:in `inject'
    # ./spec/../lib/facter/util/fact.rb:74:in `each'
    # ./spec/../lib/facter/util/fact.rb:74:in `inject'
    # ./spec/../lib/facter/util/fact.rb:74:in `value'
    # ./spec/../lib/facter/util/fact.rb:120:in `searching'
    # ./spec/../lib/facter/util/fact.rb:70:in `value'
    # ./spec/../lib/facter/util/collection.rb:118:in `value'
    # ./spec/../lib/facter.rb:98:in `send'
    # ./spec/../lib/facter.rb:98:in `value'
    # ./spec/../lib/facter/architecture.rb:16
    # ./spec/../lib/facter/util/resolution.rb:162:in `call'
    # ./spec/../lib/facter/util/resolution.rb:162:in `value'
    # ./spec/../lib/facter/util/resolution.rb:160:in `value'
    # ./spec/../lib/facter/util/fact.rb:78:in `value'
    # ./spec/../lib/facter/util/loader.rb:81:in `inject'
    # ./spec/../lib/facter/util/fact.rb:74:in `each'
    # ./spec/../lib/facter/util/fact.rb:74:in `inject'
    # ./spec/../lib/facter/util/fact.rb:74:in `value'
    # ./spec/../lib/facter/util/fact.rb:120:in `searching'
    # ./spec/../lib/facter/util/fact.rb:70:in `value'
    # ./spec/../lib/facter/util/collection.rb:118:in `value'
    # ./spec/../lib/facter.rb:98:in `send'
    # ./spec/../lib/facter.rb:98:in `value'
    # ./spec/../lib/facter/util/processor.rb:8:in `enum_cpuinfo'
    # ./spec/../lib/facter/processor.rb:83
    # ./spec/../lib/facter/util/loader.rb:81:in `load'
    # ./spec/../lib/facter/util/loader.rb:81:in `load_file'
    # ./spec/../lib/facter/util/loader.rb:21:in `load'
    # ./spec/../lib/facter/util/loader.rb:17:in `each'
    # ./spec/../lib/facter/util/loader.rb:17:in `load'
    # ./spec/unit/processor_spec.rb:23:in `load'
    # ./spec/unit/processor_spec.rb:32


Related issues

Related to Facter - Bug #11612: add facter support for ia 11.31 hpux processor discover ... Merged - Pending Release 12/29/2011

History

#1 Updated by Josh Cooper about 1 year ago

A workaround was added here https://github.com/joshcooper/facter/commit/f42896d92d8542a3017a0ac5141485888d15f3a9 it should be removed once the real issue is resolved.

#2 Updated by Alex Harvey 9 months ago

This code will also break on HP-UX, because HP-UX also has an lsdev command, and the HP-UX lsdev will fail when called with AIX-specific options in util/processor.rb.

# uname -a
HP-UX myhost B.11.23 U ia64 0573364837 unlimited-user license
# facter -d processorcount
Found no suitable resolves of 6 for macaddress
value for macaddress is still nil
Found no suitable resolves of 6 for macaddress
value for macaddress is still nil
Not an EC2 host
processor - invalid major number
usage: lsdev [-h] [-d driver | -C class] [-b block_major] [-c char_major]
             [-e major] [major] ...
Found no suitable resolves of 7 for processorcount
value for processorcount is still nil
#

#3 Updated by Alex Harvey 9 months ago

  • Assignee set to Alex Harvey

#4 Updated by Alex Harvey 9 months ago

  • Status changed from Accepted to In Topic Branch Pending Review
  • Branch set to https://github.com/alexharv074/facter/tree/1.6.x

I have submitted a patch in line with my understanding of what Josh Cooper has proposed.

#5 Updated by Jeff McCune 8 months ago

I’m currently working on this issue.

-Jeff

#6 Updated by Jeff McCune 8 months ago

  • Branch changed from https://github.com/alexharv074/facter/tree/1.6.x to https://github.com/puppetlabs/facter/pull/332

I’ve rebased Alex’s commits into my own pull request against master at:

https://github.com/puppetlabs/facter/pull/332

I’ll be merging this into 1.6.x ans master soon.

-Jeff

#7 Updated by Jeff McCune 8 months ago

  • Status changed from In Topic Branch Pending Review to Merged - Pending Release
  • Assignee deleted (Alex Harvey)
  • Target version set to 1.6.14

Merged

We need to keep an eye on our CI system since this change might affect other platforms that I don’t run on my laptop (e.g. Solaris and some Linux flavors) but if all things go well then this fix should be included in Facter 1.6.14 and 2.0.0.

Merged into 1.6.x as 278e813 in db3e2a5

Merged into master as 278e813 in 6a99c81

-Jeff

Also available in: Atom PDF