berkshelf-vagrant 1.0.6 → 1.1.0

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/README.md CHANGED
@@ -16,9 +16,16 @@ Install the Berkshelf Vagrant plugin
16
16
 
17
17
  ## Usage
18
18
 
19
- The Berkshelf Vagrant plugin automatically hooks into the Vagrant provisioning middleware; theres no need to perform any additional steps after installation.
19
+ Once the Berkshelf Vagrant plugin is installed it can be enabled in your Vagrantfile
20
20
 
21
- Just ensure that you have a Berksfile in the directory with your Vagrantfile and when you run `vagrant up`, `vagrant provision`, or `vagrant destroy` the Berkshelf integration will automatically kick in!
21
+
22
+ Vagrant.configure("2") do |config|
23
+ ...
24
+ config.berkshelf.enabled = true
25
+ ...
26
+ end
27
+
28
+ The plugin will look in your current working directory for your `Berksfile` by default. Just ensure that your Berksfile exists and when you run `vagrant up`, `vagrant provision`, or `vagrant destroy` the Berkshelf integration will automatically kick in!
22
29
 
23
30
  # Authors
24
31
  - Jamie Winsor (<reset@riotgames.com>)
@@ -10,9 +10,13 @@ module Berkshelf
10
10
  end
11
11
 
12
12
  def call(env)
13
- if chef_solo?(env) && env[:berkshelf].shelf
13
+ unless berkshelf_enabled?(env)
14
+ return @app.call(env)
15
+ end
16
+
17
+ if chef_solo?(env) && shelf = env[:berkshelf].shelf
14
18
  provisioners(:chef_solo, env).each do |provisioner|
15
- provisioner.config.cookbooks_path = provisioner.config.send(:prepare_folders_config, env[:berkshelf].shelf)
19
+ provisioner.config.cookbooks_path = provisioner.config.send(:prepare_folders_config, shelf)
16
20
  end
17
21
  end
18
22
 
@@ -10,6 +10,14 @@ module Berkshelf
10
10
  end
11
11
 
12
12
  def call(env)
13
+ unless berkshelf_enabled?(env)
14
+ if File.exist?(env[:global_config].berkshelf.berksfile_path)
15
+ warn_disabled_but_berksfile_exists(env)
16
+ end
17
+
18
+ return @app.call(env)
19
+ end
20
+
13
21
  env[:berkshelf].berksfile = Berkshelf::Berksfile.from_file(env[:global_config].berkshelf.berksfile_path)
14
22
 
15
23
  if chef_solo?(env)
@@ -30,6 +38,13 @@ module Berkshelf
30
38
  }.merge(env[:global_config].berkshelf.to_hash).symbolize_keys!
31
39
  env[:berkshelf].berksfile.install(opts)
32
40
  end
41
+
42
+ def warn_disabled_but_berksfile_exists(env)
43
+ env[:berkshelf].ui.warn "Berkshelf plugin is disabled but a Berksfile was found at" +
44
+ " your configured path: #{env[:global_config].berkshelf.berksfile_path}"
45
+ env[:berkshelf].ui.warn "Enable the Berkshelf plugin by setting 'config.berkshelf.enabled = true'" +
46
+ " in your vagrant config"
47
+ end
33
48
  end
34
49
  end
35
50
  end
@@ -10,6 +10,10 @@ module Berkshelf
10
10
  end
11
11
 
12
12
  def call(env)
13
+ unless berkshelf_enabled?(env)
14
+ return @app.call(env)
15
+ end
16
+
13
17
  shelf = load_shelf
14
18
 
15
19
  if shelf.nil?
@@ -10,6 +10,10 @@ module Berkshelf
10
10
  end
11
11
 
12
12
  def call(env)
13
+ unless berkshelf_enabled?(env)
14
+ return @app.call(env)
15
+ end
16
+
13
17
  if chef_client?(env)
14
18
  upload(env)
15
19
  end
@@ -8,6 +8,10 @@ module Berkshelf
8
8
  # path to the Berksfile to use with Vagrant
9
9
  attr_reader :berksfile_path
10
10
 
11
+ # @return [Boolean]
12
+ # disable of use Berks in Vagrant
13
+ attr_accessor :enabled
14
+
11
15
  # @return [Array<Symbol>]
12
16
  # only cookbooks in these groups will be installed and copied to
13
17
  # Vagrant's shelf
@@ -36,6 +40,7 @@ module Berkshelf
36
40
  @only = Array.new
37
41
  @node_name = Berkshelf::Config.instance.chef.node_name
38
42
  @client_key = Berkshelf::Config.instance.chef.client_key
43
+ @enabled = false
39
44
  end
40
45
 
41
46
  # @param [String] value
@@ -53,25 +58,31 @@ module Berkshelf
53
58
  def validate(machine)
54
59
  errors = Array.new
55
60
 
56
- if machine.config.berkshelf.berksfile_path.nil?
57
- errors << "berkshelf.berksfile_path cannot be nil."
61
+ unless [TrueClass, FalseClass].include?(enabled.class)
62
+ errors << "A value for berkshelf.enabled can be true or false."
58
63
  end
59
64
 
60
- unless File.exist?(machine.config.berkshelf.berksfile_path)
61
- errors << "No Berskfile was found at #{machine.config.berkshelf.berksfile_path}."
62
- end
65
+ if enabled
66
+ if machine.config.berkshelf.berksfile_path.nil?
67
+ errors << "berkshelf.berksfile_path cannot be nil."
68
+ end
63
69
 
64
- if !except.empty? && !only.empty?
65
- errors << "A value for berkshelf.empty and berkshelf.only cannot both be defined."
66
- end
70
+ unless File.exist?(machine.config.berkshelf.berksfile_path)
71
+ errors << "No Berskfile was found at #{machine.config.berkshelf.berksfile_path}."
72
+ end
67
73
 
68
- if chef_client?(machine.env)
69
- if machine.config.berkshelf.node_name.nil?
70
- errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
74
+ if !except.empty? && !only.empty?
75
+ errors << "A value for berkshelf.empty and berkshelf.only cannot both be defined."
71
76
  end
72
77
 
73
- if machine.config.berkshelf.client_key.nil?
74
- errors << "A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
78
+ if chef_client?(machine.env)
79
+ if machine.config.berkshelf.node_name.nil?
80
+ errors << "A configuration must be set for chef.node_name when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
81
+ end
82
+
83
+ if machine.config.berkshelf.client_key.nil?
84
+ errors << "A configuration must be set for chef.client_key when using the chef_client provisioner. Run 'berks configure' or edit your configuration."
85
+ end
75
86
  end
76
87
  end
77
88
 
@@ -22,7 +22,7 @@ module Berkshelf
22
22
  # @return [Array]
23
23
  def provisioners(name, env)
24
24
  config_global = env.respond_to?(:config_global) ? env.config_global : env[:global_config]
25
-
25
+
26
26
  config_global.vm.provisioners.select { |prov| prov.name == name }
27
27
  end
28
28
 
@@ -43,6 +43,15 @@ module Berkshelf
43
43
  def chef_client?(env)
44
44
  provisioners(:chef_client, env).any?
45
45
  end
46
+
47
+ # Determine if the Berkshelf plugin should be run for the given environment
48
+ #
49
+ # @param [Vagrant::Environment] env
50
+ #
51
+ # @return [Boolean]
52
+ def berkshelf_enabled?(env)
53
+ env[:global_config].berkshelf.enabled
54
+ end
46
55
  end
47
56
  end
48
57
  end
@@ -1,5 +1,5 @@
1
1
  module Berkshelf
2
2
  module Vagrant
3
- VERSION = "1.0.6"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -2,13 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe Berkshelf::Vagrant::Config do
4
4
  let(:unset_value) { described_class::UNSET_VALUE }
5
-
6
- subject { described_class.new }
5
+ let(:config) { described_class.new }
7
6
 
8
7
  it "sets a path to a Berksfile in the current working directory for berksfile_path" do
9
8
  subject.berksfile_path.should eql(File.join(Dir.pwd, "Berksfile"))
10
9
  end
11
10
 
11
+ it "set the value of disabled to a false" do
12
+ config.enabled.should be false
13
+ end
14
+
12
15
  it "sets the value of only to an empty array" do
13
16
  subject.only.should be_a(Array)
14
17
  subject.only.should be_empty
@@ -32,26 +35,46 @@ describe Berkshelf::Vagrant::Config do
32
35
  let(:config) { double('config', berkshelf: subject) }
33
36
  let(:machine) { double('machine', config: config, env: env) }
34
37
 
35
- before(:each) do
38
+ before do
36
39
  subject.finalize!
37
- subject.should_receive(:chef_client?).with(env).and_return(true)
38
40
  end
39
41
 
40
- let(:result) { subject.validate(machine) }
42
+ context "when the plugin is enabled" do
43
+ before(:each) do
44
+ subject.stub(enabled: true)
45
+ subject.should_receive(:chef_client?).with(env).and_return(true)
46
+ end
47
+
48
+ let(:result) { subject.validate(machine) }
41
49
 
42
- it "returns a Hash with a 'berkshelf configuration' key" do
43
- result.should be_a(Hash)
44
- result.should have_key("berkshelf configuration")
50
+ it "returns a Hash with a 'berkshelf configuration' key" do
51
+ result.should be_a(Hash)
52
+ result.should have_key("berkshelf configuration")
53
+ end
54
+
55
+ context "when all validations pass" do
56
+ before(:each) do
57
+ File.should_receive(:exist?).with(subject.berksfile_path).and_return(true)
58
+ end
59
+
60
+ it "contains an empty Array for the 'berkshelf configuration' key" do
61
+ result["berkshelf configuration"].should be_a(Array)
62
+ result["berkshelf configuration"].should be_empty
63
+ end
64
+ end
45
65
  end
46
66
 
47
- context "when all validations pass" do
48
- before(:each) do
49
- File.should_receive(:exist?).with(subject.berksfile_path).and_return(true)
67
+ context "when the plugin is disabled" do
68
+ let(:machine) { double('machine') }
69
+
70
+ before do
71
+ subject.stub(enabled: false)
50
72
  end
51
73
 
52
- it "contains an empty Array for the 'berkshelf configuration' key" do
53
- result["berkshelf configuration"].should be_a(Array)
54
- result["berkshelf configuration"].should be_empty
74
+ it "does not perform any validations" do
75
+ machine.should_not_receive(:config)
76
+
77
+ subject.validate(machine)
55
78
  end
56
79
  end
57
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.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-03-21 00:00:00.000000000 Z
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: berkshelf
@@ -240,10 +240,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  version: '0'
241
241
  segments:
242
242
  - 0
243
- hash: -1000128588332199351
243
+ hash: -2045934776218572655
244
244
  requirements: []
245
245
  rubyforge_project:
246
- rubygems_version: 1.8.24
246
+ rubygems_version: 1.8.23
247
247
  signing_key:
248
248
  specification_version: 3
249
249
  summary: A Vagrant plugin to add Berkshelf integration to the Chef provisioners