aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-11-03 15:28:54 +0100
committerGuido Günther <agx@sigxcpu.org>2011-11-03 17:13:07 +0100
commit26151da06a397b259f811f44965018420fb3af98 (patch)
treea4912dff1fc555910558901586656480205b4bcd
parent381046229bbc7b34351378aabeb5b8753f572f5f (diff)
Support puppet 2.7 and 2.6
-rw-r--r--git/hooks/puppethooks/checkers.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/git/hooks/puppethooks/checkers.py b/git/hooks/puppethooks/checkers.py
index 9f1dd92..3ac0f64 100644
--- a/git/hooks/puppethooks/checkers.py
+++ b/git/hooks/puppethooks/checkers.py
@@ -17,13 +17,36 @@
import subprocess
+puppet_version = None
+
class CheckFailed(Exception):
def __init__(self, error, path, details=None):
self.args = (error, path, details)
+def get_puppet_version():
+ global puppet_version
+
+ popen = subprocess.Popen(["puppet", "--version"],
+ stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ output = popen.communicate()
+ if popen.returncode:
+ puppet_version = 0
+ else:
+ ma, mi, rel = output[0].split('.')
+ puppet_version = int(ma) * 1000 + int(mi) * 100 + int(rel)
+
def puppet_checker(path):
"""Check syntax of puppet manifests"""
- cmd = ['puppet', 'parser', 'validate', '--color=false', '--noop', '--vardir=/tmp', '--confdir=/tmp', path]
+ if puppet_version == None:
+ get_puppet_version()
+
+ if puppet_version >= 2700:
+ cmd = ['puppet', 'parser', 'validate', '--color=false',
+ '--noop', '--vardir=/tmp', '--confdir=/tmp', path]
+ else:
+ cmd = ['puppet', '--color=false', '--noop', '--vardir=/tmp',
+ '--confdir=/tmp', '--parseonly', path]
+
popen = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
output = popen.communicate()
if popen.returncode: