Skip to content

Commit 25b8755

Browse files
sdelanoSeth Falcon
authored andcommitted
load environment config from knife.rb
1 parent 90da7b1 commit 25b8755

5 files changed

Lines changed: 8 additions & 5 deletions

File tree

chef/lib/chef/knife.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ def configure_chef
267267
Chef::Config[:node_name] = config[:node_name] if config[:node_name]
268268
Chef::Config[:client_key] = config[:client_key] if config[:client_key]
269269
Chef::Config[:chef_server_url] = config[:chef_server_url] if config[:chef_server_url]
270+
Chef::Config[:environment] = config[:environment] if config[:environment]
270271
Mixlib::Log::Formatter.show_time = false
271272
Chef::Log.init(Chef::Config[:log_location])
272273
Chef::Log.level(Chef::Config[:log_level])

chef/lib/chef/knife/cookbook_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CookbookList < Knife
3131
:description => "Show corresponding URIs"
3232

3333
def run
34-
env = config[:environment]
34+
env = Chef::Config[:environment]
3535
api_endpoint = env ? "/environments/#{env}/cookbooks" : "/cookbooks/_latest"
3636
output(format_cookbooks_for_display(rest.get_rest(api_endpoint)))
3737
end

chef/lib/chef/knife/node_list.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class NodeList < Knife
3232
:description => "Show corresponding URIs"
3333

3434
def run
35-
output(format_list_for_display( config[:environment] ? Chef::Node.list_by_environment(config[:environment]) : Chef::Node.list ))
35+
env = Chef::Config[:environment]
36+
output(format_list_for_display( env ? Chef::Node.list_by_environment(env) : Chef::Node.list ))
3637
end
3738

3839
end

chef/spec/unit/application/knife_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
end
5151

5252
describe "with environment configuration" do
53-
it "should default to the 'default' environment" do
53+
it "should default to no environment" do
5454
with_argv(*%w{test yourself}) do
5555
@knife.should_receive(:exit).with(0)
5656
@knife.run
5757
end
58-
Chef::Config[:environment].should == 'default'
58+
Chef::Config[:environment].should == nil
5959
end
6060

6161
it "should load the environment from the config file" do

chef/spec/unit/knife/node_list_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
describe Chef::Knife::NodeList do
2222
before(:each) do
2323
Chef::Config[:node_name] = "webmonkey.example.com"
24+
Chef::Config[:environment] = nil # reset this value each time, as it is not reloaded
2425
@knife = Chef::Knife::NodeList.new
2526
@knife.stub!(:output).and_return(true)
2627
@list = {
@@ -44,7 +45,7 @@
4445
end
4546

4647
it "should list nodes in the specific environment if -E ENVIRONMENT is specified" do
47-
@knife.config = {:environment => "prod"}
48+
Chef::Config[:environment] = "prod"
4849
Chef::Node.should_receive(:list_by_environment).with("prod").and_return(@list)
4950
@knife.run
5051
end

0 commit comments

Comments
 (0)