Move user logging and passing optional

Only pass the user in payload if it is not root and not the specified
user from the configuration file.  Those two users are implied to be
the executor if there's no specific user.  Log statements referencing
the user have been wrapped in statements testing for the existence of
the user key in the payload, otherwise log messages fall back to a
non-user log message (it will continue to do this for root).

This preserves backwards compatibility for masters that would never
pass the user as well
This commit is contained in:
Grier Johnson 2012-02-28 14:31:34 -08:00
parent 6a80f56a77
commit 679a3843b1
3 changed files with 44 additions and 30 deletions

View File

@ -94,6 +94,11 @@ class LocalClient(object):
for evar in env_vars:
if evar in os.environ:
return os.environ[evar]
return None
# If the running user is just the specified user in the
# conf file, don't pass the user as it's implied.
elif user == self.opts['user']:
return None
return user
def _check_glob_minions(self, expr):
@ -454,31 +459,27 @@ class LocalClient(object):
if not minions:
return {'jid': '',
'minions': minions}
# Generate the standard keyword args to feed to format_payload
payload_kwargs = { 'cmd': 'publish',
'tgt': tgt,
'fun': fun,
'arg': arg,
'key': self.key,
'tgt_type': expr_form,
'ret': ret,
'jid': jid }
# If we have a salt user, add it to the payload
if self.salt_user:
payload_kwargs['user'] = self.salt_user
# If we're a syndication master, pass the timeout
if self.opts['order_masters']:
package = salt.payload.format_payload(
'clear',
cmd='publish',
tgt=tgt,
fun=fun,
arg=arg,
key=self.key,
tgt_type=expr_form,
ret=ret,
jid=jid,
user=self.salt_user,
to=timeout)
else:
package = salt.payload.format_payload(
'clear',
cmd='publish',
tgt=tgt,
fun=fun,
arg=arg,
key=self.key,
tgt_type=expr_form,
jid=jid,
user=self.salt_user,
ret=ret)
payload_kwargs['to'] = timeout
package = salt.payload.format_payload( 'clear', **payload_kwargs)
# Prep zmq
context = zmq.Context()
socket = context.socket(zmq.REQ)

View File

@ -854,8 +854,12 @@ class ClearFuncs(object):
if 'to' in clear_load:
load['to'] = clear_load['to']
log.info(('User {0[user]} Published command {0[fun]} with jid'
' {0[jid]}').format(clear_load))
if 'user' in clear_load:
log.info(('User {0[user]} Published command {0[fun]} with jid'
' {0[jid]}').format(clear_load))
else:
log.info(('Published command {0[fun]} with jid'
' {0[jid]}').format(clear_load))
log.debug('Published command details {0}'.format(load))
payload['load'] = self.crypticle.dumps(load)

View File

@ -159,7 +159,12 @@ class Minion(object):
# from returning a predictable exception
#if data['fun'] not in self.functions:
# return
log.info('Executing command {0[fun]} with jid {0[jid]}'.format(data))
if 'user' in data:
log.info(('User {0[user]} Executing command {0[fun]} with jid '
'{0[jid]}'.format(data)))
else:
log.info(('Executing command {0[fun]} with jid {0[jid]}'
.format(data)))
log.debug('Command details {0}'.format(data))
self._handle_decoded_payload(data)
@ -472,9 +477,13 @@ class Syndic(salt.client.LocalClient, Minion):
or 'to' not in data or 'arg' not in data:
return
data['to'] = int(data['to']) - 1
log.debug(('Executing syndic command {0[fun]} with jid {0[jid]}'
.format(data)))
log.debug('Command details {0}'.format(data))
if 'user' in data:
log.debug(('User {0[user]} Executing syndic command {0[fun]} with '
'jid {0[jid]}'.format(data)))
else:
log.debug(('Executing syndic command {0[fun]} with jid {0[jid]}'
.format(data)))
log.debug('Command details: {0}'.format(data))
self._handle_decoded_payload(data)
def _handle_decoded_payload(self, data):