Commit Graph

83 Commits

Author SHA1 Message Date
Jay Faulkner 800c58826e Utilize the new RequestContext redacted_copy method
We now expect context objects to support returning a redacted copy of
themselves.

As a related cleanup, removed the practice entirely of using
dictionaries to represent contexts in unit tests and the logging driver.

As part of developing this change, I discovered code in Glance (and
potentially other services) which explicitly pass {} in lieu of a
context when notifying; so we now properly handle dictionaries as
contexts.

To ensure we have the method required; require oslo.context 5.3.0 or
newer.

Change-Id: I894f38cc83c98d3e8d48b59864c0c7c2d27e7dcd
2024-01-16 12:08:20 -08:00
Jay Faulkner c1b606f77e Add is_admin to safe fields list for notifications
We encountered bug 2037312 in unit tests when attempting to get this
change rolled out. Heat apparently will attempt to set is_admin using
policy logic if it's not passed in for a new context; this breaks as the
context we are requested doesn't have all the needed information to
exercise the policy logic.

is_admin is just a bool; it's not sensitive; easiest route forward is to
add it to the safe list

Closes-bug: 2037312
Change-Id: I78b08edfcb8115cddd7de9c6c788c0a57c8218a8
2023-09-25 17:51:32 +00:00
Jay Faulkner 1b315615e7 Only allow safe context fields in notifications
Publishing a fully hydrated context object in a notification would give
someone with access to that notification the ability to impersonate the
original actor through inclusion of sensitive fields.

Now, instead, we pare down the context object to the bare minimum before
passing it for serialization in notification workflows.

Related-bug: 2030976
Change-Id: Ic94323658c89df1c1ff32f511ca23502317d0f00
2023-08-11 13:07:54 -07:00
Balazs Gibizer 7b3968d9b0 [rabbit] use retry parameters during notification sending
The rabbit backend now applies the [oslo_messaging_notifications]retry,
[oslo_messaging_rabbit]rabbit_retry_interval, rabbit_retry_backoff and
rabbit_interval_max configuration parameters when tries to establish the
connection to the message bus during notification sending.

This patch also clarifies the differences between the behavior
of the kafka and the rabbit drivers in this regard.

Closes-Bug: #1917645
Change-Id: Id4ccafc95314c86ae918336e42cca64a6acd4d94
2022-01-12 12:22:55 +01:00
dengzhaosen 39826f06f1 Remove the oslo_utils.fnmatch
Oslo.utils's fnmatch module was added to fix the py2.7 fnmatch module
who was not thread safe [1]. Python 2.7 is no longer supported so now we
can use the stdlib's fnmatch module and deprecate the one of oslo.utils.

[1] https://bugs.python.org/issue23191$

Change-Id: Id5381a0a5216783f0df594b126786947db16a8d1
2021-05-11 01:02:11 +00:00
Andreas Jaeger e44c988306 Remove six usage
Remove six, the python 2/3 compatibility library. It's not needed
anymore since the repo is python3 only.

Remove a now unneeded hacking test.

Change-Id: I40522c4accb4aaf8115d11fee8b081e2d991cb4d
2020-05-11 10:21:58 +02:00
Andreas Jaeger 7f638bb493 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Update local hacking check for new flake8 version.

Blacklist:
W504 line break after binary operator

Fix:
E741 ambiguous variable name
E117 over-indented
E305 expected 2 blank lines after class or function definition, found 1
F841 local variable 'e' is assigned to but never used
W605 invalid escape sequence '\.'

Change-Id: I99d574ca6569f1f177d2c5ce1011f269f4343619
2020-03-30 13:49:29 +00:00
Hervé Beraud fed48aea44 Remove the deprecated blocking executor
The blocking executor has been deprecated in Pike and marked for removal
in Rocky, but some user like Mistral asked us to wait before. We decided
to remove this executor for Train or next cycle, now we are in the
Ussuri and after some researchs on usage I think we can go ahead.

This patch drop the deprecation warnings, related unit tests and
set the server with the threading executor is the default executor.

Change-Id: If07bab61ee2b148658b88be98b12f8539f274efe
Closes-Bug: #1715141
2020-02-18 15:49:27 +01:00
Hervé Beraud 1a860467bd Add help msg to payload for CLI notifier
Change-Id: I3d712ecfcea00ece0180108c585c858795fd2bce
2019-05-23 18:52:19 +02:00
Hervé Beraud 4f385720d7 Remove log translation and i18n
Log messages are no longer being translated. This removes all use of
the _LE, _LI, and _LW translation markers to simplify logging and to
avoid confusion with new contributions.

Change-Id: I9ddb6595fc52e46ed8844e39d2fa71029c90b65c
Closes-Bug: #1674567
2019-04-24 11:55:38 +02:00
Kenneth Giusti 855a85fa2d Clarify the documentation for pooled Notification Listeners
Change-Id: I184b045edaa8e61f075df576992426e94bf7386a
Closes-Bug: #1814544
2019-03-11 09:31:38 -04:00
Steve Kowalik e55f419017 Remove transport aliases support
To facilitate removing rpc_backend support, disentangle the aliases
code by removing it to simplify the code and the tests. Aliases were
first depreacted in 5.20.0 during Pike.

Change-Id: I7d80cd050ce1eca2c6b6c38f0fac29d090b90bf3
Closes-Bug: #1424728
2018-07-05 15:58:05 +10:00
Zuul c7eb5cac66 Merge "sort when using groupby" 2017-11-29 19:43:46 +00:00
gord chung 7c65038e79 don't convert generator to list unless required
there's only one scenario where the generator actually needs to be
forced into a list. don't waste time doing something unnecessary.

Change-Id: Iec897b1f6fed3d88b798eb673779e7c68ff930ec
2017-11-27 13:41:31 -05:00
gord chung b8a686fc52 sort when using groupby
groupby requires items to be sorted as it's clumping consecutive
items together. also, just use itemgetter instead of lambda

Change-Id: I1676fc60ebc2c9ff03ea00cc67061fdfb3b50868
2017-11-26 10:46:58 -05:00
Rajath Agasthya 03b6f18f80 Warn when wrong transport instance is used
Since RPC and notifications can have different backends, it is
useful to warn users if they use a notification transport in RPC
and vice versa. This patch introduces RPCTransport and
NotificationTransport subclasses of Transport, so it's easier to
add different behavior for them if need be.

Related-Bug: #1680192
Change-Id: Iab60544d69053c8e74c28a2d5c84665be749013f
2017-09-11 07:07:30 -07:00
Mehdi Abaakouk 2566be199a deprecated blocking executor
Using blocking executor is not recommended for application. But it looks
like some use it just because it's the default and are not aware their
should change it despite of documentation and logging message.

Choosing the application threading model is an important step
of an application.

This change deprecates it, in the future we will just make executor
mandatory. This will ensure that application make a choice.

Also this will reduce headache of oslo.messaging developers to
make the driver code working in a sync and async.

And to finish test coverage of blocking executor is 0%...

This rework some tests to remove logging.captureWarnings() that can
catch unwanted warning of other tests. Tests mocks warning instead.

Related-bug: #694728
Change-Id: Ic67164d12e7a9bed76d6e64ca2ced12e3984ff5f
2017-06-04 14:27:41 +02:00
Kenneth Giusti c7d880c33a Clean up the TransportURL documentation
Be specific regarding which characters can be used in the 'username'
and 'password' fields of the URL.

Change-Id: I9a2a801b3dd86fceffb05f4d52c715748c88d0cb
Closes-Bug: #1693967
2017-06-01 15:43:03 -04:00
Andrew Smith ec4d6639bc Add get_rpc_transport call
The get_rpc_transport wraps get_transport to unify the API in
anticipation of comprehensive separation of RPC and Notification
messaging backends.

Related-Bug: 1680192
Change-Id: Ic6af07b98ff43806c2af38a3ba129991f1e0ec86
2017-05-12 12:30:41 -04:00
Elancheran Subramanian cc406e4edc Retry support for oslo_messaging_notifications driver
When the underlying RPC is configured with rabbit along
with oslo_messaging_notifications, currently the retry is
not supported. There are retry support specific to drivers,
it's better to have the support uniform across the drivers,
by adding configuration retry on the oslo_messaging_notifier.

Closes-bug: 1666364

Change-Id: I8d547ef2a9e8b086f94a1efca17735f3f3cdaac1
2017-04-18 11:53:19 -07:00
ChangBo Guo(gcb) abc269b7e5 Trivial: Add executor 'threading' in docstring
oslo.messaging supports three types of executors: blocking, eventlet
and threading, so it's good to list all of them in docstring.

Change-Id: Ief14d54b5f029cf3e9c79334e405dca5cf2dc13d
2017-03-20 17:24:32 +08:00
Jenkins 4f7198597e Merge "Allow checking if notifier is enabled" 2017-03-06 18:30:03 +00:00
Matt Riedemann afd4ecfb42 Remove old messaging notify driver alias
15cd99050c added this alias
to workaround an issue with neutron using the internal
path in liberty. That was fixed in neutron in mitaka:

225663888e71d44e9732951f515da925b8799b74

The alias was left for liberty, but liberty is end of life
now so we can remove this.

Change-Id: I145921b98d48e03df38ebcbaebc1a4375911f9ff
2017-03-05 17:33:21 -05:00
Balazs Gibizer ed149bae81 Allow checking if notifier is enabled
Generating the payload of a notificatiton might be expensive due
to database access. This expensive step is unnecessary if the
notification driver is set to noop because it means that the
generated payload will not be sent.

This patch makes it possible for the user of the notifier to check
if the notifier will emit any notification before the payload
is generated.

Cinder already implemented similar behavior in
I77f655d3ef90088ce71304da5d4ea7b543991e90 and nova also plans
to do it in I3e6741d59df49e1e58409314008c2ed609fdedc1

Change-Id: Ib992f5c20fef85224fb00823e1d8d9c6cff19bec
2017-03-03 17:47:52 +01:00
gord chung 94c818dc98 drop topic keyword from Notifier
we marked it for removal >=5.0.0

Change-Id: I4634c082c2383569c4aa8a6d9a8a560de7e3c12f
2017-02-27 14:13:11 +00:00
Li-zhigang ea8fad47a5 Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using six.iteritems to achieve iterators.
We can use dict.items instead, as it will return iterators in PY3 as well.
And dict.items/keys will more readable. 2.In py2, the performance about
list should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: Ia235afc3532f62f265f91ca46d2306c72fc2a2a2
2016-11-23 09:02:14 +00:00
Hiroyasu.OHYAMA beb23103b0 [document] The example which is written in the developer guide of
'Notification Listener' doesn't work.

I fixed the example which is described in developer guide to work fine.
These are the main points of this correction.

* specify namespace for NotificationFilter.
* set 2 blank lines between class definitions according to E302 of pep8.
* change argument of 'pool' to keyward arguemnt, because 4th argument of
  'get_notification_listener' requires the name of message executor.

Change-Id: I75800309f2294fe9f17ea2a2b1638de57ef2922e
Closes-Bug: #1618394
2016-10-07 18:07:00 +09:00
Kenneth Giusti 9bc9c0dc6a Fixups to the inline documentation
Rework the inline documentation for executors, RPC servers and
clients, notifiers and notification listeners for clarity and flow.

Change-Id: If4f1db853a7fc85340177fd2c9c43a479d72459d
2016-09-12 09:49:00 -04:00
tengqm 3cdfe15897 Fix notify filter when data item is None
When data[k] is None during match check, we are getting annoying
TypeError exceptions like: "TypeError: expected string or buffer".
This patch adds a check that data[k] is something the regex can do
matching.

Change-Id: I75c8f602a59a90aeb5a6973f2e9e25708194ad78
2016-09-03 14:45:44 +00:00
George Silvis, III a011cb2448 Add docstring for get_notification_transport
This was previously undocumented.  Most of the information was taken from the
docstring for get_transport

Change-Id: I92652f4de9dd1e59ae5c3f9ce39e5ee808f24c7d
2016-08-15 11:51:47 -04:00
Gregory Haynes 317641c42f Fix syntax error on notification listener docs
We are missing a list delimiter in our docs example for a notification
listener.

Change-Id: Ib8b9c35e7bff241bf8473a98a2ee188da7e194e4
2016-07-28 01:57:35 +00:00
Julien Danjou ff9b4bb938 notify: add a CLI tool to manually send notifications
Change-Id: I01ebd8402e322c5c27dc2fc4c61fb5beb2dddae8
2016-07-13 17:30:56 +02:00
liusheng e57afac051 [Trival] fix a typo nit
Change-Id: I3d40726cf55aedb838ebe605f3d58618d594acca
2016-06-13 16:34:12 +08:00
Mehdi Abaakouk 5dd059aa3c Remove deprecated localcontext
Change-Id: Ib109ced5ee6a706853b0f54be6756cfaf63e2164
2016-05-18 09:28:15 +02:00
Dmitriy Ukhlov 4df633db74 Improves exception handling and logging
1) try to catch all possible exceptions during message acknowledging
    and dispatching to send ack/nack when we can to do it
2) improve logging in case of exceptions during message acknowledging
    and dispatching

Depends-On: I2d230d49e5aff6ab4d84ab8c3d2834f85e3405eb
Change-Id: I41a768c5624fa2212257ce20bf9a67d09de0c4ab
2016-04-26 12:34:46 +00:00
Jenkins f22a1a4fec Merge "Refactor base interfaces" 2016-04-22 14:01:08 +00:00
ZhiQiang Fan 5b94b4b7a9 use thread safe fnmatch
fnmatch is not thread safe in python <2.7.10, let's use the safe
one in oslo.utils

Change-Id: If3d480436506ecc5f3c2fcbd51ceaac59f2b7dec
ref: https://hg.python.org/cpython/rev/fe12c34c39eb
2016-04-21 11:43:53 +08:00
Dmitriy Ukhlov 6db00c77b0 Refactor base interfaces
1) Add MessageHandler base interface for on_incoming_callback replacement
2) Move message_handler parameter form Listener's __init__() to start()
3) Remove wait method from listener

Change-Id: Id414446817e3d2ff67b815074d042a9ce637ec24
2016-04-20 20:46:28 +00:00
Jenkins 55c0b3b52f Merge "Make transport_url config option secret" 2016-04-07 15:05:23 +00:00
Juan Antonio Osorio Robles cbaf71edfa Make transport_url config option secret
The transport_url may contain credentials to the message queue; For
this reason, this option should be secret for it to not leak into the
logs.

Closes-Bug: #1567233

Change-Id: I49c641a2662976d7220e4222e3c4a4d2586b1336
2016-04-07 05:43:18 +00:00
Dmitriy Ukhlov 5d7d7253d1 Refactor driver's listener interface
Current Listener interface has poll() method which return messages

To use it we need have poller thread which is located in MessageHandlerServer
But my investigations of existing driver's code shows that some implemetations have
its own thread inside for processing connection event loop. This event loop received
messages and store in queue object. And then our poller's thread reads this queue
This situation can be improved. we can remove poller's thread, remove queue object
and just call on_message server's callback from connection eventloop thread

This path provide posibility to do this for one of drivers and leave as is other drivers

Change-Id: I3e3d4369d8fdadcecf079d10af58b1e4f5616047
2016-04-05 18:08:08 +00:00
Jenkins d4e8ac42b5 Merge "Move server related logic from dispatchers" 2016-03-30 15:36:03 +00:00
Dmitriy Ukhlov 990d894eaf Move server related logic from dispatchers
Dispatcher should be responsible for routing message to the
callback method of endpoint object and returning result back to the
server only. But now it is also responsible for sending reply,
ack/reque messages etc.

Also this patch makes small improvements:
   1) Notification dispatcher now requeue message if endpoint raises exception
   2) unstable behaviour of test_mask_passwords test is fixed

Change-Id: I5f23e23644e90919cb67f81fc306ee85c5e09974
2016-03-30 11:07:32 +00:00
Davanum Srinivas f8969e97ce [py34] replace file() with open()
Running flake8 with python3 finds this problem:
./oslo_messaging/notify/_impl_routing.py:55:16: F821 undefined name 'file'
        return file(filename, 'r')

Change-Id: I5cd7475618f7a7532db770c2c5c61576a657fbb4
2016-03-24 11:32:25 +00:00
Jenkins cc89fc3174 Merge "Revert "Ensure the json result type is bytes on Python 3"" 2016-03-11 14:25:05 +00:00
Victor Stinner bb4121a465 Revert "Ensure the json result type is bytes on Python 3"
This reverts commit bd81d09c02.

I understand that the change was supposed to fix something, but instead it broke all tests on Python 3!?

It's wrong to replace blindly json.dumps() with jsonutils.dump_as_bytes(). In oslo messaging, the result is usually used as a value in a dictionary, and then the whole dictionary is passed to a second serializer which also serialize to JSON.

Sorry, I don't understand everything, but at least I see that tests passed on py3 before the change, and started to fail with the change.

Maybe json(utils).dumps() is misused in some places, but in this case, you should write a change which only fix these specific places, not replace all calls to dumps().

Change-Id: Icd54ee8e3f5c976dfd50b4b62c7f51288649e112
2016-03-11 09:00:08 +00:00
Jenkins 67c8987372 Merge "Ensure the json result type is bytes on Python 3" 2016-03-11 04:10:35 +00:00
Davanum Srinivas 2d53db6c51 Allow Notifier to have multiple topics
Looks like there is a disconnect between the __init__
parameter 'topic' in Notifier and what we need when
we look up a driver. We should allow multiple topics
to be specified as a new topics parameter and pass
that along directly.

Change-Id: Id89957411aa219cff92fafec2f448c81cb57b3ca
2016-02-25 06:43:00 +00:00
Javeme bd81d09c02 Ensure the json result type is bytes on Python 3
Since the json.dumps() returns Unicode string On Python 3, to
ensure that the result type is bytes on Python 2 and Python 3
that if the result is used for the message body, let's replace
    json.dumps() /  oslo_serialization.jsonutils.dumps()
with
    oslo_serialization.jsoutils.dump_as_bytes()

Change-Id: I0e0f6b715ffc4a9ad82be52e55696d032b6d0976
2016-02-24 15:20:08 +08:00
Javeme 3288c4d7e2 Use more efficient mask_dict_password to mask password
The mask_dict_password method is added from oslo_utils 3.4.0, and it's
about five times faster than the mask_password method, so it's better
to use mask_dict_password instead of mask_password.

Change-Id: I6629ed1232f2e6f1c72b9f13b361e2f9e14b50a4
2016-02-24 13:19:53 +08:00