Add ENTRYPOINT_DEBUG env config ad fix tests

pull/3/head v0.3.3
Christophe Mehay 8 years ago
parent 0bfa834b71
commit 4a56f62f71

@ -226,7 +226,10 @@ You have 4 available objects in your templates.
Some setups can be overridden using environment variables.
- `ENTRYPOINT_CONFIG` overrides path of `entrypoint-config.yml` file.
- `ENTRYPOINT_FORCE` applying configuration and run pre and post conf commands even if the `command` provided is not handled.
- `ENTRYPOINT_FORCE` is applying configuration and runs pre and post conf commands even if the `command` provided is not handled.
- `ENTRYPOINT_DEBUG` enables debug logs.
- `ENTRYPOINT_RAW` does not use logging to display pre and post conf commands.
This can be useful if output is serialized.
### Running Tests

@ -5,5 +5,8 @@ Some setups can be overridden using environment variables in the container.
- ``ENTRYPOINT_CONFIG`` overrides path of ``entrypoint-config.yml``
file.
- ``ENTRYPOINT_FORCE`` applying configuration and run pre and post conf
- ``ENTRYPOINT_FORCE`` applies configuration and runs pre and post conf
commands even if the ``command`` provided is not handled.
- ``ENTRYPOINT_DEBUG`` enables debug logs.
- ``ENTRYPOINT_RAW`` does not use logging to display pre and post conf commands.
This can be useful if output is serialized.

@ -150,6 +150,8 @@ class Config(object):
@property
def debug(self):
"""Enable debug logs."""
if 'ENTRYPOINT_DEBUG' in os.environ:
return True
if 'debug' in self._config:
return bool(self._config['debug'])
return False

@ -10,6 +10,7 @@ import os
from subprocess import PIPE
from subprocess import Popen
from sys import argv
from sys import exit
from sys import stdout
from jinja2 import Environment
@ -38,8 +39,11 @@ class Entrypoint(object):
self.config = Config(conf=conf, args=args)
except Exception as err:
self.log.error(err)
if self.config.debug:
Logs.set_debug()
self.log.critical('Fail to initialize config, exiting now')
exit(1)
else:
if self.config.debug:
Logs.set_debug()
self.args = args
@property

@ -2,3 +2,5 @@ command: bash
user: www-data
group: www-data
debug: true

@ -199,7 +199,7 @@ def test_command():
def test_config_file():
os.environ['ENTRYPOINT_CONFIG'] = 'configs/base.yml'
entry = Entrypoint(conf='configs/base.yml')
entry = Entrypoint()
assert entry.config.has_config
@ -207,7 +207,7 @@ def test_config_file():
def test_force_config():
entry = Entrypoint(conf='configs/base.yml')
entry = Entrypoint()
assert not entry.should_config
os.environ['ENTRYPOINT_FORCE'] = 'True'
@ -217,10 +217,19 @@ def test_force_config():
def test_display_raw():
entry = Entrypoint(conf='configs/base.yml')
entry = Entrypoint()
assert not entry.raw_output
os.environ['ENTRYPOINT_RAW'] = 'True'
assert entry.raw_output
del os.environ['ENTRYPOINT_RAW']
def test_debug_env():
os.environ['ENTRYPOINT_DEBUG'] = 'true'
entry = Entrypoint(conf='configs/empty.yml')
assert entry.config.debug
del os.environ['ENTRYPOINT_DEBUG']

Loading…
Cancel
Save