Giuseppe Lavagetto has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/394981 )
Change subject: Puppet 4 compatibility ...................................................................... Puppet 4 compatibility Change-Id: I509e00f6363a7245f19c0717e35d0f2c9a48a00a --- M puppet_compiler/controller.py M puppet_compiler/differ.py M puppet_compiler/puppet.py M puppet_compiler/tests/test_controller.py M puppet_compiler/tests/test_puppet.py 5 files changed, 44 insertions(+), 11 deletions(-) Approvals: Giuseppe Lavagetto: Looks good to me, approved jenkins-bot: Verified diff --git a/puppet_compiler/controller.py b/puppet_compiler/controller.py index 6722380..ced40c2 100644 --- a/puppet_compiler/controller.py +++ b/puppet_compiler/controller.py @@ -1,5 +1,7 @@ +import os import re import sys +import subprocess import yaml @@ -30,6 +32,8 @@ def __init__(self, configfile, job_id, change_id, host_list=[], nthreads=2, modes=['change']): + # Let's first detect the installed puppet version + self.set_puppet_version() self.config = { # Url under which results will be found 'http_url': 'https://puppet-compiler.wmflabs.org/html', @@ -68,6 +72,11 @@ html.change_id = change_id html.job_id = job_id + def set_puppet_version(self): + if not os.environ.get('PUPPET_VERSION', False): + major = subprocess.check_output(['puppet', '--version']).rstrip().split('.')[0] + os.environ['PUPPET_VERSION'] = major + def pick_hosts(self, host_list): if not host_list: _log.info("No host list provided, generating the nodes list") diff --git a/puppet_compiler/differ.py b/puppet_compiler/differ.py index b9c9a71..061dc13 100644 --- a/puppet_compiler/differ.py +++ b/puppet_compiler/differ.py @@ -95,11 +95,15 @@ self.resources = {} with open(filename, 'r') as fh: catalog = json.load(fh, 'latin_1') - for resource in catalog['data']['resources']: + if 'data' in catalog: + base = catalog['data'] # Puppet 3 + else: + base = catalog # Puppet 4 and above + for resource in base['resources']: r = PuppetResource(resource, resource_filter) self.resources[str(r)] = r self.all_resources = set(self.resources.keys()) - self.name = catalog['data']['name'] + self.name = base['name'] def diff_if_present(self, other): diffs = [] diff --git a/puppet_compiler/puppet.py b/puppet_compiler/puppet.py index 4b6261c..c56aabe 100644 --- a/puppet_compiler/puppet.py +++ b/puppet_compiler/puppet.py @@ -9,6 +9,7 @@ def compile_cmd_env(hostname, label, vardir, *extra_flags): + puppet_version = int(os.environ.get('PUPPET_VERSION', 4)) env = os.environ.copy() if label == 'prod': basedir = FHS.prod_dir @@ -24,13 +25,13 @@ '--modulepath=%s:%s' % (os.path.join(privdir, 'modules'), os.path.join(srcdir, 'modules')), '--confdir=%s' % srcdir, - '--trusted_node_data', '--compile=%s' % hostname, '--color=false', - '--parser=future', '--manifest=$confdir/manifests', - '--environment=future' + '--environmentpath=$confdir/environments' ] + if puppet_version < 4: + cmd.extend(['--trusted_node_data', '--parser=future', '--environment=future']) cmd.extend(extra_flags) return (cmd, env) diff --git a/puppet_compiler/tests/test_controller.py b/puppet_compiler/tests/test_controller.py index 8af9350..53fc2bf 100644 --- a/puppet_compiler/tests/test_controller.py +++ b/puppet_compiler/tests/test_controller.py @@ -10,6 +10,7 @@ @classmethod def setUpClass(cls): cls.fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') + os.environ['PUPPET_VERSION'] = '4' def test_initialize_no_configfile(self): c = controller.Controller(None, 19, 224570, 'test.eqiad.wmnet', nthreads=2) @@ -30,6 +31,14 @@ controller.Controller('unexistent', 19, 224570, 'test.eqiad.wmnet', nthreads=2) self.assertRaises(SystemExit, controller.Controller, filename + '.invalid', 1, 1, 'test.eqiad.wmnet') + @mock.patch('subprocess.check_output') + def test_set_puppet_version(self, mocker): + del os.environ['PUPPET_VERSION'] + mocker.return_value = '3.8.2\n' + controller.Controller(None, 19, 224570, 'test.eqiad.wmnet', nthreads=2) + mocker.assert_called_with(['puppet', '--version']) + self.assertEqual(os.environ['PUPPET_VERSION'], '3') + @mock.patch('puppet_compiler.worker.HostWorker.html_index') @mock.patch('puppet_compiler.worker.HostWorker.run_host') def test_run_single_host(self, mocker, html_mocker): diff --git a/puppet_compiler/tests/test_puppet.py b/puppet_compiler/tests/test_puppet.py index 38455dc..8123322 100644 --- a/puppet_compiler/tests/test_puppet.py +++ b/puppet_compiler/tests/test_puppet.py @@ -9,6 +9,7 @@ class TestPuppetCalls(unittest.TestCase): def setUp(self): + os.environ['PUPPET_VERSION'] = '3' subprocess.check_call = mock.Mock() self.fixtures = os.path.join(os.path.dirname(__file__), 'fixtures') FHS.setup(10, self.fixtures) @@ -30,10 +31,13 @@ '--modulepath=%(basedir)s/private/modules:' '%(basedir)s/src/modules' % {'basedir': FHS.prod_dir}, '--confdir=%s/%s' % (FHS.prod_dir, 'src'), - '--trusted_node_data', '--compile=test.codfw.wmnet', '--color=false', - '--parser=future', '--manifest=$confdir/manifests', '--environment=future'], + '--manifest=$confdir/manifests', + '--environmentpath=$confdir/environments', + '--trusted_node_data', + '--parser=future', + '--environment=future'], env=env, stdout=spool, stderr=mocker.return_value @@ -53,10 +57,13 @@ '--modulepath=%(basedir)s/private/modules:' '%(basedir)s/src/modules' % {'basedir': FHS.change_dir}, '--confdir=%s/%s' % (FHS.change_dir, 'src'), - '--trusted_node_data', '--compile=test.codfw.wmnet', '--color=false', - '--parser=future', '--manifest=$confdir/manifests', '--environment=future'], + '--manifest=$confdir/manifests', + '--environmentpath=$confdir/environments', + '--trusted_node_data', + '--parser=future', + '--environment=future'], env=env, stdout=tf_mocker.return_value, stderr=mocker.return_value @@ -84,10 +91,13 @@ '--modulepath=%(basedir)s/private/modules:' '%(basedir)s/src/modules' % {'basedir': FHS.prod_dir}, '--confdir=%s/%s' % (FHS.prod_dir, 'src'), - '--trusted_node_data', '--compile=test.codfw.wmnet', '--color=false', - '--parser=future', '--manifest=$confdir/manifests', '--environment=future', + '--manifest=$confdir/manifests', + '--environmentpath=$confdir/environments', + '--trusted_node_data', + '--parser=future', + '--environment=future', '--dummy'], env=env, stdout=tf_mocker.return_value, -- To view, visit https://gerrit.wikimedia.org/r/394981 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I509e00f6363a7245f19c0717e35d0f2c9a48a00a Gerrit-PatchSet: 2 Gerrit-Project: operations/software/puppet-compiler Gerrit-Branch: master Gerrit-Owner: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits