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

Version method for kernel_module #1435

Merged
merged 2 commits into from
Jan 27, 2017
Merged

Version method for kernel_module #1435

merged 2 commits into from
Jan 27, 2017

Conversation

aladmit
Copy link

@aladmit aladmit commented Jan 27, 2017

Hi! This version method for kernel_module.

issue: #993

Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @postgred for this great addition. I added ideas for minor improvements.

Right now, rubocop is failing with:

Offenses:
lib/resources/kernel_module.rb:46:42: C: Use delete instead of gsub.
      cmd.exit_status.zero? ? cmd.stdout.gsub("\n", '') : false
                                         ^^^^^^^^^^^^^^

Could you please sign-off your work, too. Instructions are available here: https://github.com/chef/inspec/blob/master/CONTRIBUTING.md#developer-certification-of-origin-dco

# default modinfo command
modinfo_cmd = "modinfo -F version #{@module}"
# command for CentOS 5 and sudo
modinfo_cmd = "/sbin/modinfo -F version #{@module}" if inspec.os[:name] == 'centos' && inspec.os[:release].to_i == 5
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe:

if inspec.os.name == 'centos' && inspec.os.release.to_i == 5
   ...
else
   modinfo_cmd = "modinfo -F version #{@module}"
end

modinfo_cmd = "/sbin/modinfo -F version #{@module}" if inspec.os[:name] == 'centos' && inspec.os[:release].to_i == 5

cmd = inspec.command(modinfo_cmd)
cmd.exit_status.zero? ? cmd.stdout.gsub("\n", '') : false
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be better to return nil, since we could not determine a version

Signed-off-by: Andrey Aleksandrov <postgred@gmail.com>
Signed-off-by: Andrey Aleksandrov <postgred@gmail.com>
@chris-rock
Copy link
Contributor

@postgred Thank you for the quick improvements. The implementation looks great. I was just thinking, we should add this to our integration tests as well, to ensure it works across linux systems. The test is located here: https://github.com/chef/inspec/blob/master/test/integration/default/kernel_module_spec.rb#L21-L23

This will be executed with every travis run. See https://github.com/chef/inspec/blob/master/.travis.yml#L28-L55

@aladmit
Copy link
Author

aladmit commented Jan 27, 2017

@chris-rock We can't add this to integration tests because modinfo can't work in docker. Example:

root@580f55841391:/# modinfo video
libkmod: ERROR ../libkmod/libkmod.c:556 kmod_search_moddep: could not open moddep file '/lib/modules/4.9.5-200.fc25.x86_64/modules.dep.bin'
modinfo: ERROR: Module alias video not found.

@chris-rock
Copy link
Contributor

@postgred Agreed. Thank you.

@chris-rock chris-rock merged commit 78b7a2c into inspec:master Jan 27, 2017
@arlimus arlimus added the Type: Enhancement Improves an existing feature label Feb 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improves an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants