Gracefully print an error when running salt-call as non-root

Fixes #438

This also sets a default "level" argument to setup_console_logger()
to error which it already does when the level isn't in the dict.
This commit is contained in:
Jeff Schroeder 2012-01-07 21:37:05 -08:00
parent 8139578c4a
commit f02cb42be3
3 changed files with 6 additions and 2 deletions

View file

@ -54,7 +54,7 @@ def init():
logging.getLogger().setLevel(1)
def setup_console_logger(log_level):
def setup_console_logger(log_level='error'):
'''
Setup the console logger
'''

View file

@ -6,6 +6,7 @@ A few checks to make sure the environment is sane
import os
import sys
import logging
import salt.log
log = logging.getLogger(__name__)
__all__ = ('zmq_version', 'check_root', 'run')
@ -28,8 +29,9 @@ def check_root():
if 'os' in os.environ:
if os.environ['os'].startswith('Windows'):
return True
msg = 'Sorry, the salt must run as root. http://xkcd.com/838'
if os.getuid():
log.critical('Sorry, the salt must run as root. It needs to operate in a privileged environment to do what it does. http://xkcd.com/838/')
log.critical(msg)
return False
return True

View file

@ -5,6 +5,8 @@ minion to run.
'''
import salt.cli
import salt.log
salt.log.setup_console_logger()
def main():