Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not cache compliance when version unspecified, support 'clear_cache'
Fixes Customer Bug 236 (see there for repro) Currently, when we run `inspec compliance upload my_profile` it is cached locally in inspec when run. If we update the version in the core code and run another upload, `inspec compliance upload my_profile` again it will run the old cached version instead of running a new copy from automate. The current workaround is to specify the desired version with `inspec exec compliance://my_profile/admin#0.1.1`. The caching happens before we have forward sight into the profile's contents and only the target name. So the text used to generate the cache would be `compliance://my_profile/admin` which does not change version to version. The fix here simply identifies when we are doing a local `inspec exec compliance://` (hitting local profiles does not generate a cache) and skips the cache if there's no version specified. This will eliminate the unexpected behavior. Additionally, we have included a `clear_cache` cli method for InSpec, which should assist the core team and other developers in the future when debugging edge case issues in InSpec. Signed-off-by: Nick Schwaderer <nschwaderer@chef.io>
- Loading branch information
Nick Schwaderer
committed
Oct 19, 2020
1 parent
38971c7
commit 7fc5caa
Showing
6 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "functional/helper" | ||
require "securerandom" | ||
|
||
describe "inspec check" do | ||
include FunctionalHelper | ||
|
||
parallelize_me! | ||
|
||
describe "inspec clear_cache" do | ||
it "clears any existing cache" do | ||
dirname = File.expand_path("~/.inspec/cache") | ||
unless File.directory?(dirname) | ||
FileUtils.mkdir_p(dirname) | ||
end | ||
newfile = "#{dirname}/#{SecureRandom.hex(10)}.txt" | ||
File.write(newfile, SecureRandom.hex(100)) | ||
|
||
assert !Dir.glob(newfile).empty? | ||
|
||
out = inspec("clear_cache") | ||
|
||
assert_empty Dir.glob(newfile) | ||
assert_exit_code 0, out | ||
_(out.stdout).must_include "== InSpec cache cleared successfully ==\n" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters