mirror of
https://github.com/certbot/certbot.git
synced 2026-06-04 06:15:36 -04:00
Use util.check_output in Postfix installer
This commit is contained in:
parent
5a1d031f07
commit
4e5740615c
2 changed files with 13 additions and 9 deletions
|
|
@ -13,6 +13,8 @@ from certbot import util as certbot_util
|
|||
from certbot.plugins import common as plugins_common
|
||||
from certbot.plugins import util as plugins_util
|
||||
|
||||
from certbot_postfix import util
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -240,10 +242,13 @@ class Installer(plugins_common.Plugin):
|
|||
|
||||
"""
|
||||
# Parse Postfix version number (feature support, syntax changes etc.)
|
||||
cmd = subprocess.Popen([self.conf('config-utility'), '-d', 'mail_version'],
|
||||
stdout=subprocess.PIPE)
|
||||
stdout, _ = cmd.communicate()
|
||||
if cmd.returncode != 0:
|
||||
try:
|
||||
stdout = util.check_output(
|
||||
[self.conf('config-utility'), '-d', 'mail_version'])
|
||||
except subprocess.CalledProcessError:
|
||||
logger.debug(
|
||||
'Encountered an error when trying to determine Postfix version.',
|
||||
exc_info=True)
|
||||
raise errors.PluginError('Unable to determine Postfix version.')
|
||||
|
||||
# grabs version component of string like "mail_version = 2.11.3"
|
||||
|
|
|
|||
|
|
@ -84,12 +84,11 @@ class TestPostfixConfigGenerator(unittest.TestCase):
|
|||
"""
|
||||
installer = self._create_installer()
|
||||
|
||||
check_output_path = "certbot_postfix.installer.util.check_output"
|
||||
exe_exists_path = "certbot_postfix.installer.certbot_util.exe_exists"
|
||||
popen_path = "certbot_postfix.installer.subprocess.Popen"
|
||||
with mock.patch(exe_exists_path, return_value=True) as mock_exe_exists:
|
||||
with mock.patch(popen_path) as mock_popen:
|
||||
mock_popen().returncode = 0
|
||||
mock_popen().communicate.return_value = ("mail_version = 3.1.4", "")
|
||||
with mock.patch(check_output_path) as mock_check_output:
|
||||
with mock.patch(exe_exists_path, return_value=True):
|
||||
mock_check_output.return_value = "mail_version = 3.1.4"
|
||||
installer.prepare()
|
||||
|
||||
return installer
|
||||
|
|
|
|||
Loading…
Reference in a new issue