vagrant-foodtaster-server 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/vagrant-foodtaster-server.rb +3 -0
- data/lib/vagrant-foodtaster-server/plugin.rb +8 -0
- data/lib/vagrant-foodtaster-server/server.rb +87 -0
- data/lib/vagrant-foodtaster-server/server_command.rb +19 -0
- data/lib/vagrant-foodtaster-server/version.rb +3 -0
- data/vagrant-foodtaster-server.gemspec +19 -0
- metadata +57 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Mike Lapshin
|
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,31 @@
|
|
1
|
+
# Vagrant Foodtaster Server
|
2
|
+
|
3
|
+
Foodtaster is a tool for testing Chef cookbooks using RSpec and
|
4
|
+
Vagrant. This plugin allows Foodtaster to interact with Vagrant via
|
5
|
+
simple DRb protocol.
|
6
|
+
|
7
|
+
Foodtaster is in early development stage, so don't expect too much
|
8
|
+
from code and functionality.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
First, install [sahara](http://github.com/jedi4ever/sahara/) plugin for snapshot support:
|
13
|
+
|
14
|
+
vagrant plugin install sahara
|
15
|
+
|
16
|
+
Then, install Foodtaster Server:
|
17
|
+
|
18
|
+
vagrant plugin install vagrant-foodtaster-server
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
To start server:
|
23
|
+
|
24
|
+
vagrant foodtaster-server
|
25
|
+
|
26
|
+
To terminate press Ctrl+C.
|
27
|
+
|
28
|
+
## Limitations
|
29
|
+
|
30
|
+
* only VirtualBox provider is supported
|
31
|
+
* only chef-solo provisioner is supported
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class VagrantFoodtasterServer
|
2
|
+
class Server
|
3
|
+
def initialize(app, env)
|
4
|
+
@env = env
|
5
|
+
@app = app
|
6
|
+
|
7
|
+
@sahara = Sahara::Session::Command.new(@app, @env)
|
8
|
+
end
|
9
|
+
|
10
|
+
def redirect_stdstreams(stdout, stderr)
|
11
|
+
$stdout = stdout
|
12
|
+
$stderr = stderr
|
13
|
+
end
|
14
|
+
|
15
|
+
def prepare_vm(vm_name)
|
16
|
+
vm = get_vm(vm_name)
|
17
|
+
|
18
|
+
if vm.state.id.to_s != 'running'
|
19
|
+
vm.action(:up, provision_enabled: false)
|
20
|
+
end
|
21
|
+
|
22
|
+
unless @sahara.is_snapshot_mode_on?(vm)
|
23
|
+
@sahara.on(vm)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def rollback_vm(vm_name)
|
28
|
+
vm = get_vm(vm_name)
|
29
|
+
@env.ui.info "[FT] rollback #{vm_name}"
|
30
|
+
|
31
|
+
@sahara.rollback(vm)
|
32
|
+
end
|
33
|
+
|
34
|
+
def vm_defined?(vm_name)
|
35
|
+
@env.machine_names.include?(vm_name)
|
36
|
+
end
|
37
|
+
|
38
|
+
def run_chef_on_vm(vm_name, current_run_config)
|
39
|
+
vm = get_vm(vm_name)
|
40
|
+
chef_solo_config = vm.config.vm.provisioners.find { |p| p.name == :chef_solo }
|
41
|
+
|
42
|
+
unless chef_solo_config
|
43
|
+
raise RuntimeError, <<-EOT
|
44
|
+
VM '#{vm_name}' doesn't have a configured chef-solo provisioner, which is requied by Foodtaster to run specs on this VM.
|
45
|
+
Please, add dummy chef-solo provisioner to your Vagrantfile, like this:
|
46
|
+
|
47
|
+
config.vm.provision :chef_solo do |chef|
|
48
|
+
chef.cookbooks_path = %w[site-cookbooks]
|
49
|
+
end
|
50
|
+
EOT
|
51
|
+
end
|
52
|
+
|
53
|
+
provisioner_klass = Vagrant.plugin("2").manager.provisioners[:chef_solo]
|
54
|
+
provisioner = provisioner_klass.new(vm, chef_solo_config.config)
|
55
|
+
|
56
|
+
current_run_chef_solo_config = apply_current_run_config(vm.config, current_run_config)
|
57
|
+
provisioner.configure(current_run_chef_solo_config)
|
58
|
+
|
59
|
+
provisioner.provision
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute_command_on_vm(vm_name, command)
|
63
|
+
vm = get_vm(vm_name)
|
64
|
+
exec_result = {}
|
65
|
+
|
66
|
+
exec_result[:exit_status] = vm.communicate.sudo(command, error_check: false) do |stream_type, data|
|
67
|
+
exec_result[stream_type] = exec_result[stream_type].to_s + data
|
68
|
+
end
|
69
|
+
|
70
|
+
exec_result
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def get_vm(vm_name)
|
76
|
+
@env.machine(vm_name, :virtualbox)
|
77
|
+
end
|
78
|
+
|
79
|
+
def apply_current_run_config(vm_config, current_run_config)
|
80
|
+
modified_config = vm_config.dup
|
81
|
+
modified_config.vm.provisioners[0].config.run_list = current_run_config[:run_list]
|
82
|
+
modified_config.vm.provisioners[0].config.json = current_run_config[:json]
|
83
|
+
|
84
|
+
modified_config
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'drb'
|
2
|
+
require_relative 'server'
|
3
|
+
|
4
|
+
class VagrantFoodtasterServer
|
5
|
+
class ServerCommand < Vagrant.plugin(2, :command)
|
6
|
+
def execute
|
7
|
+
argv = parse_options
|
8
|
+
|
9
|
+
port_number = argv.size == 0 ? 35672 : argv[0].to_i
|
10
|
+
DRb.start_service "druby://localhost:#{port_number}", VagrantFoodtasterServer::Server.new(@app, @env)
|
11
|
+
|
12
|
+
begin
|
13
|
+
DRb.thread.join
|
14
|
+
rescue Interrupt
|
15
|
+
DRb.stop_service
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-foodtaster-server/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "vagrant-foodtaster-server"
|
8
|
+
gem.version = VagrantFoodtasterServer::VERSION
|
9
|
+
gem.authors = ["Mike Lapshin"]
|
10
|
+
gem.email = ["mikhail.a.lapshin@gmail.com"]
|
11
|
+
gem.description = %q{A Foodtaster DRb server.}
|
12
|
+
gem.summary = %q{Foodtaster is a tool for testing Chef cookbooks using RSpec and Vagrant. This plugin allows Foodtaster to interact with Vagrant via simple DRb protocol. }
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vagrant-foodtaster-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Lapshin
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Foodtaster DRb server.
|
15
|
+
email:
|
16
|
+
- mikhail.a.lapshin@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/vagrant-foodtaster-server.rb
|
27
|
+
- lib/vagrant-foodtaster-server/plugin.rb
|
28
|
+
- lib/vagrant-foodtaster-server/server.rb
|
29
|
+
- lib/vagrant-foodtaster-server/server_command.rb
|
30
|
+
- lib/vagrant-foodtaster-server/version.rb
|
31
|
+
- vagrant-foodtaster-server.gemspec
|
32
|
+
homepage: ''
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.24
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Foodtaster is a tool for testing Chef cookbooks using RSpec and Vagrant.
|
56
|
+
This plugin allows Foodtaster to interact with Vagrant via simple DRb protocol.
|
57
|
+
test_files: []
|