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

Chef install now works when lockfile alone exists #1292 #131

Merged
merged 2 commits into from
Sep 16, 2020

Conversation

rclarkmorrow
Copy link
Contributor

Description

The install.rb script in the Chef CLI tool checked for the present of a policy file ending with
an .rb extension even when a lockfile (.lock.json) was passed as an argument. This produced
an error when a user tried to install from a .lock.json file.

Changes:

  • Modified code in install.rb to check extension in the file path, and then verify that a policy file exists
    with that extension.
  • Modified code in storage_config_spec.rb so that error messaging now includes .lock.json as an
    extension.
  • Added test to verify new error language, and added a test to check for failure when a policy file
    is passed as an argument, but doesn't exist.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@rclarkmorrow rclarkmorrow requested review from a team as code owners September 8, 2020 22:11
Issue #1292: chef install requires .rb file present #1292:

Issue located in the Chef CLI tool. The install.rb script only checked
for the presence of a policy file with an .rb extension whether or not
the user entered a policy lockfile. Changed code to check for .rb and
.lock.json extensions in the policy file path, and then verify the
existence of a policy file with that extension.

Updated error message in storage_config_spec.rb to correctly address
both .rb and .lock.json extensions.

Created test for new error language, and created test to verify error
when a policy file name is given, but the file does not exist.

DCO:
By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the
    best of my knowledge, is covered under an appropriate open
    source license and I have the right under that license to
    submit that work with modifications, whether created in whole
    or in part by me, under the same open source license (unless
    I am permitted to submit under a different license), as
    Indicated in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including
    all personal information I submit with it, including my
    sign-off) is maintained indefinitely and may be redistributed
    consistent with this project or the open source license(s)
    involved.

Signed-off-by: Rick Morrow <rclark.morrow@gmail.com>
# See card CC-232
# TODO: suggest next step. Add a generator/init command? Specify path to Policyfile.rb?
# See card CC-232
if @policyfile_rel_path.end_with?(".lock.json") && !File.exist?(policyfile_lock_expanded_path)

Choose a reason for hiding this comment

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

My only complaint on this PR - and it is minor - is that it feels odd to create an instance variable just for these checks. Couldn't we check the ending of the return value from policyfile_lock_expanded_path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if this is the right answer, however, I am fairly positive that "policyfile_lock_expanded_path" will always end with ".lock.json" and "policfile_expanded_path" will always end with ".rb" regardless of what file the user passes with the install command. Checking on "policyfile_rel_path" does check against what the user passes with the install command.

Copy link
Member

@marcparadise marcparadise left a comment

Choose a reason for hiding this comment

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

Thanks for doing this work @rclarkmorrow, and welcome to Chef Workstation!

This change looks good, and your reasoning around creating an instance var for relative path makes sense. I left one follow-up inline with this review. Once you update for that, I think we'll be in good shape to merge.

spec/unit/policyfile_services/install_spec.rb Show resolved Hide resolved
Adding additional test per comment: "Because it's a separate
validation path, this test should also be done for when a lockfile
is given."

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the
    best of my knowledge, is covered under an appropriate open
    source license and I have the right under that license to
    submit that work with modifications, whether created in whole
    or in part by me, under the same open source license (unless
    I am permitted to submit under a different license), as
    Indicated in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including
    all personal information I submit with it, including my
    sign-off) is maintained indefinitely and may be redistributed
    consistent with this project or the open source license(s)
    involved.

Signed-off-by: Rick Morrow <rclark.morrow@gmail.com>
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

3 participants