vagrant-chef-zero 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0
2
+
3
+ * Add support for `chef_repo_path`, graciously provided by @tduffield via pull request, as I was taking too long.
4
+
1
5
  ## 0.2.10
2
6
 
3
7
  * Fix bug where we could find multiple gem paths with 'vagrant' in them, causing the construction of an erroneous Chef Zero binary path. Fixes [#10](https://github.com/andrewgross/vagrant-chef-zero/issues/10)
data/README.md CHANGED
@@ -36,6 +36,21 @@ config.chef_zero.roles = "../foobar/roles/*.json"
36
36
  config.chef_zero.cookbooks = "spec/fixtures/cookbooks"
37
37
  ```
38
38
 
39
+ Alternatively, you can use `chef_repo_path` and it will attempt to intelligently find the appropriate sub directories:
40
+
41
+ ```ruby
42
+ config.chef_zero.chef_repo_path = "../foobar/my_repo/"
43
+ # This implies
44
+ # config.chef_zero.nodes = "../foobar/nodes"
45
+ # config.chef_zero.environments = "../foobar/environments"
46
+ # config.chef_zero.data_bags = "../foobar/data_bags"
47
+ # config.chef_zero.roles = "../foobar/roles"
48
+ # config.chef_zero.cookbooks = "../foobar/coobooks"
49
+
50
+ # Failure to find any of these is ok, it will just be ignored.
51
+ ```
52
+
53
+
39
54
  As Vagrant is booting up, `vagrant-chef-zero` will search each specified location for files to upload to Chef-Zero. The upload will be done via Ridley APIs.
40
55
 
41
56
  Check out the included [Vagrantfile](https://github.com/andrewgross/vagrant-chef-zero/blob/master/Vagrantfile) for example usage.
data/Vagrantfile CHANGED
@@ -3,11 +3,12 @@ Vagrant.require_plugin "vagrant-berkshelf"
3
3
 
4
4
  Vagrant.configure("2") do |config|
5
5
  config.berkshelf.enabled = true
6
- config.chef_zero.nodes = "spec/vagrant-chef-zero/fixtures/nodes"
7
- config.chef_zero.environments = "spec/vagrant-chef-zero/fixtures/environments"
8
- config.chef_zero.data_bags = "spec/vagrant-chef-zero/fixtures/data_bags"
9
- config.chef_zero.cookbooks = "spec/vagrant-chef-zero/fixtures/cookbooks"
10
- config.chef_zero.roles = "foobar"
6
+ config.chef_zero.chef_repo_path = "spec/vagrant-chef-zero/fixtures/"
7
+ #config.chef_zero.nodes = "spec/vagrant-chef-zero/fixtures/nodes"
8
+ #config.chef_zero.environments = "spec/vagrant-chef-zero/fixtures/environments"
9
+ #config.chef_zero.data_bags = "spec/vagrant-chef-zero/fixtures/data_bags"
10
+ #config.chef_zero.cookbooks = "spec/vagrant-chef-zero/fixtures/cookbooks"
11
+ #config.chef_zero.roles = "foobar"
11
12
 
12
13
  config.vm.box = ENV['YIPIT_VAGRANT_BOX']
13
14
  config.vm.provision :chef_client do |chef|
@@ -3,6 +3,7 @@ require "vagrant"
3
3
  module VagrantPlugins
4
4
  module ChefZero
5
5
  class Config < Vagrant.plugin("2", :config)
6
+
6
7
  # Path to role fixtures
7
8
  #
8
9
  # @return [String]
@@ -33,7 +34,23 @@ module VagrantPlugins
33
34
  # @return [TrueClass, FalseClass]
34
35
  attr_accessor :enabled
35
36
 
37
+ # Path to a chef repo
38
+ #
39
+ # @return [String]
40
+ attr_reader :chef_repo_path
41
+
42
+ def chef_repo_path=(path)
43
+ @chef_repo_path = path
44
+ @roles = path_exists?("#{path}/roles") ? "#{path}/roles" : nil
45
+ @environments = path_exists?("#{path}/environments") ? "#{path}/environments" : nil
46
+ @nodes = path_exists?("#{path}/nodes") ? "#{path}/nodes" : nil
47
+ @cookbooks = path_exists?("#{path}/cookbooks") ? "#{path}/cookbooks" : nil
48
+ @data_bags = path_exists?("#{path}/data_bags") ? "#{path}/data_bags" : nil
49
+ end
50
+
51
+
36
52
  def initialize
53
+ @chef_repo_path = UNSET_VALUE
37
54
  @roles = UNSET_VALUE
38
55
  @environments = UNSET_VALUE
39
56
  @nodes = UNSET_VALUE
@@ -46,6 +63,10 @@ module VagrantPlugins
46
63
  { "Chef Zero" => [] }
47
64
  end
48
65
 
66
+ def path_exists?(path)
67
+ File.directory? path
68
+ end
69
+
49
70
  def finalize!
50
71
  @enabled = true if @enabled == UNSET_VALUE
51
72
  @roles = nil if @roles == UNSET_VALUE
@@ -53,9 +74,10 @@ module VagrantPlugins
53
74
  @nodes = nil if @nodes == UNSET_VALUE
54
75
  @cookbooks = nil if @cookbooks == UNSET_VALUE
55
76
  @data_bags = nil if @data_bags == UNSET_VALUE
77
+ @chef_repo_path = nil if @chef_repo_path == UNSET_VALUE
56
78
  {}
57
79
  end
58
80
 
59
81
  end
60
82
  end
61
- end
83
+ end
@@ -12,4 +12,4 @@ module VagrantPlugins
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ChefZero
3
- VERSION = "0.2.10"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -0,0 +1,84 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe "VagrantPlugins::ChefZero::Config" do
4
+
5
+ before do
6
+ class DummyClass < VagrantPlugins::ChefZero::Config
7
+ end
8
+ end
9
+
10
+ describe "config object is created" do
11
+
12
+ it "should set all paths to nil" do
13
+ d = DummyClass.new
14
+ d.finalize!
15
+ d.chef_repo_path.must_equal nil
16
+ d.roles.must_equal nil
17
+ d.environments.must_equal nil
18
+ d.nodes.must_equal nil
19
+ d.cookbooks.must_equal nil
20
+ d.data_bags.must_equal nil
21
+ end
22
+
23
+ end
24
+
25
+ describe "chef_repo_path is the only defined path" do
26
+
27
+ it "chef_repo_path should be set" do
28
+ d = DummyClass.new
29
+ d.chef_repo_path = "/foo"
30
+ d.finalize!
31
+ d.chef_repo_path.must_equal "/foo"
32
+ end
33
+
34
+
35
+ it "should use sane defaults and prefix all fixture paths with the chef_repo_path" do
36
+ d = DummyClass.new
37
+ d.stubs(:path_exists?).returns(true)
38
+ d.chef_repo_path = "/foo"
39
+ d.finalize!
40
+
41
+ d.roles.must_equal "/foo/roles"
42
+ d.environments.must_equal "/foo/environments"
43
+ d.nodes.must_equal "/foo/nodes"
44
+ d.cookbooks.must_equal "/foo/cookbooks"
45
+ d.data_bags.must_equal "/foo/data_bags"
46
+ end
47
+
48
+
49
+ it "should keep nil value if sane default path does not exist" do
50
+ d = DummyClass.new
51
+ d.stubs(:path_exists?).returns(true)
52
+ d.stubs(:path_exists?).with("/foo/roles").returns(false)
53
+ d.unstubs(:path_exists?)
54
+ d.chef_repo_path = "/foo"
55
+ d.finalize!
56
+
57
+ d.roles.must_equal nil
58
+ end
59
+ end
60
+
61
+ describe "chef_repo_path is defined" do
62
+
63
+ describe "specific fixture path is also defined" do
64
+
65
+ it "should use sane defaults for all fixture paths except the overloaded path" do
66
+ DummyClass.any_instance.stubs(:path_exists?).returns(true)
67
+ d = DummyClass.new
68
+ d.chef_repo_path = "/foo"
69
+ d.roles = "/bar/roles"
70
+ d.finalize!
71
+
72
+ d.roles.must_equal "/bar/roles"
73
+ d.environments.must_equal "/foo/environments"
74
+ d.nodes.must_equal "/foo/nodes"
75
+ d.cookbooks.must_equal "/foo/cookbooks"
76
+ d.data_bags.must_equal "/foo/data_bags"
77
+ end
78
+
79
+ end
80
+ end
81
+
82
+
83
+
84
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-chef-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-17 00:00:00.000000000 Z
12
+ date: 2013-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef-zero
@@ -234,6 +234,7 @@ files:
234
234
  - Makefile
235
235
  - Rakefile
236
236
  - README.md
237
+ - spec/lib/config_spec.rb
237
238
  - spec/lib/server_helpers_spec.rb
238
239
  - spec/spec_helper.rb
239
240
  - spec/vagrant-chef-zero/fixtures/cookbooks/blah/metadata.rb
@@ -276,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
276
277
  version: '0'
277
278
  segments:
278
279
  - 0
279
- hash: 1858234695228214747
280
+ hash: -1290762954162071308
280
281
  required_rubygems_version: !ruby/object:Gem::Requirement
281
282
  none: false
282
283
  requirements: