Skip to content

Commit 409ffd2

Browse files
committed
Adding feature checks for transferring remote files
1 parent 3865a6e commit 409ffd2

10 files changed

Lines changed: 160 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
easy like sunday morning
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Cookbook Name:: transfer_remote_files
3+
# Recipe:: default
4+
#
5+
# Copyright 2009, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Cookbook Name:: transfer_remote_files
3+
# Recipe:: default
4+
#
5+
# Copyright 2009, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
remote_file "#{node[:tmpdir]}/host_specific.txt" do
21+
source "host_specific.txt"
22+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Cookbook Name:: transfer_remote_files
3+
# Recipe:: default
4+
#
5+
# Copyright 2009, Opscode
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
remote_file "#{node[:tmpdir]}/transfer_a_file_from_a_cookbook.txt" do
21+
source "transfer_a_file_from_a_cookbook.txt"
22+
end

‎features/manage_files.feature‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ Feature: Manage Files
3939
When I run the chef-client
4040
Then the run should exit '0'
4141
And the atime of 'touch_test.txt' should be different
42-
And the mtime of 'touch_test.txt' should be different
42+
And the mtime of 'touch_test.txt' should be different
43+

‎features/steps/files.rb‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@
5353
end
5454
end
5555

56-
Then /^the file named '(.+)' should be owned by '(.+)'$/ do |filename, owner|
57-
56+
Then /^a file named '(.+)' should contain '(.+)'$/ do |filename, contents|
57+
file = IO.read(File.join(tmpdir, filename))
58+
file.should =~ /#{contents}/m
59+
end
60+
61+
Then /^a file named '(.+)' should be from the '(.+)' specific directory$/ do |filename, specificity|
62+
file = IO.read(File.join(tmpdir, filename))
63+
file.should == "#{specificity}\n"
5864
end
5965

‎features/steps/nodes.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
end
2929

3030
Given /^it includes the recipe '(.+)'$/ do |recipe|
31+
@recipe = recipe
3132
@client.node.recipes << recipe
3233
@client.save_node
3334
end

‎features/steps/recipe.rb‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Given /^the cookbook has a '(.+)' named '(.+)' in the '(.+)' specific directory$/ do |file_type, filename, specificity|
2+
cookbook_name, recipe_name = @recipe.split('::')
3+
type_dir = file_type == 'file' ? 'files' : 'templates'
4+
specific_dir = nil
5+
case specificity
6+
when "host"
7+
specific_dir = "host-#{@client.node[:fqdn]}"
8+
when "platform-version"
9+
specific_dir = "#{@client.node[:platform]}-#{@client.node[:platform_version]}"
10+
when "platform"
11+
specific_dir = @client.node[:platform]
12+
when "default"
13+
specific_dir = "default"
14+
end
15+
new_file_dir = File.expand_path(
16+
File.join(
17+
File.dirname(__FILE__),
18+
"..",
19+
"data",
20+
"cookbooks",
21+
cookbook_name,
22+
type_dir,
23+
specific_dir
24+
)
25+
)
26+
@cleanup_dirs << new_file_dir unless new_file_dir =~ /default$/
27+
system("mkdir -p #{new_file_dir}")
28+
new_file_name = File.join(new_file_dir, filename)
29+
@cleanup_files << new_file_name
30+
new_file = File.open(new_file_name, "w")
31+
new_file.puts(specificity)
32+
new_file.close
33+
end

‎features/support/env.rb‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,22 @@ class ChefWorld
3535
def initialize
3636
@client = Chef::Client.new
3737
@tmpdir = File.join(Dir.tmpdir, "chef_integration")
38+
@cleanup_files = Array.new
39+
@cleanup_dirs = Array.new
40+
@recipe = nil
3841
end
3942
end
4043

4144
World do
4245
ChefWorld.new
4346
end
4447

48+
After do
49+
@cleanup_files.each do |file|
50+
system("rm #{file}")
51+
end
52+
@cleanup_dirs.each do |dir|
53+
system("rm -rf #{dir}")
54+
end
55+
end
56+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Feature: Transfer Remote Files
2+
In order to easily manage many systems at once
3+
As a Developer
4+
I want to manage the contents of files remotely
5+
6+
Scenario: Transfer a file from a cookbook
7+
Given a validated node
8+
And it includes the recipe 'transfer_remote_files::transfer_a_file_from_a_cookbook'
9+
When I run the chef-client
10+
Then the run should exit '0'
11+
And a file named 'transfer_a_file_from_a_cookbook.txt' should contain 'easy like sunday morning'
12+
13+
Scenario: Should prefer the file for this specific host
14+
Given a validated node
15+
And it includes the recipe 'transfer_remote_files::should_prefer_the_file_for_this_specific_host'
16+
And the cookbook has a 'file' named 'host_specific.txt' in the 'host' specific directory
17+
And the cookbook has a 'file' named 'host_specific.txt' in the 'platform-version' specific directory
18+
And the cookbook has a 'file' named 'host_specific.txt' in the 'platform' specific directory
19+
And the cookbook has a 'file' named 'host_specific.txt' in the 'default' specific directory
20+
When I run the chef-client
21+
Then the run should exit '0'
22+
And a file named 'host_specific.txt' should be from the 'host' specific directory
23+
24+
Scenario: Should prefer the file for the correct platform version
25+
Given a validated node
26+
And it includes the recipe 'transfer_remote_files::should_prefer_the_file_for_this_specific_host'
27+
And the cookbook has a 'file' named 'host_specific.txt' in the 'platform-version' specific directory
28+
And the cookbook has a 'file' named 'host_specific.txt' in the 'platform' specific directory
29+
And the cookbook has a 'file' named 'host_specific.txt' in the 'default' specific directory
30+
When I run the chef-client
31+
Then the run should exit '0'
32+
And a file named 'host_specific.txt' should be from the 'platform-version' specific directory
33+
34+
Scenario: Should prefer the file for the correct platform
35+
Given a validated node
36+
And it includes the recipe 'transfer_remote_files::should_prefer_the_file_for_this_specific_host'
37+
And the cookbook has a 'file' named 'host_specific.txt' in the 'platform' specific directory
38+
And the cookbook has a 'file' named 'host_specific.txt' in the 'default' specific directory
39+
When I run the chef-client
40+
Then the run should exit '0'
41+
And a file named 'host_specific.txt' should be from the 'platform' specific directory

0 commit comments

Comments
 (0)