summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chef/lib/chef/client.rb13
-rw-r--r--chef/lib/chef/knife.rb12
-rw-r--r--features/chef-client/attribute_settings.feature57
-rw-r--r--features/chef-client/roles.feature6
-rw-r--r--features/steps/cookbook_steps.rb17
-rw-r--r--features/steps/node_steps.rb2
-rw-r--r--features/steps/run_solo.rb6
-rw-r--r--features/support/env.rb4
8 files changed, 61 insertions, 56 deletions
diff --git a/chef/lib/chef/client.rb b/chef/lib/chef/client.rb
index 55555d11a3..c7521094e7 100644
--- a/chef/lib/chef/client.rb
+++ b/chef/lib/chef/client.rb
@@ -270,15 +270,15 @@ class Chef
#
# === Returns
# rest<Chef::REST>:: returns Chef::REST connection object
- def register
- if File.exists?(Chef::Config[:client_key])
- Chef::Log.debug("Client key #{Chef::Config[:client_key]} is present - skipping registration")
+ def register(client_name=node_name, config=Chef::Config)
+ if File.exists?(config[:client_key])
+ Chef::Log.debug("Client key #{config[:client_key]} is present - skipping registration")
else
- Chef::Log.info("Client key #{Chef::Config[:client_key]} is not present - registering")
- Chef::REST.new(Chef::Config[:client_url], Chef::Config[:validation_client_name], Chef::Config[:validation_key]).register(node_name, Chef::Config[:client_key])
+ Chef::Log.info("Client key #{config[:client_key]} is not present - registering")
+ Chef::REST.new(config[:client_url], config[:validation_client_name], config[:validation_key]).register(client_name, config[:client_key])
end
# We now have the client key, and should use it from now on.
- self.rest = Chef::REST.new(Chef::Config[:chef_server_url], node_name, Chef::Config[:client_key])
+ self.rest = Chef::REST.new(config[:chef_server_url], client_name, config[:client_key])
end
# Sync_cookbooks eagerly loads all files except files and
@@ -357,5 +357,6 @@ class Chef
end
# HACK cannot load this first, but it must be loaded.
+require 'chef/cookbook_loader'
require 'chef/cookbook_version'
diff --git a/chef/lib/chef/knife.rb b/chef/lib/chef/knife.rb
index 9b370caea6..67028b6a3c 100644
--- a/chef/lib/chef/knife.rb
+++ b/chef/lib/chef/knife.rb
@@ -189,18 +189,6 @@ class Chef
@dependency_loader && @dependency_loader.call
end
- protected
-
- def load_late_dependency(dep, gem_name = nil)
- begin
- require dep
- rescue LoadError
- gem_name ||= dep.gsub('/', '-')
- ui.fatal "#{gem_name} is not installed. run \"gem install #{gem_name}\" to install it."
- exit 1
- end
- end
-
private
# :nodoc:
diff --git a/features/chef-client/attribute_settings.feature b/features/chef-client/attribute_settings.feature
index e2c9a6d1c4..018f9511e7 100644
--- a/features/chef-client/attribute_settings.feature
+++ b/features/chef-client/attribute_settings.feature
@@ -1,12 +1,13 @@
@client @attribute_settings
-Feature: Set default, normal, and override attributes
+Feature: Set default, normal, and override attributes
In order to easily configure similar systems
As an Administrator
- I want to use different kinds of attributes
+ I want to use different kinds of attributes
Scenario: Set a default attribute in a cookbook attribute file
- Given a validated node
+ Given I am an administrator
+ And a validated node
And it includes the recipe 'attribute_settings'
When I run the chef-client
Then the run should exit '0'
@@ -14,8 +15,9 @@ Feature: Set default, normal, and override attributes
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings\] attributes'
- Scenario: Set the default attribute in a role
- Given a 'role' named 'attribute_settings_default' exists
+ Scenario: Set the default attribute in a role
+ Given I am an administrator
+ And a 'role' named 'attribute_settings_default' exists
And a validated node
And it includes the role 'attribute_settings_default'
When I run the chef-client
@@ -23,9 +25,10 @@ Feature: Set default, normal, and override attributes
And a file named 'attribute_setting.txt' should contain 'came from role\[attribute_settings_default\] default attributes'
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from role\[attribute_settings_default\] default attributes'
-
- Scenario: Set the default attribute in a recipe
- Given a 'role' named 'attribute_settings_default' exists
+
+ Scenario: Set the default attribute in a recipe
+ Given I am an administrator
+ And a 'role' named 'attribute_settings_default' exists
And a validated node
And it includes the role 'attribute_settings_default'
And it includes the recipe 'attribute_settings::default_in_recipe'
@@ -36,7 +39,8 @@ Feature: Set default, normal, and override attributes
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings::default_in_recipe\]'
Scenario: Set a normal attribute in a cookbook attribute file
- Given a validated node
+ Given I am an administrator
+ And a validated node
And a 'role' named 'attribute_settings_default' exists
And it includes the role 'attribute_settings_default'
And it includes the recipe 'attribute_settings::default_in_recipe'
@@ -47,8 +51,9 @@ Feature: Set default, normal, and override attributes
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings_normal\] attributes'
- Scenario: Set a normal attribute in a cookbook recipe
- Given a validated node
+ Scenario: Set a normal attribute in a cookbook recipe
+ Given I am an administrator
+ And a validated node
And a 'role' named 'attribute_settings_default' exists
And it includes the role 'attribute_settings_default'
And it includes the recipe 'attribute_settings::default_in_recipe'
@@ -60,7 +65,8 @@ Feature: Set default, normal, and override attributes
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings_normal::normal_in_recipe\]'
Scenario: Set an override attribute in a cookbook attribute file
- Given a validated node
+ Given I am an administrator
+ And a validated node
And a 'role' named 'attribute_settings_default' exists
And it includes the role 'attribute_settings_default'
And it includes the recipe 'attribute_settings::default_in_recipe'
@@ -72,8 +78,9 @@ Feature: Set default, normal, and override attributes
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings_override\] override attributes'
- Scenario: Set the override attribute in a role
- Given a 'role' named 'attribute_settings_default' exists
+ Scenario: Set the override attribute in a role
+ Given I am an administrator
+ And a 'role' named 'attribute_settings_default' exists
And a 'role' named 'attribute_settings_override' exists
And a validated node
And it includes the role 'attribute_settings_default'
@@ -86,9 +93,10 @@ Feature: Set default, normal, and override attributes
And a file named 'attribute_setting.txt' should contain 'came from role\[attribute_settings_override\] override attributes'
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from role\[attribute_settings_override\] override attributes'
-
+
Scenario: Set the attribute in a environment
- Given an 'environment' named 'cucumber' exists
+ Given I am an administrator
+ And an 'environment' named 'cucumber' exists
And a 'role' named 'attribute_settings_default' exists
And a 'role' named 'attribute_settings_override' exists
And a validated node in the 'cucumber' environment
@@ -102,9 +110,10 @@ Feature: Set default, normal, and override attributes
And a file named 'attribute_setting.txt' should contain 'came from environment cucumber'
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from environment cucumber'
-
- Scenario: Set the override attribute in a recipe
- Given a 'role' named 'attribute_settings_default' exists
+
+ Scenario: Set the override attribute in a recipe
+ Given I am an administrator
+ And a 'role' named 'attribute_settings_default' exists
And a 'role' named 'attribute_settings_override' exists
And a validated node
And it includes the role 'attribute_settings_default'
@@ -119,8 +128,9 @@ Feature: Set default, normal, and override attributes
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings_override::override_in_recipe\]'
- Scenario: Data is removed from override attribute in a recipe
- Given a 'role' named 'attribute_settings_override' exists
+ Scenario: Data is removed from override attribute in a recipe
+ Given I am an administrator
+ And a 'role' named 'attribute_settings_override' exists
And a validated node
And it includes the role 'attribute_settings_override'
When I run the chef-client
@@ -139,14 +149,15 @@ Feature: Set default, normal, and override attributes
# Test that attributes from JSON are applied before attribute files are applied.
@chef1286
Scenario: Attributes from JSON files are normal attributes applied before attribute files
- Given a validated node
+ Given I am an administrator
+ And a validated node
And it includes the recipe 'attribute_settings_normal'
When I run the chef-client with json attributes
Then the run should exit '0'
Then a file named 'attribute_setting.txt' should contain 'came from recipe\[attribute_settings_normal\] attributes'
When the node is retrieved from the API
Then the inflated responses key 'attribute_priority_was' should match 'came from recipe\[attribute_settings_normal\] attributes'
-
+
@chef1286
Scenario: Attributes from JSON files have higher precedence than defaults
Given a 'role' named 'attribute_settings_default' exists
diff --git a/features/chef-client/roles.feature b/features/chef-client/roles.feature
index e86564c6db..26d8cf885f 100644
--- a/features/chef-client/roles.feature
+++ b/features/chef-client/roles.feature
@@ -5,7 +5,8 @@ Feature: Configure nodes based on their role
I want to define and utilize roles
Scenario: Apply a role to a node
- Given a validated node
+ Given I am an administrator
+ And a validated node
And it includes the role 'role_test'
And a 'role' named 'role_test' exists
When I run the chef-client with '-l debug'
@@ -16,7 +17,8 @@ Feature: Configure nodes based on their role
And a file named 'role_test_ruby_version.txt' should contain '1.\d+.\d+'
Scenario: Apply a role with multiple environment specific run_lists to a node
- Given an 'environment' named 'cucumber' exists
+ Given I am an administrator
+ And an 'environment' named 'cucumber' exists
And a validated node in the 'cucumber' environment
And it includes the role 'role_env_test'
And a 'role' named 'role_env_test' exists
diff --git a/features/steps/cookbook_steps.rb b/features/steps/cookbook_steps.rb
index 3e4e78f9c0..ac629e7b45 100644
--- a/features/steps/cookbook_steps.rb
+++ b/features/steps/cookbook_steps.rb
@@ -110,16 +110,15 @@ end
When "I upload a cookbook named '$name' at version '$version'" do |name, version|
- # This is total crap :(
- Chef::Config[:client_key] = rest.auth_credentials.key_file
- Chef::Config[:node_name] = rest.auth_credentials.client_name
- cookbook = @cookbook_loader_not_uploaded_at_feature_start[name]
- uploader = Chef::CookbookUploader.new(cookbook, [EXTRA_COOKBOOKS], :rest => rest)
- begin
- uploader.upload_cookbook
- rescue Exception => e
- @exception = e
+ call_as_admin do
+ cookbook = @cookbook_loader_not_uploaded_at_feature_start[name]
+ uploader = Chef::CookbookUploader.new(cookbook, [EXTRA_COOKBOOKS], :rest => rest)
+ begin
+ uploader.upload_cookbook
+ rescue Exception => e
+ @exception = e
+ end
end
end
diff --git a/features/steps/node_steps.rb b/features/steps/node_steps.rb
index 13c2dff2dd..5f97044d6f 100644
--- a/features/steps/node_steps.rb
+++ b/features/steps/node_steps.rb
@@ -21,7 +21,7 @@
###
Given /^a validated node$/ do
# client should have cached ohai assigned to it
- client.register
+ client.register(ohai[:fqdn], :client_key => client_key )
client.build_node
client.node.run_list << "integration_setup"
end
diff --git a/features/steps/run_solo.rb b/features/steps/run_solo.rb
index e9157d8bd1..458e80714d 100644
--- a/features/steps/run_solo.rb
+++ b/features/steps/run_solo.rb
@@ -27,10 +27,10 @@ When /^I run chef-solo with the '(.+)' recipe$/ do |recipe_name|
binary_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'chef', 'bin', 'chef-solo'))
command = "#{binary_path} -c #{config_file} -j #{dna_file}"
- command += " -l debug" if ENV['LOG_LEVEL'] == 'debug'
+ command += " -l debug" if Chef::Log.debug?
# Run it
- puts "Running solo: #{command}" if ENV['LOG_LEVEL'] == 'debug'
+ puts "Running solo: #{command}" if Chef::Log.debug?
status = Chef::Mixin::Command.popen4(command) do |p, i, o, e|
@stdout = o.gets(nil)
@@ -38,7 +38,7 @@ When /^I run chef-solo with the '(.+)' recipe$/ do |recipe_name|
end
@status = status
- print_output if ENV['LOG_LEVEL'] == 'debug'
+ print_output if Chef::Log.debug?
end
diff --git a/features/support/env.rb b/features/support/env.rb
index d29d60776f..d1a45d436d 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -196,6 +196,10 @@ module ChefWorld
end
end
+ def client_key
+ File.join(tmpdir, "client.pem")
+ end
+
def rest
@rest ||= Chef::REST.new('http://localhost:4000', nil, nil)
end