Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #519 from iashwash/sudo_clean
Browse files Browse the repository at this point in the history
Uses sudo when running clean
  • Loading branch information
matschaffer authored Aug 20, 2017
2 parents a9fdf73 + 2904233 commit 98a4d7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/chef/knife/solo_clean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SoloClean < Knife
def run
validate!
ui.msg "Cleaning up #{host}..."
run_command "rm -rf #{provisioning_path}"
run_command "#{sudo_command} rm -rf #{provisioning_path}"
end

def validate!
Expand All @@ -33,6 +33,10 @@ def provisioning_path
# TODO de-duplicate this method with solo cook
KnifeSolo::Tools.config_value(config, :provisioning_path, '~/chef-solo')
end

def sudo_command
KnifeSolo::Tools.config_value(config, :sudo_command, 'sudo')
end
end
end
end
8 changes: 7 additions & 1 deletion test/solo_clean_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ class SoloCleanTest < TestCase

def test_removes_provision_path
cmd = command('somehost', '--provisioning-path=/foo/bar')
cmd.expects(:run_command).with('rm -rf /foo/bar').returns(SuccessfulResult.new)
cmd.expects(:run_command).with('sudo rm -rf /foo/bar').returns(SuccessfulResult.new)
cmd.run
end

def test_removes_with_custom_sudo
cmd = command('somehost', '--sudo-command=/usr/some/sudo')
cmd.expects(:run_command).with('/usr/some/sudo rm -rf ~/chef-solo').returns(SuccessfulResult.new)
cmd.run
end

Expand Down

0 comments on commit 98a4d7f

Please sign in to comment.