Skip to content

Get default logging level and log file from default opts dict - #37272

Merged
cachedout merged 19 commits into
saltstack:2016.3from
vutny:fix-getting-default-logging-opts
Nov 28, 2016
Merged

cachedout merged 19 commits into
saltstack:2016.3from
vutny:fix-getting-default-logging-opts

Conversation

@vutny

@vutny vutny commented Oct 27, 2016 •

Copy link
Copy Markdown
Contributor

What does this PR do?

It establishes a single source of truth for default logging level and log file path setting for Salt components. In other words, the motivation is to get rid of hard-coded values in salt/utils/parsers.py which are not taken into account in any case, but this could give some side-effects like described below.

What issues does this PR fix or reference?

For example, the salt-call and salt-cloud commands are displaying wrong information about default log-level in their online help.

I have completely empty /etc/salt/minion file and nothing in /etc/salt/minion.d.
Help says that default log level is info:

# salt-call --help
Usage: salt-call [options] <function> [arguments]

Salt call is used to execute module functions locally on a minion

...
  Logging Options:
    Logging options which override any settings defined on the
    configuration files.

    -l LOG_LEVEL, --log-level=LOG_LEVEL
                        Console logging log level. One of 'all', 'garbage',
                        'trace', 'debug', 'profile', 'info', 'warning',
                        'error', 'critical', 'quiet'. Default: 'info'.
    --log-file=LOG_FILE
                        Log file path. Default: '/var/log/salt/minion'.
    --log-file-level=LOG_LEVEL_LOGFILE
                        Logfile logging log level. One of 'all', 'garbage',
                        'trace', 'debug', 'profile', 'info', 'warning',
                        'error', 'critical', 'quiet'. Default: 'info'.

But actually it is not:

# salt-call config.get log_level
local:
    warning

Tests written?

No

@cachedout

Copy link
Copy Markdown
Contributor

I think is is all likely fine but I believe it should go in develop instead of in a point release. @vutny what do you think about resubmitting this PR on the develop branch?

@cachedout cachedout added the pending-discussion The issue or pull request needs more discussion before it can be closed or merged label Oct 28, 2016
@vutny

vutny commented Oct 28, 2016

Copy link
Copy Markdown
Contributor Author

@cachedout At first look this was a minor issue to me. I've spotted that Salt commands are displaying wrong default log-level settings, instead of real default and documented values.

But when I looked at code in salt/utils/parsers.py I've found that there are just hard-coded log level and file default settings for each CLI tool. And they are different for salt-call and salt-cloud option parsers than the settings defined in salt/config/__init__.py.

The problem here is that the only method which honors such settings is _mixin_setup in LogLevelMixIn class when it constructs help messages for those options. In all other cases the defaults from salt.config module are taking precedence. Local defaults are ignored because config dictionaries already have instantiated the settings from constants even if user didn't redefined them.

Currently, only the help messages are affected (this is all I've found so far), but it's very easy to forget/miss the fact that different logging settings are defined twice in the code, which may lead to a situation where some parts of the code would use local defaults, but others use "real" ones.

TL;DR

I believe this should be fixed in earliest branch possible, but it appears that the 2015.8 is left behind to much. That's why I think this PR should go to the 2016.3 since it will be kept maintained long enough.

@cachedout

Copy link
Copy Markdown
Contributor

@s0undt3ch Any comments on this?

@isbm

isbm commented Nov 2, 2016 •

Copy link
Copy Markdown
Contributor

@cachedout I think this is a good idea. I went through the PR and seems like it does the right thing. The only thing is that this should have also unit tests, as it touches released versions and we unlikely want to have an adventures here.

So, @vutny, please make a Unit Test for this, or let it be only in develop for now.

Oh, and this can be also done to 2015.8, if @vutny does not mind to back-port that there. We will happily accept the patch to our package! 😄

@cachedout

Copy link
Copy Markdown
Contributor

@isbm Sounds totally reasonable.

@vutny Any chance you could make a unit test here?

@vutny

vutny commented Nov 3, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @isbm !

@cachedout , I'll try to get my hands on writing some unit test(s) for this particular case. Stay tuned 😄

@cachedout

Copy link
Copy Markdown
Contributor

@vutny Great! We'll also need this rebased, since it's now conflicting. Thanks.

@cachedout

Copy link
Copy Markdown
Contributor

Thanks for the rebase. Let me know when you have tests ready and we'll get this in. Thanks, @vutny

@cachedout

Copy link
Copy Markdown
Contributor

Hi @vutny

No hurry here but just checking with you on the test progress. Thanks!

@vutny

vutny commented Nov 11, 2016

Copy link
Copy Markdown
Contributor Author

@cachedout Thanks for the ping back.

I'm working on the tests and actually discovering many little inconsistencies in the code during the process 😄
I think I'm close to finish it soon enough.

@cachedout

Copy link
Copy Markdown
Contributor

Thanks, @vutny. Just let me know when you're ready to go.

@vutny

vutny commented Nov 21, 2016

Copy link
Copy Markdown
Contributor Author

@cachedout Finally, this day has come! 😄
I've added 130 unit tests for parsing logging options expressed via CLI and configuration for all Salt executables.

Please review, now it's ready for merge.

@cachedout
cachedout merged commit ea46639 into saltstack:2016.3 Nov 28, 2016
@cachedout

Copy link
Copy Markdown
Contributor

Great work here, @vutny. We really appreciate this one!

@vutny
vutny deleted the fix-getting-default-logging-opts branch November 29, 2016 12:55
@Ch3LL Ch3LL mentioned this pull request Jan 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-discussion The issue or pull request needs more discussion before it can be closed or merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants