vagrant-foodtaster-server 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/README.md +3 -6
- data/lib/vagrant-foodtaster-server.rb +1 -0
- data/lib/vagrant-foodtaster-server/server.rb +78 -19
- data/lib/vagrant-foodtaster-server/server_command.rb +12 -5
- data/lib/vagrant-foodtaster-server/string_ext.rb +7 -0
- data/lib/vagrant-foodtaster-server/version.rb +1 -1
- data/vagrant-foodtaster-server.gemspec +1 -0
- metadata +7 -4
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
# Vagrant Foodtaster Server
|
2
2
|
|
3
|
-
Foodtaster is a tool for
|
4
|
-
|
5
|
-
simple DRb protocol.
|
6
|
-
|
7
|
-
Foodtaster is in early development stage, so don't expect too much
|
8
|
-
from code and functionality.
|
3
|
+
[Foodtaster](http://github.com/mlapshin/foodtaster) is a tool for
|
4
|
+
testing Chef cookbooks using RSpec and Vagrant. This Vagrant plugin
|
5
|
+
allows Foodtaster to interact with Vagrant via simple DRb protocol.
|
9
6
|
|
10
7
|
## Installation
|
11
8
|
|
@@ -4,7 +4,21 @@ class VagrantFoodtasterServer
|
|
4
4
|
@env = env
|
5
5
|
@app = app
|
6
6
|
|
7
|
-
|
7
|
+
begin
|
8
|
+
require 'sahara/session/virtualbox'
|
9
|
+
rescue LoadError
|
10
|
+
raise RuntimeError, <<-EOT.strip_heredoc
|
11
|
+
Cannot find `sahara' plugin. Please, make sure that `sahara' plugin is installed using command:
|
12
|
+
$ vagrant plugin list
|
13
|
+
|
14
|
+
If `sahara' plugin is not installed, install it:
|
15
|
+
$ vagrant plugin install sahara
|
16
|
+
EOT
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def version
|
21
|
+
VagrantFoodtasterServer::VERSION
|
8
22
|
end
|
9
23
|
|
10
24
|
def redirect_stdstreams(stdout, stderr)
|
@@ -16,19 +30,35 @@ class VagrantFoodtasterServer
|
|
16
30
|
vm = get_vm(vm_name)
|
17
31
|
|
18
32
|
if vm.state.id.to_s != 'running'
|
19
|
-
|
33
|
+
chef_run_list = get_chef_solo_run_list(vm)
|
34
|
+
provision_types = [:shell, :puppet]
|
35
|
+
|
36
|
+
unless chef_run_list.empty?
|
37
|
+
provision_types << :chef_solo
|
38
|
+
end
|
39
|
+
|
40
|
+
vm.action(:up,
|
41
|
+
provision_types: provision_types,
|
42
|
+
provision_enabled: true)
|
20
43
|
end
|
21
44
|
|
22
|
-
|
23
|
-
|
45
|
+
sahara = sahara_for(vm)
|
46
|
+
|
47
|
+
unless sahara.is_snapshot_mode_on?
|
48
|
+
sahara.on
|
24
49
|
end
|
25
50
|
end
|
26
51
|
|
27
52
|
def rollback_vm(vm_name)
|
28
53
|
vm = get_vm(vm_name)
|
29
|
-
@env.ui.info "[FT] rollback #{vm_name}"
|
30
54
|
|
31
|
-
|
55
|
+
sahara_for(vm).rollback
|
56
|
+
end
|
57
|
+
|
58
|
+
def shutdown_vm(vm_name)
|
59
|
+
vm = get_vm(vm_name)
|
60
|
+
|
61
|
+
vm.action(:halt)
|
32
62
|
end
|
33
63
|
|
34
64
|
def vm_defined?(vm_name)
|
@@ -37,18 +67,10 @@ class VagrantFoodtasterServer
|
|
37
67
|
|
38
68
|
def run_chef_on_vm(vm_name, current_run_config)
|
39
69
|
vm = get_vm(vm_name)
|
40
|
-
chef_solo_config = vm.config.vm.provisioners.find { |p| p.name == :chef_solo }
|
41
70
|
|
42
|
-
|
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:
|
71
|
+
validate_vm!(vm)
|
46
72
|
|
47
|
-
|
48
|
-
chef.cookbooks_path = %w[site-cookbooks]
|
49
|
-
end
|
50
|
-
EOT
|
51
|
-
end
|
73
|
+
chef_solo_config = vm.config.vm.provisioners.find { |p| p.name == :chef_solo }
|
52
74
|
|
53
75
|
provisioner_klass = Vagrant.plugin("2").manager.provisioners[:chef_solo]
|
54
76
|
provisioner = provisioner_klass.new(vm, chef_solo_config.config)
|
@@ -56,7 +78,11 @@ class VagrantFoodtasterServer
|
|
56
78
|
current_run_chef_solo_config = apply_current_run_config(vm.config, current_run_config)
|
57
79
|
provisioner.configure(current_run_chef_solo_config)
|
58
80
|
|
59
|
-
|
81
|
+
begin
|
82
|
+
provisioner.provision
|
83
|
+
rescue Exception
|
84
|
+
raise RuntimeError, "Chef Run failed on #{vm_name} with config #{current_run_config.inspect}"
|
85
|
+
end
|
60
86
|
end
|
61
87
|
|
62
88
|
def execute_command_on_vm(vm_name, command)
|
@@ -72,14 +98,47 @@ class VagrantFoodtasterServer
|
|
72
98
|
|
73
99
|
private
|
74
100
|
|
101
|
+
def sahara_for(vm)
|
102
|
+
Sahara::Session::Virtualbox.new(vm)
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_chef_solo_run_list(vm)
|
106
|
+
vm.config.vm.provisioners.map do |c|
|
107
|
+
if c.name == :chef_solo
|
108
|
+
c.config.run_list
|
109
|
+
else
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
end.compact.flatten
|
113
|
+
end
|
114
|
+
|
75
115
|
def get_vm(vm_name)
|
76
116
|
@env.machine(vm_name, :virtualbox)
|
77
117
|
end
|
78
118
|
|
119
|
+
def validate_vm!(vm)
|
120
|
+
chef_solo_config = vm.config.vm.provisioners.find { |p| p.name == :chef_solo }
|
121
|
+
|
122
|
+
unless chef_solo_config
|
123
|
+
raise RuntimeError, <<-EOT.strip_heredoc
|
124
|
+
VM '#{vm.name}' doesn't have a configured chef-solo provisioner, which is requied by Foodtaster to run specs on this VM.
|
125
|
+
Please, add dummy chef-solo provisioner to your Vagrantfile, like this:
|
126
|
+
config.vm.provision :chef_solo do |chef|
|
127
|
+
chef.cookbooks_path = %w[site-cookbooks]
|
128
|
+
end
|
129
|
+
EOT
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
79
133
|
def apply_current_run_config(vm_config, current_run_config)
|
80
134
|
modified_config = vm_config.dup
|
81
|
-
|
82
|
-
modified_config.vm.provisioners
|
135
|
+
|
136
|
+
provisioner_index = modified_config.vm.provisioners.find_index do |prov|
|
137
|
+
prov.name == :chef_solo
|
138
|
+
end
|
139
|
+
|
140
|
+
modified_config.vm.provisioners[provisioner_index].config.run_list = current_run_config[:run_list]
|
141
|
+
modified_config.vm.provisioners[provisioner_index].config.json = current_run_config[:json]
|
83
142
|
|
84
143
|
modified_config
|
85
144
|
end
|
@@ -8,12 +8,19 @@ class VagrantFoodtasterServer
|
|
8
8
|
|
9
9
|
port_number = argv.size == 0 ? 35672 : argv[0].to_i
|
10
10
|
DRb.start_service "druby://localhost:#{port_number}", VagrantFoodtasterServer::Server.new(@app, @env)
|
11
|
+
DRb.thread.join
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
rescue RuntimeError, Errno::EADDRINUSE => e
|
14
|
+
write_formatted_exception_message(e)
|
15
|
+
rescue Interrupt
|
16
|
+
DRb.stop_service
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def write_formatted_exception_message(e)
|
22
|
+
error = "#{e.message}\n\nServer Error Backtrace:\n #{e.backtrace.join("\n ")}"
|
23
|
+
@env.ui.error(error)
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
@@ -11,6 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.description = %q{A Foodtaster DRb server.}
|
12
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
13
|
gem.homepage = ""
|
14
|
+
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
16
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-foodtaster-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.2
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mike Lapshin
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Foodtaster DRb server.
|
15
15
|
email:
|
@@ -27,10 +27,12 @@ files:
|
|
27
27
|
- lib/vagrant-foodtaster-server/plugin.rb
|
28
28
|
- lib/vagrant-foodtaster-server/server.rb
|
29
29
|
- lib/vagrant-foodtaster-server/server_command.rb
|
30
|
+
- lib/vagrant-foodtaster-server/string_ext.rb
|
30
31
|
- lib/vagrant-foodtaster-server/version.rb
|
31
32
|
- vagrant-foodtaster-server.gemspec
|
32
33
|
homepage: ''
|
33
|
-
licenses:
|
34
|
+
licenses:
|
35
|
+
- MIT
|
34
36
|
post_install_message:
|
35
37
|
rdoc_options: []
|
36
38
|
require_paths:
|
@@ -49,9 +51,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
51
|
version: '0'
|
50
52
|
requirements: []
|
51
53
|
rubyforge_project:
|
52
|
-
rubygems_version: 1.8.
|
54
|
+
rubygems_version: 1.8.25
|
53
55
|
signing_key:
|
54
56
|
specification_version: 3
|
55
57
|
summary: Foodtaster is a tool for testing Chef cookbooks using RSpec and Vagrant.
|
56
58
|
This plugin allows Foodtaster to interact with Vagrant via simple DRb protocol.
|
57
59
|
test_files: []
|
60
|
+
has_rdoc:
|