soloist 0.0.6 → 0.0.7

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/bin/soloist CHANGED
@@ -39,12 +39,7 @@ config_generator = ChefConfigGenerator.new(soloistrc_contents, soloistrc_path)
39
39
  solo_rb = fileify(config_generator.solo_rb)
40
40
  metadata_json = fileify(config_generator.json_file)
41
41
 
42
- env_vars = ["PATH=#{ENV['PATH']}"]
43
- %w{BUNDLE_PATH GEM_HOME GEM_PATH RAILS_ENV RACK_ENV}.each do |v|
44
- env_vars << "#{v}=#{ENV[v]}" unless ENV[v].nil?
45
- end
46
-
47
- command = "sudo bash -c '#{env_vars.join(' ')} chef-solo -j #{metadata_json.path} -c #{solo_rb.path} -l #{log_level}'"
42
+ command = "sudo bash -c '#{config_generator.preserved_environment_variables_string} chef-solo -j #{metadata_json.path} -c #{solo_rb.path} -l #{log_level}'"
48
43
 
49
44
  puts "running chef: " + command
50
45
  system(command) || exit(1)
@@ -42,4 +42,17 @@ class ChefConfigGenerator
42
42
  def json_file
43
43
  json_hash.to_json
44
44
  end
45
+
46
+ def preserved_environment_variables
47
+ always_passed = %w{PATH BUNDLE_PATH GEM_HOME GEM_PATH RAILS_ENV RACK_ENV}
48
+ always_passed += @hash["env_variable_switches"].keys if @hash["env_variable_switches"]
49
+ always_passed
50
+ end
51
+
52
+ def preserved_environment_variables_string
53
+ variable_array = []
54
+ preserved_environment_variables.map do |env_variable|
55
+ "#{env_variable}=#{ENV[env_variable]}" unless ENV[env_variable].nil?
56
+ end.compact.join(" ")
57
+ end
45
58
  end
@@ -1,3 +1,3 @@
1
1
  module Soloist
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -33,6 +33,37 @@ CONFIG
33
33
  "recipes" => ['pivotal_workstation::ack']
34
34
  }
35
35
  end
36
+
37
+ describe "passing env variables to chef-solo through sudo" do
38
+ it "has a list of env variables which are passed through" do
39
+ @generator.preserved_environment_variables.should == %w{PATH BUNDLE_PATH GEM_HOME GEM_PATH RAILS_ENV RACK_ENV}
40
+ end
41
+
42
+ it "can generate an env_variable_string which is passed through sudo to chef-solo" do
43
+ ENV["FOO"]="BAR"
44
+ ENV["FAZ"]="FUZ"
45
+ @generator.stub!(:preserved_environment_variables).and_return(["FOO", "FAZ"])
46
+ @generator.preserved_environment_variables_string.should == "FOO=BAR FAZ=FUZ"
47
+ end
48
+
49
+ it "adds any environment variables that are switched in the config" do
50
+ @config = <<-CONFIG
51
+ cookbook_paths:
52
+ - ./chef/cookbooks/
53
+ recipes:
54
+ - pivotal_workstation::ack
55
+ env_variable_switches:
56
+ ME_TOO:
57
+ development:
58
+ cookbook_paths:
59
+ - ./chef/dev_cookbooks/
60
+ recipes:
61
+ - pivotal_dev::foo
62
+ CONFIG
63
+ @generator = ChefConfigGenerator.new(@config, "")
64
+ @generator.preserved_environment_variables.should =~ %w{PATH BUNDLE_PATH GEM_HOME GEM_PATH RAILS_ENV RACK_ENV ME_TOO}
65
+ end
66
+ end
36
67
  end
37
68
 
38
69
  describe "yaml config values" do
@@ -64,7 +95,6 @@ CONFIG
64
95
  @generator.json_hash.should == { "recipes" => ["pivotal_workstation::ack"]}
65
96
  end
66
97
  end
67
-
68
98
 
69
99
  describe "environment variable merging" do
70
100
  before do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soloist
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Kocher
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-08 00:00:00 -08:00
18
+ date: 2011-02-09 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency