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 for issue 5809 Service checks failing on Amazon linux 2022 #5998

Merged

Conversation

ahasunos
Copy link
Contributor

@ahasunos ahasunos commented Apr 20, 2022

✅ Signed-off-by: Sonu Saha sonu.saha@progress.com

Related Issue

Issue #5809: Service checks failing on Amazon linux 2022

Description

CFINSPEC-186 - Issue 5809: Service checks are failing on Amazon linux 2022
The service resource checks were failing on Amazon Linux 2 as InSpec was using initctl instead of systemd because of the following logic:

if os[:release] =~ /^20\d\d/

The above logic fails because on os[:release] both Amazon Linux 1 and Amazon Linux 2 gives the output as their release years (eg: 2018.03 or 2022) thus failing to differentiate Amazon Linux 2022 as Amazon Linux 2 and triggering service with initctl instead of systemd.

The patch for this is done by checking the availability of the utility on the system.

  if inspec.command("initctl").exist? || inspec.command("/sbin/initctl").exist?
    Upstart.new(inspec, service_ctl)
  else
    Systemd.new(inspec, service_ctl)
  end

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New content (non-breaking change)
  • Breaking change (a content change which would break existing functionality or processes)

Checklist:

  • I have read the CONTRIBUTING document.

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
Commented out unit test for Amazon 1 Linux

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
@ahasunos ahasunos requested a review from a team as a code owner April 20, 2022 11:40
@ahasunos ahasunos self-assigned this Apr 20, 2022
@ahasunos ahasunos requested a review from Vasu1105 April 20, 2022 11:40
@netlify
Copy link

netlify bot commented Apr 20, 2022

Deploy Preview for chef-inspec canceled.

Name Link
🔨 Latest commit a8fb7bb
🔍 Latest deploy log https://app.netlify.com/sites/chef-inspec/deploys/625ff14741bae50008f00137

@ahasunos ahasunos changed the title WIP on Fix for issue 5809 Service checks failing on Amazon linux 2022 Fix for issue 5809 Service checks failing on Amazon linux 2022 Apr 20, 2022
@chef-expeditor
Copy link
Contributor

Hello ahasunos! Thanks for the pull request!

Here is what will happen next:

  1. Your PR will be reviewed by the maintainers.
  2. Possible Outcomes
    a. If everything looks good, one of them will approve it, and your PR will be merged.
    b. The maintainer may request follow-on work (e.g. code fix, linting, etc). We would encourage you to address this work in 2-3 business days to keep the conversation going and to get your contribution in sooner.
    c. Cases exist where a PR is neither aligned to Chef InSpec's product roadmap, or something the team can own or maintain long-term. In these cases, the maintainer will provide justification and close out the PR.

Thank you for contributing!

@@ -124,19 +124,24 @@
_(resource.params).must_equal params
end

# [-] Todo: Check with team if we can remove the below unit test or find a way to include it.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need comment on this.

I have commented out the below unit this because imo

The below test is not required because we cannot differentiate between amazon and amazon2 during testing. After all, the differentiation is not based on the version but based on the utility available on the system. However, the service resource works perfectly fine for the actual instance of Amazon and Amazon2 Linux.

@ahasunos
Copy link
Contributor Author

An attempt to fix the issue was done in PR #2901

@clintoncwolfe clintoncwolfe merged commit fa19d29 into main Apr 28, 2022
@clintoncwolfe clintoncwolfe deleted the ss/fix-service-resource-for-amazon-linux-issue-5809 branch April 28, 2022 00:59
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.

None yet

2 participants