Permalink
Browse files

Merge pull request #197 from matschaffer/issue/avoid-cache-path-1

Another attempt at transfering to a re-writable protected path.
  • Loading branch information...
2 parents 47f0343 + 525e232 commit 3ee5254ea429042a1bd138f006d46a59742019b0 @matschaffer committed Feb 12, 2013
View
@@ -18,6 +18,7 @@
* Drop support for Debian 5.0 Lenny (#172)
* Integration tests for Debian 6 and 7 (74c6ed1 - f299a6)
* Travis tests for both Chef 10 and 11 (#183)
+* Remove solo.rb and transfer cookbooks to user-owned path (#1, #86, #125, #128, #177). See https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.2.0
## Fixes
View
@@ -19,11 +19,12 @@ lib/knife-solo/bootstraps/darwin.rb
lib/knife-solo/bootstraps/freebsd.rb
lib/knife-solo/bootstraps/linux.rb
lib/knife-solo/bootstraps/sun_os.rb
+lib/knife-solo/config.rb
lib/knife-solo/deprecated_command.rb
lib/knife-solo/gitignore.rb
lib/knife-solo/info.rb
-lib/knife-solo/kitchen_command.rb
lib/knife-solo/node_config_command.rb
+lib/knife-solo/resources/solo.rb
lib/knife-solo/ssh_command.rb
lib/knife-solo/tools.rb
test/bootstraps_test.rb
@@ -32,6 +33,7 @@ test/gitignore_test.rb
test/integration/amazon_linux_2012_09_bootstrap_test.rb
test/integration/cases/apache2_bootstrap.rb
test/integration/cases/apache2_cook.rb
+test/integration/cases/cache_path_usage.rb
test/integration/cases/empty_cook.rb
test/integration/cases/encrypted_data_bag.rb
test/integration/centos5_6_test.rb
@@ -45,7 +47,7 @@ test/integration/ubuntu10_04_test.rb
test/integration/ubuntu12_04_bootstrap_test.rb
test/integration/ubuntu12_04_test.rb
test/integration_helper.rb
-test/kitchen_command_test.rb
+test/knife-solo/config_test.rb
test/minitest/parallel.rb
test/node_config_command_test.rb
test/solo_bootstrap_test.rb
@@ -54,6 +56,8 @@ test/solo_cook_test.rb
test/solo_init_test.rb
test/solo_prepare_test.rb
test/ssh_command_test.rb
+test/support/cache_using_cookbook/metadata.rb
+test/support/cache_using_cookbook/recipes/default.rb
test/support/config.yml.example
test/support/data_bag_key
test/support/ec2_runner.rb
@@ -2,13 +2,11 @@
require 'chef/knife/solo_cook'
require 'chef/knife/solo_prepare'
-require 'knife-solo/kitchen_command'
require 'knife-solo/ssh_command'
class Chef
class Knife
class SoloBootstrap < Knife
- include KnifeSolo::KitchenCommand
include KnifeSolo::SshCommand
deps do
@@ -36,7 +34,6 @@ def run
def validate!
validate_ssh_options!
- validate_kitchen!
end
def command_with_same_args(klass)
@@ -1,24 +1,24 @@
require 'chef/knife'
+
require 'knife-solo/ssh_command'
-require 'knife-solo/kitchen_command'
+require 'knife-solo/config'
class Chef
class Knife
class SoloClean < Knife
include KnifeSolo::SshCommand
- include KnifeSolo::KitchenCommand
banner "knife solo clean [USER@]HOSTNAME"
def run
+ @solo_config = KnifeSolo::Config.new
validate!
- Chef::Config.from_file('solo.rb')
- run_command "rm -rf #{Chef::Config.file_cache_path}"
+ run_command "rm -rf #{@solo_config.chef_path}"
end
def validate!
validate_ssh_options!
- validate_kitchen!
+ @solo_config.validate!
end
end
end
@@ -1,9 +1,10 @@
require 'chef/knife'
+require 'knife-solo'
require 'knife-solo/ssh_command'
-require 'knife-solo/kitchen_command'
require 'knife-solo/node_config_command'
require 'knife-solo/tools'
+require 'knife-solo/config'
class Chef
class Knife
@@ -13,7 +14,6 @@ class SoloCook < Knife
CHEF_VERSION_CONSTRAINT = ">=0.10.4" unless defined? CHEF_VERSION_CONSTRAINT
include KnifeSolo::SshCommand
- include KnifeSolo::KitchenCommand
include KnifeSolo::NodeConfigCommand
include KnifeSolo::Tools
@@ -52,60 +52,44 @@ class SoloCook < Knife
:description => 'Enable whyrun mode'
def run
+ @solo_config = KnifeSolo::Config.new
+
time('Run') do
if config[:skip_chef_check]
ui.warn '`--skip-chef-check` is deprecated, please use `--no-chef-check`.'
config[:chef_check] = false
end
validate!
- Chef::Config.from_file('solo.rb')
check_chef_version if config[:chef_check]
generate_node_config
librarian_install if config[:librarian]
rsync_kitchen
add_patches
+ add_solo_config unless using_custom_solorb?
cook unless config[:sync_only]
end
end
+ def_delegators :@solo_config,
+ :chef_path,
+ :using_custom_solorb?,
+ :patch_path
+
def validate!
validate_ssh_options!
- validate_kitchen!
- end
-
- def chef_path
- Chef::Config.file_cache_path
+ @solo_config.validate!
end
def chefignore
@chefignore ||= ::Chef::Cookbook::Chefignore.new("./")
end
- # cygwin rsync path must be adjusted to work
- def adjust_rsync_path(path)
- path.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
- end
-
- def adjust_rsync_path_on_node(path)
- return path unless windows_node?
- adjust_rsync_path(path)
- end
-
- def adjust_rsync_path_on_client(path)
- return path unless windows_client?
- adjust_rsync_path(path)
- end
-
# see http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
def rsync_permissions
'--chmod=ugo=rwX' if windows_client?
end
- def patch_path
- Array(Chef::Config.cookbook_path).first + "/chef_solo_patches/libraries"
- end
-
def rsync_excludes
(%w{revision-deploys tmp '.*'} + chefignore.ignores).uniq
end
@@ -149,8 +133,12 @@ def add_patches
end
end
+ def add_solo_config
+ rsync(KnifeSolo.resource('solo.rb'), chef_path)
+ end
+
def rsync(source_path, target_path, extra_opts = '')
- cmd = %Q{rsync -rl #{rsync_permissions} --rsh="ssh #{ssh_args}" #{extra_opts} #{rsync_excludes.collect{ |ignore| "--exclude #{ignore} " }.join} #{adjust_rsync_path_on_client(source_path)} :#{adjust_rsync_path_on_node(target_path)}}
+ cmd = %Q|rsync -rl #{rsync_permissions} --rsh="ssh #{ssh_args}" #{extra_opts} #{rsync_excludes.collect{ |ignore| "--exclude #{ignore} " }.join} #{source_path} :#{target_path}|
ui.msg cmd if debug?
system! cmd
end
@@ -26,7 +26,6 @@ def run
create_kitchen
create_cupboards %w[nodes roles data_bags site-cookbooks cookbooks]
librarian_init if config[:librarian]
- create_solo_config
end
def validate!
@@ -51,22 +50,6 @@ def create_kitchen
mkdir @base unless @base == '.'
end
- def create_solo_config
- solo_file = File.join(@base, 'solo.rb')
- return if File.exist? solo_file
-
- File.open(solo_file, 'w') do |f|
- f << <<-RUBY.gsub(/^ {12}/, '')
- file_cache_path "/tmp/chef-solo"
- data_bag_path "/tmp/chef-solo/data_bags"
- encrypted_data_bag_secret "/tmp/chef-solo/data_bag_key"
- cookbook_path [ "/tmp/chef-solo/site-cookbooks",
- "/tmp/chef-solo/cookbooks" ]
- role_path "/tmp/chef-solo/roles"
- RUBY
- end
- end
-
def librarian_init
cheffile = File.join(@base, 'Cheffile')
unless File.exist?(cheffile)
@@ -1,6 +1,5 @@
require 'chef/knife'
require 'knife-solo/ssh_command'
-require 'knife-solo/kitchen_command'
require 'knife-solo/node_config_command'
class Chef
@@ -9,7 +8,6 @@ class Knife
# Copyright 2010, 2011, Miquel Torres <tobami@googlemail.com>
class SoloPrepare < Knife
include KnifeSolo::SshCommand
- include KnifeSolo::KitchenCommand
include KnifeSolo::NodeConfigCommand
deps do
@@ -44,7 +42,6 @@ def run
def validate!
validate_ssh_options!
- validate_kitchen!
end
def bootstrap
View
@@ -1 +1,7 @@
require 'knife-solo/info'
+
+module KnifeSolo
+ def self.resource(name)
+ Pathname.new(__FILE__).dirname.join('knife-solo/resources', name)
+ end
+end
@@ -0,0 +1,39 @@
+require 'chef/config'
+
+module KnifeSolo
+ # Encapsulates some logic for checking and extracting
+ # path configuration from the structure of the
+ # current kitchen
+ class Config
+ def solo_path
+ Chef::Config.knife[:solo_path]
+ end
+
+ def chef_path
+ solo_path || './chef-solo'
+ end
+
+ def cookbook_path
+ if using_custom_solorb?
+ Chef::Config.from_file('solo.rb')
+ Array(Chef::Config.cookbook_path).first
+ else
+ chef_path + '/cookbooks'
+ end
+ end
+
+ def patch_path
+ cookbook_path + "/chef_solo_patches/libraries"
+ end
+
+ def using_custom_solorb?
+ File.exist?('solo.rb')
+ end
+
+ def validate!
+ raise Error, "You have a solo.rb file, but knife[:solo_path] is not set. You probably need to delete solo.rb unless you've customized it. See https://github.com/matschaffer/knife-solo/wiki/Upgrading-to-0.3.0 for more information." if using_custom_solorb? && solo_path.nil?
+ end
+
+ class Error < StandardError; end
+ end
+end
@@ -1,26 +0,0 @@
-module KnifeSolo
- module KitchenCommand
- def self.required_files
- %w(solo.rb)
- end
-
- def validate_kitchen!
- unless required_files_present?
- ui.fatal "This command must be run inside a Chef solo kitchen."
- exit 1
- end
- end
-
- def required_files_present?
- KitchenCommand.required_files.inject(true) do |m, f|
- check = File.exists?(f)
- warn_for_required_file(f) unless check
- m && check
- end
- end
-
- def warn_for_required_file(file)
- ui.error "#{file} is a required file/directory"
- end
- end
-end
@@ -0,0 +1,6 @@
+base = File.expand_path('..', __FILE__)
+
+data_bag_path base + '/data_bags'
+encrypted_data_bag_secret base + '/data_bag_key'
+role_path base + '/roles'
+cookbook_path [ base + '/site-cookbooks', base + '/cookbooks' ]
@@ -0,0 +1,13 @@
+module CachePathUsage
+ def setup
+ super
+ FileUtils.cp_r $base_dir.join('support', 'cache_using_cookbook'), 'cookbooks/cache_using_cookbook'
+ end
+
+ def test_changing_a_cached_directory_between_cooks
+ write_nodefile(run_count: 1, run_list: ["cache_using_cookbook"])
+ assert_subcommand "cook"
+ write_nodefile(run_count: 2, run_list: ["cache_using_cookbook"])
+ assert_subcommand "cook"
+ end
+end
@@ -12,4 +12,5 @@ def image_id
include EmptyCook
include Apache2Cook
include EncryptedDataBag
+ include CachePathUsage
end
@@ -1,31 +0,0 @@
-require 'test_helper'
-require 'support/kitchen_helper'
-
-require 'chef/knife'
-require 'knife-solo/kitchen_command'
-
-class DummyKitchenCommand < Chef::Knife
- include KnifeSolo::KitchenCommand
-end
-
-class KitchenCommandTest < TestCase
- include KitchenHelper
-
- def test_barks_outside_of_the_kitchen
- cmd = command
- cmd.ui.expects(:err).with(regexp_matches(/must be run inside .* kitchen/))
- outside_kitchen do
- assert_exits { cmd.validate_kitchen! }
- end
- end
-
- def test_runs_when_in_a_kitchen
- in_kitchen do
- command.validate_kitchen!
- end
- end
-
- def command(*args)
- knife_command(DummyKitchenCommand, *args)
- end
-end
Oops, something went wrong. Retry.

0 comments on commit 3ee5254

Please sign in to comment.