Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Support for app_management flag #68

Merged
merged 3 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a corresponding after block to reset this to false? I notice the future parser block doesn't have it, but both probably should, unless there's a global reset somewhere that I'm missing.

}
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, it should be reset after.

If you run this spec then manifests_spec.rb in sequence, the app_management = false (default) example fails as the default has been changed. It seems to work on Travis CI, possibly by luck as the files run in the opposite order.

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