Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use embeds software updates #3275

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

arbulu89
Copy link
Contributor

@arbulu89 arbulu89 commented Feb 5, 2025

Description

Refactor SUMA software updates discovered struct to use known fields.
All of this started with the intention to remove the Jason.decode!(keys: :atoms) in https://github.com/trento-project/web/blob/main/lib/trento/software_updates/discovery.ex#L309
This piece of code is potentially dangerous as it creates not existing atoms with data coming from external sources (it uses String.to_atom behind the scenes).
It is true that this information is coming from SUMA and we know the sent values so it should be safe.
But knowing the values, having a embedded schema makes sense as it gives some more control and we don't need to relay in jsonb plain maps.

I have tested a transition from old stored code to the new and works fine. (embeds_many takes care of using already existing empty list and nil values, and always return a list).

As a bonus, we fix the openapi schema error, as the to_package_id field returns an integer and we define it as string. Now this is fixed.
We most probably had this issue as SUMA docs themselves define this as string, even though they send an integer and they confirmed that this is a docs bug:
https://documentation.suse.com/suma/4.3/api/suse-manager/api/system.html#apidoc-system-listLatestUpgradablePackages-loggedInUser-sid

How was this tested?

UT and manual testing to test the regression

@arbulu89 arbulu89 added enhancement New feature or request env Create an ephimeral environment for the pr branch labels Feb 5, 2025
@@ -59,7 +59,7 @@ defmodule Trento.Infrastructure.SoftwareUpdates.MockSuma do
to_version: "1.16.2",
to_release: "1",
to_epoch: "0",
to_package_id: 92_348_112_636
to_package_id: "92348112636"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will require to reset SUMA values in demo, as using an integer was not expected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nelsonkopliku @janvhs Do you know why we moved this value to integer in the past?
Here: #2916
The to_package_id value is defined as string in the SUMA docs: https://documentation.suse.com/suma/4.3/api/suse-manager/api/system.html#apidoc-system-listLatestUpgradablePackages-loggedInUser-sid

With that change, if the value is really a string I don't really know how this worked in the first place...
And if it is an number, our backend code was wrong.

Copy link
Member

@nelsonkopliku nelsonkopliku Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why it became an integer. In other places is considered a string, as it seems it should be.
What happens if you just put back to strings in the mock definition (the only place in the backend where it seems to be an integer)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it works with my mocked data. I was wondering if the SUMA docs have some typo.
I will start a SUMA instance and try myself.
The code with different types is suspicious

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it looks like suma is actually returning an integer, at least on our testing instance running on 4.3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'm going to change the field type to integer. Now everything works with a real SUMA instance.
I asked the SUMA team as well.
I hope it is only a documentation error, otherwise we might need to do changes if they fix it

@arbulu89 arbulu89 force-pushed the use-embeds-software-updates branch from e42e034 to 0e6b693 Compare February 5, 2025 09:19
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciated, thanks!

Copy link

github-actions bot commented Feb 5, 2025

The preview environment for this pull request is ready at 3275.prenv.trento.suse.com.

@arbulu89 arbulu89 marked this pull request as ready for review February 5, 2025 13:03
@arbulu89
Copy link
Contributor Author

arbulu89 commented Feb 5, 2025

The API bc check is failing due the change, but this is actually normal, as we fix an error with this.
It was a bug, so we don't need to do anything else.
I will force merge once everything else is green

@arbulu89 arbulu89 added the bug Something isn't working label Feb 5, 2025
Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, as long as things keep working lgtm 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request env Create an ephimeral environment for the pr branch
Development

Successfully merging this pull request may close these issues.

2 participants