← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1500896] [NEW] It's not necessary to pass context as kwarg to oslo.log in most cases

 

Public bug reported:

Nova is using oslo.context's RequestContext which means the context
object is in scope when doing logging using oslo.log:

http://docs.openstack.org/developer/oslo.log/usage.html#passing-context

But there are a lot of places in nova where we do something like:

        context = context.elevated()
        LOG.info(_LI("Rebooting instance"), context=context, instance=instance)

This is confusing because it makes you wonder if (1) you should be
passing context in logging method and (2) if it's OK to pass the
elevated context in this case or if you should be passing the original
context.

It turns out that in this case neither is necessary.  The elevated
context just has the admin flag set, the request / user / project IDs in
the context are left unchanged, which is what we want for logging.  And
the context is already in scope because of:

http://git.openstack.org/cgit/openstack/oslo.context/tree/oslo_context/context.py#n71

So we don't need to pass it as a kwarg.

This bug is meant to scrub through nova and remove any unnecessary
passing of the context object to oslo.log methods.

** Affects: nova
     Importance: Low
         Status: Triaged


** Tags: logging low-hanging-fruit

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Compute (nova).
https://bugs.launchpad.net/bugs/1500896

Title:
  It's not necessary to pass context as kwarg to oslo.log in most cases

Status in OpenStack Compute (nova):
  Triaged

Bug description:
  Nova is using oslo.context's RequestContext which means the context
  object is in scope when doing logging using oslo.log:

  http://docs.openstack.org/developer/oslo.log/usage.html#passing-
  context

  But there are a lot of places in nova where we do something like:

          context = context.elevated()
          LOG.info(_LI("Rebooting instance"), context=context, instance=instance)

  This is confusing because it makes you wonder if (1) you should be
  passing context in logging method and (2) if it's OK to pass the
  elevated context in this case or if you should be passing the original
  context.

  It turns out that in this case neither is necessary.  The elevated
  context just has the admin flag set, the request / user / project IDs
  in the context are left unchanged, which is what we want for logging.
  And the context is already in scope because of:

  http://git.openstack.org/cgit/openstack/oslo.context/tree/oslo_context/context.py#n71

  So we don't need to pass it as a kwarg.

  This bug is meant to scrub through nova and remove any unnecessary
  passing of the context object to oslo.log methods.

To manage notifications about this bug go to:
https://bugs.launchpad.net/nova/+bug/1500896/+subscriptions


Follow ups