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

tests: updates of mock-insights from subscription-manager-cockpit #20842

Merged

Conversation

ptoscano
Copy link
Contributor

@ptoscano ptoscano commented Aug 5, 2024

This forwards various updates to mock-insights as done in subscription-manager-cockpit, where it is stressed/used a bit more; in particular, the changes come from:

This should hopefully avoid failures in case insights-client (or better, insights-core) switches the default value of legacy_upload from true to false; no ETA planned for that, although that's what we are trying to work on.

See the message of each commit for longer explanations.

When querying for the details of a system, properly return 404 in case
the system was not registered previously. This makes sure that
insights-client properly reacts to this situation, mimicking what
happens with a real Inventory service.
Tweak their implementations a bit to prepare them for more substantial
changes; in particular:
- properly name the ID we get: the "insights_id" query parameter as
  such, and the UUID as Inventory ID
- use an helper variable to which add/set all the bits to the replies,
  dumping them as JSON only in one place

This is only a refactor with no behaviour change.
Currently, the fake systems (or better, only one) is kept in the helper
"systems" dictionary by the machine ID; while this seems to work fine,
in practice it will not work for upcoming changes, and it does not match
what Inventory actually does.

Change the ID handling to represent better what Inventory does:
- assign "id" as Inventory ID for each newly registered system; in
  practice we have only one, and keep hardcoding "123-nice-id" for now
  (the "testInsights" test checks for it)
- use the "id" as key in the "systems" dictionary, rather than the
  "machine_id"
- when registering a new system, copy "machine_id" as "insights_id";
  this will help later on when implementing the non-legacy API endpoints
- adapt endpoints to search for the ID they need

Even with all the changes, there should be no behaviour changes.
Implement a couple of missing platform endpoints needed to make
insights-client work in non-legacy-upload mode:
- the upload endpoint, which needs to get the system metadata from the
  MIME data sent with POST: because of this, the implementation needs a
  bit more work; because of testing reasons, the Inventory ID is still
  hardcoded as "123-nice-id"
- the delete endpoint, needed to unregister a system
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! None of this is super important -- if you don't want to touch this again, I'm fine with landing as-is. Just giving you a chance to re-review.

if insights_id in systems:
res["total"] += 1
res["results"].append({"id": "123-nice-id"})
self.wfile.write(json.dumps(res).encode("utf-8") + b"\n")
Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, "UTF-8" is the default. See commit c0caea8

(Not enough by itself to block this PR)

Comment on lines +55 to +56
for system in systems.values():
if system["machine_id"] == machine_id:
Copy link
Member

Choose a reason for hiding this comment

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

Ah, so systems is not indexed by machine ID any more but by "inventory ID" like "123-nice-id". So many IDs! 😉

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 yes, Inventory has lots of IDs: the ID of a system, the machine ID, the Insights ID, etc...

Comment on lines +140 to +142
+ b"""

"""
Copy link
Member

Choose a reason for hiding this comment

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

This is quite hard to read, and may be better written as b"\n\n"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hm not bad- would it be possible to fix it in a followup? this PR is a simple backport of the existing commits from sub-man-cockpit

if part.get_filename() == "metadata":
s = json.loads(part.get_payload())
s["id"] = "123-nice-id"
print(s)
Copy link
Member

Choose a reason for hiding this comment

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

debugging leftover

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is the same in the other endpoint that "uploads" a system, so it's consistent :P i find it useful to check the log file for the result of the registration, especially in this case that the metadata is even more "entangled"

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks for checking!

@martinpitt martinpitt merged commit 5bc6133 into cockpit-project:main Aug 6, 2024
77 checks passed
@ptoscano ptoscano deleted the tests-mock-insights-updates branch August 7, 2024 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants