Jcrespo has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/331239 )

Change subject: puppet parse validate from rake
......................................................................


puppet parse validate from rake

Lint manifests,templates,hiera files using the puppet-syntax gem which
has a rake task for convenience.

Drop the old 'validate' task and related color handling code.

Craft syntax:manifests_head that runs parser validation solely against
files changes in HEAD.  That dramatically speed up local test and CI.

Add a syntax:head that encompass all the puppet-syntax check and add
that to our CI entry point task 'lint_head'.

For a parse of everything:

 bundle exec rake lint

Making some check to only against files changes in HEAD, use either one
of:

 bundle exec rake lint_head

 bundle exec rake test

Do not fail on deprecation notices yet since site.pp still uses an
import statement for realm.pp (T154915):
    PuppetSyntax.fail_on_deprecation_notices = false

Bug: T154915
Bug: T154894
Change-Id: Ie6712bada947214dd222ef2090103c046530d0fa
---
M Rakefile
1 file changed, 31 insertions(+), 53 deletions(-)

Approvals:
  Alexandros Kosiaris: Looks good to me, but someone else must approve
  Hashar: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  Jcrespo: Looks good to me, approved
  Filippo Giunchedi: Looks good to me, but someone else must approve
  Volans: Looks good to me, but someone else must approve



diff --git a/Rakefile b/Rakefile
index 34c0a07..4eb0a65 100644
--- a/Rakefile
+++ b/Rakefile
@@ -28,7 +28,11 @@
 require 'git'
 require 'puppet-lint/tasks/puppet-lint'
 require 'puppet-strings/tasks/generate'
+require 'puppet-syntax/tasks/puppet-syntax'
 require 'rubocop/rake_task'
+
+# site.pp still uses an import statement for realm.pp (T154915)
+PuppetSyntax.fail_on_deprecation_notices = false
 
 # Find files modified in HEAD
 def git_changed_in_head(file_exts=[])
@@ -41,6 +45,31 @@
     else
         files.select { |fname| fname.end_with?(*file_exts) }
     end
+end
+
+namespace :syntax do
+    desc 'Syntax check Puppet manifests against HEAD'
+    task :manifests_head do
+        Puppet::Util::Log.newdestination(:console)
+        files = git_changed_in_head ['.pp']
+        files << 'manifests/site.pp'
+
+        # XXX This is copy pasted from the puppet-syntax rake task. It does not
+        # support injecting a specific list of files but always uses:
+        #   FileList['**/*.pp']
+        c = PuppetSyntax::Manifests.new
+        output, has_errors = c.check(files)
+        Puppet::Util::Log.close_all
+        fail if has_errors || (output.any? && 
PuppetSyntax.fail_on_deprecation_notices)
+    end
+
+    desc 'Syntax checks against HEAD'
+    task :head => [
+        'syntax:manifests_head',
+        'syntax:hiera',
+        'syntax:templates',
+    ]
+
 end
 
 RuboCop::RakeTask.new(:rubocop)
@@ -57,25 +86,6 @@
     config.pattern = git_changed_in_head ['.pp']
 end
 
-# Only care about color when using a tty.
-if Rake.application.tty_output?
-    # Since we are going to use puppet internal stuff, we might as
-    # well attempt to reuse their colorization utility. Note the utility class
-    # is not available in older puppet versions.
-    begin
-        require'puppet/util/colors'
-        include Puppet::Util::Colors
-    rescue LoadError
-        puts "Cant load puppet/util/colors .. no color for you!"
-    end
-end
-
-unless respond_to? :console_color
-    # Define our own colorization method that simply outputs the message.
-    def console_color(_level, message)
-        message
-    end
-end
 
 task :default => [:help]
 
@@ -83,10 +93,10 @@
 task test: [:lint_head]
 
 desc 'Run all linting commands'
-task lint: [:rubocop, :puppetlint]
+task lint: [:rubocop, :syntax, :puppetlint]
 
 desc 'Run all linting commands against HEAD'
-task lint_head: [:rubocop, :puppetlint_head]
+task lint_head: [:rubocop, :"syntax:head", :puppetlint_head]
 
 
 desc 'Show the help'
@@ -128,38 +138,6 @@
         'false', # backtrace
         'rdoc',  # markup format
     )
-end
-
-desc "Validate puppet syntax (default: manifests/site.pp)"
-task :validate, [:files ] do |_t, args|
-
-    success = true
-
-    if args.files
-        puts console_color(:info, "Validating " + args.files.inspect)
-        ok = puppet_parser_validate args.files
-    else
-        ok = puppet_parser_validate 'manifests/site.pp'
-        success &&= ok
-
-        Dir.glob("modules/*").each do |dir|
-            puts console_color(:info, "Validating manifests in '#{dir}'")
-            ok = puppet_parser_validate Dir.glob("#{dir}/**/*.pp")
-            success &&= ok
-        end
-    end
-
-    if success
-        puts "[OK] " + console_color(:info,  "files looks fine!")
-    else
-        raise console_color(:alert, "puppet failed to validate files (exit: 
#{res.exitstatus}")
-    end
-end
-
-# Validate manifests passed as an array of filenames.
-def puppet_parser_validate(*manifests)
-    manifests = manifests.join(' ')
-    sh "puppet parser validate #{manifests}"
 end
 
 desc "Run spec tests found in modules"

-- 
To view, visit https://gerrit.wikimedia.org/r/331239
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie6712bada947214dd222ef2090103c046530d0fa
Gerrit-PatchSet: 11
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Hashar <[email protected]>
Gerrit-Reviewer: Alexandros Kosiaris <[email protected]>
Gerrit-Reviewer: Dduvall <[email protected]>
Gerrit-Reviewer: Elukey <[email protected]>
Gerrit-Reviewer: Filippo Giunchedi <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Jcrespo <[email protected]>
Gerrit-Reviewer: Volans <[email protected]>
Gerrit-Reviewer: Zfilipin <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to