From e41fcf67368d7df608f52fef9de5493157c6eedb Mon Sep 17 00:00:00 2001 From: ipcrm Date: Sun, 22 Jan 2017 18:17:19 -0500 Subject: [PATCH 1/3] Adding Support for `app_management` flag Prior to this commit code written for application orchestration could not be parsed correctly. This commit adds support for this feature. --- README.md | 4 ++ lib/puppet-syntax.rb | 3 +- lib/puppet-syntax/manifests.rb | 1 + lib/puppet-syntax/tasks/puppet-syntax.rb | 7 ++++ .../test_module/manifests/test_app.pp | 3 ++ spec/puppet-syntax/manifests_spec.rb | 40 +++++++++++++++++++ .../puppet-syntax/tasks/puppet-syntax_spec.rb | 2 +- spec/puppet-syntax_spec.rb | 5 +++ 8 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/test_module/manifests/test_app.pp diff --git a/README.md b/README.md index 2129f8f..d703e1e 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/puppet-syntax.rb b/lib/puppet-syntax.rb index e41c646..8c2021f 100644 --- a/lib/puppet-syntax.rb +++ b/lib/puppet-syntax.rb @@ -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 diff --git a/lib/puppet-syntax/manifests.rb b/lib/puppet-syntax/manifests.rb index 821fc05..85ed992 100644 --- a/lib/puppet-syntax/manifests.rb +++ b/lib/puppet-syntax/manifests.rb @@ -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 diff --git a/lib/puppet-syntax/tasks/puppet-syntax.rb b/lib/puppet-syntax/tasks/puppet-syntax.rb index 7ea07cf..bfe730f 100644 --- a/lib/puppet-syntax/tasks/puppet-syntax.rb +++ b/lib/puppet-syntax/tasks/puppet-syntax.rb @@ -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_managment` 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 diff --git a/spec/fixtures/test_module/manifests/test_app.pp b/spec/fixtures/test_module/manifests/test_app.pp new file mode 100644 index 0000000..e15d502 --- /dev/null +++ b/spec/fixtures/test_module/manifests/test_app.pp @@ -0,0 +1,3 @@ +application test_app { + +} diff --git a/spec/puppet-syntax/manifests_spec.rb b/spec/puppet-syntax/manifests_spec.rb index 738b99b..62d258e 100644 --- a/spec/puppet-syntax/manifests_spec.rb +++ b/spec/puppet-syntax/manifests_spec.rb @@ -136,6 +136,46 @@ end end + describe 'app_management' do + 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 diff --git a/spec/puppet-syntax/tasks/puppet-syntax_spec.rb b/spec/puppet-syntax/tasks/puppet-syntax_spec.rb index eaf881e..f1117c9 100644 --- a/spec/puppet-syntax/tasks/puppet-syntax_spec.rb +++ b/spec/puppet-syntax/tasks/puppet-syntax_spec.rb @@ -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 diff --git a/spec/puppet-syntax_spec.rb b/spec/puppet-syntax_spec.rb index 7ab5d22..b4f4c06 100644 --- a/spec/puppet-syntax_spec.rb +++ b/spec/puppet-syntax_spec.rb @@ -24,6 +24,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) From aac22cc881ca860d745087542f3c75040ae576cd Mon Sep 17 00:00:00 2001 From: ipcrm Date: Wed, 25 Jan 2017 13:45:26 -0500 Subject: [PATCH 2/3] Correct typo in warning message app_managment -> app_management --- lib/puppet-syntax/tasks/puppet-syntax.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet-syntax/tasks/puppet-syntax.rb b/lib/puppet-syntax/tasks/puppet-syntax.rb index bfe730f..b23d14d 100644 --- a/lib/puppet-syntax/tasks/puppet-syntax.rb +++ b/lib/puppet-syntax/tasks/puppet-syntax.rb @@ -56,7 +56,7 @@ def initialize(*args) end if Puppet::PUPPETVERSION.to_f < 4.3 and PuppetSyntax.app_management $stderr.puts <<-EOS -[WARNING] Puppet `app_managment` has been detected but the Puppet +[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 From 4da620e2a07f95e53d3215e6836d2d62348f7372 Mon Sep 17 00:00:00 2001 From: ipcrm Date: Wed, 25 Jan 2017 14:01:00 -0500 Subject: [PATCH 3/3] Add Reset for app_management test Reverting PuppetSynatx.app_management back to the default `false` value after test execute. --- spec/puppet-syntax/manifests_spec.rb | 4 ++++ spec/puppet-syntax_spec.rb | 1 + 2 files changed, 5 insertions(+) diff --git a/spec/puppet-syntax/manifests_spec.rb b/spec/puppet-syntax/manifests_spec.rb index 62d258e..52d0880 100644 --- a/spec/puppet-syntax/manifests_spec.rb +++ b/spec/puppet-syntax/manifests_spec.rb @@ -137,6 +137,10 @@ 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 diff --git a/spec/puppet-syntax_spec.rb b/spec/puppet-syntax_spec.rb index b4f4c06..e2c77d3 100644 --- a/spec/puppet-syntax_spec.rb +++ b/spec/puppet-syntax_spec.rb @@ -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