fauxhai 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +20 -0
- data/.rvmrc +48 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +159 -0
- data/Rakefile +2 -0
- data/bin/fauxhai +12 -0
- data/examples/chefspec.md +68 -0
- data/examples/rspec-chef.md +62 -0
- data/fauxhai.gemspec +20 -0
- data/lib/fauxhai.rb +17 -0
- data/lib/fauxhai/exception.rb +8 -0
- data/lib/fauxhai/fetcher.rb +78 -0
- data/lib/fauxhai/keys/id_dsa +12 -0
- data/lib/fauxhai/keys/id_dsa.pub +1 -0
- data/lib/fauxhai/keys/id_rsa +27 -0
- data/lib/fauxhai/keys/id_rsa.pub +1 -0
- data/lib/fauxhai/mocker.rb +79 -0
- data/lib/fauxhai/platforms/centos/6.0.json +404 -0
- data/lib/fauxhai/platforms/centos/default.json +3 -0
- data/lib/fauxhai/platforms/chefspec/0.6.1.json +14 -0
- data/lib/fauxhai/platforms/chefspec/default.json +3 -0
- data/lib/fauxhai/platforms/mac_os_x/10.7.4.json +785 -0
- data/lib/fauxhai/platforms/mac_os_x/default.json +3 -0
- data/lib/fauxhai/platforms/ubuntu/10.04.json +500 -0
- data/lib/fauxhai/platforms/ubuntu/default.json +3 -0
- data/lib/fauxhai/runner.rb +237 -0
- metadata +107 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p194@fauxhai"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.14.3 (master)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
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/README.md
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
Fauxhai
|
2
|
+
=======
|
3
|
+
Fauxhai is a gem for mocking out [ohai](https://github.com/opscode/ohai) data in your chef testing. Fauxhai is community supported, so we need **your help** to populate our dataset. Here's an example for testing my "awesome_cookbook" on Ubuntu:
|
4
|
+
|
5
|
+
**Fauxhai is still in alpha stages and should not be considered stable! Pull Requests and feedback are welcome :)**
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'chefspec'
|
9
|
+
|
10
|
+
describe 'awesome_cookbook::default' do
|
11
|
+
before do
|
12
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should install awesome' do
|
16
|
+
@runner = ChefSpec::ChefRunner.new.converge('tmpreaper::default')
|
17
|
+
@runner.should install_package 'awesome'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
Alternatively, you can pull "real" ohai data from an existing server:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'chefspec'
|
26
|
+
|
27
|
+
describe 'awesome_cookbook::default' do
|
28
|
+
before do
|
29
|
+
Fauxhai.fetch(host:'server01.example.com')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should install awesome' do
|
33
|
+
@runner = ChefSpec::ChefRunner.new.converge('tmpreaper::default')
|
34
|
+
@runner.should install_package 'awesome'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Fauxhai supports [ChefSpec](https://github.com/acrmp/chefspec) and [rspec-chef](https://github.com/calavera/rspec-chef). In order to prevent polluting the README, only ChefSpec examples will be provided. However, there is an extensive README for each testing framework in the [examples](https://github.com/customink/fauxhai/tree/master/examples) directory.
|
40
|
+
|
41
|
+
Important Note
|
42
|
+
--------------
|
43
|
+
Fauxhai ships with a command line tool - `fauxhai`. This is **not** the same as Fauxhai.mock. Running `fauxhai` on a machine effectively runs `ohai`, but then sanitizes the data, removing/replacing things like:
|
44
|
+
|
45
|
+
- users
|
46
|
+
- ssh keys
|
47
|
+
- usernames in paths
|
48
|
+
- sensitive system information
|
49
|
+
|
50
|
+
`fauxhai` should only be used by developers wishing to submit a new json file.
|
51
|
+
|
52
|
+
Usage
|
53
|
+
-----
|
54
|
+
Fauxhai provides a bunch of default attributes so that you don't need to mock out your entire infastructure to write a simple test. That being said, not all configurations will suit your needs. Because of that, Fauxhai provides two ways to configure your mocks:
|
55
|
+
|
56
|
+
### Overriding
|
57
|
+
`Fauxhai.mock` will also accept a block with override attributes that are merged with all the default attributes. For example, the default Ubutnu 12.04 mock uses `Ruby 1.9.3`. Maybe your system is using `ree`, and you want to verify that the cookbooks work with that data as well:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
require 'chefspec'
|
61
|
+
|
62
|
+
describe 'awesome_cookbook::default' do
|
63
|
+
before do
|
64
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04') do |node|
|
65
|
+
node['languages']['ruby']['version'] = 'ree'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should install awesome' do
|
70
|
+
@runner = ChefSpec::ChefRunner.new.converge('tmpreaper::default')
|
71
|
+
@runner.should install_package 'awesome'
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
The `node` block variable allows you to set any Ohai attribute on the mock that you want. This provides an easy way to manage your environments. If you find that you are overridding attributes like OS or platform, you should see the section on Contributing.
|
77
|
+
|
78
|
+
### Fetching
|
79
|
+
Alternatively, if you do not want to mock the data, Fauxhai provides a `fetch` mechanism for collecting "real" ohai data from a remote server or local file. Maybe you want to test against the fully-replicated environment for a front-facing server in your pool. Just pass in the `url` option instead of a `platform`:
|
80
|
+
|
81
|
+
The `fetch` method supports all the same options as the Net-SSH command, such as `:user`, `:password`, `:key_file`, etc.
|
82
|
+
|
83
|
+
The `fetch` method will cache the JSON file in a temporary path on your local machine. Similar to gems like VCR, this allows fauxhai to use the cached copy, making your test suite run faster. You can optionally force a cache miss by passing the `:force_cache_miss => true` option to the `fetch` initializer. **Because this is real data, there may be a security concern. Secure your laptop accordingly.**
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
require 'chefspec'
|
87
|
+
|
88
|
+
describe 'awesome_cookbook::default' do
|
89
|
+
before do
|
90
|
+
Fauxhai.fetch(host:'server01.example.com')
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should install awesome' do
|
94
|
+
@runner = ChefSpec::ChefRunner.new.converge('tmpreaper::default')
|
95
|
+
@runner.should install_package 'awesome'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
100
|
+
This will ssh into the machine (you must have authorization to run `sudo ohai` on that machine), download a copy of the ohai output, and optionally cache that data inside the test directory (speeding up future tests).
|
101
|
+
|
102
|
+
### Overriding + Fetching
|
103
|
+
As you might expect, you can combine overriding and fetching like so:
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
require 'chefspec'
|
107
|
+
|
108
|
+
describe 'awesome_cookbook::default' do
|
109
|
+
before do
|
110
|
+
Fauxhai.fetch(host:'server01.example.com') do |node|
|
111
|
+
node['languages']['ruby']['version'] = 'ree'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should install awesome' do
|
116
|
+
@runner = ChefSpec::ChefRunner.new.converge('tmpreaper::default')
|
117
|
+
@runner.should install_package 'awesome'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
Contributing
|
123
|
+
------------
|
124
|
+
Fauxhai is community-maintained and updated. Aside from the initial files, all of the ohai system mocks have been created by the community. If you have a system that you think would benefit the community, here's how you get it into [fauxhai](https://github.com/customink/fauxhai):
|
125
|
+
|
126
|
+
1. Build a system to your liking (on a virtual machine, for example)
|
127
|
+
2. Install chef, ohai, and fauxhai
|
128
|
+
3. Run the following at the command line:
|
129
|
+
|
130
|
+
sudo fauxhai
|
131
|
+
|
132
|
+
4. This will create a file `/tmp/fauxhai.json`
|
133
|
+
5. Copy the contents of this file to your local development machine (using scp or sftp, for example)
|
134
|
+
6. Clone and `bundle` this repo:
|
135
|
+
|
136
|
+
git clone git@github.com:customink/fauxhai.git
|
137
|
+
cd fauxhai
|
138
|
+
bundle
|
139
|
+
|
140
|
+
7. Create a new branch named `add_[platform]_[version]` (e.g. `add_ubuntu_12_04`) without dashes and dots replaced with underscores. Be sure to use the official version number, not a package name (e.g. '12_04', not 'precise') if avaliable:
|
141
|
+
|
142
|
+
Ubuntu Precise, 12.04 add_ubuntu_12_04
|
143
|
+
Ubuntu Lucid, 11.5 add_ubuntu_11_5
|
144
|
+
OSX Lion, 10.7.4 add_osx_10_7_4
|
145
|
+
Windows XP add_windows_xp
|
146
|
+
|
147
|
+
**Q:** Is there a reason for this super-specific naming convention?
|
148
|
+
**A:** No, but it helps in tracking problems and analyzing pull requests. Ultimately it just ensures your pull request is merged as quickly as possible.
|
149
|
+
|
150
|
+
8. Create a new json file in `fauxhai/[os]/[version].json` (e.g. `fauxhai/ubuntu/12_04.json`)
|
151
|
+
9. Copy-paste the contents of the file from `Step 4` into this file and save
|
152
|
+
10. Verify the installation was successful by doing the following:
|
153
|
+
|
154
|
+
irb -rubygems -rfauxhai
|
155
|
+
Fauxhai.mock('[os]', '[version') # e.g. Fauxhai.mock('ubuntu', '12.04')
|
156
|
+
|
157
|
+
As long as that does not throw an error, you're good to go!
|
158
|
+
|
159
|
+
11. Submit a pull request on github
|
data/Rakefile
ADDED
data/bin/fauxhai
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '../../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'fauxhai'
|
7
|
+
require 'fauxhai/runner'
|
8
|
+
|
9
|
+
args = ARGV.dup
|
10
|
+
ARGV.clear
|
11
|
+
|
12
|
+
Fauxhai::Runner.new(args)
|
@@ -0,0 +1,68 @@
|
|
1
|
+
Fauxhai ChefSpec Examples
|
2
|
+
=========================
|
3
|
+
|
4
|
+
Mocking a Box
|
5
|
+
-------------
|
6
|
+
```ruby
|
7
|
+
require 'chefspec'
|
8
|
+
|
9
|
+
describe 'awesome_cookbook::default' do
|
10
|
+
before do
|
11
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
Mocking a Box with a Custom Ruby Version
|
17
|
+
----------------------------------------
|
18
|
+
```ruby
|
19
|
+
require 'chefspec'
|
20
|
+
|
21
|
+
describe 'awesome_cookbook::default' do
|
22
|
+
before do
|
23
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04') do |node|
|
24
|
+
node['languages']['ruby']['version'] = 'ree'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Mocking a Box with Custom Hostname
|
31
|
+
----------------------------------
|
32
|
+
```ruby
|
33
|
+
require 'chefspec'
|
34
|
+
|
35
|
+
describe 'awesome_cookbook::default' do
|
36
|
+
before do
|
37
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04') do |node|
|
38
|
+
node['hostname'] = 'server01.example.com'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Fetching a Remote Box
|
45
|
+
---------------------
|
46
|
+
```ruby
|
47
|
+
require 'chefspec'
|
48
|
+
|
49
|
+
describe 'awesome_cookbook::default' do
|
50
|
+
before do
|
51
|
+
Fauxhai.fetch(host:'server01.example.com')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Fetching a Remote Box with custom Ruby Version
|
57
|
+
----------------------------------------------
|
58
|
+
```ruby
|
59
|
+
require 'chefspec'
|
60
|
+
|
61
|
+
describe 'awesome_cookbook::default' do
|
62
|
+
before do
|
63
|
+
Fauxhai.fetch(host:'server01.example.com') do |node|
|
64
|
+
node['languages']['ruby']['version'] = 'ree'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
@@ -0,0 +1,62 @@
|
|
1
|
+
Fauxhai Rspec-Chef Examples
|
2
|
+
===========================
|
3
|
+
|
4
|
+
Mocking a Box
|
5
|
+
-------------
|
6
|
+
```ruby
|
7
|
+
describe 'foo::bar' do
|
8
|
+
let(:json_attributes) { Fauxhai.mock(platform:'ubuntu', version:'12.04') }
|
9
|
+
end
|
10
|
+
```
|
11
|
+
|
12
|
+
Or as a default
|
13
|
+
```ruby
|
14
|
+
# spec/spec_helper.rb
|
15
|
+
RSpec.configure do |c|
|
16
|
+
c.json_attributes = Fauxhai.mock(platform:'ubuntu', version:'12.04')
|
17
|
+
end
|
18
|
+
```
|
19
|
+
|
20
|
+
Mocking a Box with a Custom Ruby Version
|
21
|
+
----------------------------------------
|
22
|
+
```ruby
|
23
|
+
describe 'foo::bar' do
|
24
|
+
let(:json_attributes) do
|
25
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04') do |node|
|
26
|
+
node['languages']['ruby']['version'] = 'ree'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Mocking a Box with Custom Hostname
|
33
|
+
----------------------------------
|
34
|
+
```ruby
|
35
|
+
describe 'foo::bar' do
|
36
|
+
let(:json_attributes) do
|
37
|
+
Fauxhai.mock(platform:'ubuntu', version:'12.04') do |node|
|
38
|
+
node['hostname'] = 'server01.example.com'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
Fetching a Remote Box
|
45
|
+
---------------------
|
46
|
+
```ruby
|
47
|
+
describe 'foo::bar' do
|
48
|
+
let(:json_attributes) { Fauxhai.fetch(host:'server01.example.com' }
|
49
|
+
end
|
50
|
+
```
|
51
|
+
|
52
|
+
Fetching a Remote Box with custom Ruby Version
|
53
|
+
----------------------------------------------
|
54
|
+
```ruby
|
55
|
+
describe 'foo::bar' do
|
56
|
+
let(:json_attributes) do
|
57
|
+
Fauxhai.fetch(host:'server01.example.com') do |node|
|
58
|
+
node['languages']['ruby']['version'] = 'ree'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
```
|
data/fauxhai.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$:.unshift(lib) unless $:.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.version = '0.0.1'
|
6
|
+
gem.authors = ['Seth Vargo']
|
7
|
+
gem.email = ['svargo@customink.com']
|
8
|
+
gem.description = %q{Easily mock out ohai data}
|
9
|
+
gem.summary = %q{Fauxhai provides an easy way to mock out your ohai data for testing with chefspec!}
|
10
|
+
gem.homepage = 'https://github.com/customink/fauxhai'
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = 'fauxhai'
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.add_runtime_dependency 'chef'
|
19
|
+
gem.add_runtime_dependency 'net-ssh'
|
20
|
+
end
|
data/lib/fauxhai.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fauxhai
|
2
|
+
require 'fauxhai/exception'
|
3
|
+
require 'fauxhai/fetcher'
|
4
|
+
require 'fauxhai/mocker'
|
5
|
+
|
6
|
+
def self.root
|
7
|
+
@@root ||= File.expand_path('../../', __FILE__)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.mock(*args)
|
11
|
+
Fauxhai::Mocker.new(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.fetch(*args)
|
15
|
+
Fauxhai::Fetcher.new(*args)
|
16
|
+
end
|
17
|
+
end
|