diff --git a/requirements.txt b/requirements.txt index 515e15564..200ed81a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0 Babel!=2.4.0,>=2.3.4 # BSD GitPython>=1.0.1 # BSD License (3 clause) +eventlet!=0.20.1,>=0.20.0 # MIT python-heatclient>=1.10.0 # Apache-2.0 oslo.config>=5.2.0 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 diff --git a/tripleo_common/actions/vcs.py b/tripleo_common/actions/vcs.py index 924a71fa1..8c5a685d6 100644 --- a/tripleo_common/actions/vcs.py +++ b/tripleo_common/actions/vcs.py @@ -17,10 +17,11 @@ import logging import shutil import tempfile -from git import Repo import six from mistral_lib import actions +from tripleo_common.utils.safe_import import Repo + LOG = logging.getLogger(__name__) diff --git a/tripleo_common/tests/actions/test_vcs.py b/tripleo_common/tests/actions/test_vcs.py index 16ecd4a12..6dcbf7134 100644 --- a/tripleo_common/tests/actions/test_vcs.py +++ b/tripleo_common/tests/actions/test_vcs.py @@ -18,11 +18,11 @@ import shutil import tempfile import uuid -import git from mistral_lib import actions from tripleo_common.actions import vcs from tripleo_common.tests import base +from tripleo_common.utils.safe_import import git class GitCloneActionTest(base.TestCase): diff --git a/tripleo_common/tests/utils/test_config.py b/tripleo_common/tests/utils/test_config.py index cab67b9a7..fa6b04e94 100644 --- a/tripleo_common/tests/utils/test_config.py +++ b/tripleo_common/tests/utils/test_config.py @@ -12,7 +12,6 @@ import datetime import fixtures -import git import mock import os import uuid @@ -26,6 +25,7 @@ from tripleo_common import constants from tripleo_common.tests import base from tripleo_common.tests.fake_config import fakes from tripleo_common.utils import config as ooo_config +from tripleo_common.utils.safe_import import git class TestConfig(base.TestCase): diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index 620bd9428..b2936f59a 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -12,7 +12,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import git + import json import logging import os @@ -25,7 +25,7 @@ import yaml import jinja2 from tripleo_common import constants - +from tripleo_common.utils.safe_import import git warnings.filterwarnings('once') diff --git a/tripleo_common/utils/safe_import.py b/tripleo_common/utils/safe_import.py new file mode 100644 index 000000000..2f63e90a6 --- /dev/null +++ b/tripleo_common/utils/safe_import.py @@ -0,0 +1,28 @@ +# Copyright 2019 Red Hat, Inc. +# All Rights Reserved. +# +# 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. + + +import eventlet +from eventlet.green import subprocess + +# Due to an eventlet issue subprocess is not being correctly patched +# on git module so it has to be done manually + +git = eventlet.import_patched('git', ('subprocess', subprocess)) +Repo = git.Repo + +# git.refs is lazy loaded when there's a new commit, this needs to be +# patched as well. +eventlet.import_patched('git.refs')