certbot/certbot-ci/certbot_integration_tests/apache_tests/context.py

52 lines
1.8 KiB
Python
Raw Permalink Normal View History

2019-08-28 15:51:22 -04:00
import errno
2019-08-28 06:23:24 -04:00
import os
2019-08-28 10:05:34 -04:00
import signal
import subprocess
2019-08-28 06:23:24 -04:00
from certbot_integration_tests.certbot_tests import context as certbot_context
2019-08-28 10:05:34 -04:00
from certbot_integration_tests.apache_tests import apache_config
from certbot_integration_tests.utils import certbot_call
2019-08-28 06:23:24 -04:00
class IntegrationTestsContext(certbot_context.IntegrationTestsContext):
def __init__(self, request):
super(IntegrationTestsContext, self).__init__(request)
2019-08-28 10:05:34 -04:00
subprocess.check_output(['chmod', '+x', self.workspace])
2019-08-28 06:23:24 -04:00
self.apache_root = os.path.join(self.workspace, 'apache')
os.mkdir(self.apache_root)
2019-08-28 11:16:58 -04:00
self.env, self.config_dir, self.pid_file = apache_config.construct_apache_config_dir(
2019-08-28 10:05:34 -04:00
self.apache_root, self.http_01_port, self.tls_alpn_01_port,
wtf_prefix=self.worker_id)
2019-08-28 06:23:24 -04:00
def cleanup(self):
self._stop_apache()
2019-08-28 11:16:58 -04:00
super(IntegrationTestsContext, self).cleanup()
2019-08-28 10:05:34 -04:00
def certbot_test_apache(self, args):
2019-08-28 11:16:58 -04:00
command = ['--authenticator', 'apache', '--installer', 'apache',
'--apache-server-root', self.config_dir,
'--apache-challenge-location', self.apache_root]
2019-08-28 10:05:34 -04:00
command.extend(args)
2019-08-28 06:23:24 -04:00
2019-08-28 10:05:34 -04:00
return certbot_call.certbot_test(
command, self.directory_url, self.http_01_port, self.tls_alpn_01_port,
2019-08-28 11:16:58 -04:00
self.config_dir, self.workspace, env=self.env, force_renew=True)
2019-08-28 06:23:24 -04:00
def _stop_apache(self):
2019-08-28 10:05:34 -04:00
try:
2019-08-28 11:16:58 -04:00
with open(self.pid_file) as file_h:
2019-08-28 10:05:34 -04:00
pid = int(file_h.read().strip())
except BaseException:
pid = None
if pid:
2019-08-28 15:51:22 -04:00
try:
os.kill(pid, signal.SIGTERM)
except OSError as err:
# Ignore "No such process" error, Apache may already be stopped.
if err.errno != errno.ESRCH:
raise