This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/conf/init/test/test_supervisord_conf_create.py

54 lines
1.4 KiB
Python
Raw Normal View History

from contextlib import contextmanager
2019-11-12 16:09:47 +00:00
import os
import tempfile
from six import iteritems
from supervisor.options import ServerOptions
2019-11-12 16:09:47 +00:00
import jinja2
import pytest
2019-11-12 16:09:47 +00:00
from ..supervisord_conf_create import (default_services, limit_services, override_services,
QUAY_SERVICES, QUAY_OVERRIDE_SERVICES)
@contextmanager
def environ(**kwargs):
original_env = {key: os.getenv(key) for key in kwargs}
os.environ.update(**kwargs)
try:
yield
finally:
for key, value in iteritems(original_env):
if value is None:
del os.environ[key]
else:
os.environ[key] = value
2019-11-12 16:09:47 +00:00
def render_supervisord_conf(config):
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../supervisord.conf.jnj")) as f:
template = jinja2.Template(f.read())
return template.render(config=config)
def test_supervisord_conf_validates():
2019-11-12 16:09:47 +00:00
config = default_services()
limit_services(config, QUAY_SERVICES)
override_services(config, QUAY_OVERRIDE_SERVICES)
rendered_config_file = render_supervisord_conf(config)
print rendered_config_file
2019-11-12 16:09:47 +00:00
with environ(QUAYPATH='.', QUAYDIR='/', QUAYCONF='/conf', DB_CONNECTION_POOLING_REGISTRY='true'):
opts = ServerOptions()
2019-11-12 16:09:47 +00:00
with tempfile.NamedTemporaryFile() as f:
f.write(rendered_config_file)
f.flush()
2019-11-12 16:09:47 +00:00
opts.searchpaths = [f.name]
assert opts.default_configfile() == f.name
2019-11-12 16:09:47 +00:00
opts.realize([])
opts.process_config()