-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(SIMP-5636) Add confinement for checks in v2 format (#64)
* Add 'compliance_markup::debug::hiera_backend_compile_time' virtual parameter for use in debugging performance in production environments. * This is accessible both through puppet lookup and puppet catalog compilations * Add 'confine' to version 2 checks, to limit checks based on puppet facts, or special options: * module_name - fully qualified module name from metadata.json, ie puppetlabs-apache * module_version - SemanticPuppet VersionRange for checking module version, ie '>= 2.0.0' SIMP-5636 #comment pupmod-simp-compliance_markup SIMP-5600 #comment pupmod-simp-compliance_markup
- Loading branch information
1 parent
268fd61
commit d322dd7
Showing
7 changed files
with
238 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
* Fri Aug 09 2019 Dylan Cochran <[email protected]> - 3.0.1-0 | ||
- Add confinement on modules and facts to SIMP Compliance Engine. | ||
|
||
* Wed Aug 07 2019 Trevor Vaughan <[email protected]> - 3.0.0-0 | ||
- Converted the `compliance_map` function to a Puppet 4 function called | ||
`compliance_markup::compliance_map()` | ||
|
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,163 @@ | ||
#!/usr/bin/env ruby -S rspec | ||
|
||
require 'spec_helper' | ||
require 'semantic_puppet' | ||
require 'puppet/pops/lookup/context' | ||
puppetver = SemanticPuppet::Version.parse(Puppet.version) | ||
requiredver = SemanticPuppet::Version.parse("4.10.0") | ||
|
||
describe 'compliance_markup::hiera_backend' do | ||
skip 'requires function and test changes to handle incomplete LookupContext in rspec' do | ||
if (puppetver > requiredver) | ||
context "when key doesn't exist in the compliance map" do | ||
let(:hieradata) {"test_spec"} | ||
it 'should throw an error' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::nonexistent", {}, Puppet::LookupContext.new('rp_env', 'compliance_markup')) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(errored).to eql(true) | ||
end | ||
it 'should throw a :no_such_key error' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::nonexistent", {}, Puppet::LookupContext.new('rp_env', 'compliance_markup')) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(ex.to_s).to match(/no_such_key/) | ||
end | ||
end | ||
context "when key does exist in the compliance map" do | ||
let(:hieradata) {"test_spec"} | ||
it 'should not throw an error' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::testvariable", {}, Puppet::LookupContext.new('rp_env', 'compliance_markup')) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(errored).to eql(false) | ||
end | ||
it 'should not throw a :no_such_key error' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::testvariable", {}, Puppet::LookupContext.new('rp_env', 'compliance_markup')) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(ex.to_s).to_not match(/no_such_key/) | ||
end | ||
it 'should return "disa"' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::testvariable", {}, Puppet::LookupContext.new('m')) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(ex.to_s).to_not match(/no_such_key/) | ||
end | ||
|
||
context "when key == compliance_markup::debug::hiera_backend_compile_time" do | ||
let(:hieradata) {"test_spec"} | ||
it 'should return an number' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::debug::hiera_backend_compile_time", {}, nil) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
puts " completed in #{result} seconds" | ||
expect(result).to be_a(Float) | ||
end | ||
end | ||
end | ||
end | ||
context "when key == compliance_markup::test::confined_by_module" do | ||
let(:hieradata){ "test_spec" } | ||
it 'should return "confined"' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::confined_by_module", {}, nil) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(result).to eql("confined") | ||
end | ||
end | ||
context "when key == compliance_markup::test::unconfined" do | ||
let(:hieradata){ "test_spec" } | ||
it 'should return "confined"' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::unconfined", {}, nil) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(result).to eql("confined") | ||
end | ||
end | ||
context "when key == compliance_markup::test::confined_with_matching_fact" do | ||
let(:hieradata){ "test_spec" } | ||
it 'should return "confined"' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::confined_with_matching_fact", {}, nil) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(result).to eql("confined") | ||
end | ||
end | ||
context "when key == compliance_markup::test::confined_with_not_matching_fact" do | ||
let(:hieradata){ "test_spec" } | ||
it 'should return "confined"' do | ||
errored = false | ||
ex = nil | ||
begin | ||
result = subject.execute("compliance_markup::test::confined_with_not_matching_fact", {}, nil) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(result).to_not eql("confined") | ||
end | ||
end | ||
context "when key == compliance_markup::test::confined_with_wrong_module_version" do | ||
let(:hieradata){ "test_spec" } | ||
it 'should not return "confined"' do | ||
errored = false | ||
ex = nil | ||
begin | ||
$pry_debug = true | ||
result = subject.execute("compliance_markup::test::confined_with_wrong_module_version", {}, nil) | ||
rescue Exception => e | ||
ex = e | ||
errored = true | ||
end | ||
expect(result).to_not eql("confined") | ||
end | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.