kitchen-vagrant_sandbox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +8 -0
- data/LICENSE +17 -0
- data/README.md +315 -0
- data/Rakefile +21 -0
- data/kitchen-vagrant_sandbox.gemspec +26 -0
- data/lib/kitchen/driver/vagrant_sandbox.rb +245 -0
- data/lib/kitchen/driver/vagrant_sandbox_version.rb +28 -0
- data/lib/kitchen/vagrant_sandbox/vagrantfile_creator.rb +185 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67a4eb87f37ca0f562f17c7286764f6fc53c448f
|
4
|
+
data.tar.gz: 04455b1a0b543b263b877b0bd657724c59246ce6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06ee0ccffd5b2191631e320318dc5af20ce488febdddd08bfff10a6996f17e9b6c3bbd1eb199d4639f28ca16f4d5dc7e0e0d3ae2dacd65683a1f7b228e7a1b76
|
7
|
+
data.tar.gz: f55026a89659badfff02b4087075a76829f28b4820abcfca321a66acc87d2f144096d511b3c40ece9219706a6a0a6e25545eef822e627414e85891b69e38e6ba
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
This is modified version by Ryota Arai (<ryota.arai@gmail.com>)
|
2
|
+
|
3
|
+
Author:: Fletcher Nichol (<fnichol@nichol.ca>), Ryota Arai (<ryota.arai@gmail.com>)
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,315 @@
|
|
1
|
+
# <a name="title"></a> Kitchen::VagrantSandbox
|
2
|
+
|
3
|
+
A Test Kitchen Driver for Vagrant.
|
4
|
+
|
5
|
+
**This is a fork version of [Kitchen::Vagrant driver][original_repo].**
|
6
|
+
|
7
|
+
This driver works by generating a single Vagrantfile for each instance in a
|
8
|
+
sandboxed directory. Since the Vagrantfile is written out on disk, Vagrant
|
9
|
+
needs absolutely no knowledge of Test Kitchen. So no Vagrant plugin gem is
|
10
|
+
required.
|
11
|
+
|
12
|
+
## <a name="requirements"></a> Requirements
|
13
|
+
|
14
|
+
### <a name="dependencies-vagrant"></a> Vagrant
|
15
|
+
|
16
|
+
A Vagrant version of 1.1.0 or higher is required for this driver which means
|
17
|
+
that a [native package][vagrant_dl] must be installed on the system running
|
18
|
+
Test Kitchen.
|
19
|
+
|
20
|
+
**Note:** If you have previously installed Vagrant as a gem (a version prior
|
21
|
+
to 1.1.0), this version may be resolved first in your `PATH`. If you receive an
|
22
|
+
error message that Vagrant is too old despite having installed Vagrant as a
|
23
|
+
package, you may be required to uninstall the gem version or modify your `PATH`
|
24
|
+
environment. If you require the vagrant gem for older projects you should
|
25
|
+
consider the [vagrant-wrapper][vagrant_wrapper] gem which helps manage both
|
26
|
+
styles of Vagrant installations
|
27
|
+
([background details][vagrant_wrapper_background]).
|
28
|
+
|
29
|
+
### Vagrant Sandbox (Sahara) Plugin
|
30
|
+
|
31
|
+
This driver uses `vagrant sandbox status`, `vagrant sandbox on` and `vagrant sandbox rollback`.
|
32
|
+
To use sandbox features, you should install sahara plugin:
|
33
|
+
|
34
|
+
```
|
35
|
+
$ vagrant plugin install sahara
|
36
|
+
```
|
37
|
+
|
38
|
+
### <a name="dependencies-berkshelf"></a> Vagrant Berkshelf Plugin
|
39
|
+
|
40
|
+
If a Berksfile is present in your project's root directory, then this driver
|
41
|
+
will check to ensure that the [vagrant-berkshelf][vagrant_berkshelf] plugin is
|
42
|
+
installed.
|
43
|
+
|
44
|
+
If your project doesn't use Berkshelf then this check will be skipped.
|
45
|
+
|
46
|
+
**Note:** Prior to release 1.2.0, then name of the vagrant-berkshelf gem was
|
47
|
+
berkshelf-vagrant. This driver no longer checks for the existance of
|
48
|
+
berkshelf-vagrant, so upgrading this Vagrant plugin is recommended.
|
49
|
+
|
50
|
+
### <a name="dependencies-virtualization"></a> Virtualbox and/or VMware Fusion/Workstation
|
51
|
+
|
52
|
+
Currently this driver supports VirtualBox and VMware Fusion/Workstation.
|
53
|
+
Virtualbox is free and is the default provider for Vagrant.
|
54
|
+
|
55
|
+
[VirtualBox package][virtualbox_dl]
|
56
|
+
|
57
|
+
If you would like to use VMware Fusion/Workstation you must purchase the
|
58
|
+
software from VMware and then must also purchase the Vagrant VMware plugin.
|
59
|
+
|
60
|
+
[Vagrant VMware Plugin][vmware_plugin]
|
61
|
+
|
62
|
+
[VMware Fusion][fusion_dl]
|
63
|
+
|
64
|
+
[VMware Workstation][workstation_dl]
|
65
|
+
|
66
|
+
## <a name="installation"></a> Installation and Setup
|
67
|
+
|
68
|
+
Please read the [Driver usage][driver_usage] page for more details.
|
69
|
+
|
70
|
+
## Usage
|
71
|
+
|
72
|
+
### Destroy Vagrant VM
|
73
|
+
|
74
|
+
With this plugin, `kitchen destroy` doesn't executes `vagrant destroy` but executes `vagrant sandbox rollback`.
|
75
|
+
If you would like to destroy vagrant VM, please set `KITCHEN_DESTROY_VM` env variable:
|
76
|
+
```
|
77
|
+
KITCHEN_DESTROY_VM=1 kitchen destroy [(all|<REGEX>)] [opts]
|
78
|
+
```
|
79
|
+
|
80
|
+
## <a name="default-config"></a> Default Configuration
|
81
|
+
|
82
|
+
This driver can determine the Vagrant box name and download URL for a select
|
83
|
+
number of platforms. Currently, the following platform names are supported:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
---
|
87
|
+
platforms:
|
88
|
+
- name: ubuntu-10.04
|
89
|
+
- name: ubuntu-12.04
|
90
|
+
- name: ubuntu-12.10
|
91
|
+
- name: ubuntu-13.04
|
92
|
+
- name: centos-5.9
|
93
|
+
- name: centos-6.4
|
94
|
+
- name: debian-7.1.0
|
95
|
+
```
|
96
|
+
|
97
|
+
This will effectively generate a configuration similar to:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
---
|
101
|
+
platforms:
|
102
|
+
- name: ubuntu-10.04
|
103
|
+
driver_config:
|
104
|
+
box: opscode-ubuntu-10.04
|
105
|
+
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-10.04_provisionerless.box
|
106
|
+
- name: ubuntu-12.04
|
107
|
+
driver_config:
|
108
|
+
box: opscode-ubuntu-12.04
|
109
|
+
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
|
110
|
+
- name: ubuntu-12.10
|
111
|
+
driver_config:
|
112
|
+
box: opscode-ubuntu-12.10
|
113
|
+
box_url: ...
|
114
|
+
# ...
|
115
|
+
```
|
116
|
+
|
117
|
+
## <a name="config"></a> Configuration
|
118
|
+
|
119
|
+
### <a name="config-box"></a> box
|
120
|
+
|
121
|
+
**Required** This determines which Vagrant box will be used. For more
|
122
|
+
details, please read the Vagrant [machine settings][vagrant_machine_settings]
|
123
|
+
page.
|
124
|
+
|
125
|
+
There is **no** default value set.
|
126
|
+
|
127
|
+
### <a name="config-box-url"></a> box\_url
|
128
|
+
|
129
|
+
The URL that the configured box can be found at. If the box is not installed on
|
130
|
+
the system, it will be retrieved from this URL when the virtual machine is
|
131
|
+
started.
|
132
|
+
|
133
|
+
There is **no** default value set.
|
134
|
+
|
135
|
+
### <a name="config-provider"></a> provider
|
136
|
+
|
137
|
+
This determines which Vagrant provider to use when testing and should match
|
138
|
+
the provider name in Vagrant. For example, to use VMware Fusion the provider
|
139
|
+
should be `vmware_fusion`. Please see the docs on [providers][vagrant_providers]
|
140
|
+
for further details.
|
141
|
+
|
142
|
+
By default the value is unset, or `nil`. In this case the driver will use the
|
143
|
+
Vagrant default provider which at this current time is **virtualbox**
|
144
|
+
|
145
|
+
### <a name="config-customize"></a> customize
|
146
|
+
|
147
|
+
A **Hash** of customizations to a Vagrant virtual machine. Each key/value
|
148
|
+
pair will be passed to your providers customization block. For example, with
|
149
|
+
the default `virtualbox` provider:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
driver_config:
|
153
|
+
customize:
|
154
|
+
memory: 1024
|
155
|
+
cpuexecutioncap: 50
|
156
|
+
```
|
157
|
+
|
158
|
+
will generate a Vagrantfile configuration similar to:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
Vagrant.configure("2") do |config|
|
162
|
+
# ...
|
163
|
+
|
164
|
+
config.vm.provider :virtualbox do |virtualbox|
|
165
|
+
virtualbox.customize ["modifyvm", :id, "--memory", "1024"]
|
166
|
+
virtualbox.customize ["modifyvm", :id, "--cpuexecutioncap", "50"]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
Please read the [Vagrantfile configuration][vagrantfile] page for
|
172
|
+
more details.
|
173
|
+
|
174
|
+
By default, each Vagrant virtual machine is configured with 256 MB of RAM. In
|
175
|
+
other words the default value for `customize` is `{:memory => '256'}`.
|
176
|
+
|
177
|
+
### <a name="config-dry-run"></a> dry\_run
|
178
|
+
|
179
|
+
Useful when debugging Vagrant CLI commands. If set to `true`, all Vagrant CLI
|
180
|
+
commands will be displayed rather than executed.
|
181
|
+
|
182
|
+
The default is unset, or `nil`.
|
183
|
+
|
184
|
+
### <a name="config-network"></a> network
|
185
|
+
|
186
|
+
An **Array** of network customizations for the virtual machine. Each Array
|
187
|
+
element is itself an Array of arguments to be passed to the `config.vm.netork`
|
188
|
+
method. For example:
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
driver_config:
|
192
|
+
network:
|
193
|
+
- ["forwarded_port", {guest: 80, host: 8080}]
|
194
|
+
- ["private_network", {ip: "192.168.33.33"}]
|
195
|
+
```
|
196
|
+
|
197
|
+
will generate a Vagrantfile configuration similar to:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
Vagrant.configure("2") do |config|
|
201
|
+
# ...
|
202
|
+
|
203
|
+
config.vm.network :forwarded_port, guest: 80, host: 8080
|
204
|
+
config.vm.network :private_network, ip: "192.168.33.33"
|
205
|
+
end
|
206
|
+
```
|
207
|
+
|
208
|
+
Please read the Vagrant [networking basic usage][vagrant_networking] page for
|
209
|
+
more details.
|
210
|
+
|
211
|
+
There is **no** default value set.
|
212
|
+
|
213
|
+
### <a name="config-use-vagrant-provision"></a> use_vagrant_provision
|
214
|
+
|
215
|
+
Determines whether or not this driver will use a `vagrant provision` shell out
|
216
|
+
in the **converge** action. If this value is falsey (`nil`, `false`) the
|
217
|
+
behavior from `Kitchen::Driver::SSHBase` will be used, bypassing the Vagrant
|
218
|
+
Chef solo provisioner. If this value is truthy, a `vagrant provision` will
|
219
|
+
be used.
|
220
|
+
|
221
|
+
The default is unset, or `nil`.
|
222
|
+
|
223
|
+
### vagrant\_provision\_run\_list
|
224
|
+
|
225
|
+
### do\_not\_vagrant\_provision\_in\_converge
|
226
|
+
|
227
|
+
### <a name="config-use-vagrant-berkshelf-plugin"></a> use_vagrant_berkshelf_plugin
|
228
|
+
|
229
|
+
Determines whether or not this driver will use the vagrant-berkself Vagrant
|
230
|
+
plugin to assemble cookbook dependencies. If this value if falsey (`nil`,
|
231
|
+
`false`) then the driver will skip the vagrant-berkshelf dependency check
|
232
|
+
and not activate the plugin in the rendered Vagrantfile. If this value is
|
233
|
+
truthy the opposite behvior will be used.
|
234
|
+
|
235
|
+
The default is unset, or `nil`.
|
236
|
+
|
237
|
+
### <a name="config-synced-folders"></a> synced_folders
|
238
|
+
|
239
|
+
Allow the user to specify a collection of synced folders for on each Vagrant
|
240
|
+
instance.
|
241
|
+
|
242
|
+
The default is an empty Hash, or `{}`.
|
243
|
+
|
244
|
+
### <a name="config-require-chef-omnibus"></a> require\_chef\_omnibus
|
245
|
+
|
246
|
+
Determines whether or not a Chef [Omnibus package][chef_omnibus_dl] will be
|
247
|
+
installed. There are several different behaviors available:
|
248
|
+
|
249
|
+
* `true` - the latest release will be installed. Subsequent converges
|
250
|
+
will skip re-installing if chef is present.
|
251
|
+
* `latest` - the latest release will be installed. Subsequent converges
|
252
|
+
will always re-install even if chef is present.
|
253
|
+
* `<VERSION_STRING>` (ex: `10.24.0`) - the desired version string will
|
254
|
+
be passed the the install.sh script. Subsequent converges will skip if
|
255
|
+
the installed version and the desired version match.
|
256
|
+
* `false` or `nil` - no chef is installed.
|
257
|
+
|
258
|
+
The default value is unset, or `nil`.
|
259
|
+
|
260
|
+
### <a name="config-username"></a> username
|
261
|
+
|
262
|
+
This is the username used for SSH authentication if you
|
263
|
+
would like to connect with a different account than Vagrant default user.
|
264
|
+
|
265
|
+
If this value is nil, then Vagrant parameter `config.ssh.default.username`
|
266
|
+
will be used (which is usually set to 'vagrant').
|
267
|
+
|
268
|
+
The default value is unset, or `nil`.
|
269
|
+
|
270
|
+
## <a name="development"></a> Development
|
271
|
+
|
272
|
+
* Source hosted at [GitHub][repo]
|
273
|
+
* Report issues/questions/feature requests on [GitHub Issues][issues]
|
274
|
+
|
275
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
276
|
+
Ideally create a topic branch for every separate change you make. For
|
277
|
+
example:
|
278
|
+
|
279
|
+
1. Fork the repo
|
280
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
281
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
282
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
283
|
+
5. Create new Pull Request
|
284
|
+
|
285
|
+
## <a name="authors"></a> Authors
|
286
|
+
|
287
|
+
Modified by [Ryota Arai][author] (<ryota.arai@gmail.com>)
|
288
|
+
|
289
|
+
Originally created and maintained by [Fletcher Nichol][author] (<fnichol@nichol.ca>)
|
290
|
+
|
291
|
+
## <a name="license"></a> License
|
292
|
+
|
293
|
+
Apache 2.0 (see [LICENSE][license])
|
294
|
+
|
295
|
+
|
296
|
+
[author]: https://github.com/ryotarai
|
297
|
+
[issues]: https://github.com/ryotarai/kitchen-vagrant_sandbox/issues
|
298
|
+
[license]: https://github.com/ryotarai/kitchen-vagrant_sandbox/blob/master/LICENSE
|
299
|
+
[repo]: https://github.com/ryotarai/kitchen-vagrant_sandbox
|
300
|
+
[original_repo]: https://github.com/opscode/kitchen-vagrant
|
301
|
+
[driver_usage]: http://docs.kitchen-ci.org/drivers/usage
|
302
|
+
[chef_omnibus_dl]: http://www.opscode.com/chef/install/
|
303
|
+
|
304
|
+
[vagrant_berkshelf]: http://rubygems.org/gems/vagrant-berkshelf
|
305
|
+
[vagrant_dl]: http://downloads.vagrantup.com/
|
306
|
+
[vagrant_machine_settings]: http://docs.vagrantup.com/v2/vagrantfile/machine_settings.html
|
307
|
+
[vagrant_networking]: http://docs.vagrantup.com/v2/networking/basic_usage.html
|
308
|
+
[virtualbox_dl]: https://www.virtualbox.org/wiki/Downloads
|
309
|
+
[vagrantfile]: http://docs.vagrantup.com/v2/vagrantfile/index.html
|
310
|
+
[vagrant_providers]: http://docs.vagrantup.com/v2/providers/index.html
|
311
|
+
[vagrant_wrapper]: https://github.com/org-binbab/gem-vagrant-wrapper
|
312
|
+
[vagrant_wrapper_background]: https://github.com/org-binbab/gem-vagrant-wrapper#background---aka-the-vagrant-gem-enigma
|
313
|
+
[vmware_plugin]: http://www.vagrantup.com/vmware
|
314
|
+
[fusion_dl]: http://www.vmware.com/products/fusion/overview.html
|
315
|
+
[workstation_dl]: http://www.vmware.com/products/workstation/
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
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
|
7
|
+
|
8
|
+
Tailor::RakeTask.new do |task|
|
9
|
+
task.file_set('lib/**/*.rb', 'code')
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Display LOC stats"
|
13
|
+
task :stats do
|
14
|
+
puts "\n## Production Code Stats"
|
15
|
+
sh "countloc -r lib/kitchen"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run all quality tasks"
|
19
|
+
task :quality => [:cane, :tailor, :stats]
|
20
|
+
|
21
|
+
task :default => [ :quality ]
|
@@ -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_sandbox_version.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "kitchen-vagrant_sandbox"
|
8
|
+
gem.version = Kitchen::Driver::VAGRANT_VERSION
|
9
|
+
gem.license = 'Apache 2.0'
|
10
|
+
gem.authors = ["Ryota Arai"]
|
11
|
+
gem.email = ["ryota.arai@gmail.com"]
|
12
|
+
gem.description = "Kitchen::Driver::VagrantSandbox - A Vagrant Driver with sandbox for Test Kitchen. (Fork Version of Kitchen::Driver::Vagrant)"
|
13
|
+
gem.summary = gem.description
|
14
|
+
gem.homepage = "https://github.com/ryotarai/kitchen-vagrant_sandbox/"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = []
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_dependency 'test-kitchen', '~> 1.0.0.beta.1'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'cane'
|
24
|
+
gem.add_development_dependency 'tailor'
|
25
|
+
gem.add_development_dependency 'countloc'
|
26
|
+
end
|
@@ -0,0 +1,245 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Modified version by Ryota Arai (<ryota.arai@gmail.com>)
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
6
|
+
#
|
7
|
+
# Copyright (C) 2012, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
|
21
|
+
require 'fileutils'
|
22
|
+
require 'rubygems/version'
|
23
|
+
|
24
|
+
require 'kitchen'
|
25
|
+
require 'kitchen/vagrant_sandbox/vagrantfile_creator'
|
26
|
+
|
27
|
+
module Kitchen
|
28
|
+
|
29
|
+
module Driver
|
30
|
+
|
31
|
+
# Vagrant driver for Kitchen. It communicates to Vagrant via the CLI.
|
32
|
+
#
|
33
|
+
# @author Fletcher Nichol <fnichol@nichol.ca>
|
34
|
+
#
|
35
|
+
# @todo Vagrant installation check and version will be placed into any
|
36
|
+
# dependency hook checks when feature is released
|
37
|
+
class VagrantSandbox < Kitchen::Driver::SSHBase
|
38
|
+
|
39
|
+
default_config :customize, { :memory => '256' }
|
40
|
+
default_config :synced_folders, {}
|
41
|
+
default_config :box do |driver|
|
42
|
+
driver.default_values("box")
|
43
|
+
end
|
44
|
+
default_config :box_url do |driver|
|
45
|
+
driver.default_values("box_url")
|
46
|
+
end
|
47
|
+
|
48
|
+
required_config :box
|
49
|
+
|
50
|
+
no_parallel_for :create, :destroy
|
51
|
+
|
52
|
+
def create(state)
|
53
|
+
create_vagrantfile
|
54
|
+
if sandbox_on?
|
55
|
+
sandbox_rollback
|
56
|
+
set_ssh_state(state)
|
57
|
+
info("Vagrant instance #{instance.to_str} created (by rollback).")
|
58
|
+
else
|
59
|
+
cmd = "vagrant up"
|
60
|
+
cmd += " --no-provision" unless config[:use_vagrant_provision]
|
61
|
+
cmd += " --provider=#{@config[:provider]}" if @config[:provider]
|
62
|
+
run cmd
|
63
|
+
set_ssh_state(state)
|
64
|
+
sandbox_on
|
65
|
+
info("Vagrant instance #{instance.to_str} created.")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def converge(state)
|
70
|
+
create_vagrantfile
|
71
|
+
if config[:use_vagrant_provision] && !config[:do_not_vagrant_provision_in_converge]
|
72
|
+
run "vagrant provision"
|
73
|
+
else
|
74
|
+
super
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup(state)
|
79
|
+
create_vagrantfile
|
80
|
+
super
|
81
|
+
end
|
82
|
+
|
83
|
+
def verify(state)
|
84
|
+
create_vagrantfile
|
85
|
+
super
|
86
|
+
end
|
87
|
+
|
88
|
+
def destroy(state)
|
89
|
+
if ENV['KITCHEN_DESTROY_VM']
|
90
|
+
create_vagrantfile
|
91
|
+
@vagrantfile_created = false
|
92
|
+
run "vagrant destroy -f"
|
93
|
+
FileUtils.rm_rf(vagrant_root)
|
94
|
+
info("Vagrant instance #{instance.to_str} destroyed.")
|
95
|
+
state.delete(:hostname)
|
96
|
+
else
|
97
|
+
info "If you would like to destroy vagrant VM, run `KITCHEN_DESTROY_VM=1 kitchen destroy <REGEX>`"
|
98
|
+
# return if state[:hostname].nil?
|
99
|
+
#
|
100
|
+
# sandbox_rollback
|
101
|
+
# info("Vagrant instance #{instance.to_str} rollbacked.")
|
102
|
+
# state.delete(:hostname)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def verify_dependencies
|
107
|
+
check_vagrant_version
|
108
|
+
check_berkshelf_plugin if config[:use_vagrant_berkshelf_plugin]
|
109
|
+
end
|
110
|
+
|
111
|
+
def default_values(value)
|
112
|
+
(default_boxes[instance.platform.name] || Hash.new)[value]
|
113
|
+
end
|
114
|
+
|
115
|
+
protected
|
116
|
+
|
117
|
+
WEBSITE = "http://downloads.vagrantup.com/"
|
118
|
+
MIN_VER = "1.1.0"
|
119
|
+
OMNITRUCK_PREFIX = "https://opscode-vm-bento.s3.amazonaws.com/vagrant"
|
120
|
+
PLATFORMS = %w{
|
121
|
+
ubuntu-10.04 ubuntu-12.04 ubuntu-12.10 ubuntu-13.04
|
122
|
+
centos-6.4 centos-5.9 debian-7.1.0
|
123
|
+
}
|
124
|
+
|
125
|
+
def default_boxes
|
126
|
+
@default_boxes ||= begin
|
127
|
+
hash = Hash.new
|
128
|
+
PLATFORMS.each do |platform|
|
129
|
+
hash[platform] = Hash.new
|
130
|
+
hash[platform]["box"] = "opscode-#{platform}"
|
131
|
+
hash[platform]["box_url"] =
|
132
|
+
"#{OMNITRUCK_PREFIX}/opscode_#{platform}_provisionerless.box"
|
133
|
+
end
|
134
|
+
hash
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def run(cmd, options = {})
|
139
|
+
cmd = "echo #{cmd}" if config[:dry_run]
|
140
|
+
run_command(cmd, { :cwd => vagrant_root }.merge(options))
|
141
|
+
end
|
142
|
+
|
143
|
+
def silently_run(cmd, options = {})
|
144
|
+
options = {
|
145
|
+
:live_stream => nil,
|
146
|
+
:quiet => logger.debug? ? false : true,
|
147
|
+
}.merge(options)
|
148
|
+
run_command(cmd, options)
|
149
|
+
end
|
150
|
+
|
151
|
+
def vagrant_root
|
152
|
+
@vagrant_root ||= File.join(
|
153
|
+
config[:kitchen_root], %w{.kitchen kitchen-vagrant}, instance.name
|
154
|
+
)
|
155
|
+
end
|
156
|
+
|
157
|
+
def create_vagrantfile
|
158
|
+
return if @vagrantfile_created
|
159
|
+
|
160
|
+
vagrantfile = File.join(vagrant_root, "Vagrantfile")
|
161
|
+
debug("Creating Vagrantfile for #{instance.to_str} (#{vagrantfile})")
|
162
|
+
FileUtils.mkdir_p(vagrant_root)
|
163
|
+
File.open(vagrantfile, "wb") { |f| f.write(creator.render) }
|
164
|
+
@vagrantfile_created = true
|
165
|
+
end
|
166
|
+
|
167
|
+
def creator
|
168
|
+
Kitchen::VagrantSandbox::VagrantfileCreator.new(instance, config)
|
169
|
+
end
|
170
|
+
|
171
|
+
def set_ssh_state(state)
|
172
|
+
hash = vagrant_ssh_config
|
173
|
+
|
174
|
+
state[:hostname] = hash["HostName"]
|
175
|
+
state[:username] = hash["User"]
|
176
|
+
state[:ssh_key] = hash["IdentityFile"]
|
177
|
+
state[:port] = hash["Port"]
|
178
|
+
end
|
179
|
+
|
180
|
+
def vagrant_ssh_config
|
181
|
+
output = run("vagrant ssh-config", :live_stream => nil)
|
182
|
+
lines = output.split("\n").map do |line|
|
183
|
+
tokens = line.strip.partition(" ")
|
184
|
+
[tokens.first, tokens.last.gsub(/"/, '')]
|
185
|
+
end
|
186
|
+
Hash[lines]
|
187
|
+
end
|
188
|
+
|
189
|
+
def vagrant_version
|
190
|
+
version_string = silently_run("vagrant --version")
|
191
|
+
version_string = version_string.chomp.split(" ").last
|
192
|
+
rescue Errno::ENOENT
|
193
|
+
raise UserError, "Vagrant #{MIN_VER} or higher is not installed." +
|
194
|
+
" Please download a package from #{WEBSITE}."
|
195
|
+
end
|
196
|
+
|
197
|
+
def check_vagrant_version
|
198
|
+
version = vagrant_version
|
199
|
+
if Gem::Version.new(version) < Gem::Version.new(MIN_VER)
|
200
|
+
raise UserError, "Detected an old version of Vagrant (#{version})." +
|
201
|
+
" Please upgrade to version #{MIN_VER} or higher from #{WEBSITE}."
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def check_berkshelf_plugin
|
206
|
+
if File.exists?(File.join(config[:kitchen_root], "Berksfile"))
|
207
|
+
plugins = silently_run("vagrant plugin list").split("\n")
|
208
|
+
if ! plugins.find { |p| p =~ /^vagrant-berkshelf\b/ }
|
209
|
+
raise UserError, "Detected a Berksfile but the vagrant-berkshelf" +
|
210
|
+
" plugin was not found in Vagrant. Please run:" +
|
211
|
+
" `vagrant plugin install vagrant-berkshelf' and retry."
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def check_sandbox_plugin_installed
|
217
|
+
unless silently_run('vagrant help', returns: 0..1) =~ /^\s{5}sandbox$/
|
218
|
+
raise UserError, <<-EOS
|
219
|
+
Vagrant sandbox plugin is not installed.
|
220
|
+
You can install the plugin by `vagrant plugin install sahara`.
|
221
|
+
EOS
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def sandbox_on?
|
226
|
+
check_sandbox_plugin_installed
|
227
|
+
return true if run('vagrant sandbox status') =~ /Sandbox\ mode\ is\ on/
|
228
|
+
false
|
229
|
+
end
|
230
|
+
|
231
|
+
def sandbox_on
|
232
|
+
check_sandbox_plugin_installed
|
233
|
+
run 'vagrant sandbox on'
|
234
|
+
end
|
235
|
+
|
236
|
+
def sandbox_rollback
|
237
|
+
check_sandbox_plugin_installed
|
238
|
+
unless sandbox_on?
|
239
|
+
raise UserError, "sandbox mode is not on"
|
240
|
+
end
|
241
|
+
run 'vagrant sandbox rollback'
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Modified version by Ryota Arai (<ryota.arai@gmail.com>)
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
6
|
+
#
|
7
|
+
# Copyright (C) 2012, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
|
21
|
+
module Kitchen
|
22
|
+
|
23
|
+
module Driver
|
24
|
+
|
25
|
+
# Version string for Vagrant Sandbox Kitchen driver
|
26
|
+
VAGRANT_VERSION = "0.1.0"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Modified version by Ryota Arai (<ryota.arai@gmail.com>)
|
4
|
+
#
|
5
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>)
|
6
|
+
#
|
7
|
+
# Copyright (C) 2013, Fletcher Nichol
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
|
21
|
+
module Kitchen
|
22
|
+
|
23
|
+
module VagrantSandbox
|
24
|
+
|
25
|
+
# Class to render Vagrantfiles to be used by the Kitchen Vagrant driver.
|
26
|
+
#
|
27
|
+
# @author Fletcher Nichol <fnichol@nichol.ca>
|
28
|
+
class VagrantfileCreator
|
29
|
+
|
30
|
+
def initialize(instance, config)
|
31
|
+
@instance = instance
|
32
|
+
@config = config
|
33
|
+
end
|
34
|
+
|
35
|
+
def render
|
36
|
+
arr = []
|
37
|
+
arr << %{Vagrant.configure("2") do |c|}
|
38
|
+
common_block(arr)
|
39
|
+
guest_block(arr)
|
40
|
+
network_block(arr)
|
41
|
+
provider_block(arr)
|
42
|
+
chef_block(arr) if config[:use_vagrant_provision]
|
43
|
+
berkshelf_block(arr) if config[:use_vagrant_berkshelf_plugin]
|
44
|
+
synced_folders_block(arr)
|
45
|
+
arr << %{end}
|
46
|
+
arr.join("\n")
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
attr_reader :instance, :config
|
52
|
+
|
53
|
+
def common_block(arr)
|
54
|
+
arr << %{ c.vm.box = "#{config[:box]}"}
|
55
|
+
arr << %{ c.vm.box_url = "#{config[:box_url]}"} if config[:box_url]
|
56
|
+
arr << %{ c.vm.hostname = "#{instance.name}.vagrantup.com"}
|
57
|
+
arr << %{ c.ssh.username = "#{config[:username]}"} if config[:username]
|
58
|
+
end
|
59
|
+
|
60
|
+
def guest_block(arr)
|
61
|
+
if config[:guest]
|
62
|
+
arr << %{ c.vm.guest = #{config[:guest]}}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def network_block(arr)
|
67
|
+
Array(config[:network]).each do |network_options|
|
68
|
+
options = Array(network_options.dup)
|
69
|
+
type = options.shift
|
70
|
+
arr << %{ c.vm.network(:#{type}, #{options.join(", ")})}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def provider_block(arr)
|
75
|
+
arr << %{ c.vm.provider :#{provider} do |p|}
|
76
|
+
case provider
|
77
|
+
when 'virtualbox'
|
78
|
+
virtualbox_customize(arr)
|
79
|
+
when 'vmware_fusion', 'vmware_workstation'
|
80
|
+
vmware_customize(arr)
|
81
|
+
when 'rackspace'
|
82
|
+
rackspace_customize(arr)
|
83
|
+
end
|
84
|
+
arr << %{ end}
|
85
|
+
end
|
86
|
+
|
87
|
+
def chef_block(arr)
|
88
|
+
arr << %{ c.vm.provision :chef_solo do |chef|}
|
89
|
+
arr << %{ chef.log_level = #{vagrant_logger_level}}
|
90
|
+
if config[:vagrant_provision_run_list]
|
91
|
+
arr << %{ chef.run_list = #{config[:vagrant_provision_run_list].inspect}}
|
92
|
+
else
|
93
|
+
arr << %{ chef.run_list = #{instance.run_list.inspect}}
|
94
|
+
end
|
95
|
+
arr << %{ chef.json = #{instance.attributes.to_s}}
|
96
|
+
if instance.suite.data_bags_path
|
97
|
+
arr << %{ chef.data_bags_path = "#{instance.suite.data_bags_path}"}
|
98
|
+
end
|
99
|
+
if key_path
|
100
|
+
arr << %{ chef.encrypted_data_bag_secret_key_path = "#{key_path}"}
|
101
|
+
end
|
102
|
+
if instance.suite.roles_path
|
103
|
+
arr << %{ chef.roles_path = "#{instance.suite.roles_path}"}
|
104
|
+
end
|
105
|
+
arr << %{ end}
|
106
|
+
end
|
107
|
+
|
108
|
+
def berkshelf_block(arr)
|
109
|
+
if File.exists?(berksfile)
|
110
|
+
arr << %{ c.berkshelf.berksfile_path = "#{berksfile}"}
|
111
|
+
arr << %{ if c.berkshelf.respond_to?(:enabled)}
|
112
|
+
arr << %{ c.berkshelf.enabled = true}
|
113
|
+
arr << %{ end}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def synced_folders_block(arr)
|
118
|
+
config[:synced_folders].each do |source, destination|
|
119
|
+
arr << %{ c.vm.synced_folder "#{source}", "#{destination}" }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def vagrant_logger_level
|
124
|
+
if instance.logger.debug?
|
125
|
+
":debug"
|
126
|
+
elsif instance.logger.info?
|
127
|
+
":info"
|
128
|
+
elsif instance.logger.error?
|
129
|
+
":error"
|
130
|
+
elsif instance.logger.fatal?
|
131
|
+
":fatal"
|
132
|
+
else
|
133
|
+
":info"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def berksfile
|
138
|
+
File.join(config[:kitchen_root], "Berksfile")
|
139
|
+
end
|
140
|
+
|
141
|
+
def provider
|
142
|
+
config[:provider] || ENV['VAGRANT_DEFAULT_PROVIDER'] || 'virtualbox'
|
143
|
+
end
|
144
|
+
|
145
|
+
def virtualbox_customize(arr)
|
146
|
+
config[:customize].each do |key, value|
|
147
|
+
arr << %{ p.customize ["modifyvm", :id, "--#{key}", "#{value}"]}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def vmware_customize(arr)
|
152
|
+
config[:customize].each do |key, value|
|
153
|
+
if key == :memory
|
154
|
+
# XXX: This is kind of a hack to address the fact that
|
155
|
+
# "memory" is a default attribute in our Vagrant driver.
|
156
|
+
#
|
157
|
+
# The VMware VMX format expects to see "memsize" instead of
|
158
|
+
# just "memory" like Virtualbox would. So if "memsize" has
|
159
|
+
# been specified we simply ignore the "memory" option.
|
160
|
+
unless config[:customize].include?(:memsize)
|
161
|
+
arr << %{ p.vmx["memsize"] = "#{value}"}
|
162
|
+
end
|
163
|
+
else
|
164
|
+
arr << %{ p.vmx["#{key}"] = "#{value}"}
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def rackspace_customize(arr)
|
170
|
+
config[:customize].each do |key, value|
|
171
|
+
arr << %{ p.#{key} = "#{value}"}
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def key_path
|
176
|
+
return nil if instance.suite.encrypted_data_bag_secret_key_path.nil?
|
177
|
+
|
178
|
+
File.join(
|
179
|
+
config[:kitchen_root],
|
180
|
+
instance.suite.encrypted_data_bag_secret_key_path
|
181
|
+
)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-vagrant_sandbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryota Arai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: test-kitchen
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0.beta.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0.beta.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: cane
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tailor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: countloc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Kitchen::Driver::VagrantSandbox - A Vagrant Driver with sandbox for Test
|
70
|
+
Kitchen. (Fork Version of Kitchen::Driver::Vagrant)
|
71
|
+
email:
|
72
|
+
- ryota.arai@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- kitchen-vagrant_sandbox.gemspec
|
85
|
+
- lib/kitchen/driver/vagrant_sandbox.rb
|
86
|
+
- lib/kitchen/driver/vagrant_sandbox_version.rb
|
87
|
+
- lib/kitchen/vagrant_sandbox/vagrantfile_creator.rb
|
88
|
+
homepage: https://github.com/ryotarai/kitchen-vagrant_sandbox/
|
89
|
+
licenses:
|
90
|
+
- Apache 2.0
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.0.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Kitchen::Driver::VagrantSandbox - A Vagrant Driver with sandbox for Test
|
112
|
+
Kitchen. (Fork Version of Kitchen::Driver::Vagrant)
|
113
|
+
test_files: []
|