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

N°7506 - Add method to check if a specific module is installed in iTop #39

Merged

Conversation

Hipska
Copy link
Collaborator

@Hipska Hipska commented Sep 19, 2023

I wasn't sure to which class it could be added. Might as well be a static method on Utils or even somewhere else.

@piRGoif piRGoif added the enhancement New feature or request label Sep 19, 2023
@Hipska Hipska changed the title Add method to check if a specific module is installed in iTop feat(RestClient): Add method to check if a specific module is installed in iTop Dec 22, 2023
@Molkobain Molkobain self-assigned this Apr 25, 2024
Copy link
Member

@Molkobain Molkobain left a comment

Choose a reason for hiding this comment

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

Discussed with Denis, as-is the PR doesn't suit us for the following reasons:

  • Just looking for a module in that class / table can return true even though the module has been uninstalled. This table is an history, not the current state of the instance.
  • Ideally, it would look for the most recent "datamodel %" entry, than look for the module at the exact same datetime.

@Hipska
Copy link
Collaborator Author

Hipska commented Apr 25, 2024

Oh, that's right indeed. I'll see how it could be retrieved the best then...

@Molkobain
Copy link
Member

It seems that the ModuleInstallation class is already ordered by desc. installation datetime (see here), so you could:

  • Make a first call to core/get, with a limit to 1 for SELECT ModuleInstallation WHERE name = "datamodel", which will return the last compilation datetime.
    • Mind to make a cache for that datetime info, so you don't have to make the call again if you are checking more than 1 module.
  • Then make a second call to core/get, also with a limit to 1 for SELECT ModuleInstallation WHERE name = "<YOUR_MODULE_CODE>" AND installed = "<DATETIME_FROM_PREVIOUS_CALL>"

@Hipska
Copy link
Collaborator Author

Hipska commented Apr 26, 2024

Yeah, also had something like this in mind. Please see 8b8849d.

@Hipska Hipska requested a review from Molkobain April 26, 2024 10:15
Copy link
Member

@Molkobain Molkobain left a comment

Choose a reason for hiding this comment

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

Can you add a unit test that check:

  • That a common module is present (eg. itop-structure as tests run on an iTop 3.2, or itop-config)
  • That a fake module is not present (eg. fake-module)

core/restclient.class.inc.php Outdated Show resolved Hide resolved
core/restclient.class.inc.php Outdated Show resolved Hide resolved
core/restclient.class.inc.php Outdated Show resolved Hide resolved
core/restclient.class.inc.php Outdated Show resolved Hide resolved
@Hipska
Copy link
Collaborator Author

Hipska commented Apr 29, 2024

I lost a full day trying to get the tests working, so I added what I got and should work, but the old version of phpunit does not seem to do what I'm expecting it to do somehow..

@Hipska Hipska requested a review from Molkobain April 29, 2024 15:46
@Molkobain
Copy link
Member

Thank you very much for coding the extra mile with the unit test, it means a lot.

@Molkobain Molkobain changed the title feat(RestClient): Add method to check if a specific module is installed in iTop N°7506 - Add method to check if a specific module is installed in iTop May 3, 2024
@Molkobain
Copy link
Member

Just discussing the unit test with @odain-cbd before merging

@odain-cbd
Copy link
Contributor

Dear Thomas,

I just cloned your fork and indeed there issues with PHPUNIT somehow. we will upgrade this lib.

test/RestTest.php Outdated Show resolved Hide resolved
Copy link
Contributor

@odain-cbd odain-cbd left a comment

Choose a reason for hiding this comment

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

please see my proposal

@Hipska
Copy link
Collaborator Author

Hipska commented May 3, 2024

I don't feel like this method fits well into the Utils class, but I have moved and fixed the test.

@Hipska Hipska requested a review from odain-cbd May 3, 2024 14:44
@Hipska Hipska force-pushed the feature/check_module_installation branch from c78f77e to f35e7f7 Compare May 3, 2024 14:46
@Hipska Hipska force-pushed the feature/check_module_installation branch from f35e7f7 to 3e2120d Compare May 3, 2024 14:47
@Molkobain
Copy link
Member

Discussing this with Stephen, wouldn't it be better if we could pass an optional "min version" for the module?
It could be helpful to adapt what we send when there is a DM change in a module version.

@odain-cbd
Copy link
Contributor

"I don't feel like this method fits well into the Utils class, but I have moved and fixed the test."

I agree with you. maybe it should be located somewhere else than Utils. I just proposed it to let you validate this feature. now that is tested you may easily move it in a proper place. maybe a new class?

@Hipska
Copy link
Collaborator Author

Hipska commented May 7, 2024

Discussing this with Stephen, wouldn't it be better if we could pass an optional "min version" for the module? It could be helpful to adapt what we send when there is a DM change in a module version.

@Molkobain I'm not sure if this should also be in the same method.. What do you propose as its prototype then? An optional argument or the method returning the latest version number (as it is now putting into the logs)?

I don't think the versions are that relevant for the collectors. The one I know that has module checks, only checks if the classes are available: example. For my own use-case I wouldn't mind the version as well. Do you have other examples?

I agree with you. maybe it should be located somewhere else than Utils.

@odain-cbd I still feel it fits well in RestClient similar to GetFullSynchroDataSource also is located there. Maybe it could be a method of Orchestrator? Similar to AddRequirements and CheckRequirements, but those are related to PHP modules.

@Molkobain
Copy link
Member

For instance, if you collect data about racks or servers, the "width" field was not added ar first in the molkobain-datacenter-view module, it came later on. So if you want to collect this, you need to know which version of the module is present.

Regarding the signature, I'd say something like the following, but totally open to other suggestions:

public static function CheckModuleInstallation(string $sName, ?string $sMinVersion = null, bool $bRequired = false, RestClient $oClient = null): bool

If $sMinVersion is null, then don't check the version at all. Otherwise, ensure that it is >= (You can use version_compare() to compare 2 string version numberings)

@Hipska
Copy link
Collaborator Author

Hipska commented May 7, 2024

I was more asking for current existing collectors that actually check for a version or have a need for it. Your example is also a valid one.

I'm more in favour of this method returning the installed version, so the version can be checked elsewhere.

@Molkobain
Copy link
Member

Discussed in DM with Hipska, prototype will remain the same, but $sName will allow to pass the complete module identifer as well (eg. "some-module" or "some-module/1.2.3")

@Hipska Hipska requested a review from Molkobain May 13, 2024 14:01
core/utils.class.inc.php Outdated Show resolved Hide resolved
test/UtilsTest.php Show resolved Hide resolved
Co-authored-by: Molkobain <lajarige.guillaume@free.fr>
@Molkobain Molkobain merged commit f66f19b into Combodo:master May 15, 2024
@Hipska Hipska deleted the feature/check_module_installation branch May 15, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
4 participants