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
This commit is contained in:
Oleg Gelbukh 2016-04-04 10:28:37 +00:00
parent 31246fa85d
commit 4aabc73400
2 changed files with 32 additions and 13 deletions

28
octane/util/patch.py Normal file
View File

@ -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)

View File

@ -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)