This repository was archived by the owner on Nov 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:miroswan/vagrant_spec
- Loading branch information
Showing
15 changed files
with
206 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.vagrant | ||
Gemfile.lock | ||
vagrantspec_inventory | ||
.vagrantspec_machine_data | ||
serverspec/spec_helper.rb | ||
coverage | ||
pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'json' | ||
require 'vagrant_spec/machine_finder' | ||
|
||
module VagrantSpec | ||
# Handle machine data generation | ||
class MachineData | ||
attr_accessor :env, :m_finder, :data | ||
def initialize(env) | ||
@env = env | ||
@m_finder = VagrantSpec::MachineFinder.new(@env) | ||
@data = [] | ||
end | ||
|
||
def generate | ||
populate_data | ||
IO.write('.vagrantspec_machine_data', JSON.pretty_generate(@data)) | ||
end | ||
|
||
def populate_data | ||
@m_finder.machines do |m| | ||
private_key = m.ssh_info[:private_key_path][0] | ||
@data << { | ||
name: m.name, | ||
host: m.ssh_info[:host], | ||
port: m.ssh_info[:port], | ||
username: m.ssh_info[:username], | ||
private_key: private_key | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
The init subcommand initializes state-based configuration for vagrant_spec. | ||
|
||
It creates a spec_helper.rb file under the configured serverspec directory. This | ||
file is used to setup serverspec backend configuration and ease serverspec | ||
testing. | ||
|
||
If config.spec.ansible_inventory configuration directive is used within the | ||
Vagrantfile, then init will generate a test inventory file | ||
vagrantspec_inventory. This file can be used for ansible orchestration against | ||
the vagrant instances. | ||
|
||
By default, init will generate a json file containing machine data for each | ||
vagrant instance at .vagrantspec_machine_data. This file can be used by | ||
orchestration tooling outside of ansible to map events to vagrant nodes. The | ||
config.spec.generate_machine_data configuration parameter controls the | ||
generation of this file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The test subcommand will execute the serverspec tests configured in the | ||
Vagrantfile under the config.spec.test_plan directive. This directive accepts | ||
an array of hashes. For example: | ||
|
||
config.spec.test_plan = [ | ||
{ | ||
'nodes' => /nginx/, | ||
'flags' => '--format documentation --pattern serverspec/nginx*' | ||
}, | ||
{ | ||
'nodes' => %w(app1 app2), | ||
'flags' => '--format documentation --pattern serverspec/app*' | ||
} | ||
] | ||
|
||
Each hash have two required keys: nodes and flags. The nodes key accepts a | ||
regular expression object matching the names of the vagrant machines defined in | ||
the Vagrantfile. Alternatively, you can explicility pass an array of node names. | ||
The flags key accepts a string of command line arguments to pass to rspec. Any | ||
of the acceptable rspec options and parameters are leagle. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# encoding: UTF-8 | ||
|
||
require 'spec_helper' | ||
require 'vagrant_spec/machine_data' | ||
|
||
describe VagrantSpec::MachineData do | ||
include_context 'unit' | ||
include_examples 'shared_mocks' | ||
|
||
let(:mock_machine_ssh_config) do | ||
{ | ||
host: '127.0.0.1', | ||
port: '2222', | ||
username: 'vagrant', | ||
private_key_path: %w(mock_key) | ||
} | ||
end | ||
|
||
let(:mock_data) do | ||
{ | ||
name: 'default', | ||
host: '127.0.0.1', | ||
port: '2222', | ||
username: 'vagrant', | ||
private_key: 'mock_key' | ||
} | ||
end | ||
|
||
before do | ||
allow(mock_node).to receive(:name) { 'default' } | ||
allow(mock_node).to receive(:ssh_info) { mock_machine_ssh_config } | ||
end | ||
|
||
subject { VagrantSpec::MachineData.new(iso_env) } | ||
|
||
it '#generate create the .vagrantspec_machine_data file' do | ||
allow(subject).to receive(:populate_data) | ||
allow(IO).to receive(:write) | ||
.with('.vagrantspec_machine_data', JSON.pretty_generate(subject.data)) | ||
expect(IO).to receive(:write) | ||
.with('.vagrantspec_machine_data', JSON.pretty_generate(subject.data)) | ||
subject.generate | ||
end | ||
|
||
it '#populate_data stores json data' do | ||
allow(subject.m_finder).to receive(:machines).and_yield(mock_node) | ||
allow(mock_node).to receive(:ssh_info) { mock_machine_ssh_config } | ||
expect(subject.data).to receive(:<<).with(mock_data) | ||
subject.populate_data | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ Gem::Specification.new do |s| | |
s.name = 'vagrant_spec' | ||
s.version = VagrantSpec::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.licenses = %w(Apache2) | ||
s.authors = %w(Demitri Swan) | ||
s.email = %w([email protected]) | ||
s.homepage = 'http://github.com/miroswan/vagrant_spec' | ||
|