kitchen-vagrant 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ notifications:
5
+ irc:
6
+ channels:
7
+ - "irc.freenode.org#jamie-ci"
8
+ use_notice: true
9
+ skip_join: true
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kitchen-vagrant.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ Author:: Fletcher Nichol (<fnichol@nichol.ca>)
2
+
3
+ Copyright (C) 2012, Fletcher Nichol
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Kitchen::Vagrant
2
+
3
+ [![Build Status](https://secure.travis-ci.org/jamie-ci/kitchen-vagrant.png)](https://travis-ci.org/jamie-ci/kitchen-vagrant)
4
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/jamie-ci/kitchen-vagrant)
5
+
6
+ This gem provides `kitchen-vagrant`, a driver for `test-kitchen` to provision systems to test under Vagrant.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'kitchen-vagrant'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install kitchen-vagrant
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+ require 'cane/rake_task'
3
+ require 'tailor/rake_task'
4
+
5
+ desc "Run cane to check quality metrics"
6
+ Cane::RakeTask.new do |cane|
7
+ cane.abc_exclude = %w(
8
+ Kitchen::Vagrant.define_vagrant_vm
9
+ )
10
+ end
11
+
12
+ Tailor::RakeTask.new
13
+
14
+ desc "Display LOC stats"
15
+ task :stats do
16
+ puts "\n## Production Code Stats"
17
+ sh "countloc -r lib/kitchen"
18
+ end
19
+
20
+ task :default => [ :cane, :tailor, :stats ]
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/vagrant_version.rb'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "kitchen-vagrant"
8
+ gem.version = Kitchen::Driver::VAGRANT_VERSION
9
+ gem.authors = ["Fletcher Nichol"]
10
+ gem.email = ["fnichol@nichol.ca"]
11
+ gem.description = "Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen."
12
+ gem.summary = gem.description
13
+ gem.homepage = "https://github.com/opscode/kitchen-vagrant/"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = []
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'test-kitchen', '~> 1.0.0.alpha.0'
21
+ gem.add_dependency 'vagrant', '~> 1.0'
22
+
23
+ gem.add_development_dependency 'cane'
24
+ gem.add_development_dependency 'tailor'
25
+ gem.add_development_dependency 'countloc'
26
+ end
@@ -0,0 +1,92 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'kitchen'
20
+
21
+ module Kitchen
22
+
23
+ module Driver
24
+
25
+ # Vagrant driver for Kitchen. It communicates to Vagrant via the CLI.
26
+ #
27
+ # @author Fletcher Nichol <fnichol@nichol.ca>
28
+ class Vagrant < Kitchen::Driver::SSHBase
29
+
30
+ default_config :customize, {:memory => '256'}
31
+
32
+ no_parallel_for :create, :destroy
33
+
34
+ def create(state)
35
+ # @todo Vagrantfile setup will be placed in any dependency hook
36
+ # checks when feature is released
37
+ vagrantfile = File.join(config[:kitchen_root], "Vagrantfile")
38
+ create_vagrantfile(vagrantfile) unless File.exists?(vagrantfile)
39
+
40
+ state[:hostname] = instance.name
41
+ run "vagrant up #{state[:hostname]} --no-provision"
42
+ info("Vagrant instance <#{state[:hostname]}> created.")
43
+ end
44
+
45
+ def converge(state)
46
+ ssh_args = build_ssh_args(state)
47
+ install_omnibus(ssh_args) if config[:require_chef_omnibus]
48
+ run "vagrant provision #{state[:hostname]}"
49
+ end
50
+
51
+ def destroy(state)
52
+ return if state[:hostname].nil?
53
+
54
+ run "vagrant destroy #{state[:hostname]} -f"
55
+ info("Vagrant instance <#{state[:hostname]}> destroyed.")
56
+ state.delete(:hostname)
57
+ end
58
+
59
+ def login_command(state)
60
+ %W{vagrant ssh #{state[:hostname]}}
61
+ end
62
+
63
+ protected
64
+
65
+ def ssh(ssh_args, cmd)
66
+ run %{vagrant ssh #{ssh_args.first} --command '#{cmd}'}
67
+ end
68
+
69
+ def run(cmd)
70
+ cmd = "echo #{cmd}" if config[:dry_run]
71
+ run_command(cmd)
72
+ end
73
+
74
+ def create_vagrantfile(vagrantfile)
75
+ File.open(vagrantfile, "wb") { |f| f.write(vagrantfile_contents) }
76
+ end
77
+
78
+ def vagrantfile_contents
79
+ arr = []
80
+ arr << %{require 'kitchen/vagrant'}
81
+ if File.exists?(File.join(config[:kitchen_root], "Berksfile"))
82
+ arr << %{require 'berkshelf/vagrant'}
83
+ end
84
+ arr << %{}
85
+ arr << %{Vagrant::Config.run do |config|}
86
+ arr << %{ Kitchen::Vagrant.define_vms(config)}
87
+ arr << %{end\n}
88
+ arr.join("\n")
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+
21
+ module Driver
22
+
23
+ # Version string for Vagrant Kitchen driver
24
+ VAGRANT_VERSION = "0.6.0"
25
+ end
26
+ end
@@ -0,0 +1,101 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require 'forwardable'
20
+ require 'vagrant'
21
+
22
+ require 'kitchen'
23
+
24
+ module Kitchen
25
+
26
+ module Vagrant
27
+
28
+ # A Vagrant confiuration class which wraps a Kitchen::Config instance.
29
+ #
30
+ # @author Fletcher Nichol <fnichol@nichol.ca>
31
+ class Config < ::Vagrant::Config::Base
32
+ extend Forwardable
33
+
34
+ def_delegators :@config, :suites, :suites=, :platforms, :platforms=,
35
+ :instances, :yaml_file, :yaml_file=, :log_level, :log_level=,
36
+ :test_base_path, :test_base_path=, :yaml_data
37
+
38
+ def initialize
39
+ @config = Kitchen::Config.new
40
+ @config.yaml_file = ENV['KITCHEN_YAML'] if ENV['KITCHEN_YAML']
41
+ end
42
+
43
+ # Override default implementation to prevent serializing the config
44
+ # instance variable, which may contain circular references.
45
+ #
46
+ # @return [Hash] an empty Hash
47
+ def instance_variables_hash
48
+ {}
49
+ end
50
+ end
51
+
52
+ # Defines all Vagrant virtual machines, one for each instance.
53
+ #
54
+ # @param config [Vagrant::Config::Top] Vagrant top level config object
55
+ def self.define_vms(config)
56
+ config.kitchen.instances.each do |instance|
57
+ define_vagrant_vm(config, instance)
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def self.define_vagrant_vm(config, instance)
64
+ driver = instance.driver
65
+
66
+ config.vm.define instance.name do |c|
67
+ c.vm.box = driver[:box]
68
+ c.vm.box_url = driver[:box_url] if driver[:box_url]
69
+ c.vm.host_name = "#{instance.name}.vagrantup.com"
70
+
71
+ Array(driver[:forward_port]).each do |ports|
72
+ if ports.length != 2
73
+ raise ArgumentError,
74
+ "Vagrant config.vm.forward_port only accepts two arguments"
75
+ end
76
+ c.vm.forward_port(*ports)
77
+ end
78
+
79
+ Array(driver[:network]).each do |network_options|
80
+ options = Array(network_options)
81
+ type = options.shift
82
+ c.vm.network(type.to_sym, *options)
83
+ end
84
+
85
+ driver[:customize].each do |key, value|
86
+ c.vm.customize ["modifyvm", :id, "--#{key}", value]
87
+ end
88
+
89
+ c.vm.provision :chef_solo do |chef|
90
+ chef.log_level = config.kitchen.log_level
91
+ chef.run_list = instance.run_list
92
+ chef.json = instance.attributes
93
+ chef.data_bags_path = instance.suite.data_bags_path
94
+ chef.roles_path = instance.suite.roles_path
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ Vagrant.config_keys.register(:kitchen) { Kitchen::Vagrant::Config }
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-vagrant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Fletcher Nichol
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: test-kitchen
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0.alpha.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0.alpha.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: vagrant
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: cane
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: tailor
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: countloc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen.
95
+ email:
96
+ - fnichol@nichol.ca
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .travis.yml
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - kitchen-vagrant.gemspec
108
+ - lib/kitchen/driver/vagrant.rb
109
+ - lib/kitchen/driver/vagrant_version.rb
110
+ - lib/kitchen/vagrant.rb
111
+ homepage: https://github.com/opscode/kitchen-vagrant/
112
+ licenses: []
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: -433240395816256093
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: -433240395816256093
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.24
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Kitchen::Driver::Vagrant - A Vagrant Driver for Test Kitchen.
141
+ test_files: []