Skip to content

Commit

Permalink
Add ChefDeprecations/WindowsFeatureServermanagercmd
Browse files Browse the repository at this point in the history
Detect the old install_method value that is no longer accepted.

Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Feb 26, 2020
1 parent a42c627 commit fa747d1
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
9 changes: 9 additions & 0 deletions config/cookstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,15 @@ ChefDeprecations/DeprecatedChefSpecPlatform:
Include:
- '**/spec/**/*.rb'

ChefDeprecations/WindowsFeatureServermanagercmd:
Description: The `windows_feature` resource no longer supports setting the `install_method` to `:servermanagercmd`. `:windows_feature_dism` or `:windows_feature_powershell` should be used instead.
Enabled: true
VersionAdded: '5.22.0'
Exclude:
- '**/metadata.rb'
- '**/attributes/*.rb'
- '**/Berksfile'

###############################
# ChefModernize: Cleaning up legacy code and using new built-in resources
###############################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# Copyright:: 2020, Chef Software, Inc.
# Author:: Tim Smith (<tsmith@chef.io>)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module RuboCop
module Cop
module Chef
module ChefDeprecations
# The `windows_feature` resource no longer supports setting the `install_method` to `:servermanagercmd`. `:windows_feature_dism` or `:windows_feature_powershell` should be used instead.
#
# @example
#
# # bad
# windows_feature 'DHCP' do
# install_method :servermanagercmd
# end
#
# # good
# windows_feature 'DHCP' do
# install_method :windows_feature_dism
# end
#
# windows_feature 'DHCP' do
# install_method :windows_feature_powershell
# end
#
# windows_feature_dism 'DHCP'
#
# windows_feature_powershell 'DHCP'
#
class WindowsFeatureServermanagercmd < Cop
include RuboCop::Chef::CookbookHelpers

MSG = 'The `windows_feature` resource no longer supports setting the `install_method` to `:servermanagercmd`. `:windows_feature_dism` or `:windows_feature_powershell` should be used instead.'.freeze

def on_block(node)
match_property_in_resource?(:windows_feature, :install_method, node) do |prop_node|
add_offense(prop_node, location: :expression, message: MSG, severity: :refactor) if prop_node.source.match?(/:servermanagercmd/)
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Copyright:: 2020, Chef Software, Inc.
# Author:: Tim Smith (<tsmith@chef.io>)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'spec_helper'

describe RuboCop::Cop::Chef::ChefDeprecations::WindowsFeatureServermanagercmd, :config do
subject(:cop) { described_class.new(config) }

it 'registers an offense when windows_feature sets install_method to :servermanagercmd' do
expect_offense(<<~RUBY)
windows_feature 'DHCP' do
install_method :servermanagercmd
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The `windows_feature` resource no longer supports setting the `install_method` to `:servermanagercmd`. `:windows_feature_dism` or `:windows_feature_powershell` should be used instead.
end
RUBY
end

it "doesn't register an offense when windows_feature sets install_method to :windows_feature_dism" do
expect_no_offenses(<<~RUBY)
windows_feature 'DHCP' do
install_method :windows_feature_dism
end
RUBY
end
end

0 comments on commit fa747d1

Please sign in to comment.