Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Clean up for logging levels and tailing ansible output. Closes #213.
Browse files Browse the repository at this point in the history
  • Loading branch information
chambridge committed Aug 22, 2017
1 parent 91bd6d5 commit ee0f0da
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
6 changes: 4 additions & 2 deletions rho/clicommand.py
Expand Up @@ -16,6 +16,7 @@
import logging
import sys
from optparse import OptionParser # pylint: disable=deprecated-module
from rho.utilities import ensure_config_dir_exists
from rho.translation import _


Expand Down Expand Up @@ -71,14 +72,15 @@ def main(self):
# modules can just use Python logging and it will work with
# the verbosity by default.
self.verbosity = self.options.verbosity
if self.verbosity == 0:
if self.verbosity is None:
log_level = logging.WARNING
elif self.verbosity == 1:
log_level = logging.INFO
else:
log_level = logging.DEBUG

logging.basicConfig(level=log_level)
ensure_config_dir_exists()
logging.basicConfig(filename='data/rho_log', level=log_level)

self._validate_options()

Expand Down
4 changes: 2 additions & 2 deletions rho/factlistcommand.py
Expand Up @@ -25,8 +25,8 @@ class FactListCommand(CliCommand):

def __init__(self):
usage = _('usage: %prog fact list')
shortdesc = _('list facts that Rho can detect')
desc = _('list facts that Rho can detect. Filter fact names with '
shortdesc = _('list facts that rho can detect')
desc = _('list facts that rho can detect. Filter fact names with '
'--filter <regex>')

CliCommand.__init__(self, 'fact list', usage, shortdesc, desc)
Expand Down
5 changes: 1 addition & 4 deletions rho/scancommand.py
Expand Up @@ -305,7 +305,6 @@ def run_ansible_with_vault(cmd_string, vault_pass, ssh_key_passphrase=None,

if log_to_stdout:
tail = subprocess.Popen(['tail', '-f', '-n', '+0',
'--pid={0}'.format(child.pid),
log_path])

result = child.expect('Vault password:')
Expand All @@ -324,9 +323,7 @@ def run_ansible_with_vault(cmd_string, vault_pass, ssh_key_passphrase=None,
if child.isalive():
child.wait()
if log_to_stdout:
# tail will kill itself once it is done copying data
# to stdout, thanks to the --pid option.
tail.wait()
tail.terminate()

return child
except pexpect.EOF:
Expand Down
3 changes: 0 additions & 3 deletions test/test_clicommand.py
Expand Up @@ -14,7 +14,6 @@
""" Unit tests for CLI """

import contextlib
import logging
import unittest
import sys
import os
Expand Down Expand Up @@ -675,5 +674,3 @@ def test_verbosity(self):
command.main()

self.assertEqual(command.verbosity, 2)
self.assertEqual(logging.getLogger().getEffectiveLevel(),
logging.DEBUG)

0 comments on commit ee0f0da

Please sign in to comment.