Modifications needed for merging to master

This commit is contained in:
Joona Hoikkala
2020-01-06 17:19:33 +02:00
parent 0f5bda4ff9
commit 3b065238b3
16 changed files with 51 additions and 50 deletions
@@ -1,8 +1,8 @@
""" apacheconfig implementation of the ParserNode interfaces """ """ apacheconfig implementation of the ParserNode interfaces """
from certbot_apache import assertions from certbot_apache._internal import assertions
from certbot_apache import interfaces from certbot_apache._internal import interfaces
from certbot_apache import parsernode_util as util from certbot_apache._internal import parsernode_util as util
class ApacheParserNode(interfaces.ParserNode): class ApacheParserNode(interfaces.ParserNode):
@@ -73,9 +73,9 @@ class ApacheDirectiveNode(ApacheParserNode):
self.metadata == other.metadata) self.metadata == other.metadata)
return False return False
def set_parameters(self, parameters): def set_parameters(self, _parameters):
"""Sets the parameters for DirectiveNode""" """Sets the parameters for DirectiveNode"""
pass return
class ApacheBlockNode(ApacheDirectiveNode): class ApacheBlockNode(ApacheDirectiveNode):
@@ -153,7 +153,7 @@ class ApacheBlockNode(ApacheDirectiveNode):
def delete_child(self, child): # pragma: no cover def delete_child(self, child): # pragma: no cover
"""Deletes a ParserNode from the sequence of children""" """Deletes a ParserNode from the sequence of children"""
pass return
def unsaved_files(self): # pragma: no cover def unsaved_files(self): # pragma: no cover
"""Returns a list of unsaved filepaths""" """Returns a list of unsaved filepaths"""
@@ -1,7 +1,7 @@
"""Dual parser node assertions""" """Dual parser node assertions"""
import fnmatch import fnmatch
from certbot_apache import interfaces from certbot_apache._internal import interfaces
PASS = "CERTBOT_PASS_ASSERT" PASS = "CERTBOT_PASS_ASSERT"
@@ -36,8 +36,8 @@ def assertEqualComment(first, second): # pragma: no cover
assert isinstance(first, interfaces.CommentNode) assert isinstance(first, interfaces.CommentNode)
assert isinstance(second, interfaces.CommentNode) assert isinstance(second, interfaces.CommentNode)
if not isPass(first.comment) and not isPass(second.comment): if not isPass(first.comment) and not isPass(second.comment): # type: ignore
assert first.comment == second.comment assert first.comment == second.comment # type: ignore
def _assertEqualDirectiveComponents(first, second): # pragma: no cover def _assertEqualDirectiveComponents(first, second): # pragma: no cover
""" Handles assertion for instance variables for DirectiveNode and BlockNode""" """ Handles assertion for instance variables for DirectiveNode and BlockNode"""
@@ -68,11 +68,11 @@ from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-m
from certbot import errors from certbot import errors
from certbot.compat import os from certbot.compat import os
from certbot_apache import apache_util from certbot_apache._internal import apache_util
from certbot_apache import assertions from certbot_apache._internal import assertions
from certbot_apache import interfaces from certbot_apache._internal import interfaces
from certbot_apache import parser from certbot_apache._internal import parser
from certbot_apache import parsernode_util as util from certbot_apache._internal import parsernode_util as util
class AugeasParserNode(interfaces.ParserNode): class AugeasParserNode(interfaces.ParserNode):
@@ -1,7 +1,7 @@
""" Dual ParserNode implementation """ """ Dual ParserNode implementation """
from certbot_apache import assertions from certbot_apache._internal import assertions
from certbot_apache import augeasparser from certbot_apache._internal import augeasparser
from certbot_apache import apacheparser from certbot_apache._internal import apacheparser
class DualNodeBase(object): class DualNodeBase(object):
+10 -9
View File
@@ -1,12 +1,13 @@
"""Tests for AugeasParserNode classes""" """Tests for AugeasParserNode classes"""
import mock import mock
import util
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from certbot import errors from certbot import errors
from certbot_apache import assertions from certbot_apache._internal import assertions
from certbot_apache.tests import util
class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-methods class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-methods
@@ -21,19 +22,19 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
self.temp_dir, "debian_apache_2_4/multiple_vhosts") self.temp_dir, "debian_apache_2_4/multiple_vhosts")
def test_save(self): def test_save(self):
with mock.patch('certbot_apache.parser.ApacheParser.save') as mock_save: with mock.patch('certbot_apache._internal.parser.ApacheParser.save') as mock_save:
self.config.parser_root.save("A save message") self.config.parser_root.save("A save message")
self.assertTrue(mock_save.called) self.assertTrue(mock_save.called)
self.assertEqual(mock_save.call_args[0][0], "A save message") self.assertEqual(mock_save.call_args[0][0], "A save message")
def test_unsaved_files(self): def test_unsaved_files(self):
with mock.patch('certbot_apache.parser.ApacheParser.unsaved_files') as mock_uf: with mock.patch('certbot_apache._internal.parser.ApacheParser.unsaved_files') as mock_uf:
mock_uf.return_value = ["first", "second"] mock_uf.return_value = ["first", "second"]
files = self.config.parser_root.unsaved_files() files = self.config.parser_root.unsaved_files()
self.assertEqual(files, ["first", "second"]) self.assertEqual(files, ["first", "second"])
def test_get_block_node_name(self): def test_get_block_node_name(self):
from certbot_apache.augeasparser import AugeasBlockNode from certbot_apache._internal.augeasparser import AugeasBlockNode
block = AugeasBlockNode( block = AugeasBlockNode(
name=assertions.PASS, name=assertions.PASS,
ancestor=None, ancestor=None,
@@ -102,9 +103,9 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
self.assertTrue("going_to_set_this" in names) self.assertTrue("going_to_set_this" in names)
def test_set_parameters_atinit(self): def test_set_parameters_atinit(self):
from certbot_apache.augeasparser import AugeasDirectiveNode from certbot_apache._internal.augeasparser import AugeasDirectiveNode
servernames = self.config.parser_root.find_directives("servername") servernames = self.config.parser_root.find_directives("servername")
setparam = "certbot_apache.augeasparser.AugeasDirectiveNode.set_parameters" setparam = "certbot_apache._internal.augeasparser.AugeasDirectiveNode.set_parameters"
with mock.patch(setparam) as mock_set: with mock.patch(setparam) as mock_set:
AugeasDirectiveNode( AugeasDirectiveNode(
name=servernames[0].name, name=servernames[0].name,
@@ -241,7 +242,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
self.assertTrue(vh.primary.metadata["augeaspath"].endswith("VirtualHost[2]")) self.assertTrue(vh.primary.metadata["augeaspath"].endswith("VirtualHost[2]"))
def test_node_init_error_bad_augeaspath(self): def test_node_init_error_bad_augeaspath(self):
from certbot_apache.augeasparser import AugeasBlockNode from certbot_apache._internal.augeasparser import AugeasBlockNode
parameters = { parameters = {
"name": assertions.PASS, "name": assertions.PASS,
"ancestor": None, "ancestor": None,
@@ -258,7 +259,7 @@ class AugeasParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-
) )
def test_node_init_error_missing_augeaspath(self): def test_node_init_error_missing_augeaspath(self):
from certbot_apache.augeasparser import AugeasBlockNode from certbot_apache._internal.augeasparser import AugeasBlockNode
parameters = { parameters = {
"name": assertions.PASS, "name": assertions.PASS,
"ancestor": None, "ancestor": None,
+2 -2
View File
@@ -106,7 +106,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
def test_get_parser(self): def test_get_parser(self):
self.assertIsInstance(self.config.parser, override_centos.CentOSParser) self.assertIsInstance(self.config.parser, override_centos.CentOSParser)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get): def test_opportunistic_httpd_runtime_parsing(self, mock_get):
define_val = ( define_val = (
'Define: TEST1\n' 'Define: TEST1\n'
@@ -155,7 +155,7 @@ class MultipleVhostsTestCentOS(util.ApacheTest):
raise Exception("Missed: %s" % vhost) # pragma: no cover raise Exception("Missed: %s" % vhost) # pragma: no cover
self.assertEqual(found, 2) self.assertEqual(found, 2)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_get_sysconfig_vars(self, mock_cfg): def test_get_sysconfig_vars(self, mock_cfg):
"""Make sure we read the sysconfig OPTIONS variable correctly""" """Make sure we read the sysconfig OPTIONS variable correctly"""
# Return nothing for the process calls # Return nothing for the process calls
+3 -3
View File
@@ -76,7 +76,7 @@ class MultipleVhostsTest(util.ApacheTest):
@mock.patch("certbot_apache._internal.parser.ApacheParser") @mock.patch("certbot_apache._internal.parser.ApacheParser")
@mock.patch("certbot_apache._internal.configurator.util.exe_exists") @mock.patch("certbot_apache._internal.configurator.util.exe_exists")
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.get_parsernode_root") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.get_parsernode_root")
def _test_prepare_locked(self, unused_parser, unused_exe_exists): def _test_prepare_locked(self, _node, _exists, _parser):
try: try:
self.config.prepare() self.config.prepare()
except errors.PluginError as err: except errors.PluginError as err:
@@ -800,7 +800,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertEqual(mock_restart.call_count, 1) self.assertEqual(mock_restart.call_count, 1)
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_cleanup(self, mock_cfg, mock_restart): def test_cleanup(self, mock_cfg, mock_restart):
mock_cfg.return_value = "" mock_cfg.return_value = ""
_, achalls = self.get_key_and_achalls() _, achalls = self.get_key_and_achalls()
@@ -816,7 +816,7 @@ class MultipleVhostsTest(util.ApacheTest):
self.assertFalse(mock_restart.called) self.assertFalse(mock_restart.called)
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart")
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_cleanup_no_errors(self, mock_cfg, mock_restart): def test_cleanup_no_errors(self, mock_cfg, mock_restart):
mock_cfg.return_value = "" mock_cfg.return_value = ""
_, achalls = self.get_key_and_achalls() _, achalls = self.get_key_and_achalls()
+1 -1
View File
@@ -46,7 +46,7 @@ class MultipleVhostsTestDebian(util.ApacheTest):
@mock.patch("certbot.util.run_script") @mock.patch("certbot.util.run_script")
@mock.patch("certbot.util.exe_exists") @mock.patch("certbot.util.exe_exists")
@mock.patch("certbot_apache._internal.parser.subprocess.Popen") @mock.patch("certbot_apache._internal.apache_util.subprocess.Popen")
def test_enable_mod(self, mock_popen, mock_exe_exists, mock_run_script): def test_enable_mod(self, mock_popen, mock_exe_exists, mock_run_script):
mock_popen().communicate.return_value = ("Define: DUMP_RUN_CFG", "") mock_popen().communicate.return_value = ("Define: DUMP_RUN_CFG", "")
mock_popen().returncode = 0 mock_popen().returncode = 0
+3 -3
View File
@@ -3,9 +3,9 @@ import unittest
import mock import mock
from certbot_apache import assertions from certbot_apache._internal import assertions
from certbot_apache import augeasparser from certbot_apache._internal import augeasparser
from certbot_apache import dualparser from certbot_apache._internal import dualparser
class DualParserNodeTest(unittest.TestCase): # pylint: disable=too-many-public-methods class DualParserNodeTest(unittest.TestCase): # pylint: disable=too-many-public-methods
+2 -2
View File
@@ -100,7 +100,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
def test_get_parser(self): def test_get_parser(self):
self.assertIsInstance(self.config.parser, override_fedora.FedoraParser) self.assertIsInstance(self.config.parser, override_fedora.FedoraParser)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get): def test_opportunistic_httpd_runtime_parsing(self, mock_get):
define_val = ( define_val = (
'Define: TEST1\n' 'Define: TEST1\n'
@@ -155,7 +155,7 @@ class MultipleVhostsTestFedora(util.ApacheTest):
raise Exception("Missed: %s" % vhost) # pragma: no cover raise Exception("Missed: %s" % vhost) # pragma: no cover
self.assertEqual(found, 2) self.assertEqual(found, 2)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_get_sysconfig_vars(self, mock_cfg): def test_get_sysconfig_vars(self, mock_cfg):
"""Make sure we read the sysconfig OPTIONS variable correctly""" """Make sure we read the sysconfig OPTIONS variable correctly"""
# Return nothing for the process calls # Return nothing for the process calls
+2 -2
View File
@@ -90,7 +90,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
for define in defines: for define in defines:
self.assertTrue(define in self.config.parser.variables.keys()) self.assertTrue(define in self.config.parser.variables.keys())
@mock.patch("certbot_apache._internal.parser.ApacheParser.parse_from_subprocess") @mock.patch("certbot_apache._internal.apache_util.parse_from_subprocess")
def test_no_binary_configdump(self, mock_subprocess): def test_no_binary_configdump(self, mock_subprocess):
"""Make sure we don't call binary dumps other than modules from Apache """Make sure we don't call binary dumps other than modules from Apache
as this is not supported in Gentoo currently""" as this is not supported in Gentoo currently"""
@@ -104,7 +104,7 @@ class MultipleVhostsTestGentoo(util.ApacheTest):
self.config.parser.reset_modules() self.config.parser.reset_modules()
self.assertTrue(mock_subprocess.called) self.assertTrue(mock_subprocess.called)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_opportunistic_httpd_runtime_parsing(self, mock_get): def test_opportunistic_httpd_runtime_parsing(self, mock_get):
mod_val = ( mod_val = (
'Loaded Modules:\n' 'Loaded Modules:\n'
+6 -6
View File
@@ -165,7 +165,7 @@ class BasicParserTest(util.ParserTest):
self.assertTrue(mock_logger.debug.called) self.assertTrue(mock_logger.debug.called)
@mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir") @mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_update_runtime_variables(self, mock_cfg, _): def test_update_runtime_variables(self, mock_cfg, _):
define_val = ( define_val = (
'ServerRoot: "/etc/apache2"\n' 'ServerRoot: "/etc/apache2"\n'
@@ -271,7 +271,7 @@ class BasicParserTest(util.ParserTest):
self.assertEqual(mock_parse.call_count, 25) self.assertEqual(mock_parse.call_count, 25)
@mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir") @mock.patch("certbot_apache._internal.parser.ApacheParser.find_dir")
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_update_runtime_variables_alt_values(self, mock_cfg, _): def test_update_runtime_variables_alt_values(self, mock_cfg, _):
inc_val = ( inc_val = (
'Included configuration files:\n' 'Included configuration files:\n'
@@ -293,7 +293,7 @@ class BasicParserTest(util.ParserTest):
# path derived from root configuration Include statements # path derived from root configuration Include statements
self.assertEqual(mock_parse.call_count, 1) self.assertEqual(mock_parse.call_count, 1)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_update_runtime_vars_bad_output(self, mock_cfg): def test_update_runtime_vars_bad_output(self, mock_cfg):
mock_cfg.return_value = "Define: TLS=443=24" mock_cfg.return_value = "Define: TLS=443=24"
self.parser.update_runtime_variables() self.parser.update_runtime_variables()
@@ -303,7 +303,7 @@ class BasicParserTest(util.ParserTest):
errors.PluginError, self.parser.update_runtime_variables) errors.PluginError, self.parser.update_runtime_variables)
@mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.option") @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.option")
@mock.patch("certbot_apache._internal.parser.subprocess.Popen") @mock.patch("certbot_apache._internal.apache_util.subprocess.Popen")
def test_update_runtime_vars_bad_ctl(self, mock_popen, mock_opt): def test_update_runtime_vars_bad_ctl(self, mock_popen, mock_opt):
mock_popen.side_effect = OSError mock_popen.side_effect = OSError
mock_opt.return_value = "nonexistent" mock_opt.return_value = "nonexistent"
@@ -311,7 +311,7 @@ class BasicParserTest(util.ParserTest):
errors.MisconfigurationError, errors.MisconfigurationError,
self.parser.update_runtime_variables) self.parser.update_runtime_variables)
@mock.patch("certbot_apache._internal.parser.subprocess.Popen") @mock.patch("certbot_apache._internal.apache_util.subprocess.Popen")
def test_update_runtime_vars_bad_exit(self, mock_popen): def test_update_runtime_vars_bad_exit(self, mock_popen):
mock_popen().communicate.return_value = ("", "") mock_popen().communicate.return_value = ("", "")
mock_popen.returncode = -1 mock_popen.returncode = -1
@@ -355,7 +355,7 @@ class ParserInitTest(util.ApacheTest):
ApacheParser, os.path.relpath(self.config_path), ApacheParser, os.path.relpath(self.config_path),
"/dummy/vhostpath", version=(2, 4, 22), configurator=self.config) "/dummy/vhostpath", version=(2, 4, 22), configurator=self.config)
@mock.patch("certbot_apache._internal.parser.ApacheParser._get_runtime_cfg") @mock.patch("certbot_apache._internal.apache_util._get_runtime_cfg")
def test_unparseable(self, mock_cfg): def test_unparseable(self, mock_cfg):
from certbot_apache._internal.parser import ApacheParser from certbot_apache._internal.parser import ApacheParser
mock_cfg.return_value = ('Define: TEST') mock_cfg.return_value = ('Define: TEST')
@@ -3,7 +3,7 @@ import unittest
import mock import mock
from certbot_apache.tests import util import util
class ConfiguratorParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-methods class ConfiguratorParserNodeTest(util.ApacheTest): # pylint: disable=too-many-public-methods
+2 -2
View File
@@ -2,8 +2,8 @@
import unittest import unittest
from certbot_apache import interfaces from certbot_apache._internal import interfaces
from certbot_apache import parsernode_util as util from certbot_apache._internal import parsernode_util as util
class DummyParserNode(interfaces.ParserNode): class DummyParserNode(interfaces.ParserNode):
+1 -1
View File
@@ -1,7 +1,7 @@
""" Tests for ParserNode utils """ """ Tests for ParserNode utils """
import unittest import unittest
from certbot_apache import parsernode_util as util from certbot_apache._internal import parsernode_util as util
class ParserNodeUtilTest(unittest.TestCase): class ParserNodeUtilTest(unittest.TestCase):
+1 -1
View File
@@ -111,7 +111,7 @@ def get_apache_configurator(
mock_exe_exists.return_value = True mock_exe_exists.return_value = True
with mock.patch("certbot_apache._internal.parser.ApacheParser." with mock.patch("certbot_apache._internal.parser.ApacheParser."
"update_runtime_variables"): "update_runtime_variables"):
with mock.patch("certbot_apache.apache_util.parse_from_subprocess") as mock_sp: with mock.patch("certbot_apache._internal.apache_util.parse_from_subprocess") as mock_sp:
mock_sp.return_value = [] mock_sp.return_value = []
try: try:
config_class = entrypoint.OVERRIDE_CLASSES[os_info] config_class = entrypoint.OVERRIDE_CLASSES[os_info]