Skip to content

Commit

Permalink
Use apache2ctl modules for Gentoo systems. (#5349)
Browse files Browse the repository at this point in the history
* Do not call Apache binary for module reset in cleanup()

* Use apache2ctl modules for Gentoo
  • Loading branch information
joohoi authored and bmw committed Jan 4, 2018
1 parent a7d00ee commit a3a66cd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
8 changes: 8 additions & 0 deletions certbot-apache/certbot_apache/override_gentoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ def __init__(self, *args, **kwargs):
def update_runtime_variables(self):
""" Override for update_runtime_variables for custom parsing """
self.parse_sysconfig_var()
self.update_modules()

def parse_sysconfig_var(self):
""" Parses Apache CLI options from Gentoo configuration file """
defines = apache_util.parse_define_file(self.apacheconfig_filep,
"APACHE2_OPTS")
for k in defines.keys():
self.variables[k] = defines[k]

def update_modules(self):
"""Get loaded modules from httpd process, and add them to DOM"""
mod_cmd = [self.configurator.constant("apache_cmd"), "modules"]
matches = self.parse_from_subprocess(mod_cmd, r"(.*)_module")
for mod in matches:
self.add_mod(mod.strip())
49 changes: 45 additions & 4 deletions certbot-apache/certbot_apache/tests/gentoo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import os
import unittest

import mock

from certbot_apache import override_gentoo
from certbot_apache import obj
from certbot_apache.tests import util
Expand Down Expand Up @@ -46,9 +48,10 @@ def setUp(self): # pylint: disable=arguments-differ
config_root=config_root,
vhost_root=vhost_root)

self.config = util.get_apache_configurator(
self.config_path, self.vhost_path, self.config_dir, self.work_dir,
os_info="gentoo")
with mock.patch("certbot_apache.override_gentoo.GentooParser.update_runtime_variables"):
self.config = util.get_apache_configurator(
self.config_path, self.vhost_path, self.config_dir, self.work_dir,
os_info="gentoo")
self.vh_truth = get_vh_truth(
self.temp_dir, "gentoo_apache/apache")

Expand Down Expand Up @@ -78,9 +81,47 @@ def test_get_sysconfig_vars(self):
self.config.parser.apacheconfig_filep = os.path.realpath(
os.path.join(self.config.parser.root, "../conf.d/apache2"))
self.config.parser.variables = {}
self.config.parser.update_runtime_variables()
with mock.patch("certbot_apache.override_gentoo.GentooParser.update_modules"):
self.config.parser.update_runtime_variables()
for define in defines:
self.assertTrue(define in self.config.parser.variables.keys())

@mock.patch("certbot_apache.parser.ApacheParser.parse_from_subprocess")
def test_no_binary_configdump(self, mock_subprocess):
"""Make sure we don't call binary dumps other than modules from Apache
as this is not supported in Gentoo currently"""

with mock.patch("certbot_apache.override_gentoo.GentooParser.update_modules"):
self.config.parser.update_runtime_variables()
self.config.parser.reset_modules()
self.assertFalse(mock_subprocess.called)

self.config.parser.update_runtime_variables()
self.config.parser.reset_modules()
self.assertTrue(mock_subprocess.called)

@mock.patch("certbot_apache.parser.ApacheParser._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get):
mod_val = (
'Loaded Modules:\n'
' mock_module (static)\n'
' another_module (static)\n'
)
def mock_get_cfg(command):
"""Mock httpd process stdout"""
if command == ['apache2ctl', 'modules']:
return mod_val
mock_get.side_effect = mock_get_cfg
self.config.parser.modules = set()

with mock.patch("certbot.util.get_os_info") as mock_osi:
# Make sure we have the have the CentOS httpd constants
mock_osi.return_value = ("gentoo", "123")
self.config.parser.update_runtime_variables()

self.assertEquals(mock_get.call_count, 1)
self.assertEquals(len(self.config.parser.modules), 4)
self.assertTrue("mod_another.c" in self.config.parser.modules)

if __name__ == "__main__":
unittest.main() # pragma: no cover

0 comments on commit a3a66cd

Please sign in to comment.