Fix PhaseLoggerMixin in case of compose has _logger = None

80fa723 breaks pungi-config-validate that using ValidationCompose
with _logger set to None.

Signed-off-by: Qixiang Wan <qwan@redhat.com>
This commit is contained in:
Qixiang Wan 2016-11-29 19:43:03 +08:00
parent dd814a5f4d
commit 75934f20e5
2 changed files with 46 additions and 9 deletions

View File

@ -162,6 +162,8 @@ class PhaseLoggerMixin(object):
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(PhaseLoggerMixin, self).__init__(*args, **kwargs) super(PhaseLoggerMixin, self).__init__(*args, **kwargs)
self.logger = None
if self.compose._logger and self.compose._logger.handlers:
self.logger = logging.getLogger(self.name.upper()) self.logger = logging.getLogger(self.name.upper())
self.logger.setLevel(logging.DEBUG) self.logger.setLevel(logging.DEBUG)
format = "%(asctime)s [%(name)-16s] [%(levelname)-8s] %(message)s" format = "%(asctime)s [%(name)-16s] [%(levelname)-8s] %(message)s"

View File

@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import mock
import os
import subprocess
import sys
HERE = os.path.abspath(os.path.dirname(__file__))
BINDIR = os.path.join(HERE, '../bin')
PUNGI_CONFIG_VALIDATE = os.path.join(BINDIR, 'pungi-config-validate')
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from tests import helpers
class ConfigValidateScriptTest(helpers.PungiTestCase):
@mock.patch('kobo.shortcuts.run')
def test_validate_dummy_config(self, run):
DUMMY_CONFIG = os.path.join(HERE, 'data/dummy-pungi.conf')
p = subprocess.Popen([PUNGI_CONFIG_VALIDATE, DUMMY_CONFIG],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
self.assertEqual(0, p.returncode)
self.assertEqual('', stdout)
self.assertEqual('', stderr)
if __name__ == '__main__':
unittest.main()