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

fix: check status created a machine-id file #3965

Merged
merged 3 commits into from
Feb 6, 2024
Merged

fix: check status created a machine-id file #3965

merged 3 commits into from
Feb 6, 2024

Conversation

ahitacat
Copy link
Contributor

@ahitacat ahitacat commented Dec 4, 2023

All Pull Requests:

Check all that apply:

  • Have you followed the guidelines in our Contributing document, including the instructions about commit messages?
  • Is this PR to correct an issue?
  • Is this PR an enhancement?

Complete Description of Additions/Changes:

When insights-client checked the status created a machine-id file to make some calls to the console service. That created a residual machine file if it had not access to the service (i.e. system was not registered to rhsm).

This PR refactors a bit the logic of generate_machine_id, and splits in a new function that will only get the machine id get_machineid().

Checking status and generate_machine_id will use this new function.

Test have been changed and a new one has been created.

Resolves: CCT-161

@ahitacat ahitacat added bug client These issues represent work to be done by the "client" team. WIP Includes: Approved but Not Ready for Merging/Releasing and removed WIP Includes: Approved but Not Ready for Merging/Releasing labels Dec 4, 2023
Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

This would solve it, but I am not really a fan of some of the parts.

  1. Have you considered changing the original client.get_machine_id to accept a create flag, instead of creating a new function with similar name in the utils?
    def get_machine_id():
    return generate_machine_id()
  2. If that would be too complicated, I found out you are only checking if the returned value is not None. Would it make sense to rename it to something like machine_id_exists() returning a bool?

@ahitacat
Copy link
Contributor Author

ahitacat commented Dec 19, 2023

  1. Have you considered changing the original client.get_machine_id to accept a create flag, instead of creating a new function with similar name in the utils?
    def get_machine_id():
    return generate_machine_id()

I considered that, but there is also a flag to create a new file, independently if it already exists. After this fix, I was considering to create a new ticket to make some effort refactoring this utility because is a bit entangled. Ideally, discerning the functions that use this method into 2, the ones that need by any cost an id, and the ones that doesn't need an id.

  1. If that would be too complicated, I found out you are only checking if the returned value is not None. Would it make sense to rename it to something like machine_id_exists() returning a bool?

Not only, if it exists it returns the value of machine-id

@ahitacat
Copy link
Contributor Author

Changelog

  • Created a method to check if the machine-id file exists, this modify back the change on generate_machine_id function.
  • Function that checked registration will check first if the machine-id file exists, it will avoid to generate a machine-id file if it don't exists. Solving the issue described in CCT-161

@@ -42,10 +44,10 @@ def test_registration_check_ok_reg_then_unreg(get_proxies, _init_session, _):
assert conn.api_registration_check() == '2019-04-10'


@patch("insights.client.connection.generate_machine_id", return_value='xxxxxx')
@patch("insights.client.connection.False", return_value=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably a bad copy-paste

Copy link
Contributor

@m-horky m-horky left a comment

Choose a reason for hiding this comment

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

LGTM

@ahitacat ahitacat added the WIP Includes: Approved but Not Ready for Merging/Releasing label Dec 20, 2023
@ahitacat
Copy link
Contributor Author

test me

@zhangqianqian
Copy link
Collaborator

Verification pass on this open PR, please refer details: https://issues.redhat.com/browse/CCT-161

@ahitacat ahitacat removed the WIP Includes: Approved but Not Ready for Merging/Releasing label Jan 30, 2024
@ahitacat
Copy link
Contributor Author

@xiangce This can be on the next egg release

This method returns a boolean whether the machine-id file exists or
not. This will be used to check the file before call, generate_machine_id
to get the machine-id, as this last method will create a new id if it
doesn't exist.

Resolves: CCT-161

Signed-off-by: ahitacat <[email protected]>
When checking registration status, first check if the machine-id file
exists. When checking status it is not needed to generate a machine-id
file if it doesn't exists.

Resolves: CCT-161

Signed-off-by: ahitacat <[email protected]>
Also create a new test to check a new machine id is created if the
file does not exists.

Signed-off-by: ahitacat <[email protected]>
@xiangce xiangce merged commit 5697ed4 into RedHatInsights:master Feb 6, 2024
9 of 11 checks passed
xiangce pushed a commit that referenced this pull request Feb 8, 2024
* feat: add machine_id_exists method

This method returns a boolean whether the machine-id file exists or
not. This will be used to check the file before call, generate_machine_id
to get the machine-id, as this last method will create a new id if it
doesn't exist.

Resolves: CCT-161

Signed-off-by: ahitacat <[email protected]>

* fix: use machine_id_exists before checking host status

When checking registration status, first check if the machine-id file
exists. When checking status it is not needed to generate a machine-id
file if it doesn't exists.

Resolves: CCT-161

Signed-off-by: ahitacat <[email protected]>

* fix: Change test that generated id and now use get_machineid

Also create a new test to check a new machine id is created if the
file does not exists.

Signed-off-by: ahitacat <[email protected]>

---------

Signed-off-by: ahitacat <[email protected]>
(cherry picked from commit 5697ed4)
xiangce added a commit that referenced this pull request Feb 8, 2024
xiangce added a commit that referenced this pull request Feb 9, 2024
xiangce added a commit that referenced this pull request Feb 9, 2024
xiangce added a commit that referenced this pull request Mar 26, 2024
- #3965 was reverted in #4018 due to a false positive test failure
  This PR is going to re-do the #3906 by reverting the #4018.
  Hopes all things could be self-linked in this way.

This reverts commit 39f95b1.

Signed-off-by: Xiangce Liu <[email protected]>
xiangce added a commit that referenced this pull request Mar 26, 2024
- #3965 was reverted in #4018 due to a false positive test failure
  This PR is going to re-do the #3906 by reverting the #4018.
  Hopes all things could be self-linked in this way.

This reverts commit 39f95b1.

Signed-off-by: Xiangce Liu <[email protected]>
(cherry picked from commit b5a055d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug client These issues represent work to be done by the "client" team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants