Module: RspecPuppetFacts

Defined in:
lib/rspec-puppet-facts.rb,
lib/rspec-puppet-facts/version.rb

Defined Under Namespace

Modules: Version

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_meta_supported_osObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
58
59
60
61
# File 'lib/rspec-puppet-facts.rb', line 55

def self.get_meta_supported_os
   = 
  if ['operatingsystem_support'].nil?
    fail StandardError, "Unknown operatingsystem support"
  end
  ['operatingsystem_support']
end

.get_metadataObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
67
68
69
# File 'lib/rspec-puppet-facts.rb', line 64

def self.
  if ! File.file?('metadata.json')
    fail StandardError, "Can't find metadata.json... dunno why"
  end
  JSON.parse(File.read('metadata.json'))
end

.meta_supported_osObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



50
51
52
# File 'lib/rspec-puppet-facts.rb', line 50

def self.meta_supported_os
  @meta_supported_os ||= get_meta_supported_os
end

Instance Method Details

#on_supported_os(opts = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rspec-puppet-facts.rb', line 6

def on_supported_os( opts = {} )
  opts[:hardwaremodels] ||= ['x86_64']
  opts[:supported_os] ||= RspecPuppetFacts.meta_supported_os

  h = {}

  opts[:supported_os].map do |os_sup|
    operatingsystem = os_sup['operatingsystem'].downcase
    if os_sup['operatingsystemrelease']
      os_sup['operatingsystemrelease'].map do |operatingsystemmajrelease|
        opts[:hardwaremodels].each do |hardwaremodel|
          os = "#{operatingsystem}-#{operatingsystemmajrelease.split(" ")[0]}-#{hardwaremodel}"
          # TODO: use SemVer here
          facter_minor_version = Facter.version[0..2]
          file = File.expand_path(File.join(File.dirname(__FILE__), "../facts/#{facter_minor_version}/#{os}.facts"))
          # Use File.exists? instead of File.file? here so that we can stub File.file?
          if ! File.exists?(file)
            warn "Can't find facts for '#{os}' for facter #{facter_minor_version}, skipping..."
          else
            h[os] = JSON.parse(IO.read(file), :symbolize_names => true)
          end
        end
      end
    else
      # Assuming this is a rolling release Operating system
      opts[:hardwaremodels].each do |hardwaremodel|
        os = "#{operatingsystem}-#{hardwaremodel}"
        # TODO: use SemVer here
        facter_minor_version = Facter.version[0..2]
        file = File.expand_path(File.join(File.dirname(__FILE__), "../facts/#{facter_minor_version}/#{os}.facts"))
        # Use File.exists? instead of File.file? here so that we can stub File.file?
        if ! File.exists?(file)
          warn "Can't find facts for '#{os}' for facter #{facter_minor_version}, skipping..."
        else
          h[os] = JSON.parse(IO.read(file), :symbolize_names => true)
        end
      end
    end
  end

  h
end