Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Replace update-strategy option by exclude-deps flag
Browse files Browse the repository at this point in the history
This makes a more simple api for users.
If we ever work on an 3rd way to upgrade, we can revert this commit
easily.

Change-Id: Ica31debfbae8d44f803b9cd2bae2500f38302456
Signed-off-by: Grégoire Seux <g.seux@criteo.com>
  • Loading branch information
kamaradclimber committed Sep 25, 2018
1 parent bc77a81 commit 4868bd9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
11 changes: 3 additions & 8 deletions RELEASE_NOTES.md
Expand Up @@ -122,15 +122,10 @@ include_policy 'base_policy',
path: 'policies/base/Policyfile.lock.json'
```

## Policyfiles: `chef update` gains `--update-strategy` option
## Policyfiles: `chef update` gains `--exclude-deps` flag

This option can take two values:

- 'relaxed' (default value). This was the behavior before this release
`chef update Policyfile.rb apache2` will upgrade apache2 and all its
dependencies
- 'strict'. This behavior is very strict: it updates only the cookbook(s)
mentionned in the command line.
When using this, behavior is very strict: it updates only the cookbook(s)
mentioned on command line.

## Updated Tooling

Expand Down
12 changes: 6 additions & 6 deletions lib/chef-dk/command/update.rb
Expand Up @@ -67,11 +67,11 @@ class Update < Base
default: false,
boolean: true

option :update_strategy,
long: "--update-strategy STRATEGY",
description: "Use the given strategy for update. Possible values: relaxed (default), strict",
default: "relaxed",
in: %w{relaxed strict}
option :exclude_deps,
long: "--exclude-deps",
description: "Only update cookbooks explicitely mentioned on the command line",
boolean: true,
default: false

attr_reader :policyfile_relative_path

Expand All @@ -90,7 +90,7 @@ def initialize(*args)
def run(params = [])
return 1 unless apply_params!(params)
attributes_updater.run
installer.run(@cookbooks_to_update, config[:update_strategy]) unless update_attributes_only?
installer.run(@cookbooks_to_update, config[:exclude_deps]) unless update_attributes_only?
0
rescue PolicyfileServiceError => e
handle_error(e)
Expand Down
15 changes: 7 additions & 8 deletions lib/chef-dk/policyfile_services/install.rb
Expand Up @@ -50,7 +50,7 @@ def initialize(policyfile: nil, ui: nil, root_dir: nil, overwrite: false, config
@policyfile_compiler = nil
end

def run(cookbooks_to_update = [], update_strategy = "relaxed")
def run(cookbooks_to_update = [], exclude_deps = false)
unless File.exist?(policyfile_expanded_path)
# TODO: suggest next step. Add a generator/init command? Specify path to Policyfile.rb?
# See card CC-232
Expand All @@ -62,7 +62,7 @@ def run(cookbooks_to_update = [], update_strategy = "relaxed")
elsif cookbooks_to_update.empty? # means update everything
generate_lock_and_install
else
update_lock_and_install(cookbooks_to_update, update_strategy)
update_lock_and_install(cookbooks_to_update, exclude_deps)
end
end

Expand Down Expand Up @@ -114,13 +114,12 @@ def generate_lock_and_install
raise PolicyfileInstallError.new("Failed to generate Policyfile.lock", error)
end

def update_lock_and_install(cookbooks_to_update, update_strategy)
ui.msg "Updating #{cookbooks_to_update.join(',')} cookbooks with #{update_strategy} strategy"
to_update = case update_strategy
when "relaxed"
policyfile_lock.solution_dependencies.transitive_deps(cookbooks_to_update)
else
def update_lock_and_install(cookbooks_to_update, exclude_deps)
ui.msg "Updating #{cookbooks_to_update.join(',')} cookbooks #{exclude_deps ? '(excluding dependencies)' : ''}"
to_update = if exclude_deps
cookbooks_to_update
else
policyfile_lock.solution_dependencies.transitive_deps(cookbooks_to_update)
end
prepare_constraints_for_update(to_update)
prepare_constraints_for_policies
Expand Down
10 changes: 5 additions & 5 deletions spec/unit/policyfile_services/update_spec.rb
Expand Up @@ -130,11 +130,11 @@ def cookbook_lock(name, version)
# elsewhere. We only check constraints changes
expect(install_service).to receive(:generate_lock_and_install)

expect { install_service.run(["top-level"], update_strategy) }.not_to raise_error
expect { install_service.run(["top-level"], exclude_deps) }.not_to raise_error
end

context "with relaxed update strategy" do
let(:update_strategy) { "relaxed" }
context "without exclude-deps flag" do
let(:exclude_deps) { false }

it_behaves_like "regular update operation"

Expand All @@ -147,8 +147,8 @@ def cookbook_lock(name, version)
end
end

context "with strict update strategy" do
let(:update_strategy) { "strict" }
context "with exclude-deps flag" do
let(:exclude_deps) { true }

it_behaves_like "regular update operation"

Expand Down

0 comments on commit 4868bd9

Please sign in to comment.