fauxhai-ng-slim 7.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/lib/fauxhai.rb +18 -0
- data/lib/fauxhai/exception.rb +6 -0
- data/lib/fauxhai/fetcher.rb +79 -0
- data/lib/fauxhai/mocker.rb +143 -0
- data/lib/fauxhai/runner.rb +44 -0
- data/lib/fauxhai/runner/default.rb +284 -0
- data/lib/fauxhai/runner/windows.rb +101 -0
- data/lib/fauxhai/version.rb +3 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 957547ab00be9439b62882ffe9f86a44907ca1a674a09a70dbabe58f746b2741
|
4
|
+
data.tar.gz: e8d8a0b544cf6040d9cd208c297d91b4f1c1ade598656014703685a071cbefcf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fa21a70c06d155ef481ad7a60ac5c86794c92a7226422bff2bd47b21eab78a2054a5e03297cffc1b4b3cbfe4616484456453a989cc44070e01209f68eec1a4cb
|
7
|
+
data.tar.gz: 0240fe739bbf5905967f9beee07f2e03d3a39fdb757aabdcf4f0981a01ffafe89501ccc3b801e130e9fcfb148da42d5d60092eeaabce96333ab78fe00a21676c
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Seth Vargo and CustomInk, LCC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/fauxhai.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fauxhai
|
2
|
+
autoload :Exception, 'fauxhai/exception'
|
3
|
+
autoload :Fetcher, 'fauxhai/fetcher'
|
4
|
+
autoload :Mocker, 'fauxhai/mocker'
|
5
|
+
autoload :VERSION, 'fauxhai/version'
|
6
|
+
|
7
|
+
def self.root
|
8
|
+
@@root ||= File.expand_path('../../', __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.mock(*args, &block)
|
12
|
+
Fauxhai::Mocker.new(*args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.fetch(*args, &block)
|
16
|
+
Fauxhai::Fetcher.new(*args, &block)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
require 'json'
|
3
|
+
require 'net/ssh'
|
4
|
+
|
5
|
+
module Fauxhai
|
6
|
+
class Fetcher
|
7
|
+
def initialize(options = {}, &override_attributes)
|
8
|
+
@options = options
|
9
|
+
|
10
|
+
if !force_cache_miss? && cached?
|
11
|
+
@data = cache
|
12
|
+
else
|
13
|
+
Net::SSH.start(host, user, @options) do |ssh|
|
14
|
+
@data = JSON.parse(ssh.exec!('ohai'))
|
15
|
+
end
|
16
|
+
|
17
|
+
# cache this data so we do not have to SSH again
|
18
|
+
File.open(cache_file, 'w+') { |f| f.write(@data.to_json) }
|
19
|
+
end
|
20
|
+
|
21
|
+
yield(@data) if block_given?
|
22
|
+
|
23
|
+
if defined?(ChefSpec)
|
24
|
+
data = @data
|
25
|
+
::ChefSpec::Runner.send :define_method, :fake_ohai do |ohai|
|
26
|
+
data.each_pair do |attribute, value|
|
27
|
+
ohai[attribute] = value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
@data
|
33
|
+
end
|
34
|
+
|
35
|
+
def cache
|
36
|
+
@cache ||= JSON.parse(File.read(cache_file))
|
37
|
+
end
|
38
|
+
|
39
|
+
def cached?
|
40
|
+
File.exist?(cache_file)
|
41
|
+
end
|
42
|
+
|
43
|
+
def cache_key
|
44
|
+
Digest::SHA2.hexdigest("#{user}@#{host}")
|
45
|
+
end
|
46
|
+
|
47
|
+
def cache_file
|
48
|
+
File.expand_path(File.join(Fauxhai.root, 'tmp', cache_key))
|
49
|
+
end
|
50
|
+
|
51
|
+
def force_cache_miss?
|
52
|
+
@force_cache_miss ||= @options.delete(:force_cache_miss) || false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Return the given `@data` attribute as a Ruby hash instead of a JSON object
|
56
|
+
#
|
57
|
+
# @return [Hash] the `@data` represented as a Ruby hash
|
58
|
+
def to_hash(*args)
|
59
|
+
@data.to_hash(*args)
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
"#<Fauxhai::Fetcher @host=#{host}, @options=#{@options}>"
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def host
|
69
|
+
@host ||= begin
|
70
|
+
raise ArgumentError, ':host is a required option for Fauxhai.fetch' unless @options[:host]
|
71
|
+
@options.delete(:host)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def user
|
76
|
+
@user ||= (@options.delete(:user) || ENV['USER'] || ENV['USERNAME']).chomp
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pathname'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
module Fauxhai
|
6
|
+
class Mocker
|
7
|
+
# The base URL for the GitHub project (raw)
|
8
|
+
RAW_BASE = 'https://raw.githubusercontent.com/chefspec/fauxhai/master'.freeze
|
9
|
+
|
10
|
+
# A message about where to find a list of platforms
|
11
|
+
PLATFORM_LIST_MESSAGE = 'A list of available platforms is available at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md'.freeze
|
12
|
+
|
13
|
+
# Create a new Ohai Mock with fauxhai.
|
14
|
+
#
|
15
|
+
# @param [Hash] options
|
16
|
+
# the options for the mocker
|
17
|
+
# @option options [String] :platform
|
18
|
+
# the platform to mock
|
19
|
+
# @option options [String] :version
|
20
|
+
# the version of the platform to mock
|
21
|
+
# @option options [String] :path
|
22
|
+
# the path to a local JSON file
|
23
|
+
# @option options [Bool] :github_fetching
|
24
|
+
# whether to try loading from Github
|
25
|
+
def initialize(options = {}, &override_attributes)
|
26
|
+
@options = { github_fetching: true }.merge(options)
|
27
|
+
|
28
|
+
yield(data) if block_given?
|
29
|
+
end
|
30
|
+
|
31
|
+
def data
|
32
|
+
@fauxhai_data ||= lambda do
|
33
|
+
# If a path option was specified, use it
|
34
|
+
if @options[:path]
|
35
|
+
filepath = File.expand_path(@options[:path])
|
36
|
+
|
37
|
+
unless File.exist?(filepath)
|
38
|
+
raise Fauxhai::Exception::InvalidPlatform.new("You specified a path to a JSON file on the local system that does not exist: '#{filepath}'")
|
39
|
+
end
|
40
|
+
else
|
41
|
+
filepath = File.join(platform_path, "#{version}.json")
|
42
|
+
end
|
43
|
+
|
44
|
+
if File.exist?(filepath)
|
45
|
+
parse_and_validate(File.read(filepath))
|
46
|
+
elsif @options[:github_fetching]
|
47
|
+
# Try loading from github (in case someone submitted a PR with a new file, but we haven't
|
48
|
+
# yet updated the gem version). Cache the response locally so it's faster next time.
|
49
|
+
begin
|
50
|
+
response = open("#{RAW_BASE}/lib/fauxhai/platforms/#{platform}/#{version}.json")
|
51
|
+
rescue OpenURI::HTTPError
|
52
|
+
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}")
|
53
|
+
end
|
54
|
+
|
55
|
+
if response.status.first.to_i == 200
|
56
|
+
response_body = response.read
|
57
|
+
path = Pathname.new(filepath)
|
58
|
+
FileUtils.mkdir_p(path.dirname)
|
59
|
+
|
60
|
+
begin
|
61
|
+
File.open(filepath, 'w') { |f| f.write(response_body) }
|
62
|
+
rescue Errno::EACCES # a pretty common problem in CI systems
|
63
|
+
puts "Fetched '#{platform}/#{version}' from GitHub, but could not write to the local path: #{filepath}. Fix the local file permissions to avoid downloading this file every run."
|
64
|
+
end
|
65
|
+
return parse_and_validate(response_body)
|
66
|
+
else
|
67
|
+
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and an Github fetching returned http error code #{response.status.first.to_i}! #{PLATFORM_LIST_MESSAGE}")
|
68
|
+
end
|
69
|
+
else
|
70
|
+
raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and Github fetching is disabled! #{PLATFORM_LIST_MESSAGE}")
|
71
|
+
end
|
72
|
+
end.call
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
# As major releases of Ohai ship it's difficult and sometimes impossible
|
78
|
+
# to regenerate all fauxhai data. This allows us to deprecate old releases
|
79
|
+
# and eventually remove them while giving end users ample warning.
|
80
|
+
def parse_and_validate(unparsed_data)
|
81
|
+
parsed_data = JSON.parse(unparsed_data)
|
82
|
+
if parsed_data['deprecated']
|
83
|
+
STDERR.puts "WARNING: Fauxhai platform data for #{parsed_data['platform']} #{parsed_data['platform_version']} is deprecated and will be removed in the 7.0 release 3/2019. #{PLATFORM_LIST_MESSAGE}"
|
84
|
+
end
|
85
|
+
parsed_data
|
86
|
+
end
|
87
|
+
|
88
|
+
def platform
|
89
|
+
@options[:platform] ||= begin
|
90
|
+
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}"
|
91
|
+
'chefspec'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def platform_path
|
96
|
+
File.join(Fauxhai.root, 'lib', 'fauxhai', 'platforms', platform)
|
97
|
+
end
|
98
|
+
|
99
|
+
def version
|
100
|
+
@version ||= begin
|
101
|
+
if File.exist?("#{platform_path}/#{@options[:version]}.json")
|
102
|
+
# Whole version, use it as-is.
|
103
|
+
@options[:version]
|
104
|
+
else
|
105
|
+
# Check if it's a prefix of an existing version.
|
106
|
+
versions = Dir["#{platform_path}/*.json"].map {|path| File.basename(path, '.json') }
|
107
|
+
unless @options[:version].to_s == ''
|
108
|
+
# If the provided version is nil or '', that means take anything,
|
109
|
+
# otherwise run the prefix match with an extra \D to avoid the
|
110
|
+
# case where "7.1" matches "7.10.0".
|
111
|
+
prefix_re = /^#{Regexp.escape(@options[:version])}\D/
|
112
|
+
versions.select! {|ver| ver =~ prefix_re }
|
113
|
+
end
|
114
|
+
|
115
|
+
if versions.empty?
|
116
|
+
# No versions available, either an unknown platform or nothing matched
|
117
|
+
# the prefix check. Pass through the option as given so we can try
|
118
|
+
# github fetching.
|
119
|
+
@options[:version]
|
120
|
+
else
|
121
|
+
# Take the highest version available, trying to use rules that should
|
122
|
+
# probably mostly work on all OSes. Famous last words. The idea of
|
123
|
+
# the regex is to split on any punctuation (the common case) and
|
124
|
+
# also any single letter with digit on either side (2012r2). This
|
125
|
+
# leaves any long runs of letters intact (4.2-RELEASE). Then convert
|
126
|
+
# any run of digits to an integer to get version-ish comparison.
|
127
|
+
# This is basically a more flexible version of Gem::Version.
|
128
|
+
versions.max_by do |ver|
|
129
|
+
ver.split(/[^a-z0-9]|(?<=\d)[a-z](?=\d)/i).map do |part|
|
130
|
+
if part =~ /^\d+$/
|
131
|
+
part.to_i
|
132
|
+
else
|
133
|
+
part
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'ohai'
|
2
|
+
require 'ohai/plugins/chef'
|
3
|
+
|
4
|
+
module Fauxhai
|
5
|
+
class Runner
|
6
|
+
def initialize(args)
|
7
|
+
@system = Ohai::System.new
|
8
|
+
@system.all_plugins
|
9
|
+
|
10
|
+
case @system.data['platform']
|
11
|
+
when 'windows', :windows
|
12
|
+
require 'fauxhai/runner/windows'
|
13
|
+
self.singleton_class.send :include, ::Fauxhai::Runner::Windows
|
14
|
+
else
|
15
|
+
require 'fauxhai/runner/default'
|
16
|
+
self.singleton_class.send :include, ::Fauxhai::Runner::Default
|
17
|
+
end
|
18
|
+
|
19
|
+
result = @system.data.dup.delete_if { |k, v| !whitelist_attributes.include?(k) }.merge(
|
20
|
+
'languages' => languages,
|
21
|
+
'counters' => counters,
|
22
|
+
'current_user' => current_user,
|
23
|
+
'domain' => domain,
|
24
|
+
'hostname' => hostname,
|
25
|
+
'machinename' => hostname,
|
26
|
+
'fqdn' => fqdn,
|
27
|
+
'ipaddress' => ipaddress,
|
28
|
+
'keys' => keys,
|
29
|
+
'macaddress' => macaddress,
|
30
|
+
'network' => network,
|
31
|
+
'uptime' => uptime,
|
32
|
+
'uptime_seconds' => uptime_seconds,
|
33
|
+
'idle' => uptime,
|
34
|
+
'idletime_seconds' => uptime_seconds,
|
35
|
+
'cpu' => cpu,
|
36
|
+
'memory' => memory,
|
37
|
+
'virtualization' => virtualization,
|
38
|
+
'time' => time
|
39
|
+
)
|
40
|
+
|
41
|
+
puts JSON.pretty_generate(result.sort.to_h)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,284 @@
|
|
1
|
+
module Fauxhai
|
2
|
+
class Runner
|
3
|
+
module Default
|
4
|
+
def bin_dir
|
5
|
+
'/usr/local/bin'
|
6
|
+
end
|
7
|
+
|
8
|
+
def counters
|
9
|
+
{
|
10
|
+
'network' => {
|
11
|
+
'interfaces' => {
|
12
|
+
'lo' => {
|
13
|
+
'tx' => {
|
14
|
+
'queuelen' => '1',
|
15
|
+
'bytes' => 0,
|
16
|
+
'packets' => 0,
|
17
|
+
'errors' => 0,
|
18
|
+
'drop' => 0,
|
19
|
+
'carrier' => 0,
|
20
|
+
'collisions' => 0,
|
21
|
+
},
|
22
|
+
'rx' => {
|
23
|
+
'bytes' => 0,
|
24
|
+
'packets' => 0,
|
25
|
+
'errors' => 0,
|
26
|
+
'drop' => 0,
|
27
|
+
'overrun' => 0,
|
28
|
+
},
|
29
|
+
},
|
30
|
+
default_interface.to_s => {
|
31
|
+
'rx' => {
|
32
|
+
'bytes' => 0,
|
33
|
+
'packets' => 0,
|
34
|
+
'errors' => 0,
|
35
|
+
'drop' => 0,
|
36
|
+
'overrun' => 0,
|
37
|
+
'frame' => 0,
|
38
|
+
'compressed' => 0,
|
39
|
+
'multicast' => 0,
|
40
|
+
},
|
41
|
+
'tx' => {
|
42
|
+
'bytes' => 0,
|
43
|
+
'packets' => 0,
|
44
|
+
'errors' => 0,
|
45
|
+
'drop' => 0,
|
46
|
+
'overrun' => 0,
|
47
|
+
'collisions' => 0,
|
48
|
+
'carrier' => 0,
|
49
|
+
'compressed' => 0,
|
50
|
+
},
|
51
|
+
},
|
52
|
+
},
|
53
|
+
},
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def current_user
|
58
|
+
'fauxhai'
|
59
|
+
end
|
60
|
+
|
61
|
+
def default_gateway
|
62
|
+
'10.0.0.1'
|
63
|
+
end
|
64
|
+
|
65
|
+
def default_interface
|
66
|
+
case @system.data['platform_family']
|
67
|
+
when 'mac_os_x'
|
68
|
+
'en0'
|
69
|
+
when /bsd/
|
70
|
+
'em0'
|
71
|
+
when 'arch', 'fedora'
|
72
|
+
'enp0s3'
|
73
|
+
else
|
74
|
+
'eth0'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def domain
|
79
|
+
'local'
|
80
|
+
end
|
81
|
+
|
82
|
+
def fqdn
|
83
|
+
'fauxhai.local'
|
84
|
+
end
|
85
|
+
|
86
|
+
def gem_bin
|
87
|
+
'/usr/local/bin/gem'
|
88
|
+
end
|
89
|
+
|
90
|
+
def gems_dir
|
91
|
+
'/usr/local/gems'
|
92
|
+
end
|
93
|
+
|
94
|
+
def hostname
|
95
|
+
'Fauxhai'
|
96
|
+
end
|
97
|
+
|
98
|
+
def ipaddress
|
99
|
+
'10.0.0.2'
|
100
|
+
end
|
101
|
+
|
102
|
+
def ip6address
|
103
|
+
'fe80:0:0:0:0:0:a00:2'
|
104
|
+
end
|
105
|
+
|
106
|
+
def keys
|
107
|
+
{
|
108
|
+
'ssh' => ssh,
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def languages
|
113
|
+
{
|
114
|
+
'ruby' => @system.data['languages']['ruby'].merge('bin_dir' => bin_dir,
|
115
|
+
'gem_bin' => gem_bin,
|
116
|
+
'gems_dir' => gems_dir,
|
117
|
+
'ruby_bin' => ruby_bin),
|
118
|
+
'powershell' => @system.data['languages']['powershell'],
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def macaddress
|
123
|
+
'11:11:11:11:11:11'
|
124
|
+
end
|
125
|
+
|
126
|
+
def network
|
127
|
+
{
|
128
|
+
'interfaces' => {
|
129
|
+
'lo' => {
|
130
|
+
'mtu' => '65536',
|
131
|
+
'flags' => %w(LOOPBACK UP LOWER_UP),
|
132
|
+
'encapsulation' => 'Loopback',
|
133
|
+
'addresses' => {
|
134
|
+
'127.0.0.1' => {
|
135
|
+
'family' => 'inet',
|
136
|
+
'prefixlen' => '8',
|
137
|
+
'netmask' => '255.0.0.0',
|
138
|
+
'scope' => 'Node',
|
139
|
+
'ip_scope' => 'LOOPBACK',
|
140
|
+
},
|
141
|
+
'::1' => {
|
142
|
+
'family' => 'inet6',
|
143
|
+
'prefixlen' => '128',
|
144
|
+
'scope' => 'Node',
|
145
|
+
'tags' => [],
|
146
|
+
'ip_scope' => 'LINK LOCAL LOOPBACK',
|
147
|
+
},
|
148
|
+
},
|
149
|
+
'state' => 'unknown',
|
150
|
+
},
|
151
|
+
default_interface.to_s => {
|
152
|
+
'type' => default_interface.chop,
|
153
|
+
'number' => '0',
|
154
|
+
'mtu' => '1500',
|
155
|
+
'flags' => %w(BROADCAST MULTICAST UP LOWER_UP),
|
156
|
+
'encapsulation' => 'Ethernet',
|
157
|
+
'addresses' => {
|
158
|
+
macaddress.to_s => {
|
159
|
+
'family' => 'lladdr',
|
160
|
+
},
|
161
|
+
ipaddress.to_s => {
|
162
|
+
'family' => 'inet',
|
163
|
+
'prefixlen' => '24',
|
164
|
+
'netmask' => '255.255.255.0',
|
165
|
+
'broadcast' => '10.0.0.255',
|
166
|
+
'scope' => 'Global',
|
167
|
+
'ip_scope' => 'RFC1918 PRIVATE',
|
168
|
+
},
|
169
|
+
'fe80::11:1111:1111:1111' => {
|
170
|
+
'family' => 'inet6',
|
171
|
+
'prefixlen' => '64',
|
172
|
+
'scope' => 'Link',
|
173
|
+
'tags' => [],
|
174
|
+
'ip_scope' => 'LINK LOCAL UNICAST',
|
175
|
+
},
|
176
|
+
},
|
177
|
+
'state' => 'up',
|
178
|
+
'arp' => {
|
179
|
+
'10.0.0.1' => 'fe:ff:ff:ff:ff:ff',
|
180
|
+
},
|
181
|
+
'routes' => [
|
182
|
+
{
|
183
|
+
'destination' => 'default',
|
184
|
+
'family' => 'inet',
|
185
|
+
'via' => default_gateway,
|
186
|
+
},
|
187
|
+
{
|
188
|
+
'destination' => '10.0.0.0/24',
|
189
|
+
'family' => 'inet',
|
190
|
+
'scope' => 'link',
|
191
|
+
'proto' => 'kernel',
|
192
|
+
'src' => ipaddress,
|
193
|
+
},
|
194
|
+
{
|
195
|
+
'destination' => 'fe80::/64',
|
196
|
+
'family' => 'inet6',
|
197
|
+
'metric' => '256',
|
198
|
+
'proto' => 'kernel',
|
199
|
+
},
|
200
|
+
],
|
201
|
+
'ring_params' => {},
|
202
|
+
},
|
203
|
+
},
|
204
|
+
'default_interface' => default_interface,
|
205
|
+
'default_gateway' => default_gateway,
|
206
|
+
}
|
207
|
+
end
|
208
|
+
|
209
|
+
def ruby_bin
|
210
|
+
'/usr/local/bin/ruby'
|
211
|
+
end
|
212
|
+
|
213
|
+
def ssh
|
214
|
+
{
|
215
|
+
'host_dsa_public' => File.read(File.join(Fauxhai.root, 'lib', 'fauxhai', 'keys', 'id_dsa.pub')).strip,
|
216
|
+
'host_rsa_public' => File.read(File.join(Fauxhai.root, 'lib', 'fauxhai', 'keys', 'id_rsa.pub')).strip,
|
217
|
+
}
|
218
|
+
end
|
219
|
+
|
220
|
+
def uptime
|
221
|
+
'30 days 15 hours 07 minutes 30 seconds'
|
222
|
+
end
|
223
|
+
|
224
|
+
def uptime_seconds
|
225
|
+
2646450
|
226
|
+
end
|
227
|
+
|
228
|
+
def cpu
|
229
|
+
{
|
230
|
+
'real' => 1,
|
231
|
+
'total' => 1,
|
232
|
+
'cores' => 1,
|
233
|
+
}
|
234
|
+
end
|
235
|
+
|
236
|
+
def memory
|
237
|
+
{
|
238
|
+
'total' => '1048576kB',
|
239
|
+
}
|
240
|
+
end
|
241
|
+
|
242
|
+
def virtualization
|
243
|
+
{
|
244
|
+
'systems' => {},
|
245
|
+
}
|
246
|
+
end
|
247
|
+
|
248
|
+
def time
|
249
|
+
{
|
250
|
+
'timezone' => 'GMT',
|
251
|
+
}
|
252
|
+
end
|
253
|
+
|
254
|
+
# Whitelist attributes are attributes that we *actually* want from the node. Other attributes are
|
255
|
+
# either ignored or overridden, but we ensure these are returned with the command.
|
256
|
+
#
|
257
|
+
# @return [Array] - the key of whitelisted attributes
|
258
|
+
def whitelist_attributes
|
259
|
+
%w(
|
260
|
+
block_device
|
261
|
+
chef_packages
|
262
|
+
command
|
263
|
+
dmi
|
264
|
+
filesystem
|
265
|
+
fips
|
266
|
+
init_package
|
267
|
+
kernel
|
268
|
+
lsb
|
269
|
+
ohai_time
|
270
|
+
os
|
271
|
+
os_version
|
272
|
+
packages
|
273
|
+
platform
|
274
|
+
platform_version
|
275
|
+
platform_build
|
276
|
+
platform_family
|
277
|
+
root_group
|
278
|
+
shard_seed
|
279
|
+
shells
|
280
|
+
)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module Fauxhai
|
2
|
+
class Runner
|
3
|
+
module Windows
|
4
|
+
require 'fauxhai/runner/default'
|
5
|
+
include ::Fauxhai::Runner::Default
|
6
|
+
|
7
|
+
def default_interface
|
8
|
+
'0xe'
|
9
|
+
end
|
10
|
+
|
11
|
+
def network
|
12
|
+
{
|
13
|
+
'interfaces' => {
|
14
|
+
"#{default_interface}" => {
|
15
|
+
'configuration' => {
|
16
|
+
'caption' => '[00000012] Ethernet Adapter',
|
17
|
+
'database_path' => '%SystemRoot%\\System32\\drivers\\etc',
|
18
|
+
'default_ip_gateway' => %w(default_gateway),
|
19
|
+
'description' => 'Ethernet Adapter',
|
20
|
+
'dhcp_enabled' => false,
|
21
|
+
'dns_domain_suffix_search_order' => [],
|
22
|
+
'dns_enabled_for_wins_resolution' => false,
|
23
|
+
'dns_host_name' => hostname,
|
24
|
+
'domain_dns_registration_enabled' => false,
|
25
|
+
'full_dns_registration_enabled' => true,
|
26
|
+
'gateway_cost_metric' => [0],
|
27
|
+
'index' => 12,
|
28
|
+
'interface_index' => 14,
|
29
|
+
'ip_address' => [ipaddress],
|
30
|
+
'ip_connection_metric' => 5,
|
31
|
+
'ip_enabled' => true,
|
32
|
+
'ip_filter_security_enabled' => false,
|
33
|
+
'ip_sec_permit_ip_protocols' => [],
|
34
|
+
'ip_sec_permit_tcp_ports' => [],
|
35
|
+
'ip_sec_permit_udp_ports' => [],
|
36
|
+
'ip_subnet' => %w(255.255.255.0 64),
|
37
|
+
'mac_address' => macaddress,
|
38
|
+
'service_name' => 'netkvm',
|
39
|
+
'setting_id' => '{00000000-0000-0000-0000-000000000000}',
|
40
|
+
'tcpip_netbios_options' => 0,
|
41
|
+
'tcp_window_size' => 64240,
|
42
|
+
'wins_enable_lm_hosts_lookup' => true,
|
43
|
+
'wins_scope_id' => '',
|
44
|
+
},
|
45
|
+
'instance' => {
|
46
|
+
'adapter_type' => 'Ethernet 802.3',
|
47
|
+
'adapter_type_id' => 0,
|
48
|
+
'availability' => 3,
|
49
|
+
'caption' => '[00000012] Ethernet Adapter',
|
50
|
+
'config_manager_error_code' => 0,
|
51
|
+
'config_manager_user_config' => false,
|
52
|
+
'creation_class_name' => 'Win32_NetworkAdapter',
|
53
|
+
'description' => 'Ethernet Adapter',
|
54
|
+
'device_id' => '12',
|
55
|
+
'guid' => '{00000000-0000-0000-0000-000000000000}',
|
56
|
+
'index' => 12,
|
57
|
+
'installed' => true,
|
58
|
+
'interface_index' => 14,
|
59
|
+
'mac_address' => macaddress,
|
60
|
+
'manufacturer' => '',
|
61
|
+
'max_number_controlled' => 0,
|
62
|
+
'name' => 'Ethernet Adapter',
|
63
|
+
'net_connection_id' => 'Ethernet',
|
64
|
+
'net_connection_status' => 2,
|
65
|
+
'net_enabled' => true,
|
66
|
+
'physical_adapter' => true,
|
67
|
+
'pnp_device_id' => 'PCI\\VEN_0000&DEV_0000&SUBSYS_000000000&REV_00\\0&0000000000&00',
|
68
|
+
'power_management_supported' => false,
|
69
|
+
'product_name' => 'Ethernet Adapter',
|
70
|
+
'service_name' => 'netkvm',
|
71
|
+
'speed' => '10000000000',
|
72
|
+
'system_creation_class_name' => 'Win32_ComputerSystem',
|
73
|
+
'system_name' => hostname,
|
74
|
+
'time_of_last_reset' => '20000101000001.000000+000'
|
75
|
+
},
|
76
|
+
'counters' => {},
|
77
|
+
'addresses' => {
|
78
|
+
"#{ipaddress}" => {
|
79
|
+
'prefixlen' => '24',
|
80
|
+
'netmask' => '255.255.255.0',
|
81
|
+
'broadcast' => '10.0.0.255',
|
82
|
+
'family' => 'inet'
|
83
|
+
},
|
84
|
+
"#{macaddress}" => {
|
85
|
+
'family' => 'lladdr'
|
86
|
+
}
|
87
|
+
},
|
88
|
+
'type' => 'Ethernet 802.3',
|
89
|
+
'arp' => {
|
90
|
+
'10.0.0.1' => 'fe:ff:ff:ff:ff:ff'
|
91
|
+
},
|
92
|
+
'encapsulation' => 'Ethernet'
|
93
|
+
}
|
94
|
+
},
|
95
|
+
'default_gateway' => default_gateway,
|
96
|
+
'default_interface' => default_interface
|
97
|
+
}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fauxhai-ng-slim
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 7.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Vargo
|
8
|
+
- Tim Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2019-11-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ssh
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: chef
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '13.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '13.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: ohai
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '13.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '13.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.7'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.7'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec-its
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.2'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.2'
|
98
|
+
description: Easily mock out ohai data
|
99
|
+
email:
|
100
|
+
- sethvargo@gmail.com
|
101
|
+
- tsmith84@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- LICENSE
|
107
|
+
- lib/fauxhai.rb
|
108
|
+
- lib/fauxhai/exception.rb
|
109
|
+
- lib/fauxhai/fetcher.rb
|
110
|
+
- lib/fauxhai/mocker.rb
|
111
|
+
- lib/fauxhai/runner.rb
|
112
|
+
- lib/fauxhai/runner/default.rb
|
113
|
+
- lib/fauxhai/runner/windows.rb
|
114
|
+
- lib/fauxhai/version.rb
|
115
|
+
homepage: https://github.com/chefspec/fauxhai
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '2.3'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubygems_version: 3.0.3
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Fauxhai provides an easy way to mock out your ohai data for testing with
|
138
|
+
chefspec! This "slim" version lacks the fauxhai binary and ships without any Ohai
|
139
|
+
data and instead relies on fetching that data as needed from the source on GitHub.
|
140
|
+
test_files: []
|