From 4aabc7340059a318a143029dea913e94d748ee54 Mon Sep 17 00:00:00 2001 From: Oleg Gelbukh Date: Mon, 4 Apr 2016 10:28:37 +0000 Subject: [PATCH] Extract puppet modules patching into utils Add function to patch the puppet modules on the Fuel Master node to util/puppet.py module. Refactor handlers to work with util module for patching of puppet manifests. Change-Id: Ie7b43493b119bd46c9ac107ebda37c12520ea7a2 --- octane/util/patch.py | 28 ++++++++++++++++++++++++++++ octane/util/puppet.py | 17 ++++------------- 2 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 octane/util/patch.py diff --git a/octane/util/patch.py b/octane/util/patch.py new file mode 100644 index 00000000..6614e9b7 --- /dev/null +++ b/octane/util/patch.py @@ -0,0 +1,28 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from octane.util import subprocess + + +def patch_apply(cwd, patches, revert=False): + for path in patches: + with open(path, 'rb') as patch: + try: + subprocess.call(["patch", "-R", "-p3"], stdin=patch, cwd=cwd) + except subprocess.CalledProcessError: + if not revert: + pass + else: + raise + if not revert: + patch.seek(0) + subprocess.call(["patch", "-N", "-p3"], stdin=patch, cwd=cwd) diff --git a/octane/util/puppet.py b/octane/util/puppet.py index f8708d02..fac6f84d 100644 --- a/octane/util/puppet.py +++ b/octane/util/puppet.py @@ -14,6 +14,7 @@ import logging import os.path from octane import magic_consts +from octane.util import patch from octane.util import subprocess LOG = logging.getLogger(__name__) @@ -36,20 +37,10 @@ def apply_host(): def patch_modules(revert=False): puppet_patch_dir = os.path.join(magic_consts.CWD, "patches", "puppet") + patches = [] for d in os.listdir(puppet_patch_dir): d = os.path.join(puppet_patch_dir, d) if not os.path.isdir(d): continue - with open(os.path.join(d, "patch")) as patch: - try: - subprocess.call(["patch", "-R", "-p3"], stdin=patch, - cwd=magic_consts.PUPPET_DIR) - except subprocess.CalledProcessError: - if not revert: - pass - else: - raise - if not revert: - patch.seek(0) - subprocess.call(["patch", "-N", "-p3"], stdin=patch, - cwd=magic_consts.PUPPET_DIR) + patches.append(os.path.join(d, "patch")) + patch.patch_apply(magic_consts.PUPPET_DIR, patches, revert=revert)