summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan DeLeo <danielsdeleo@mac.com>2009-10-09 00:29:57 -0600
committerDan DeLeo <danielsdeleo@mac.com>2009-10-09 00:36:51 -0600
commitd9c07345e6b0da0bfbaa8a5f190f2d0993791390 (patch)
tree0af15368fc35aea6d575ebd75bf1b4f4669610c2
parent693f120d50ab0bdb0933258682e132d2f3e742aa (diff)
downloadchef-d9c07345e6b0da0bfbaa8a5f190f2d0993791390.tar.gz
[CHEF-603] gem install from gems.yml support
-rw-r--r--chef/lib/chef/provider/deploy.rb21
-rw-r--r--chef/spec/unit/provider/deploy_spec.rb31
2 files changed, 51 insertions, 1 deletions
diff --git a/chef/lib/chef/provider/deploy.rb b/chef/lib/chef/provider/deploy.rb
index ec864ad657..eaa5c6cca8 100644
--- a/chef/lib/chef/provider/deploy.rb
+++ b/chef/lib/chef/provider/deploy.rb
@@ -64,7 +64,7 @@ class Chef
enforce_ownership
update_cached_repo
copy_cached_repo
- # chef-deploy then installs gems. hmmm...
+ install_gems
enforce_ownership
callback(:before_migrate, @new_resource.before_migrate)
migrate
@@ -209,6 +209,25 @@ class Chef
protected
+ def install_gems
+ gems_collection = Chef::ResourceCollection.new
+ gem_packages.each { |rbgem| gems_collection << rbgem }
+ Chef::Runner.new(@node, gems_collection).converge
+ end
+
+ def gem_packages
+ return [] unless ::File.exist?("#{release_path}/gems.yml")
+ gems = YAML.load(IO.read("#{release_path}/gems.yml"))
+
+ gems.map do |g|
+ r = Chef::Resource::GemPackage.new(g[:name], nil, node)
+ r.version g[:version]
+ r.action :install
+ r.source "http://gems.github.com"
+ r
+ end
+ end
+
def run_options(run_opts={})
run_opts[:user] = @new_resource.user if @new_resource.user
run_opts[:group] = @new_resource.group if @new_resource.group
diff --git a/chef/spec/unit/provider/deploy_spec.rb b/chef/spec/unit/provider/deploy_spec.rb
index a99401bec4..b98f86e0af 100644
--- a/chef/spec/unit/provider/deploy_spec.rb
+++ b/chef/spec/unit/provider/deploy_spec.rb
@@ -40,6 +40,7 @@ describe Chef::Provider::Deploy do
@provider.should_receive(:enforce_ownership).twice
@provider.should_receive(:update_cached_repo)
@provider.should_receive(:copy_cached_repo)
+ @provider.should_receive(:install_gems)
@provider.should_receive(:callback).with(:before_migrate, nil)
@provider.should_receive(:migrate)
@provider.should_receive(:callback).with(:before_symlink, nil)
@@ -308,4 +309,34 @@ describe Chef::Provider::Deploy do
end
end
+ describe "installing gems from a gems.yml" do
+
+ before do
+ ::File.stub!(:exist?).with("#{@expected_release_dir}/gems.yml").and_return(true)
+ @gem_list = [{:name=>"ezmobius-nanite",:version=>"0.4.1.2"},{:name=>"eventmachine", :version=>"0.12.9"}]
+ end
+
+ it "reads a gems.yml file, creating gem providers for each with action :upgrade" do
+ IO.should_receive(:read).with("#{@expected_release_dir}/gems.yml").and_return("cookie")
+ YAML.should_receive(:load).with("cookie").and_return(@gem_list)
+
+ gems = @provider.send(:gem_packages)
+
+ gems.map { |g| g.action }.should == [[:install], [:install]]
+ gems.map { |g| g.name }.should == %w{ezmobius-nanite eventmachine}
+ gems.map { |g| g.version }.should == %w{0.4.1.2 0.12.9}
+ end
+
+ it "takes a list of gem providers converges them" do
+ IO.stub!(:read)
+ YAML.stub!(:load).and_return(@gem_list)
+ gem_resources = @provider.send(:gem_packages)
+ run4r = mock("Chef::Runner")
+ Chef::Runner.should_receive(:new).with(@node, an_instance_of(Chef::ResourceCollection)).and_return(run4r)
+ run4r.should_receive(:converge)
+ @provider.send(:install_gems)
+ end
+
+ end
+
end