bt2: validate parameters to _TraceClass.create_stream_class before creating the nativ...
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 28 Oct 2019 21:00:11 +0000 (17:00 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 31 Oct 2019 15:22:42 +0000 (11:22 -0400)
commitd3bf1370a437239053f532d73c4e04df53827bb9
treea542dc2d7d1e235ab378226ea855de37e3239cc8
parent9191043554194636a244960eb0a49c59582a4fb6
bt2: validate parameters to _TraceClass.create_stream_class before creating the native object

When creating a stream class (in _TraceClass.create_stream_class), we
start by creating the native object, then assign each property passed
as arguments to create_stream_class.

If the value of a parameter is invalid (e.g. wrong type), we will raise
an exception.  The problem is that at this point, the stream class
object has already been created and added to its parent, the trace
class.  This leaves the user in an uncomfortable position, where a
stream class has been created, with the parameters only partially
applied, while an exception was raised.

Instead, the stream class native object should be created only once we
know that all the parameters are valid.  This patch makes it so we
validate all parameters before calling the native creation function.

Given that the setters in _StreamClass are internal and only used in
_TraceClass.create_stream_class, we don't need to validate the values of
the parameters again in them.

I have added tests for two conditions that weren't tested, when passing
a wrong parameter type to assigns_automatic_event_class_id and
assigns_automatic_stream_id.

Otherwise, I added assertions to the test to make sure that when the
stream class Python object couldn't be created, no stream class object
was added as a child of the trace class.

Change-Id: I18cbb2e8128cf49e6a6411a225352f279aec5d02
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2279
Tested-by: jenkins <jenkins@lttng.org>
src/bindings/python/bt2/bt2/stream_class.py
src/bindings/python/bt2/bt2/trace_class.py
tests/bindings/python/bt2/test_stream_class.py
This page took 0.026568 seconds and 4 git commands to generate.