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)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 1 Nov 2019 14:49:33 +0000 (10:49 -0400)
commita373e036294d14b0abb8394d2636b04216e8ac89
treeef70cc441ebeec7fb73e0aaf276894a27c70af84
parentd5a22ce88b28f87cfcace263243510c1ad48b133
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.026403 seconds and 4 git commands to generate.