vagrant-foodtaster-server 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -18,3 +18,4 @@ test/tmp
18
18
  test/version_tmp
19
19
  tmp
20
20
  spec/environment/*.box
21
+ .vagrant
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in vagrant-drb-server.gemspec
4
3
  gemspec
4
+
5
+ group :development do
6
+ gem 'vagrant', github: 'mitchellh/vagrant', tag: 'v1.3.5'
7
+ end
8
+
9
+ group :test do
10
+ gem 'rspec'
11
+ end
data/README.md CHANGED
@@ -9,23 +9,20 @@ protocol.
9
9
 
10
10
  ## Installation
11
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
12
  vagrant plugin install vagrant-foodtaster-server
19
13
 
20
14
  ## Usage
21
15
 
22
16
  To start server:
23
17
 
24
- vagrant foodtaster-server
18
+ vagrant foodtaster-server [port number]
25
19
 
26
20
  To terminate press Ctrl+C.
27
21
 
28
22
  ## Limitations
29
23
 
30
24
  * only VirtualBox provider is supported
31
- * only chef-solo provisioner is supported
25
+ * only chef-solo provisioner is supported
26
+
27
+ ## Developing
28
+ For developing and testing plugin, please, place any box with installed Chef to spec/environment/test.box.
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ task_dir = File.expand_path("../tasks", __FILE__)
3
+ Dir["#{task_dir}/**/*.rake"].each do |task_file|
4
+ load task_file
5
+ end
data/bin/autospec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'autospec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'autospec')
data/bin/erubis ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'erubis' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('erubis', 'erubis')
data/bin/htmldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'htmldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'htmldiff')
data/bin/ldiff ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'ldiff' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('diff-lcs', 'ldiff')
data/bin/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/thor ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'thor' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('thor', 'thor')
data/bin/vagrant ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'vagrant' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('vagrant', 'vagrant')
@@ -8,12 +8,13 @@ module Vagrant
8
8
  def execute
9
9
  argv = parse_options
10
10
 
11
- port_number = argv.size == 0 ? 35672 : argv[0].to_i
12
- DRb.start_service "druby://localhost:#{port_number}", Vagrant::Foodtaster::Server::Server.new(@app, @env)
11
+ host, port = parse_args(argv.first)
12
+ DRb.start_service "druby://#{host}:#{port}", Vagrant::Foodtaster::Server::Server.new(@app, @env)
13
13
  DRb.thread.join
14
14
 
15
15
  rescue RuntimeError, Errno::EADDRINUSE => e
16
16
  write_formatted_exception_message(e)
17
+ exit 1
17
18
  rescue Interrupt
18
19
  DRb.stop_service
19
20
  end
@@ -24,6 +25,17 @@ module Vagrant
24
25
  error = "#{e.message}\n\nServer Error Backtrace:\n #{e.backtrace.join("\n ")}"
25
26
  @env.ui.error(error)
26
27
  end
28
+
29
+ def parse_args(args)
30
+ host, port = if args && args.include?(':')
31
+ args.split(':')
32
+ else
33
+ [nil, args]
34
+ end
35
+ host ||= 'localhost'
36
+ port ||= 35672
37
+ [host, port]
38
+ end
27
39
  end
28
40
  end
29
41
  end
@@ -1,7 +1,7 @@
1
1
  module Vagrant
2
2
  module Foodtaster
3
3
  module Server
4
- VERSION = "0.0.8"
4
+ VERSION = "0.0.9"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ Vagrant.require_plugin 'vagrant-foodtaster-server'
3
+ SERVER_IP = '10.0.2.15'
4
+
5
+ Vagrant.configure("2") do |config|
6
+ config.vm.box = "test"
7
+ config.vm.box_url = "test.box"
8
+ config.vm.network 'private_network', ip: SERVER_IP
9
+ config.vm.provision :chef_solo do |chef|
10
+ chef.cookbooks_path = %w[../fixtures/cookbooks]
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ maintainer "me"
2
+ maintainer_email "me@mail.me"
3
+ license "All rights reserved"
4
+ description "test cookboos"
5
+ long_description "Long"
6
+ version "0.0.1"
@@ -0,0 +1,4 @@
1
+ file "/tmp/hello" do
2
+ content 'Hello, Foodtaster!'
3
+ action :create
4
+ end
@@ -0,0 +1,37 @@
1
+ require 'bundler/setup'
2
+ require 'support/test_client'
3
+
4
+ PROJECT_ROOT = File.expand_path('../../', __FILE__)
5
+ SERVER_PORT = 31415
6
+ SERVER_IP = '10.0.2.15'
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ end
11
+
12
+ def with_test_root(command)
13
+ <<-BASH
14
+ cd #{PROJECT_ROOT}/spec/environment && \
15
+ #{command}
16
+ BASH
17
+ end
18
+
19
+ def start_server
20
+ @pid = Process.spawn(
21
+ with_test_root("vagrant foodtaster-server #{SERVER_PORT}"),
22
+ pgroup: true)
23
+ sleep 1
24
+ end
25
+
26
+ def stop_server
27
+ Process.kill('INT', -@pid)
28
+ end
29
+
30
+ def execute(command)
31
+ system with_test_root(command)
32
+ end
33
+
34
+
35
+ def client
36
+ @client ||= TestClient.new(SERVER_PORT)
37
+ end
@@ -0,0 +1,23 @@
1
+ require 'drb'
2
+
3
+ class TestClient
4
+ def initialize(port)
5
+ DRb.start_service("druby://localhost:0")
6
+ @v = DRbObject.new_with_uri("druby://localhost:#{port}")
7
+ end
8
+
9
+ [:vm_defined?, :rollback_vm, :vm_ip,
10
+ :put_file_to_vm, :get_file_from_vm,
11
+ :run_chef_on_vm, :execute_command_on_vm,
12
+ :shutdown_vm, :vm_running?, :initial_snapshot_made_on_vm?,
13
+ :start_vm, :make_initial_snapshot_on_vm].each do |method_name|
14
+ define_method method_name do |*args|
15
+ begin
16
+ @v.send(method_name, *args)
17
+ rescue DRb::DRbUnknownError => e
18
+ puts "Folowing exception was raised on server:\n#{e.unknown.buf}"
19
+ raise e
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,71 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-foodtaster-server/server'
3
+
4
+ require 'tempfile'
5
+ require 'tmpdir'
6
+
7
+ describe Vagrant::Foodtaster::Server::Server do
8
+ before(:each) do
9
+ start_server
10
+ end
11
+
12
+ after(:each) do
13
+ stop_server
14
+ end
15
+
16
+ before(:each) do
17
+ execute('bundle exec vagrant halt -f')
18
+ client.start_vm(:default)
19
+ end
20
+
21
+ it 'should start vm' do
22
+ client.vm_running?(:default).should be_true
23
+ end
24
+
25
+ it 'should shutdown started vm' do
26
+ client.shutdown_vm(:default)
27
+ client.vm_running?(:default).should_not be_true
28
+ end
29
+
30
+ it 'should return ip for vm' do
31
+ client.vm_ip(:default).should == SERVER_IP
32
+ end
33
+
34
+ it 'should check if vm defined' do
35
+ client.vm_defined?(:default).should be_true
36
+ client.vm_defined?(:magic).should_not be_true
37
+ end
38
+
39
+ it 'should put and get files' do
40
+ Tempfile.open('recipe') do |recipe|
41
+ client.put_file_to_vm(:default, recipe.path, 'recipe')
42
+ end
43
+
44
+ Dir.mktmpdir do |dir|
45
+ client.get_file_from_vm(:default, 'recipe', dir + '/recipe')
46
+ File.exist?(dir + '/recipe').should be_true
47
+ end
48
+ end
49
+
50
+ it 'should execute command on vm' do
51
+ result =
52
+ client.execute_command_on_vm(:default, 'echo Hello, Foodtaster!')
53
+ result[:stdout].should == "Hello, Foodtaster!\n"
54
+ result[:exit_status].should == 0
55
+ end
56
+
57
+ it 'should make initial snapshot on vm' do
58
+ client.make_initial_snapshot_on_vm(:default)
59
+ client.initial_snapshot_made_on_vm?(:default).should be_true
60
+ end
61
+
62
+ it 'should run chef in vm' do
63
+ run_config = {
64
+ run_list: ['test::chef_test_recipe'],
65
+ json: {}
66
+ }
67
+ client.run_chef_on_vm(:default, run_config)
68
+ result = client.execute_command_on_vm(:default, 'cat /tmp/hello')
69
+ result[:stdout].should == "Hello, Foodtaster!"
70
+ end
71
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ require 'vagrant'
3
+
4
+ task :spec do
5
+ opts = { cwd: File.expand_path('../../spec/environment', __FILE__) }
6
+ p opts
7
+ env = Vagrant::Environment.new(opts)
8
+ env.cli('up')
9
+ env.unload
10
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: vagrant-foodtaster-server
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.8
5
+ version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mike Lapshin
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-11-08 00:00:00.000000000 Z
13
+ date: 2013-12-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  prerelease: false
@@ -31,21 +31,43 @@ dependencies:
31
31
  description: A Foodtaster DRb server.
32
32
  email:
33
33
  - mikhail.a.lapshin@gmail.com
34
- executables: []
34
+ executables:
35
+ - autospec
36
+ - erubis
37
+ - htmldiff
38
+ - ldiff
39
+ - rspec
40
+ - thor
41
+ - vagrant
35
42
  extensions: []
36
43
  extra_rdoc_files: []
37
44
  files:
38
45
  - .gitignore
46
+ - .rspec
39
47
  - Gemfile
40
48
  - LICENSE.txt
41
49
  - README.md
42
50
  - Rakefile
51
+ - bin/autospec
52
+ - bin/erubis
53
+ - bin/htmldiff
54
+ - bin/ldiff
55
+ - bin/rspec
56
+ - bin/thor
57
+ - bin/vagrant
43
58
  - lib/vagrant-foodtaster-server.rb
44
59
  - lib/vagrant-foodtaster-server/plugin.rb
45
60
  - lib/vagrant-foodtaster-server/server.rb
46
61
  - lib/vagrant-foodtaster-server/server_command.rb
47
62
  - lib/vagrant-foodtaster-server/string_ext.rb
48
63
  - lib/vagrant-foodtaster-server/version.rb
64
+ - spec/environment/Vagrantfile
65
+ - spec/fixtures/cookbooks/test/metadata.rb
66
+ - spec/fixtures/cookbooks/test/recipes/chef_test_recipe.rb
67
+ - spec/spec_helper.rb
68
+ - spec/support/test_client.rb
69
+ - spec/vagrant-foodtaster-server/server_spec.rb
70
+ - tasks/spec.rake
49
71
  - vagrant-foodtaster-server.gemspec
50
72
  homepage: ''
51
73
  licenses:
@@ -73,5 +95,11 @@ signing_key:
73
95
  specification_version: 3
74
96
  summary: Foodtaster is a tool for testing Chef cookbooks using RSpec and Vagrant.
75
97
  This plugin allows Foodtaster to interact with Vagrant via simple DRb protocol.
76
- test_files: []
98
+ test_files:
99
+ - spec/environment/Vagrantfile
100
+ - spec/fixtures/cookbooks/test/metadata.rb
101
+ - spec/fixtures/cookbooks/test/recipes/chef_test_recipe.rb
102
+ - spec/spec_helper.rb
103
+ - spec/support/test_client.rb
104
+ - spec/vagrant-foodtaster-server/server_spec.rb
77
105
  has_rdoc: