summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Porter <wolfpakz@gmail.com>2011-05-29 19:01:27 -0700
committerBryan McLellan <btm@opscode.com>2011-06-01 17:58:35 -0700
commitc3c701f6efb5b7f8f4a2bb2b1140b9f9defd6c8e (patch)
tree56aebcaedad93847c8ef426b07306475305dfc0f
parent7c8a2f33a36d64952f6dbedb760081ba27848b15 (diff)
downloadchef-c3c701f6efb5b7f8f4a2bb2b1140b9f9defd6c8e.tar.gz
Fixed CHEF-2127 chef-client daemon does not pick up changes from chef server.
-rw-r--r--chef/lib/chef/run_context.rb2
-rw-r--r--features/chef-client/run_interval.feature17
-rw-r--r--features/data/cookbooks/sync_library_original/README.rdoc8
-rw-r--r--features/data/cookbooks/sync_library_original/libraries/sync_library.rb27
-rw-r--r--features/data/cookbooks/sync_library_original/metadata.rb6
-rw-r--r--features/data/cookbooks/sync_library_original/recipes/default.rb30
-rw-r--r--features/data/cookbooks/sync_library_updated/libraries/sync_library.rb8
-rw-r--r--features/steps/cookbook_steps.rb10
-rw-r--r--features/steps/run_client_steps.rb57
9 files changed, 164 insertions, 1 deletions
diff --git a/chef/lib/chef/run_context.rb b/chef/lib/chef/run_context.rb
index 44dc8a9012..6a173f57d4 100644
--- a/chef/lib/chef/run_context.rb
+++ b/chef/lib/chef/run_context.rb
@@ -79,7 +79,7 @@ class Chef
def load_libraries
foreach_cookbook_load_segment(:libraries) do |cookbook_name, filename|
Chef::Log.debug("Loading cookbook #{cookbook_name}'s library file: #{filename}")
- require filename
+ Kernel.load(filename)
end
end
diff --git a/features/chef-client/run_interval.feature b/features/chef-client/run_interval.feature
index db767c94d7..54046ceec6 100644
--- a/features/chef-client/run_interval.feature
+++ b/features/chef-client/run_interval.feature
@@ -10,3 +10,20 @@ Feature: Run chef-client at periodic intervals
When I run the chef-client with '-l info -i 1' for '12' seconds
Then 'INFO: Starting Chef Run' should appear on 'stdout' '2' times
+ Scenario: Run a background client for a few seconds
+ Given a validated node
+ And it includes the recipe 'run_interval'
+ When I run the chef-client in the background with '-l info -i 2'
+ And I stop the background chef-client after '10' seconds
+ Then the background chef-client should not be running
+ And 'INFO: Starting Chef Run' should appear on 'stdout' '2' times
+
+ Scenario: Run a background client with the sync_library cookbook, update sync_library between intervals and ensure updated library is run
+ Given I have restored the original 'sync_library' cookbook
+ And a validated node
+ And it includes the recipe 'sync_library'
+ When I run the chef-client in the background with '-l info -i 2'
+ And I update cookbook 'sync_library' from 'sync_library_updated' after the first run
+ And I stop the background chef-client after '10' seconds
+ Then 'INFO: First generation library' should appear on 'stdout' '1' times
+ And 'INFO: Second generation library' should appear on 'stdout' '1' times
diff --git a/features/data/cookbooks/sync_library_original/README.rdoc b/features/data/cookbooks/sync_library_original/README.rdoc
new file mode 100644
index 0000000000..8d774805b9
--- /dev/null
+++ b/features/data/cookbooks/sync_library_original/README.rdoc
@@ -0,0 +1,8 @@
+= DESCRIPTION:
+
+= REQUIREMENTS:
+
+= ATTRIBUTES:
+
+= USAGE:
+
diff --git a/features/data/cookbooks/sync_library_original/libraries/sync_library.rb b/features/data/cookbooks/sync_library_original/libraries/sync_library.rb
new file mode 100644
index 0000000000..659529670b
--- /dev/null
+++ b/features/data/cookbooks/sync_library_original/libraries/sync_library.rb
@@ -0,0 +1,27 @@
+
+require 'chef/index_queue/amqp_client'
+$sync_library_go_count ||= 0
+module SyncLibrary
+
+ def go
+ Chef::Log.info('First generation library')
+
+ # Publish the first run
+ $sync_library_go_count += 1
+ if $sync_library_go_count < 2
+ amqp = Chef::IndexQueue::AmqpClient.instance
+ queue = amqp.amqp_client.queue('sync_library_test')
+ queue.publish("first run complete")
+
+ # Wait until the message is consumed / the sync_library cookbook is updated
+ mcount = 1
+ while mcount > 0
+ Chef::Log.info("Sleeping while message is being consumed")
+ sleep 1
+ mcount = queue.message_count
+ end
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/features/data/cookbooks/sync_library_original/metadata.rb b/features/data/cookbooks/sync_library_original/metadata.rb
new file mode 100644
index 0000000000..0191f053a1
--- /dev/null
+++ b/features/data/cookbooks/sync_library_original/metadata.rb
@@ -0,0 +1,6 @@
+maintainer "Opscode"
+maintainer_email "do_not_reply@opscode.com"
+license "Apache 2.0"
+description "Installs/Configures sync_library"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version "0.1"
diff --git a/features/data/cookbooks/sync_library_original/recipes/default.rb b/features/data/cookbooks/sync_library_original/recipes/default.rb
new file mode 100644
index 0000000000..bb77f98632
--- /dev/null
+++ b/features/data/cookbooks/sync_library_original/recipes/default.rb
@@ -0,0 +1,30 @@
+#
+# Cookbook Name:: attribute_settings
+# Recipe:: default
+#
+# Copyright 2009, Opscode
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class Chef::Recipe
+ include SyncLibrary
+end
+
+# Run the library code
+go
+
+$sync_library_global ||= 2
+$sync_library_global -= 1
+exit(2) if $sync_library_global == 0
+
diff --git a/features/data/cookbooks/sync_library_updated/libraries/sync_library.rb b/features/data/cookbooks/sync_library_updated/libraries/sync_library.rb
new file mode 100644
index 0000000000..4a28bec485
--- /dev/null
+++ b/features/data/cookbooks/sync_library_updated/libraries/sync_library.rb
@@ -0,0 +1,8 @@
+
+module SyncLibrary
+
+ def go
+ Chef::Log.info('Second generation library')
+ end
+
+end \ No newline at end of file
diff --git a/features/steps/cookbook_steps.rb b/features/steps/cookbook_steps.rb
index b97f970b44..fadfc354a4 100644
--- a/features/steps/cookbook_steps.rb
+++ b/features/steps/cookbook_steps.rb
@@ -84,6 +84,16 @@ Given /^I delete the cookbook's on disk checksum files$/ do
end
end
+Given /^I have restored the original 'sync_library' cookbook$/ do
+ # Copy the original cookbook
+ source = File.join(datadir, 'cookbooks', 'sync_library_original')
+ dest = File.join(datadir, 'cookbooks', 'sync_library')
+ FileUtils.mkdir_p(dest)
+
+ system("cp -r #{source}/. #{dest}/.")
+ shell_out!("#{KNIFE_CMD} cookbook upload -c #{KNIFE_CONFIG} -o #{INTEGRATION_COOKBOOKS} sync_library")
+end
+
When /^I run the task to generate cookbook metadata for '(.+)'$/ do |cb|
self.cookbook = cb
When('I run the task to generate cookbook metadata')
diff --git a/features/steps/run_client_steps.rb b/features/steps/run_client_steps.rb
index 0ecf85ec00..2bc517605e 100644
--- a/features/steps/run_client_steps.rb
+++ b/features/steps/run_client_steps.rb
@@ -18,6 +18,7 @@
require 'chef/shell_out'
require 'chef/mixin/shell_out'
+require 'chef/index_queue/amqp_client'
include Chef::Mixin::ShellOut
@@ -42,6 +43,38 @@ When /^I run the chef\-client$/ do
@status = status
end
+When /^I run the chef\-client in the background with '(.+)'$/ do |args|
+ @stdout_filename = "/tmp/chef.run_interval.stdout.#{$$}.txt"
+ @stderr_filename = "/tmp/chef.run_interval.stderr.#{$$}.txt"
+
+ @chef_args = "#{args}"
+ @client_pid = Process.fork do
+ STDOUT.reopen(File.open(@stdout_filename, "w"))
+ STDERR.reopen(File.open(@stderr_filename, "w"))
+ exec chef_client_command_string()
+ exit 2
+ end
+end
+
+When /^I stop the background chef\-client after '(\d+)' seconds$/ do |timeout|
+ begin
+ sleep timeout.to_i
+ Process.kill("KILL", @client_pid)
+ rescue Errno::ESRCH
+ # Kill didn't work; the process exited while we were waiting, like
+ # it's supposed to.
+ end
+
+ # Read these in so they can be used in later steps.
+ @stdout = IO.read(@stdout_filename)
+ @stderr = IO.read(@stderr_filename)
+end
+
+Then /^the background chef\-client should not be running$/ do
+ system("ps -af | grep #{@client_pid} | grep -vq grep")
+ $?.exitstatus.should == 0
+end
+
When "I run the chef-client for no more than '$timeout' seconds" do |timeout|
cmd = shell_out("#{CHEF_CLIENT} -l info -i 1 -s 1 -c #{File.expand_path(File.join(configdir, 'client.rb'))}", :timeout => timeout.to_i)
@status = cmd.status
@@ -167,6 +200,30 @@ CONFIG
end
end
+When /^I update cookbook 'sync_library' from 'sync_library_updated' after the first run$/ do
+ amqp = Chef::IndexQueue::AmqpClient.instance
+ queue = amqp.amqp_client.queue("sync_library_test")
+ queue.subscribe(:timeout => 10) do |message|
+ if "first run complete" == message[:payload]
+
+ # Copy the updated library file over
+ source = File.join(datadir, 'cookbooks', 'sync_library_updated')
+ dest = File.join(datadir, 'cookbooks', 'sync_library')
+ cmd = "cp -r #{source}/. #{dest}/."
+ system(cmd)
+
+ # Upload the updated cookbook
+ knife_cmd = "#{KNIFE_CMD} cookbook upload -c #{KNIFE_CONFIG} -o #{INTEGRATION_COOKBOOKS} sync_library"
+ shell_out!(knife_cmd)
+
+ # Ack to release the client
+ queue.delivery_tag = message[:delivery_details][:delivery_tag]
+ queue.ack
+ break
+ end
+ end
+end
+
###
# Then
###