vagrant_spec 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca4398378f23816a6be2fe1363277f81fccc9865
4
- data.tar.gz: 0c79917845abf21b33eb88bbb0c1120b9bc040ec
3
+ metadata.gz: 7441764a1c3043878ae5e5c6b523eb83322b7038
4
+ data.tar.gz: 936ce47d1326d77b1fdcfb9eeba5004622cd59e1
5
5
  SHA512:
6
- metadata.gz: c0abf6618ed12096ad017c1e944a5036e2738af0b1b69f5c81fb4e769d6503c0c8c5b891b11e9daf7a09c440d3fd710821bb3e5eccc176bc8aaf62503cb73c1d
7
- data.tar.gz: de929a10c837c340ed464cb0536a870b6295424af94a22a27041e06c9c74b32c60f87236b40ca77e59fdbdf836948ed4f559ce924d58d73c1a16072e83b8153c
6
+ metadata.gz: 3d56eef6bd74a8280e379980001b51c48d4b8d2dd1e81ab40964e99b04d62d11c3bd98386bffdb24dfc4cb6c2c9300b04c43085851ca79b9710eef6c73e5e61e
7
+ data.tar.gz: 123fb1ea1e3de655835d54b4b3db19208dbdeeab7f3571009327027d46805a3801125ff97915d829eb87df300a35d435f2967758edcce135e36f84fc00cecee8
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  .vagrant
2
2
  Gemfile.lock
3
3
  vagrantspec_inventory
4
+ .vagrantspec_machine_data
4
5
  serverspec/spec_helper.rb
5
6
  coverage
6
7
  pkg
data/CHANGELOG.md CHANGED
@@ -1,7 +1,15 @@
1
1
  # Change Log
2
2
 
3
- ## [0.0.2](https://github.com/miroswan/vagrant_spec/tree/0.0.2) (2016-08-06)
4
- [Full Changelog](https://github.com/miroswan/vagrant_spec/compare/v0.0.1...0.0.2)
3
+ ## [v0.0.3](https://github.com/miroswan/vagrant_spec/tree/v0.0.3) (2016-08-09)
4
+ [Full Changelog](https://github.com/miroswan/vagrant_spec/compare/v0.0.2...v0.0.3)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Prepping for a v0.0.3 release [\#6](https://github.com/miroswan/vagrant_spec/pull/6) ([miroswan](https://github.com/miroswan))
9
+ - Feature/machine data [\#5](https://github.com/miroswan/vagrant_spec/pull/5) ([miroswan](https://github.com/miroswan))
10
+
11
+ ## [v0.0.2](https://github.com/miroswan/vagrant_spec/tree/v0.0.2) (2016-08-06)
12
+ [Full Changelog](https://github.com/miroswan/vagrant_spec/compare/v0.0.1...v0.0.2)
5
13
 
6
14
  **Closed issues:**
7
15
 
data/README.md CHANGED
@@ -1,18 +1,24 @@
1
1
  # vagrant_spec
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/vagrant_spec.svg)](https://badge.fury.io/rb/vagrant_spec)
3
4
  [![Build Status](https://travis-ci.org/miroswan/vagrant_spec.svg?branch=master)](https://travis-ci.org/miroswan/vagrant_spec)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/miroswan/vagrant_spec/badge.svg?branch=master)](https://coveralls.io/github/miroswan/vagrant_spec?branch=master)
5
6
 
7
+
6
8
  Vagrant Spec is a Vagrant plugin that makes integration testing for deployments
7
9
  to clustered systems a breeze. It also separates the build and deployment steps
8
- to clearly delineate pipeline tasks.
10
+ to clearly separate pipeline tasks.
11
+
12
+ ## Installation
13
+
14
+ ```vagrant plugin install vagrant_spec```
9
15
 
10
16
  ## Why not use TestKitchen or vagrant-serverspec?
11
17
 
12
18
  * Test Kitchen is an excellent integration testing system developed by Chef.
13
19
  However, it is designed to provision, test, and destroy each system one at a
14
20
  time. The directory structure it expects makes sharing tests across nodes
15
- difficult to manager. This is undesireable for testing clustered or
21
+ difficult to manage. This is undesireable for testing clustered or
16
22
  distributed systems. vagrant-serverspec has similar pitfalls.
17
23
 
18
24
  * vagrant_spec allows you to leverage your deployment tools just like you would
@@ -66,7 +72,14 @@ defaults to serverspec.
66
72
  You can specify as many groups as you need. You can match nodes by regular
67
73
  expression or explicitly provide an array of node names. This will generate
68
74
  an vagrantspec_inventory based on your active nodes. You use this file for
69
- running ansible playbooks against your Vagrant instances.
75
+ running ansible playbooks against your Vagrant instances. Use this configuration
76
+ directive if you use ansible for orchestration.
77
+
78
+ * config.spec.generate_machine_data: a boolean. If true, the init sub-command
79
+ will generate a json file at .vagrantspec_machine_data containing relevant
80
+ ssh information for each of your nodes. This can be helpful when leveraging
81
+ orchestration tooling aside from ansible. You can use this data to direct your
82
+ orchestration to your local instances. The default is set to true.
70
83
 
71
84
  * config.spec.test_plan: an array of hashes. nodes can either be a regular
72
85
  expression object that matches your desired nodes or an explicit array of
@@ -140,7 +153,15 @@ rspec ./serverspec/fail_spec.rb:4 # Thing that fails dumb_service totally fails
140
153
  1
141
154
  ```
142
155
 
156
+ ## Testing Resources
157
+
158
+ * [ServerSpec](http://serverspec.org/)
159
+ * [RSpec](http://rspec.info/)
160
+ * [RSpec Best Practices](http://betterspecs.org/)
161
+
143
162
  ## Development
144
163
 
145
164
  * Fork the development branch
165
+ * ```pip install ansible```
166
+ * ```bundle install```
146
167
  * ```bundle exec rake test```
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'vagrant_spec/ansible_inventory'
4
4
  require 'vagrant_spec/spec_helper'
5
+ require 'vagrant_spec/machine_data'
5
6
  require 'vagrant_spec/config'
6
7
 
7
8
  module VagrantSpec
@@ -15,12 +16,17 @@ module VagrantSpec
15
16
 
16
17
  DEFAULTS = VagrantSpec::Config::DEFAULTS
17
18
 
18
- attr_accessor :config, :directory, :ansible_inventory
19
+ attr_accessor :config
20
+ attr_accessor :directory
21
+ attr_accessor :ansible_inventory
22
+ attr_accessor :generate_machine_data
23
+
19
24
  def initialize(argv, env)
20
25
  super
21
- @config = VagrantSpec::Config.load env
22
- @directory = @config.spec.directory
23
- @ansible_inventory = @config.spec.ansible_inventory
26
+ @config = VagrantSpec::Config.load env
27
+ @directory = @config.spec.directory
28
+ @ansible_inventory = @config.spec.ansible_inventory
29
+ @generate_machine_data = @config.spec.generate_machine_data
24
30
  end
25
31
 
26
32
  def execute
@@ -29,14 +35,18 @@ module VagrantSpec
29
35
  unless @ansible_inventory == DEFAULTS['ansible_inventory']
30
36
  VagrantSpec::AnsibleInventory.new(@env).generate
31
37
  end
38
+ if @generate_machine_data == DEFAULTS['generate_machine_data']
39
+ VagrantSpec::MachineData.new(@env).generate
40
+ end
32
41
  end
33
42
 
34
43
  def parse_opts
35
44
  opts = OptionParser.new do |o|
36
- o.banner = "\nCreates the serverspec/spec_helper.rb file for testing"
45
+ o.banner = "\nInit: Initializes state configuration"
37
46
  o.separator ''
38
47
  o.separator 'Usage: vagrant spec init'
39
48
  o.separator ''
49
+ o.separator IO.read(File.join(template_dir, 'init_help'))
40
50
  end
41
51
  parse_options(opts)
42
52
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'vagrant_spec/test_plan'
4
+ require 'vagrant_spec/utils'
4
5
 
5
6
  module VagrantSpec
6
7
  module Command
@@ -9,6 +10,7 @@ module VagrantSpec
9
10
  # argv
10
11
  # env [Vagrant::Environment]
11
12
  class Test < Vagrant.plugin(2, :command)
13
+ include VagrantSpec::Utils
12
14
  def initialize(argv, env)
13
15
  super
14
16
  end
@@ -20,10 +22,11 @@ module VagrantSpec
20
22
 
21
23
  def parse_opts
22
24
  opts = OptionParser.new do |o|
23
- o.banner = "\nRun the tests configured in the Vagrantfile"
25
+ o.banner = "\nTest: Run the tests configured in the Vagrantfile"
24
26
  o.separator ''
25
27
  o.separator 'Usage: vagrant spec test'
26
28
  o.separator ''
29
+ o.separator IO.read(File.join(template_dir, 'test_help'))
27
30
  end
28
31
  parse_options(opts)
29
32
  end
@@ -11,11 +11,13 @@ module VagrantSpec
11
11
  attr_accessor :directory
12
12
  attr_accessor :ansible_inventory
13
13
  attr_accessor :test_plan
14
+ attr_accessor :generate_machine_data
14
15
 
15
16
  def initialize
16
- @directory = UNSET_VALUE
17
- @ansible_inventory = UNSET_VALUE
18
- @test_plan = UNSET_VALUE
17
+ @directory = UNSET_VALUE
18
+ @ansible_inventory = UNSET_VALUE
19
+ @test_plan = UNSET_VALUE
20
+ @generate_machine_data = UNSET_VALUE
19
21
  end
20
22
 
21
23
  def final_directory
@@ -32,10 +34,17 @@ module VagrantSpec
32
34
  @test_plan = DEFAULTS['test_plan'] if @test_plan == UNSET_VALUE
33
35
  end
34
36
 
37
+ def final_generate_machine_data
38
+ if @generate_machine_data == UNSET_VALUE
39
+ @generate_machine_data = DEFAULTS['generate_machine_data']
40
+ end
41
+ end
42
+
35
43
  def finalize!
36
44
  final_directory
37
45
  final_ansible_inventory
38
46
  final_test_plan
47
+ final_generate_machine_data
39
48
  end
40
49
  end
41
50
  end
@@ -6,9 +6,10 @@ module VagrantSpec
6
6
  autoload :Base, 'vagrant_spec/config/base'
7
7
 
8
8
  DEFAULTS = {
9
- 'directory' => 'serverspec',
10
- 'ansible_inventory' => {},
11
- 'test_plan' => []
9
+ 'directory' => 'serverspec',
10
+ 'ansible_inventory' => {},
11
+ 'test_plan' => [],
12
+ 'generate_machine_data' => true
12
13
  }.freeze
13
14
 
14
15
  class << self
@@ -0,0 +1,34 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'json'
4
+ require 'vagrant_spec/machine_finder'
5
+
6
+ module VagrantSpec
7
+ # Handle machine data generation
8
+ class MachineData
9
+ attr_accessor :env, :m_finder, :data
10
+ def initialize(env)
11
+ @env = env
12
+ @m_finder = VagrantSpec::MachineFinder.new(@env)
13
+ @data = []
14
+ end
15
+
16
+ def generate
17
+ populate_data
18
+ IO.write('.vagrantspec_machine_data', JSON.pretty_generate(@data))
19
+ end
20
+
21
+ def populate_data
22
+ @m_finder.machines do |m|
23
+ private_key = m.ssh_info[:private_key_path][0]
24
+ @data << {
25
+ name: m.name,
26
+ host: m.ssh_info[:host],
27
+ port: m.ssh_info[:port],
28
+ username: m.ssh_info[:username],
29
+ private_key: private_key
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -20,6 +20,13 @@ module VagrantSpec
20
20
  nil
21
21
  end
22
22
 
23
+ # Yield active machines
24
+ #
25
+ # yield [Vagrant::Machine]
26
+ def machines
27
+ @env.active_machines.each { |m| yield @env.machine(*m) }
28
+ end
29
+
23
30
  # reg [Regexp]
24
31
  #
25
32
  # return [Array<Vagrant::Machine>]
@@ -0,0 +1,16 @@
1
+ The init subcommand initializes state-based configuration for vagrant_spec.
2
+
3
+ It creates a spec_helper.rb file under the configured serverspec directory. This
4
+ file is used to setup serverspec backend configuration and ease serverspec
5
+ testing.
6
+
7
+ If config.spec.ansible_inventory configuration directive is used within the
8
+ Vagrantfile, then init will generate a test inventory file
9
+ vagrantspec_inventory. This file can be used for ansible orchestration against
10
+ the vagrant instances.
11
+
12
+ By default, init will generate a json file containing machine data for each
13
+ vagrant instance at .vagrantspec_machine_data. This file can be used by
14
+ orchestration tooling outside of ansible to map events to vagrant nodes. The
15
+ config.spec.generate_machine_data configuration parameter controls the
16
+ generation of this file.
@@ -16,4 +16,4 @@ options[:keys] = ENV['VAGRANT_KEY']
16
16
  options[:port] = ENV['VAGRANT_PORT']
17
17
 
18
18
  set :host, host
19
- set :ssh_options, options
19
+ set :ssh_options, options
@@ -0,0 +1,21 @@
1
+ The test subcommand will execute the serverspec tests configured in the
2
+ Vagrantfile under the config.spec.test_plan directive. This directive accepts
3
+ an array of hashes. For example:
4
+
5
+ config.spec.test_plan = [
6
+ {
7
+ 'nodes' => /nginx/,
8
+ 'flags' => '--format documentation --pattern serverspec/nginx*'
9
+ },
10
+ {
11
+ 'nodes' => %w(app1 app2),
12
+ 'flags' => '--format documentation --pattern serverspec/app*'
13
+ }
14
+ ]
15
+
16
+ Each hash have two required keys: nodes and flags. The nodes key accepts a
17
+ regular expression object matching the names of the vagrant machines defined in
18
+ the Vagrantfile. Alternatively, you can explicility pass an array of node names.
19
+ The flags key accepts a string of command line arguments to pass to rspec. Any
20
+ of the acceptable rspec options and parameters are leagle.
21
+
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Requisite version info
4
4
  module VagrantSpec
5
- VERSION = '0.0.2'.freeze
5
+ VERSION = '0.0.3'.freeze
6
6
  end
@@ -13,6 +13,7 @@ bundle exec vagrant spec init -h
13
13
  bundle exec vagrant spec test -h
14
14
  bundle exec vagrant spec no_command -h
15
15
  rm -f serverspec/spec_helper.rb
16
+ rm -f .vagrantspec_machine_data
16
17
  bundle exec vagrant up
17
18
  bundle exec vagrant spec init
18
19
  ansible-playbook site.yml -i vagrantspec_inventory
@@ -15,8 +15,13 @@ describe VagrantSpec::Command::Init do
15
15
  double(VagrantSpec::AnsibleInventory)
16
16
  end
17
17
 
18
+ let(:mock_machine_data) do
19
+ double(VagrantSpec::MachineData)
20
+ end
21
+
18
22
  before do
19
23
  allow(mock_spec).to receive(:ansible_inventory) { { 'all' => /node/ } }
24
+ allow(mock_spec).to receive(:generate_machine_data)
20
25
  end
21
26
 
22
27
  subject { VagrantSpec::Command::Init.new([], iso_env) }
@@ -29,8 +34,10 @@ describe VagrantSpec::Command::Init do
29
34
  proc do
30
35
  allow_any_instance_of(VagrantSpec::SpecHelper).to receive(:generate)
31
36
  allow_any_instance_of(VagrantSpec::AnsibleInventory).to receive(:generate)
32
- allow(mock_spec_helper).to receive(:generate)
37
+ allow_any_instance_of(VagrantSpec::MachineData).to receive(:generate)
38
+ allow(mock_spec_helper).to receive(:generate)
33
39
  allow(mock_ansible_inventory).to receive(:generate)
40
+ allow(mock_machine_data).to receive(:generate)
34
41
  end
35
42
  end
36
43
 
@@ -46,12 +53,11 @@ describe VagrantSpec::Command::Init do
46
53
  def execute_protection_proc
47
54
  proc do
48
55
  allow(subject).to receive(:parse_opts) { 'not_nil' }
49
- allow(VagrantSpec::SpecHelper).to receive(:new) do
50
- mock_spec_helper
51
- end
56
+ allow(VagrantSpec::SpecHelper).to receive(:new) { mock_spec_helper }
52
57
  allow(VagrantSpec::AnsibleInventory).to receive(:new) do
53
58
  mock_ansible_inventory
54
59
  end
60
+ allow(VagrantSpec::MachineData).to receive(:new) { mock_machine_data }
55
61
  execute_proc.call
56
62
  end
57
63
  end
@@ -77,6 +83,24 @@ describe VagrantSpec::Command::Init do
77
83
  subject.execute
78
84
  end
79
85
  end
86
+
87
+ context 'and when @generate_machine_data is true' do
88
+ it '#execute generates a .vagrantspec_machine_data file' do
89
+ execute_protection_proc.call
90
+ subject.generate_machine_data = true
91
+ expect(mock_machine_data).to receive(:generate)
92
+ subject.execute
93
+ end
94
+ end
95
+
96
+ context 'and when @generate_machine_data is false' do
97
+ it '#execute does not generate a .vagrantspec_machine_data file' do
98
+ execute_protection_proc.call
99
+ subject.generate_machine_data = false
100
+ expect(mock_machine_data).not_to receive(:generate)
101
+ subject.execute
102
+ end
103
+ end
80
104
  end
81
105
 
82
106
  it '#parse_opts calls parse_options' do
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'vagrant_spec/machine_data'
5
+
6
+ describe VagrantSpec::MachineData do
7
+ include_context 'unit'
8
+ include_examples 'shared_mocks'
9
+
10
+ let(:mock_machine_ssh_config) do
11
+ {
12
+ host: '127.0.0.1',
13
+ port: '2222',
14
+ username: 'vagrant',
15
+ private_key_path: %w(mock_key)
16
+ }
17
+ end
18
+
19
+ let(:mock_data) do
20
+ {
21
+ name: 'default',
22
+ host: '127.0.0.1',
23
+ port: '2222',
24
+ username: 'vagrant',
25
+ private_key: 'mock_key'
26
+ }
27
+ end
28
+
29
+ before do
30
+ allow(mock_node).to receive(:name) { 'default' }
31
+ allow(mock_node).to receive(:ssh_info) { mock_machine_ssh_config }
32
+ end
33
+
34
+ subject { VagrantSpec::MachineData.new(iso_env) }
35
+
36
+ it '#generate create the .vagrantspec_machine_data file' do
37
+ allow(subject).to receive(:populate_data)
38
+ allow(IO).to receive(:write)
39
+ .with('.vagrantspec_machine_data', JSON.pretty_generate(subject.data))
40
+ expect(IO).to receive(:write)
41
+ .with('.vagrantspec_machine_data', JSON.pretty_generate(subject.data))
42
+ subject.generate
43
+ end
44
+
45
+ it '#populate_data stores json data' do
46
+ allow(subject.m_finder).to receive(:machines).and_yield(mock_node)
47
+ allow(mock_node).to receive(:ssh_info) { mock_machine_ssh_config }
48
+ expect(subject.data).to receive(:<<).with(mock_data)
49
+ subject.populate_data
50
+ end
51
+ end
data/vagrant_spec.gemspec CHANGED
@@ -6,6 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = 'vagrant_spec'
7
7
  s.version = VagrantSpec::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
+ s.licenses = %w(Apache2)
9
10
  s.authors = %w(Demitri Swan)
10
11
  s.email = %w(demitriswan@gmail.com)
11
12
  s.homepage = 'http://github.com/miroswan/vagrant_spec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Demitri
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-08-06 00:00:00.000000000 Z
12
+ date: 2016-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: serverspec
@@ -124,9 +124,12 @@ files:
124
124
  - lib/vagrant_spec/command/test.rb
125
125
  - lib/vagrant_spec/config.rb
126
126
  - lib/vagrant_spec/config/base.rb
127
+ - lib/vagrant_spec/machine_data.rb
127
128
  - lib/vagrant_spec/machine_finder.rb
128
129
  - lib/vagrant_spec/spec_helper.rb
130
+ - lib/vagrant_spec/templates/init_help
129
131
  - lib/vagrant_spec/templates/spec_helper.erb
132
+ - lib/vagrant_spec/templates/test_help
130
133
  - lib/vagrant_spec/templates/vagrantspec_inventory.erb
131
134
  - lib/vagrant_spec/test_plan.rb
132
135
  - lib/vagrant_spec/utils.rb
@@ -143,13 +146,15 @@ files:
143
146
  - spec/unit/vagrant_spec_test/command_spec/test_spec.rb
144
147
  - spec/unit/vagrant_spec_test/config_spec.rb
145
148
  - spec/unit/vagrant_spec_test/config_spec/base_spec.rb
149
+ - spec/unit/vagrant_spec_test/machine_data_spec.rb
146
150
  - spec/unit/vagrant_spec_test/machine_finder_spec.rb
147
151
  - spec/unit/vagrant_spec_test/spec_helper_spec.rb
148
152
  - spec/unit/vagrant_spec_test/test_plan_spec.rb
149
153
  - spec/unit/vagrant_spec_test/utils_spec.rb
150
154
  - vagrant_spec.gemspec
151
155
  homepage: http://github.com/miroswan/vagrant_spec
152
- licenses: []
156
+ licenses:
157
+ - Apache2
153
158
  metadata: {}
154
159
  post_install_message:
155
160
  rdoc_options: []
@@ -180,6 +185,7 @@ test_files:
180
185
  - spec/unit/vagrant_spec_test/command_spec/test_spec.rb
181
186
  - spec/unit/vagrant_spec_test/config_spec.rb
182
187
  - spec/unit/vagrant_spec_test/config_spec/base_spec.rb
188
+ - spec/unit/vagrant_spec_test/machine_data_spec.rb
183
189
  - spec/unit/vagrant_spec_test/machine_finder_spec.rb
184
190
  - spec/unit/vagrant_spec_test/spec_helper_spec.rb
185
191
  - spec/unit/vagrant_spec_test/test_plan_spec.rb