summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Jacob <adam@hjksolutions.com>2009-02-23 16:58:07 -0800
committerAdam Jacob <adam@hjksolutions.com>2009-02-23 16:58:07 -0800
commit409ffd22488aea6afc75ad18b32e64cc8fffcc78 (patch)
treea2d9608f1ff4502d174f28e2c5d22b98cffbbc2a
parent3865a6e46f310b36217e1bcb815708a651b23c92 (diff)
downloadchef-409ffd22488aea6afc75ad18b32e64cc8fffcc78.tar.gz
Adding feature checks for transferring remote files
-rw-r--r--features/data/cookbooks/transfer_remote_files/files/default/transfer_a_file_from_a_cookbook.txt1
-rw-r--r--features/data/cookbooks/transfer_remote_files/recipes/default.rb18
-rw-r--r--features/data/cookbooks/transfer_remote_files/recipes/should_prefer_the_file_for_this_specific_host.rb22
-rw-r--r--features/data/cookbooks/transfer_remote_files/recipes/transfer_a_file_from_a_cookbook.rb22
-rw-r--r--features/manage_files.feature3
-rw-r--r--features/steps/files.rb10
-rw-r--r--features/steps/nodes.rb1
-rw-r--r--features/steps/recipe.rb33
-rw-r--r--features/support/env.rb12
-rw-r--r--features/transfer_remote_files.feature41
10 files changed, 160 insertions, 3 deletions
diff --git a/features/data/cookbooks/transfer_remote_files/files/default/transfer_a_file_from_a_cookbook.txt b/features/data/cookbooks/transfer_remote_files/files/default/transfer_a_file_from_a_cookbook.txt
new file mode 100644
index 0000000000..9fb38fab62
--- /dev/null
+++ b/features/data/cookbooks/transfer_remote_files/files/default/transfer_a_file_from_a_cookbook.txt
@@ -0,0 +1 @@
+easy like sunday morning
diff --git a/features/data/cookbooks/transfer_remote_files/recipes/default.rb b/features/data/cookbooks/transfer_remote_files/recipes/default.rb
new file mode 100644
index 0000000000..8bba761657
--- /dev/null
+++ b/features/data/cookbooks/transfer_remote_files/recipes/default.rb
@@ -0,0 +1,18 @@
+#
+# Cookbook Name:: transfer_remote_files
+# 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.
+#
diff --git a/features/data/cookbooks/transfer_remote_files/recipes/should_prefer_the_file_for_this_specific_host.rb b/features/data/cookbooks/transfer_remote_files/recipes/should_prefer_the_file_for_this_specific_host.rb
new file mode 100644
index 0000000000..98415d1b15
--- /dev/null
+++ b/features/data/cookbooks/transfer_remote_files/recipes/should_prefer_the_file_for_this_specific_host.rb
@@ -0,0 +1,22 @@
+#
+# Cookbook Name:: transfer_remote_files
+# 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.
+#
+
+remote_file "#{node[:tmpdir]}/host_specific.txt" do
+ source "host_specific.txt"
+end \ No newline at end of file
diff --git a/features/data/cookbooks/transfer_remote_files/recipes/transfer_a_file_from_a_cookbook.rb b/features/data/cookbooks/transfer_remote_files/recipes/transfer_a_file_from_a_cookbook.rb
new file mode 100644
index 0000000000..70a650c803
--- /dev/null
+++ b/features/data/cookbooks/transfer_remote_files/recipes/transfer_a_file_from_a_cookbook.rb
@@ -0,0 +1,22 @@
+#
+# Cookbook Name:: transfer_remote_files
+# 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.
+#
+
+remote_file "#{node[:tmpdir]}/transfer_a_file_from_a_cookbook.txt" do
+ source "transfer_a_file_from_a_cookbook.txt"
+end \ No newline at end of file
diff --git a/features/manage_files.feature b/features/manage_files.feature
index 59882b95cd..0035949e16 100644
--- a/features/manage_files.feature
+++ b/features/manage_files.feature
@@ -39,4 +39,5 @@ Feature: Manage Files
When I run the chef-client
Then the run should exit '0'
And the atime of 'touch_test.txt' should be different
- And the mtime of 'touch_test.txt' should be different \ No newline at end of file
+ And the mtime of 'touch_test.txt' should be different
+ \ No newline at end of file
diff --git a/features/steps/files.rb b/features/steps/files.rb
index 2f88dbe664..7decc0cec8 100644
--- a/features/steps/files.rb
+++ b/features/steps/files.rb
@@ -53,7 +53,13 @@ Then /^the (.)time of '(.+)' should be different$/ do |time_type, filename|
end
end
-Then /^the file named '(.+)' should be owned by '(.+)'$/ do |filename, owner|
-
+Then /^a file named '(.+)' should contain '(.+)'$/ do |filename, contents|
+ file = IO.read(File.join(tmpdir, filename))
+ file.should =~ /#{contents}/m
+end
+
+Then /^a file named '(.+)' should be from the '(.+)' specific directory$/ do |filename, specificity|
+ file = IO.read(File.join(tmpdir, filename))
+ file.should == "#{specificity}\n"
end
diff --git a/features/steps/nodes.rb b/features/steps/nodes.rb
index 821ce74401..36cfb76914 100644
--- a/features/steps/nodes.rb
+++ b/features/steps/nodes.rb
@@ -28,6 +28,7 @@ Given /^a validated node$/ do
end
Given /^it includes the recipe '(.+)'$/ do |recipe|
+ @recipe = recipe
@client.node.recipes << recipe
@client.save_node
end
diff --git a/features/steps/recipe.rb b/features/steps/recipe.rb
new file mode 100644
index 0000000000..7c5c96327c
--- /dev/null
+++ b/features/steps/recipe.rb
@@ -0,0 +1,33 @@
+Given /^the cookbook has a '(.+)' named '(.+)' in the '(.+)' specific directory$/ do |file_type, filename, specificity|
+ cookbook_name, recipe_name = @recipe.split('::')
+ type_dir = file_type == 'file' ? 'files' : 'templates'
+ specific_dir = nil
+ case specificity
+ when "host"
+ specific_dir = "host-#{@client.node[:fqdn]}"
+ when "platform-version"
+ specific_dir = "#{@client.node[:platform]}-#{@client.node[:platform_version]}"
+ when "platform"
+ specific_dir = @client.node[:platform]
+ when "default"
+ specific_dir = "default"
+ end
+ new_file_dir = File.expand_path(
+ File.join(
+ File.dirname(__FILE__),
+ "..",
+ "data",
+ "cookbooks",
+ cookbook_name,
+ type_dir,
+ specific_dir
+ )
+ )
+ @cleanup_dirs << new_file_dir unless new_file_dir =~ /default$/
+ system("mkdir -p #{new_file_dir}")
+ new_file_name = File.join(new_file_dir, filename)
+ @cleanup_files << new_file_name
+ new_file = File.open(new_file_name, "w")
+ new_file.puts(specificity)
+ new_file.close
+end
diff --git a/features/support/env.rb b/features/support/env.rb
index 302e72135e..978ce818bf 100644
--- a/features/support/env.rb
+++ b/features/support/env.rb
@@ -35,6 +35,9 @@ class ChefWorld
def initialize
@client = Chef::Client.new
@tmpdir = File.join(Dir.tmpdir, "chef_integration")
+ @cleanup_files = Array.new
+ @cleanup_dirs = Array.new
+ @recipe = nil
end
end
@@ -42,3 +45,12 @@ World do
ChefWorld.new
end
+After do
+ @cleanup_files.each do |file|
+ system("rm #{file}")
+ end
+ @cleanup_dirs.each do |dir|
+ system("rm -rf #{dir}")
+ end
+end
+
diff --git a/features/transfer_remote_files.feature b/features/transfer_remote_files.feature
new file mode 100644
index 0000000000..e75f582cdf
--- /dev/null
+++ b/features/transfer_remote_files.feature
@@ -0,0 +1,41 @@
+Feature: Transfer Remote Files
+ In order to easily manage many systems at once
+ As a Developer
+ I want to manage the contents of files remotely
+
+ Scenario: Transfer a file from a cookbook
+ Given a validated node
+ And it includes the recipe 'transfer_remote_files::transfer_a_file_from_a_cookbook'
+ When I run the chef-client
+ Then the run should exit '0'
+ And a file named 'transfer_a_file_from_a_cookbook.txt' should contain 'easy like sunday morning'
+
+ Scenario: Should prefer the file for this specific host
+ Given a validated node
+ And it includes the recipe 'transfer_remote_files::should_prefer_the_file_for_this_specific_host'
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'host' specific directory
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'platform-version' specific directory
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'platform' specific directory
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'default' specific directory
+ When I run the chef-client
+ Then the run should exit '0'
+ And a file named 'host_specific.txt' should be from the 'host' specific directory
+
+ Scenario: Should prefer the file for the correct platform version
+ Given a validated node
+ And it includes the recipe 'transfer_remote_files::should_prefer_the_file_for_this_specific_host'
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'platform-version' specific directory
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'platform' specific directory
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'default' specific directory
+ When I run the chef-client
+ Then the run should exit '0'
+ And a file named 'host_specific.txt' should be from the 'platform-version' specific directory
+
+ Scenario: Should prefer the file for the correct platform
+ Given a validated node
+ And it includes the recipe 'transfer_remote_files::should_prefer_the_file_for_this_specific_host'
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'platform' specific directory
+ And the cookbook has a 'file' named 'host_specific.txt' in the 'default' specific directory
+ When I run the chef-client
+ Then the run should exit '0'
+ And a file named 'host_specific.txt' should be from the 'platform' specific directory