Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --debug argument and some logging when retrieving CI status #2467

Merged
merged 3 commits into from
Aug 15, 2018

Conversation

pypingou
Copy link
Member

@pypingou pypingou commented Jul 3, 2018

No description provided.

@fedora-infra fedora-infra deleted a comment from centos-ci Jul 3, 2018
@pypingou pypingou force-pushed the debug_mode branch 2 times, most recently from 03201bf to 90e07fb Compare July 3, 2018 14:53
@fedora-infra fedora-infra deleted a comment from centos-ci Jul 3, 2018
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
log.addHandler(ch)
log.setLevel(logging.DEBUG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libraries should not set up logging handlers or set log levels. This library is not just used by the bodhi cli and so it should be unopinionated about logging. It's OK for the lib to log things at debug level, but the logger should not be configured by it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any preference where we could configure it?
I thought this was a good place since it was common with all the actions performed by the CLI, but I'm fine w/ changing this :)

@bowlofeggs
Copy link
Contributor

bowlofeggs commented Jul 25, 2018 via email

@pypingou pypingou requested a review from a team as a code owner July 26, 2018 11:19
@pypingou
Copy link
Member Author

One way I can think of to do it as a common action so you don't have to repeat code is you could set up a validator on the --debug flag that does this if --debug is set. There's already a validator in there on at least one flag as an example.

Is the validator you have in mind the callback used for the --url argument? If not then I need to look further for this validator as I think I didn't find it then :s

I took a little bit of a different approach in the mean while, I've added the --debug argument to the cli() method, so all actions have it, but it needs to be specified at the beginning of the argument list, for example:
bodhi --debug updates waive python-arrow-0.8.0-5.fc28 --show --staging
works while:
bodhi updates waive python-arrow-0.8.0-5.fc28 --show --staging --debug does not.

Again, if you prefer the validator approach I'll look into it some more :)

@bowlofeggs
Copy link
Contributor

bowlofeggs commented Jul 26, 2018 via email

@pypingou
Copy link
Member Author

I've pushed a commit porting --debug to use a callback mechanism as --url does. You will see it requires more changes than the cli() approach. If you're fine with that approach, I'll merge the third commit into the first one to clean up the history :)

@pypingou
Copy link
Member Author

Rebased to fix the conflict

@pypingou
Copy link
Member Author

pypingou commented Jul 27, 2018

--hm these tests are definitively passing locally :(--

Nevermind the last comment from jenkins confused me, they are also passing on jenkins now it seems :)

@fedora-infra fedora-infra deleted a comment from centos-ci Jul 27, 2018
client = bindings.BodhiClient(base_url=url, staging=kwargs['staging'])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated style change, so let's leave it as it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -295,7 +327,7 @@ def new(user, password, url, **kwargs):
True.
kwargs (dict): Other keyword arguments passed to us by click.
"""

kwargs.pop('debug')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what you meant by being a larger change? If so, a cleaner way to do this is to add debug as a parameter to each of these functions so it doesn't end up in kwargs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will fix

Copy link
Contributor

@bowlofeggs bowlofeggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more minor changes.

@@ -244,7 +274,8 @@ def composes():
@staging_option
@click.option('-v', '--verbose', is_flag=True, default=False, help='Display more information.')
@url_option
def list_composes(url, staging, verbose):
@debug_option
def list_composes(url, staging, verbose, debug):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we still document parameters in the "developer docs" section below, here and elsewhere in the file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add

@@ -295,7 +327,6 @@ def new(user, password, url, **kwargs):
True.
kwargs (dict): Other keyword arguments passed to us by click.
"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an unrelated style change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove

@add_options(pagination_options)
@handle_errors
def query(url, mine=False, rows=None, **kwargs):
def query(url, mine=False, rows=None, debug=False, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not define the default for debug in two places. If you move this to be after url, you don't need to give it a default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

mock.MagicMock(return_value='a_csrf_token'))
@mock.patch('bodhi.client.bindings.BodhiClient.send_request',
return_value=client_test_data.EXAMPLE_UPDATE_MUNCH, autospec=True)
def test_severity_and_debug_flags(self, send_request):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is really about testing the debug flag, so let's name it test_debug_flag for simplicity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will adjust

Copy link
Member Author

@pypingou pypingou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review

@@ -244,7 +274,8 @@ def composes():
@staging_option
@click.option('-v', '--verbose', is_flag=True, default=False, help='Display more information.')
@url_option
def list_composes(url, staging, verbose):
@debug_option
def list_composes(url, staging, verbose, debug):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add

@@ -295,7 +327,6 @@ def new(user, password, url, **kwargs):
True.
kwargs (dict): Other keyword arguments passed to us by click.
"""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will remove

@add_options(pagination_options)
@handle_errors
def query(url, mine=False, rows=None, **kwargs):
def query(url, mine=False, rows=None, debug=False, **kwargs):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

mock.MagicMock(return_value='a_csrf_token'))
@mock.patch('bodhi.client.bindings.BodhiClient.send_request',
return_value=client_test_data.EXAMPLE_UPDATE_MUNCH, autospec=True)
def test_severity_and_debug_flags(self, send_request):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will adjust

@pypingou
Copy link
Member Author

pypingou commented Aug 1, 2018

I think I got all of your comments, I also merged the new approach into the old one making the history cleaner.

@bowlofeggs
Copy link
Contributor

bowlofeggs commented Aug 1, 2018 via email

Copy link
Contributor

@bowlofeggs bowlofeggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just 3 small things I'd like to fix, then we'll be good to merge.

Args:
ctx (click.core.Context): The Click context. Unused.
param (click.core.Option): The option being handled. Unused.
value (unicode): The value of the --debug flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bool, not a unicode.

param (click.core.Option): The option being handled. Unused.
value (unicode): The value of the --debug flag.
Returns:
unicode: The value of the --debug flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a bool.

url_option = click.option('--url', envvar='BODHI_URL', default=bindings.BASE_URL,
help=('URL of a Bodhi server. Ignored if --staging is set. Can be set '
'with BODHI_URL environment variable'),
callback=_warn_if_url_and_staging_set)
staging_option = click.option('--staging', help='Use the staging bodhi instance',
is_flag=True, default=False)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated style change.

@bowlofeggs
Copy link
Contributor

I will fix these three things myself.

@bowlofeggs bowlofeggs self-assigned this Aug 15, 2018
This creates a stream handler to the log and set its level to 'DEBUG'.
This way we can use more log.info()/log.debug() in the binding files and
ask users to run the CLI with --debug to give us more context as to what
is going on.

Signed-off-by: Pierre-Yves Chibon <[email protected]>
This way when running with --debug, we should be able to have more clues
as to what is going on (if anything).

Signed-off-by: Pierre-Yves Chibon <[email protected]>
@mergify mergify bot merged commit 31c1081 into develop Aug 15, 2018
@bowlofeggs bowlofeggs deleted the debug_mode branch August 15, 2018 16:46
@pypingou
Copy link
Member Author

Thanks @bowlofeggs :)

@bowlofeggs
Copy link
Contributor

These patches are planned to be included in the upcoming 3.10.0 release: #2556.

@bowlofeggs
Copy link
Contributor

These patches are available in Copr:

https://copr.fedorainfracloud.org/coprs/bowlofeggs/bodhi-pre-release/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants