Skip to content

fix: [AAP-50916] fix rulebook activation idempotence#463

Merged
kaiokmo merged 1 commit into
ansible:mainfrom
kaiokmo:AAP-50916
Aug 11, 2025
Merged

fix: [AAP-50916] fix rulebook activation idempotence#463
kaiokmo merged 1 commit into
ansible:mainfrom
kaiokmo:AAP-50916

Conversation

@kaiokmo
Copy link
Copy Markdown
Member

@kaiokmo kaiokmo commented Aug 8, 2025

https://issues.redhat.com/browse/AAP-50916

This fixes a bug where rulebook activations with event streams were considered different even though the parameters of the tasks were the same. The cause was a difference between the information returned from the backend and the return from yaml.dump() when parsing the event streams from the task parameter. The yaml.dump() adds a trailing newline at the end of the dumped YAML string, which is the default behavior. E.g:

info from the eda-server:

'source_mappings': '- event_stream_id: 12\\n  event_stream_name: Test_EventStream_c99484c1-45a1-5c5f-a067-877f4e002f9c\\n  rulebook_hash: 1e0f22025ab0a4e729fb68bcb9497412c3d9f477ce5a8cb91cc2ef15e35c4dc6\\n  source_name: __SOURCE_1'

return from parsing the task's event streams parameter with yaml.dump():

'source_mappings': '- event_stream_id: 12\\n  event_stream_name: Test_EventStream_c99484c1-45a1-5c5f-a067-877f4e002f9c\\n  rulebook_hash: 1e0f22025ab0a4e729fb68bcb9497412c3d9f477ce5a8cb91cc2ef15e35c4dc6\\n  source_name: __SOURCE_1\\n'

This causes the module to consider the objects as different, and then call the update() function incorrectly.

To prevent this, now we simply add a rstrip("\n") to the yaml.dump() call, which removes the trailing newline from the dumped string, allowing the module to correctly compare the two objects and detect that no changes were made, thus preserving idempotence.

A test was also added to ensure the expected behavior from activations with event streams.

This fixes a bug where rulebook activations with event streams were
considered different even though the parameters of the tasks were the
same. The cause was a difference between the information returned from
the backend and the return from yaml.dump() when parsing the event
streams from the task parameter. The yaml.dump() adds a trailing
newline at the end of the dumped YAML string, which is the default
behavior. E.g:

info from the eda-server:
```
'source_mappings': '- event_stream_id: 12\\n  event_stream_name: Test_EventStream_c99484c1-45a1-5c5f-a067-877f4e002f9c\\n  rulebook_hash: 1e0f22025ab0a4e729fb68bcb9497412c3d9f477ce5a8cb91cc2ef15e35c4dc6\\n  source_name: __SOURCE_1'
```

return from parsing the task's event streams parameter with
yaml.dump():
```
'source_mappings': '- event_stream_id: 12\\n  event_stream_name: Test_EventStream_c99484c1-45a1-5c5f-a067-877f4e002f9c\\n  rulebook_hash: 1e0f22025ab0a4e729fb68bcb9497412c3d9f477ce5a8cb91cc2ef15e35c4dc6\\n  source_name: __SOURCE_1\\n'
```

This causes the module to consider the objects as different, and then
calling the update() function incorrectly.

To prevent this, now we simply add a rstrip("\n") to the yaml.dump()
call, which removes the trailing newline from the dumped string,
allowing the module to correctly compare the two objects and detect
that no changes were made, thus preserving idempotence.

A test was also added to make sure the behavior is expected for
activations with event streams.
@Alex-Izquierdo
Copy link
Copy Markdown
Contributor

good catch!

@kaiokmo kaiokmo merged commit a246834 into ansible:main Aug 11, 2025
29 of 32 checks passed
@kaiokmo kaiokmo deleted the AAP-50916 branch August 11, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants