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

Add version comparison functionality for package_version #169

Merged
merged 2 commits into from
Jan 17, 2023

Conversation

rtorrero
Copy link
Contributor

@rtorrero rtorrero commented Jan 13, 2023

This PR allows the package_version gatherer to be used to compare versions on the agent. This way, we can handle the complexity of comparing RPM package version strings to the OS using zypper versioncmp (see zypper versioncmp --help for more details).

Notice that this just adds to the existing functionality of requesting package version strings which should still work as it previously did. To request a version comparison, a package name together with a version string needs to be provided in the argument, separated by a coma (,).

The returned value for such requests is a FactValueInt, containing:

  • A value of 0 if the provided version string matches the installed package version for the requested package
  • A value of -1 if the provided version string is older that what's currently installed.
  • A value of 1 if the provided version string is newer than what's currently installed.

Example on how to collect such facts:

factRequests := []entities.FactRequest{
{
	Name:     "corosync_same_version",
	Gatherer: "package_version",
	Argument: "corosync,2.4.5",
	CheckID:  "check1",
},
{
	Name:     "corosync",
	Gatherer: "package_version",
	Argument: "corosync",
	CheckID:  "check2",
},

For such requests, the returned values should look like:

[]entities.Fact{
{
	Name:    "corosync_same_version",
	Value:   &entities.FactValueInt{Value: 0},
	CheckID: "check3",
},
{
	Name:    "corosync",
	Value:   &entities.FactValueString{Value: "2.4.5"},
	CheckID: "check1",
},

Notice how the first fact request asks for corosync against 2.4.5, which will cause that an integer instead of a regular FactValueString with a version string. The second one, as it just asks for a package name will return a version string as it did before.

@rtorrero rtorrero marked this pull request as ready for review January 13, 2023 12:52
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

I see some redundant call to get the version of the package.
PD: I wouldn't add not related changes to the PR

internal/factsengine/gatherers/packageversion.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/packageversion.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/packageversion.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/packageversion.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/verifypassword.go Outdated Show resolved Hide resolved
@rtorrero rtorrero force-pushed the package_version_agent_compare branch from f58a2b6 to ddcb758 Compare January 16, 2023 11:06
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.

Thanks!

@rtorrero rtorrero requested a review from arbulu89 January 17, 2023 08:52
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Thanks @rtorrero

@rtorrero rtorrero merged commit 0f671bd into trento-project:main Jan 17, 2023
@arbulu89 arbulu89 added the enhancement New feature or request label Apr 26, 2023
nelsonkopliku pushed a commit that referenced this pull request May 26, 2023
* Add version comparison functionality for package_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants