Skip to content

Commit

Permalink
Merge pull request #68 from ipcrm/add_app_management
Browse files Browse the repository at this point in the history
Adding Support for `app_management` flag
  • Loading branch information
domcleal authored Jan 26, 2017
2 parents 0ecd0e0 + 4da620e commit d4ec821
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ If you are using some form of hiera data inside your module, you can configure w

PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"]

If you are trying to validate the syntax of code written for application orchestration, you can enable the `app_management` setting:

PuppetSyntax.app_management = true

## Installation

Add this line to your application's Gemfile:
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet-syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ module PuppetSyntax
@future_parser = false
@hieradata_paths = ["**/data/**/*.*yaml", "hieradata/**/*.*yaml", "hiera*.*yaml"]
@fail_on_deprecation_notices = true
@app_management = false

class << self
attr_accessor :exclude_paths, :future_parser, :hieradata_paths, :fail_on_deprecation_notices, :epp_only
attr_accessor :exclude_paths, :future_parser, :hieradata_paths, :fail_on_deprecation_notices, :epp_only, :app_management
end
end
1 change: 1 addition & 0 deletions lib/puppet-syntax/manifests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def check(filelist)
private
def validate_manifest(file)
Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet::PUPPETVERSION.to_i < 4
Puppet[:app_management] = true if PuppetSyntax.app_management and Puppet::PUPPETVERSION.to_f >= 4.3
Puppet::Face[:parser, :current].validate(file)
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/puppet-syntax/tasks/puppet-syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def initialize(*args)
'true'. The `future_parser setting will be ignored.
EOS
end
if Puppet::PUPPETVERSION.to_f < 4.3 and PuppetSyntax.app_management
$stderr.puts <<-EOS
[WARNING] Puppet `app_management` has been detected but the Puppet
version is less then 4.3. The `app_management` setting will be ignored.
EOS
end

$stderr.puts "---> #{t.name}"

c = PuppetSyntax::Manifests.new
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/test_module/manifests/test_app.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
application test_app {

}
44 changes: 44 additions & 0 deletions spec/puppet-syntax/manifests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,50 @@
end
end

describe 'app_management' do
after do
PuppetSyntax.app_management = false
end

context 'app_management = false (default)' do
it 'should fail to parse an application manifest' do

files = fixture_manifests(['test_app.pp'])
output,has_errors = subject.check(files)

expect(has_errors).to eq(true)
expect(output).to include(/error/)
end
end
context 'app_management = true' do
before(:each) {
PuppetSyntax.app_management = true
}
if Puppet::PUPPETVERSION.to_f >= 4.3
it 'should successfully parse an application manifest on Puppet >= 4.3.0' do
expect(PuppetSyntax.app_management).to eq(true)

files = fixture_manifests(['test_app.pp'])
output,has_errors = subject.check(files)

expect(output.size).to eq(0)
expect(has_errors).to eq(false)
end
else
it 'should fail to parse an application manifest on Puppet < 4.3.0' do
expect(PuppetSyntax.app_management).to eq(true)

files = fixture_manifests(['test_app.pp'])
output,has_errors = subject.check(files)

expect(output).to include(/error/)
expect(has_errors).to eq(true)
end
end
end
end


describe 'future_parser' do
context 'future_parser = false (default)' do
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') < 0
Expand Down
2 changes: 1 addition & 1 deletion spec/puppet-syntax/tasks/puppet-syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
it 'should generate FileList of manifests relative to Rakefile' do
list = PuppetSyntax::RakeTask.new.filelist_manifests
expect(list).to include(known_pp)
expect(list.count).to eq 7
expect(list.count).to eq 8
end

it 'should generate FileList of templates relative to Rakefile' do
Expand Down
6 changes: 6 additions & 0 deletions spec/puppet-syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe PuppetSyntax do
after do
PuppetSyntax.exclude_paths = []
PuppetSyntax.app_management = false
end

it 'should default exclude_paths to empty array' do
Expand All @@ -24,6 +25,11 @@
expect(PuppetSyntax.future_parser).to eq(true)
end

it 'should support app_management setting setting' do
PuppetSyntax.app_management = true
expect(PuppetSyntax.app_management).to eq(true)
end

it 'should support a fail_on_deprecation_notices setting' do
PuppetSyntax.fail_on_deprecation_notices = false
expect(PuppetSyntax.fail_on_deprecation_notices).to eq(false)
Expand Down

0 comments on commit d4ec821

Please sign in to comment.