fauxhai-chef 9.4.22 → 9.4.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/fauxhai-chef.gemspec +2 -2
- data/lib/fauxhai/exception.rb +7 -0
- data/lib/fauxhai/fetcher.rb +59 -0
- data/lib/fauxhai/mocker.rb +52 -3
- data/lib/fauxhai/runner/default.rb +68 -1
- data/lib/fauxhai/runner/windows.rb +10 -0
- data/lib/fauxhai/runner.rb +15 -0
- data/lib/fauxhai/version.rb +7 -1
- data/lib/fauxhai.rb +42 -0
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6b70091182a176f59a4578fc4d12a1365f656576ed5437f8e70ae6f5f18b9347
|
|
4
|
+
data.tar.gz: 46d1ebfbb2bb45b099ff7e3d7ca59bb0b5707c43f383f8a9258fb63564282cc2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f221abe909c7e76837b6567ff19802a052adf8c2cf4966640cb25deed3b9372ba5cc86c1212de911fa9cda6c62c846590f09edbe649ff653943878f4005158f
|
|
7
|
+
data.tar.gz: 3f76106032a2eb67342b1cd6ee6b3266b0982aa9d832695fd2df60466665525860fd72e5e89bb89753032f130755d51637fb79354f6563a7b5c2ccbfc6a66d74
|
data/Gemfile
CHANGED
data/fauxhai-chef.gemspec
CHANGED
|
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
21
|
spec.add_runtime_dependency "net-ssh"
|
|
22
|
-
spec.add_runtime_dependency "ohai", ">=
|
|
22
|
+
spec.add_runtime_dependency "ohai", ">= 17.0"
|
|
23
23
|
|
|
24
|
-
spec.add_development_dependency "chef", ">=
|
|
24
|
+
spec.add_development_dependency "chef", ">= 17.0"
|
|
25
25
|
spec.add_development_dependency "rake"
|
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.7"
|
|
27
27
|
spec.add_development_dependency "rspec-its", "~> 1.2"
|
data/lib/fauxhai/exception.rb
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
module Fauxhai
|
|
2
|
+
# Errors raised by Fauxhai. Both inherit from `ArgumentError`, so existing
|
|
3
|
+
# rescues of `ArgumentError` keep working.
|
|
2
4
|
module Exception
|
|
5
|
+
# Raised when platform data cannot be located: an unknown platform, a
|
|
6
|
+
# `:path` pointing at a missing file, or a failed fetch from GitHub.
|
|
3
7
|
class InvalidPlatform < ArgumentError; end
|
|
8
|
+
|
|
9
|
+
# Raised when a platform is known but the requested version is not
|
|
10
|
+
# available for it.
|
|
4
11
|
class InvalidVersion < ArgumentError; end
|
|
5
12
|
end
|
|
6
13
|
end
|
data/lib/fauxhai/fetcher.rb
CHANGED
|
@@ -2,7 +2,31 @@ require "digest/sha1"
|
|
|
2
2
|
require "json" unless defined?(JSON)
|
|
3
3
|
|
|
4
4
|
module Fauxhai
|
|
5
|
+
# Collects real Ohai data from a remote host over SSH, rather than using the
|
|
6
|
+
# canned platform data that {Fauxhai::Mocker} loads.
|
|
7
|
+
#
|
|
8
|
+
# Results are cached on disk under the gem's `tmp` directory and keyed by
|
|
9
|
+
# user and host, so repeat runs skip the SSH round trip. Because the cache
|
|
10
|
+
# holds real data from a real machine, treat it as sensitive.
|
|
11
|
+
#
|
|
12
|
+
# @see Fauxhai.fetch
|
|
5
13
|
class Fetcher
|
|
14
|
+
# Fetch Ohai data from a host, or read it back from the local cache.
|
|
15
|
+
#
|
|
16
|
+
# @example
|
|
17
|
+
# Fauxhai::Fetcher.new(host: 'server01.example.com', user: 'deploy')
|
|
18
|
+
#
|
|
19
|
+
# @param options [Hash] options for the fetch. Beyond the keys below, any
|
|
20
|
+
# remaining options are passed straight through to `Net::SSH.start`,
|
|
21
|
+
# so `:password`, `:key_file` and friends all work.
|
|
22
|
+
# @option options [String] :host the host to collect data from (required)
|
|
23
|
+
# @option options [String] :user the SSH user, defaulting to `$USER`
|
|
24
|
+
# or `$USERNAME`
|
|
25
|
+
# @option options [Boolean] :force_cache_miss re-fetch over SSH even when
|
|
26
|
+
# a cached copy exists
|
|
27
|
+
# @yieldparam data [Hash] the fetched data, for overriding attributes
|
|
28
|
+
# @return [Fauxhai::Fetcher]
|
|
29
|
+
# @raise [ArgumentError] if no `:host` was given
|
|
6
30
|
def initialize(options = {}, &override_attributes)
|
|
7
31
|
@options = options
|
|
8
32
|
|
|
@@ -32,22 +56,39 @@ module Fauxhai
|
|
|
32
56
|
@data
|
|
33
57
|
end
|
|
34
58
|
|
|
59
|
+
# The cached Ohai data for this user and host.
|
|
60
|
+
#
|
|
61
|
+
# @return [Hash] the parsed contents of {#cache_file}
|
|
35
62
|
def cache
|
|
36
63
|
@cache ||= JSON.parse(File.read(cache_file))
|
|
37
64
|
end
|
|
38
65
|
|
|
66
|
+
# Whether a cached copy already exists for this user and host.
|
|
67
|
+
#
|
|
68
|
+
# @return [Boolean]
|
|
39
69
|
def cached?
|
|
40
70
|
File.exist?(cache_file)
|
|
41
71
|
end
|
|
42
72
|
|
|
73
|
+
# A stable digest of the user and host, used as the cache filename so
|
|
74
|
+
# that different targets do not collide.
|
|
75
|
+
#
|
|
76
|
+
# @return [String] a hex digest
|
|
43
77
|
def cache_key
|
|
44
78
|
Digest::SHA2.hexdigest("#{user}@#{host}")
|
|
45
79
|
end
|
|
46
80
|
|
|
81
|
+
# The absolute path this host's cached data is written to.
|
|
82
|
+
#
|
|
83
|
+
# @return [String] a path under the gem's `tmp` directory
|
|
47
84
|
def cache_file
|
|
48
85
|
File.expand_path(File.join(Fauxhai.root, "tmp", cache_key))
|
|
49
86
|
end
|
|
50
87
|
|
|
88
|
+
# Whether the caller asked to bypass the cache. Reading this consumes the
|
|
89
|
+
# `:force_cache_miss` option so it is not forwarded on to `Net::SSH`.
|
|
90
|
+
#
|
|
91
|
+
# @return [Boolean]
|
|
51
92
|
def force_cache_miss?
|
|
52
93
|
@force_cache_miss ||= @options.delete(:force_cache_miss) || false
|
|
53
94
|
end
|
|
@@ -59,12 +100,26 @@ module Fauxhai
|
|
|
59
100
|
@data.to_hash(*args)
|
|
60
101
|
end
|
|
61
102
|
|
|
103
|
+
# A readable representation of the fetcher.
|
|
104
|
+
#
|
|
105
|
+
# @note This interpolates the remaining `@options`, which are whatever was
|
|
106
|
+
# left after `:host`, `:user` and `:force_cache_miss` were consumed --
|
|
107
|
+
# in other words the options forwarded to `Net::SSH.start`. Those can
|
|
108
|
+
# include credentials such as `:password`, `:passphrase` or key paths,
|
|
109
|
+
# so do not log or otherwise emit this string.
|
|
110
|
+
#
|
|
111
|
+
# @return [String] a readable representation of the fetcher
|
|
62
112
|
def to_s
|
|
63
113
|
"#<Fauxhai::Fetcher @host=#{host}, @options=#{@options}>"
|
|
64
114
|
end
|
|
65
115
|
|
|
66
116
|
private
|
|
67
117
|
|
|
118
|
+
# The host to collect from. Reading this consumes the `:host` option so it
|
|
119
|
+
# is not forwarded on to `Net::SSH`.
|
|
120
|
+
#
|
|
121
|
+
# @return [String] the hostname
|
|
122
|
+
# @raise [ArgumentError] if `:host` was never given
|
|
68
123
|
def host
|
|
69
124
|
@host ||= begin
|
|
70
125
|
raise ArgumentError, ":host is a required option for Fauxhai.fetch" unless @options[:host]
|
|
@@ -73,6 +128,10 @@ module Fauxhai
|
|
|
73
128
|
end
|
|
74
129
|
end
|
|
75
130
|
|
|
131
|
+
# The SSH user, falling back to the local `$USER` or `$USERNAME`. Reading
|
|
132
|
+
# this consumes the `:user` option so it is not forwarded on to `Net::SSH`.
|
|
133
|
+
#
|
|
134
|
+
# @return [String] the username
|
|
76
135
|
def user
|
|
77
136
|
@user ||= (@options.delete(:user) || ENV["USER"] || ENV["USERNAME"]).chomp
|
|
78
137
|
end
|
data/lib/fauxhai/mocker.rb
CHANGED
|
@@ -2,11 +2,21 @@ require "json" unless defined?(JSON)
|
|
|
2
2
|
require "pathname" unless defined?(Pathname)
|
|
3
3
|
|
|
4
4
|
module Fauxhai
|
|
5
|
+
# Loads mock Ohai data for a platform and version.
|
|
6
|
+
#
|
|
7
|
+
# Data is looked up on disk first, under `lib/fauxhai/platforms`. If it is not
|
|
8
|
+
# there and `:github_fetching` is enabled, it is downloaded from the project's
|
|
9
|
+
# main branch and cached locally, so platforms contributed after the installed
|
|
10
|
+
# gem was released still resolve.
|
|
11
|
+
#
|
|
12
|
+
# @see Fauxhai.mock
|
|
5
13
|
class Mocker
|
|
6
14
|
# The base URL for the GitHub project (raw)
|
|
15
|
+
# @return [String]
|
|
7
16
|
RAW_BASE = "https://raw.githubusercontent.com/chef/fauxhai/main".freeze
|
|
8
17
|
|
|
9
18
|
# A message about where to find a list of platforms
|
|
19
|
+
# @return [String]
|
|
10
20
|
PLATFORM_LIST_MESSAGE = "A list of available platforms is available at https://github.com/chef/fauxhai/blob/main/PLATFORMS.md".freeze
|
|
11
21
|
|
|
12
22
|
# Create a new Ohai Mock with fauxhai.
|
|
@@ -21,12 +31,25 @@ module Fauxhai
|
|
|
21
31
|
# the path to a local JSON file
|
|
22
32
|
# @option options [Bool] :github_fetching
|
|
23
33
|
# whether to try loading from Github
|
|
34
|
+
# @yieldparam data [Hash] the loaded platform data, for overriding
|
|
35
|
+
# attributes in place
|
|
36
|
+
# @return [Fauxhai::Mocker]
|
|
37
|
+
# @raise [Fauxhai::Exception::InvalidPlatform] if a block is given and the
|
|
38
|
+
# platform data cannot be resolved
|
|
24
39
|
def initialize(options = {}, &override_attributes)
|
|
25
40
|
@options = { github_fetching: true }.merge(options)
|
|
26
41
|
|
|
27
42
|
yield(data) if block_given?
|
|
28
43
|
end
|
|
29
44
|
|
|
45
|
+
# The mock Ohai data, loaded on first call and memoized after that.
|
|
46
|
+
#
|
|
47
|
+
# Resolution order is `:path` if given, then the on-disk platform file,
|
|
48
|
+
# then GitHub when `:github_fetching` is enabled.
|
|
49
|
+
#
|
|
50
|
+
# @return [Hash] the parsed Ohai data
|
|
51
|
+
# @raise [Fauxhai::Exception::InvalidPlatform] if the data cannot be found
|
|
52
|
+
# on disk, or the GitHub fetch is disabled or fails
|
|
30
53
|
def data
|
|
31
54
|
@fauxhai_data ||= lambda do
|
|
32
55
|
# If a path option was specified, use it
|
|
@@ -50,7 +73,7 @@ module Fauxhai
|
|
|
50
73
|
uri = URI("#{RAW_BASE}/lib/fauxhai/platforms/#{platform}/#{version}.json")
|
|
51
74
|
response = Net::HTTP.get_response(uri)
|
|
52
75
|
rescue StandardError
|
|
53
|
-
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and an HTTP error was encountered when fetching from
|
|
76
|
+
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and an HTTP error was encountered when fetching from GitHub. #{PLATFORM_LIST_MESSAGE}")
|
|
54
77
|
end
|
|
55
78
|
|
|
56
79
|
if response.code.to_i == 200
|
|
@@ -65,10 +88,10 @@ module Fauxhai
|
|
|
65
88
|
end
|
|
66
89
|
return parse_and_validate(response_body)
|
|
67
90
|
else
|
|
68
|
-
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and
|
|
91
|
+
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and GitHub fetching returned an http error code #{response.code}! #{PLATFORM_LIST_MESSAGE}")
|
|
69
92
|
end
|
|
70
93
|
else
|
|
71
|
-
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and
|
|
94
|
+
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and GitHub fetching is disabled! #{PLATFORM_LIST_MESSAGE}")
|
|
72
95
|
end
|
|
73
96
|
end.call
|
|
74
97
|
end
|
|
@@ -78,6 +101,12 @@ module Fauxhai
|
|
|
78
101
|
# As major releases of Ohai ship it's difficult and sometimes impossible
|
|
79
102
|
# to regenerate all fauxhai data. This allows us to deprecate old releases
|
|
80
103
|
# and eventually remove them while giving end users ample warning.
|
|
104
|
+
#
|
|
105
|
+
# Data marked `deprecated` still loads; it only warns on STDERR.
|
|
106
|
+
#
|
|
107
|
+
# @param unparsed_data [String] the raw JSON read from disk or GitHub
|
|
108
|
+
# @return [Hash] the parsed data
|
|
109
|
+
# @raise [JSON::ParserError] if the data is not valid JSON
|
|
81
110
|
def parse_and_validate(unparsed_data)
|
|
82
111
|
parsed_data = JSON.parse(unparsed_data)
|
|
83
112
|
if parsed_data["deprecated"]
|
|
@@ -86,6 +115,10 @@ module Fauxhai
|
|
|
86
115
|
parsed_data
|
|
87
116
|
end
|
|
88
117
|
|
|
118
|
+
# The platform being mocked, defaulting to the synthetic "chefspec"
|
|
119
|
+
# platform with a warning when the caller omitted one.
|
|
120
|
+
#
|
|
121
|
+
# @return [String] the platform name
|
|
89
122
|
def platform
|
|
90
123
|
@options[:platform] ||= begin
|
|
91
124
|
STDERR.puts "WARNING: you must specify a 'platform' and optionally a 'version' for your ChefSpec Runner and/or Fauxhai constructor, in the future omitting the platform will become a hard error. #{PLATFORM_LIST_MESSAGE}"
|
|
@@ -93,10 +126,26 @@ module Fauxhai
|
|
|
93
126
|
end
|
|
94
127
|
end
|
|
95
128
|
|
|
129
|
+
# The directory holding the JSON files for the current platform.
|
|
130
|
+
#
|
|
131
|
+
# @return [String] an absolute path, which may not exist yet
|
|
96
132
|
def platform_path
|
|
97
133
|
File.join(Fauxhai.root, "lib", "fauxhai", "platforms", platform)
|
|
98
134
|
end
|
|
99
135
|
|
|
136
|
+
# The platform version to load.
|
|
137
|
+
#
|
|
138
|
+
# An exact filename match wins. Otherwise the option is treated as a
|
|
139
|
+
# prefix, so `"6"` resolves to CentOS `6.10`; a trailing `\D` in the
|
|
140
|
+
# prefix match keeps `"7.1"` from matching `"7.10.0"`. A nil or empty
|
|
141
|
+
# version matches anything. When several candidates remain, the highest
|
|
142
|
+
# wins under a version comparison loose enough to cope with the range of
|
|
143
|
+
# formats in use (`4.8-RELEASE`, `2012R2`, `10.15`).
|
|
144
|
+
#
|
|
145
|
+
# If nothing matches, the caller's option is passed through unchanged so
|
|
146
|
+
# that GitHub fetching still gets a chance.
|
|
147
|
+
#
|
|
148
|
+
# @return [String, nil] the resolved version
|
|
100
149
|
def version
|
|
101
150
|
@version ||= begin
|
|
102
151
|
if File.exist?("#{platform_path}/#{@options[:version]}.json")
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
module Fauxhai
|
|
2
2
|
class Runner
|
|
3
|
+
# The sanitized values {Fauxhai::Runner} substitutes into real Ohai output
|
|
4
|
+
# before it is printed.
|
|
5
|
+
#
|
|
6
|
+
# Every method here returns a fixed stand-in rather than anything read from
|
|
7
|
+
# the machine being scanned. That is the whole point: contributed platform
|
|
8
|
+
# files must not leak the hostname, username, addresses, or SSH keys of the
|
|
9
|
+
# box they were generated on. The constants are deliberately boring and
|
|
10
|
+
# identical across platforms, so diffs between platform files show real
|
|
11
|
+
# differences instead of environmental noise.
|
|
12
|
+
#
|
|
13
|
+
# {Fauxhai::Runner::Windows} overrides the handful of these that Ohai
|
|
14
|
+
# reports differently on Windows.
|
|
3
15
|
module Default
|
|
16
|
+
# @return [String] the fake directory holding the Ruby binaries
|
|
4
17
|
def bin_dir
|
|
5
18
|
"/usr/local/bin"
|
|
6
19
|
end
|
|
7
20
|
|
|
21
|
+
# Fake network traffic counters for the loopback and default interfaces.
|
|
22
|
+
#
|
|
23
|
+
# All totals are zero so that platform files never carry a real machine's
|
|
24
|
+
# traffic volume, and so mocks stay byte-identical between runs.
|
|
25
|
+
#
|
|
26
|
+
# @return [Hash] the fake counter tree, keyed by interface name
|
|
8
27
|
def counters
|
|
9
28
|
{
|
|
10
29
|
"network" => {
|
|
@@ -54,14 +73,21 @@ module Fauxhai
|
|
|
54
73
|
}
|
|
55
74
|
end
|
|
56
75
|
|
|
76
|
+
# @return [String] the fake name of the user running Ohai
|
|
57
77
|
def current_user
|
|
58
78
|
"fauxhai"
|
|
59
79
|
end
|
|
60
80
|
|
|
81
|
+
# @return [String] the fake default gateway address
|
|
61
82
|
def default_gateway
|
|
62
83
|
"10.0.0.1"
|
|
63
84
|
end
|
|
64
85
|
|
|
86
|
+
# The primary network interface name, which is the one piece of the fake
|
|
87
|
+
# network data that has to vary: cookbooks branch on the interface
|
|
88
|
+
# naming convention, so mocking `eth0` on Fedora would be wrong.
|
|
89
|
+
#
|
|
90
|
+
# @return [String] the interface name for the detected platform family
|
|
65
91
|
def default_interface
|
|
66
92
|
case @system.data["platform_family"]
|
|
67
93
|
when "mac_os_x"
|
|
@@ -75,40 +101,58 @@ module Fauxhai
|
|
|
75
101
|
end
|
|
76
102
|
end
|
|
77
103
|
|
|
104
|
+
# @return [String] the fake DNS domain
|
|
78
105
|
def domain
|
|
79
106
|
"local"
|
|
80
107
|
end
|
|
81
108
|
|
|
109
|
+
# @return [String] the fake fully qualified domain name
|
|
82
110
|
def fqdn
|
|
83
111
|
"fauxhai.local"
|
|
84
112
|
end
|
|
85
113
|
|
|
114
|
+
# @return [String] the fake path to the `gem` executable
|
|
86
115
|
def gem_bin
|
|
87
116
|
"/usr/local/bin/gem"
|
|
88
117
|
end
|
|
89
118
|
|
|
119
|
+
# @return [String] the fake directory holding installed gems
|
|
90
120
|
def gems_dir
|
|
91
121
|
"/usr/local/gems"
|
|
92
122
|
end
|
|
93
123
|
|
|
124
|
+
# @return [String] the fake hostname
|
|
94
125
|
def hostname
|
|
95
126
|
"Fauxhai"
|
|
96
127
|
end
|
|
97
128
|
|
|
129
|
+
# @return [String] the fake IPv4 address
|
|
98
130
|
def ipaddress
|
|
99
131
|
"10.0.0.2"
|
|
100
132
|
end
|
|
101
133
|
|
|
134
|
+
# @return [String] the fake IPv6 address
|
|
102
135
|
def ip6address
|
|
103
136
|
"fe80:0:0:0:0:0:a00:2"
|
|
104
137
|
end
|
|
105
138
|
|
|
139
|
+
# The fake host key data, standing in for whatever is really in
|
|
140
|
+
# `/etc/ssh` on the machine being scanned.
|
|
141
|
+
#
|
|
142
|
+
# @return [Hash] the fake key material
|
|
143
|
+
# @see #ssh
|
|
106
144
|
def keys
|
|
107
145
|
{
|
|
108
146
|
"ssh" => ssh,
|
|
109
147
|
}
|
|
110
148
|
end
|
|
111
149
|
|
|
150
|
+
# The real language data from Ohai, with the Ruby paths swapped for the
|
|
151
|
+
# fake ones. Version and platform details are genuine, since that is
|
|
152
|
+
# exactly what cookbooks need to test against; only the paths, which
|
|
153
|
+
# would otherwise embed a username, are replaced.
|
|
154
|
+
#
|
|
155
|
+
# @return [Hash] the language data for Ruby and PowerShell
|
|
112
156
|
def languages
|
|
113
157
|
{
|
|
114
158
|
"ruby" => @system.data["languages"]["ruby"].merge("bin_dir" => bin_dir,
|
|
@@ -119,10 +163,16 @@ module Fauxhai
|
|
|
119
163
|
}
|
|
120
164
|
end
|
|
121
165
|
|
|
166
|
+
# @return [String] the fake MAC address
|
|
122
167
|
def macaddress
|
|
123
168
|
"11:11:11:11:11:11"
|
|
124
169
|
end
|
|
125
170
|
|
|
171
|
+
# The fake network topology: a loopback interface and one default
|
|
172
|
+
# interface on a 10.0.0.0/24 network, with matching routes and ARP
|
|
173
|
+
# entries.
|
|
174
|
+
#
|
|
175
|
+
# @return [Hash] the fake interfaces, default interface, and gateway
|
|
126
176
|
def network
|
|
127
177
|
{
|
|
128
178
|
"interfaces" => {
|
|
@@ -206,10 +256,17 @@ module Fauxhai
|
|
|
206
256
|
}
|
|
207
257
|
end
|
|
208
258
|
|
|
259
|
+
# @return [String] the fake path to the `ruby` executable
|
|
209
260
|
def ruby_bin
|
|
210
261
|
"/usr/local/bin/ruby"
|
|
211
262
|
end
|
|
212
263
|
|
|
264
|
+
# The throwaway public keys bundled with the gem, read from
|
|
265
|
+
# `lib/fauxhai/keys`. They exist only so mocked nodes have plausibly
|
|
266
|
+
# shaped key data; they are published in the repository and guard
|
|
267
|
+
# nothing.
|
|
268
|
+
#
|
|
269
|
+
# @return [Hash] the fake DSA and RSA public keys
|
|
213
270
|
def ssh
|
|
214
271
|
{
|
|
215
272
|
"host_dsa_public" => File.read(File.join(Fauxhai.root, "lib", "fauxhai", "keys", "id_dsa.pub")).strip,
|
|
@@ -217,14 +274,17 @@ module Fauxhai
|
|
|
217
274
|
}
|
|
218
275
|
end
|
|
219
276
|
|
|
277
|
+
# @return [String] the fake uptime, as Ohai formats it for humans
|
|
220
278
|
def uptime
|
|
221
279
|
"30 days 15 hours 07 minutes 30 seconds"
|
|
222
280
|
end
|
|
223
281
|
|
|
282
|
+
# @return [Integer] the fake uptime in seconds, matching {#uptime}
|
|
224
283
|
def uptime_seconds
|
|
225
284
|
2646450
|
|
226
285
|
end
|
|
227
286
|
|
|
287
|
+
# @return [Hash] a fake single-core CPU
|
|
228
288
|
def cpu
|
|
229
289
|
{
|
|
230
290
|
"real" => 1,
|
|
@@ -233,18 +293,21 @@ module Fauxhai
|
|
|
233
293
|
}
|
|
234
294
|
end
|
|
235
295
|
|
|
296
|
+
# @return [Hash] a fake 1GB of total memory
|
|
236
297
|
def memory
|
|
237
298
|
{
|
|
238
299
|
"total" => "1048576kB",
|
|
239
300
|
}
|
|
240
301
|
end
|
|
241
302
|
|
|
303
|
+
# @return [Hash] empty virtualization data, so mocks read as bare metal
|
|
242
304
|
def virtualization
|
|
243
305
|
{
|
|
244
306
|
"systems" => {},
|
|
245
307
|
}
|
|
246
308
|
end
|
|
247
309
|
|
|
310
|
+
# @return [Hash] a fake timezone, fixed to GMT
|
|
248
311
|
def time
|
|
249
312
|
{
|
|
250
313
|
"timezone" => "GMT",
|
|
@@ -254,7 +317,11 @@ module Fauxhai
|
|
|
254
317
|
# Whitelist attributes are attributes that we *actually* want from the node. Other attributes are
|
|
255
318
|
# either ignored or overridden, but we ensure these are returned with the command.
|
|
256
319
|
#
|
|
257
|
-
#
|
|
320
|
+
# This is an allow list rather than a deny list on purpose: a new Ohai
|
|
321
|
+
# plugin that starts collecting something sensitive is dropped by
|
|
322
|
+
# default, instead of leaking until someone notices.
|
|
323
|
+
#
|
|
324
|
+
# @return [Array<String>] the attribute keys copied from the real data
|
|
258
325
|
def whitelist_attributes
|
|
259
326
|
%w{
|
|
260
327
|
block_device
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
module Fauxhai
|
|
2
2
|
class Runner
|
|
3
|
+
# Windows overrides for the sanitized values in
|
|
4
|
+
# {Fauxhai::Runner::Default}. Windows reports network interfaces in a
|
|
5
|
+
# different shape than the Unix platforms, so only the interface naming and
|
|
6
|
+
# the network structure need replacing; everything else is inherited.
|
|
3
7
|
module Windows
|
|
4
8
|
require_relative "default"
|
|
5
9
|
include ::Fauxhai::Runner::Default
|
|
6
10
|
|
|
11
|
+
# @return [String] the fake Windows interface index
|
|
7
12
|
def default_interface
|
|
8
13
|
"0xe"
|
|
9
14
|
end
|
|
10
15
|
|
|
16
|
+
# The sanitized network data, shaped the way Ohai reports it on Windows:
|
|
17
|
+
# a WMI `configuration` and `instance` pair per interface rather than the
|
|
18
|
+
# flat address list used on Unix.
|
|
19
|
+
#
|
|
20
|
+
# @return [Hash] the fake network topology
|
|
11
21
|
def network
|
|
12
22
|
{
|
|
13
23
|
"interfaces" => {
|
data/lib/fauxhai/runner.rb
CHANGED
|
@@ -2,7 +2,22 @@ require "ohai" unless defined?(Ohai::System)
|
|
|
2
2
|
require "ohai/plugins/chef"
|
|
3
3
|
|
|
4
4
|
module Fauxhai
|
|
5
|
+
# Powers the `fauxhai` command line tool.
|
|
6
|
+
#
|
|
7
|
+
# Runs every Ohai plugin on the local machine, then keeps only the
|
|
8
|
+
# attributes in {Fauxhai::Runner::Default#whitelist_attributes} and replaces
|
|
9
|
+
# the rest with sanitized stand-ins, so the result carries no usernames,
|
|
10
|
+
# hostnames, IP addresses, or real SSH keys. The sanitized JSON is printed to
|
|
11
|
+
# STDOUT, ready to be contributed as a new platform file.
|
|
12
|
+
#
|
|
13
|
+
# The sanitizing methods come from {Fauxhai::Runner::Windows} on Windows and
|
|
14
|
+
# {Fauxhai::Runner::Default} everywhere else.
|
|
5
15
|
class Runner
|
|
16
|
+
# Collect, sanitize, and print the local Ohai data.
|
|
17
|
+
#
|
|
18
|
+
# @param args [Array<String>] command line arguments, currently unused;
|
|
19
|
+
# `bin/fauxhai` handles `-v` and `-h` before constructing the runner
|
|
20
|
+
# @return [void]
|
|
6
21
|
def initialize(args)
|
|
7
22
|
@system = Ohai::System.new
|
|
8
23
|
@system.all_plugins
|
data/lib/fauxhai/version.rb
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
module Fauxhai
|
|
2
|
-
VERSION
|
|
2
|
+
# The gem version. Both this constant and the root `VERSION` file are owned
|
|
3
|
+
# by Chef Expeditor: it bumps `VERSION` when a pull request merges, then runs
|
|
4
|
+
# `.expeditor/update_version.sh` to rewrite the line below to match. Neither
|
|
5
|
+
# should be edited by hand in a pull request.
|
|
6
|
+
#
|
|
7
|
+
# @return [String]
|
|
8
|
+
VERSION = "9.4.29".freeze
|
|
3
9
|
end
|
data/lib/fauxhai.rb
CHANGED
|
@@ -1,17 +1,59 @@
|
|
|
1
|
+
# Fauxhai provides mock Ohai data for testing Chef cookbooks with ChefSpec.
|
|
2
|
+
#
|
|
3
|
+
# Platform data ships with the gem as JSON files under `lib/fauxhai/platforms`,
|
|
4
|
+
# one file per platform version. {mock} loads that canned data; {fetch} collects
|
|
5
|
+
# real Ohai output from a running host instead.
|
|
6
|
+
#
|
|
7
|
+
# @see https://github.com/chef/fauxhai
|
|
1
8
|
module Fauxhai
|
|
2
9
|
autoload :Exception, "fauxhai/exception"
|
|
3
10
|
autoload :Fetcher, "fauxhai/fetcher"
|
|
4
11
|
autoload :Mocker, "fauxhai/mocker"
|
|
5
12
|
autoload :VERSION, "fauxhai/version"
|
|
6
13
|
|
|
14
|
+
# The absolute path to the root of the installed gem. Used to locate the
|
|
15
|
+
# bundled platform data and the fake SSH keys.
|
|
16
|
+
#
|
|
17
|
+
# @return [String] the gem's root directory
|
|
7
18
|
def self.root
|
|
8
19
|
@@root ||= File.expand_path("../../", __FILE__)
|
|
9
20
|
end
|
|
10
21
|
|
|
22
|
+
# Build mock Ohai data for a platform and version.
|
|
23
|
+
#
|
|
24
|
+
# The platform data is resolved lazily: passing a block forces the load
|
|
25
|
+
# immediately, otherwise it happens on the first call to
|
|
26
|
+
# {Fauxhai::Mocker#data}.
|
|
27
|
+
#
|
|
28
|
+
# @example Mock Ubuntu 20.04
|
|
29
|
+
# Fauxhai.mock(platform: 'ubuntu', version: '20.04')
|
|
30
|
+
#
|
|
31
|
+
# @example Override an attribute on the mocked node
|
|
32
|
+
# Fauxhai.mock(platform: 'ubuntu', version: '20.04') do |node|
|
|
33
|
+
# node['languages']['ruby']['version'] = 'ree'
|
|
34
|
+
# end
|
|
35
|
+
#
|
|
36
|
+
# @param args [Array] options forwarded to {Fauxhai::Mocker#initialize}
|
|
37
|
+
# @yieldparam node [Hash] the mocked data, for overriding attributes in place
|
|
38
|
+
# @return [Fauxhai::Mocker] a mocker wrapping the platform data
|
|
39
|
+
# @see Fauxhai::Mocker#initialize
|
|
11
40
|
def self.mock(*args, &block)
|
|
12
41
|
Fauxhai::Mocker.new(*args, &block)
|
|
13
42
|
end
|
|
14
43
|
|
|
44
|
+
# Collect real Ohai data from a remote host over SSH.
|
|
45
|
+
#
|
|
46
|
+
# Unlike {mock}, this runs immediately: the SSH connection is opened (or the
|
|
47
|
+
# local cache read) during construction.
|
|
48
|
+
#
|
|
49
|
+
# @example Fetch from a running server
|
|
50
|
+
# Fauxhai.fetch(host: 'server01.example.com')
|
|
51
|
+
#
|
|
52
|
+
# @param args [Array] options forwarded to {Fauxhai::Fetcher#initialize}
|
|
53
|
+
# @yieldparam node [Hash] the fetched data, for overriding attributes in place
|
|
54
|
+
# @return [Fauxhai::Fetcher] a fetcher wrapping the collected Ohai data
|
|
55
|
+
# @raise [ArgumentError] if no `:host` option is given
|
|
56
|
+
# @see Fauxhai::Fetcher#initialize
|
|
15
57
|
def self.fetch(*args, &block)
|
|
16
58
|
Fauxhai::Fetcher.new(*args, &block)
|
|
17
59
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fauxhai-chef
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 9.4.
|
|
4
|
+
version: 9.4.29
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Seth Vargo
|
|
8
8
|
- Tim Smith
|
|
9
|
-
autorequire:
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2026-
|
|
12
|
+
date: 2026-11-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: net-ssh
|
|
@@ -31,28 +31,28 @@ dependencies:
|
|
|
31
31
|
requirements:
|
|
32
32
|
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
34
|
+
version: '17.0'
|
|
35
35
|
type: :runtime
|
|
36
36
|
prerelease: false
|
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
39
|
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '
|
|
41
|
+
version: '17.0'
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
43
|
name: chef
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '
|
|
48
|
+
version: '17.0'
|
|
49
49
|
type: :development
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
53
|
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '
|
|
55
|
+
version: '17.0'
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
57
|
name: rake
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -197,7 +197,7 @@ homepage: https://github.com/chef/fauxhai
|
|
|
197
197
|
licenses:
|
|
198
198
|
- MIT
|
|
199
199
|
metadata: {}
|
|
200
|
-
post_install_message:
|
|
200
|
+
post_install_message:
|
|
201
201
|
rdoc_options: []
|
|
202
202
|
require_paths:
|
|
203
203
|
- lib
|
|
@@ -213,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
213
213
|
version: '0'
|
|
214
214
|
requirements: []
|
|
215
215
|
rubygems_version: 3.3.27
|
|
216
|
-
signing_key:
|
|
216
|
+
signing_key:
|
|
217
217
|
specification_version: 4
|
|
218
218
|
summary: Fauxhai provides an easy way to mock out your ohai data for testing with
|
|
219
219
|
chefspec!
|