Skip to content

Commit

Permalink
1522383: Remove global option background
Browse files Browse the repository at this point in the history
* Bugfix: https://bugzilla.redhat.com/show_bug.cgi?id=1522383
* Removed background option, because it is not supported anymore.
* Removed obsolete usage of background option from init script
  service file.
* Fixed unit tests
  • Loading branch information
jirihnidek committed Jan 4, 2018
1 parent 7c8e7cd commit 068b2b4
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 33 deletions.
1 change: 0 additions & 1 deletion tests/test_config_section_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def test_validate_section_values(self):
# ),
# ('warning', 'Value for reporter_id not set, using default'),
# ('warning', 'Value for log_dir not set, using default'),
# ('warning', 'background must be a valid boolean, using default. See man virt-who-config for more info')
# ]
self.assertGreater(len(validate_messages), 0)
# self.assertEqual(expected_results, validate_messages)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def test_get_logger_no_config(self, open, getQueueLogger, isdir):
conf_values = {
'global': {
'debug': False,
'background': True,
'log_file': log.DEFAULT_LOG_FILE,
'log_dir': log.DEFAULT_LOG_DIR,
'log_per_config': False
Expand All @@ -74,7 +73,7 @@ def test_get_logger_no_config(self, open, getQueueLogger, isdir):
self.assertTrue(len(main_logger.handlers) == 1)
self.assertTrue(isinstance(main_logger.handlers[0], log.QueueHandler))
queue_handlers = queueLogger.logger.handlers
self.assertTrue(len(queue_handlers) == 1)
self.assertTrue(len(queue_handlers) == 2)
self.assertEquals(queue_handlers[0].baseFilename, '%s/%s' % (log.DEFAULT_LOG_DIR, log.DEFAULT_LOG_FILE))

@patch('virtwho.log.Logger.get_queue_logger')
Expand All @@ -88,7 +87,6 @@ def test_get_logger_different_log_file(self, getFileHandler, getQueueLogger):
options = {
'global':{
'debug': False,
'background': True,
'log_per_config': True,
'log_dir': '/test/',
'log_file': 'test.log',
Expand All @@ -99,7 +97,7 @@ def test_get_logger_different_log_file(self, getFileHandler, getQueueLogger):

self.assertTrue(test_logger.name == 'virtwho.test_log')
self.assertTrue(len(test_logger.handlers) == 1)
self.assertTrue(len(queueLogger.logger.handlers) == 1)
self.assertTrue(len(queueLogger.logger.handlers) == 2)
getFileHandler.assert_called_with(name=test_logger.name, config=options)

@patch('os.path.isdir')
Expand Down
1 change: 0 additions & 1 deletion tests/test_virtwho.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def test_default_cmdline_options(self, parseFile, getLogger):
sys.argv = ["virtwho.py"]
_, options = parse_options()
self.assertFalse(options[VW_GLOBAL]['debug'])
self.assertFalse(options[VW_GLOBAL]['background'])
self.assertFalse(options[VW_GLOBAL]['oneshot'])
self.assertEqual(options[VW_GLOBAL]['interval'], 3600)
self.assertEqual(options[VW_GLOBAL]['reporter_id'], util.generateReporterId())
Expand Down
2 changes: 0 additions & 2 deletions virt-who-initscript
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ set -a
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
set +a

export VIRTWHO_BACKGROUND=1

lockfile=/var/lock/subsys/virt-who

start() {
Expand Down
1 change: 0 additions & 1 deletion virt-who.service
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Type=notify
PIDFile=/var/run/virt-who.pid
ExecStart=/usr/bin/virt-who
EnvironmentFile=-/etc/sysconfig/virt-who
Environment=VIRTWHO_BACKGROUND=0
TimeoutStopSec=5

[Install]
Expand Down
1 change: 0 additions & 1 deletion virtwho/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,6 @@ def __init__(self, *args, **kwargs):
self.add_key('oneshot', validation_method=self._validate_str_to_bool, default=False)
self.add_key('print_', validation_method=self._validate_str_to_bool, default=False, destination='print')
self.add_key('log_per_config', validation_method=self._validate_str_to_bool, default=False)
self.add_key('background', validation_method=self._validate_str_to_bool, default=False)
self.add_key('configs', validation_method=self._validate_list, default=[])
self.add_key('reporter_id', validation_method=self._validate_non_empty_string,
default=util.generateReporterId())
Expand Down
17 changes: 4 additions & 13 deletions virtwho/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,9 @@ class Logger(object):
_level = logging.DEBUG
_rhsm_level = logging.WARN
_queue_logger = None
_background = False

@classmethod
def initialize(cls, log_dir=None, log_file=None, log_per_config=None,
debug=None, background=None):
def initialize(cls, log_dir=None, log_file=None, log_per_config=None, debug=None):
# Set defaults if necessary
if log_dir:
cls._log_dir = log_dir
Expand All @@ -187,7 +185,6 @@ def initialize(cls, log_dir=None, log_file=None, log_per_config=None,
cls._level = logging.DEBUG if debug else logging.INFO
# We don't want INFO message from RHSM in non-debug mode
cls._rhsm_level = logging.DEBUG if debug else logging.WARN
cls._background = bool(background)

@classmethod
def get_logger(cls, name=None, config=None, queue=True):
Expand Down Expand Up @@ -228,9 +225,8 @@ def get_logger(cls, name=None, config=None, queue=True):
# we're running under systemd, log to journal
journal_handler = cls.get_journal_handler()
else:
# we're not running under systemd, set up streamHandler if we're not running in the background
if not cls._background:
stream_handler = cls.get_stream_handler(name)
# we're not running under systemd, set up streamHandler
stream_handler = cls.get_stream_handler(name)

if queue:
queue_logger = cls.get_queue_logger()
Expand Down Expand Up @@ -318,9 +314,8 @@ def init(config):
log_file = config['global']['log_file']
log_per_config = config['global']['log_per_config']
debug = config['global']['debug']
background = config['global']['background']
return Logger.initialize(log_dir=log_dir, log_file=log_file, log_per_config=log_per_config,
debug=debug, background=background)
debug=debug)


def getLogger(name=None, config=None, queue=True):
Expand All @@ -329,10 +324,6 @@ def getLogger(name=None, config=None, queue=True):
the main logger instance used from virtwho as well as loggers for
all the connected virt backends
If virt-who is running in background mode, the double fork closes all the
filedescriptiors, disrupting communication to queue logger. So the
queue logger is created after the initialization phase (after the fork).
First the logger is created without the queue and it's added later on
(after the fork).
"""
Expand Down
8 changes: 1 addition & 7 deletions virtwho/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def main():
print >> sys.stderr, msg
exit(1, status=msg)


if not options[VW_GLOBAL].is_valid():
message = "Required section 'global' is invalid:\n"
message += "\n".join([msg for (level, msg) in options[VW_GLOBAL].validation_messages])
Expand Down Expand Up @@ -159,13 +158,8 @@ def main():

logger.info("Using reporter_id='%s'", options[VW_GLOBAL]['reporter_id'])
log.closeLogger(logger)
if options[VW_GLOBAL]['background']:
# This DaemonContext seems to cause import issues
locker = lambda: daemon.DaemonContext(pidfile=lock) # flake8: noqa
else:
locker = lambda: lock # flake8: noqa

with locker():
with lock:
signal.signal(signal.SIGHUP, reload)
signal.signal(signal.SIGTERM, atexit_fn)

Expand Down
3 changes: 0 additions & 3 deletions virtwho/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ def store_value(_options, _attr, _env):
store_value),
"VIRTWHO_DEBUG": ("debug",
store_const, "true"),
"VIRTWHO_BACKGROUND": ("background",
store_const,
"true"),
"VIRTWHO_ONE_SHOT": ("oneshot",
store_const,
"true"),
Expand Down

0 comments on commit 068b2b4

Please sign in to comment.