From c8f31ff2cf69866a84bd6d5515aba783c61091c3 Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:01:54 -0500 Subject: [PATCH 1/8] remove LWRP, custom resource --- providers/version.rb | 61 -------------------------------------------- resources/version.rb | 52 +++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 71 deletions(-) delete mode 100644 providers/version.rb diff --git a/providers/version.rb b/providers/version.rb deleted file mode 100644 index 34d0a6d..0000000 --- a/providers/version.rb +++ /dev/null @@ -1,61 +0,0 @@ -# -# Author:: Shawn Neal () -# Cookbook Name:: dotnetframework -# Provider:: version -# -# Copyright 2015, Shawn Neal -# -# 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. -# - -include Windows::Helper - -def whyrun_supported? - true -end - -use_inline_resources - -action :install do - if dotnet_version_or_higher_is_installed?(new_resource.version) - Chef::Log.info( - ".NET Framework #{new_resource.version} or higher is already installed" - ) - else - converge_by("Installing .NET Framework #{new_resource.version}") do - setup_exe = ::File.basename(new_resource.source) - setup_log_path = - win_friendly_path(::File.join(::Dir.tmpdir, "#{setup_exe}.html")) - - windows_package new_resource.package_name do # ~FC009 - source new_resource.source - checksum new_resource.checksum - installer_type :custom - options "/q /norestart /log \"#{setup_log_path}\"" - action :install - returns [0, 3010] - end - end - end -end - -def dotnet_version_or_higher_is_installed?(expected_version) - reg_path = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' - require 'win32/registry' - ::Win32::Registry::HKEY_LOCAL_MACHINE.open(reg_path) do |reg| - reg_version = reg['Version'] - return Gem::Version.new(reg_version) >= Gem::Version.new(expected_version) - end -rescue ::Win32::Registry::Error - false -end diff --git a/resources/version.rb b/resources/version.rb index cb7caa0..e97caa9 100644 --- a/resources/version.rb +++ b/resources/version.rb @@ -19,17 +19,49 @@ # limitations under the License. # -actions :install -default_action :install +property :version, String, name_property: true # The full .NET version: 4.0.30319, 4.5.51641 etc +property :source, String, required: true # The offline installer package URL +property :package_name, String, required: true # The installed MSI package name +property :checksum, String # The source ISO SHA256 checksum -# The full .NET version: 4.0.30319, 4.5.51641 etc -attribute :version, kind_of: String, name_attribute: true +include Windows::Helper -# The offline installer package URL -attribute :source, kind_of: String, required: true +def whyrun_supported? + true +end -# The installed MSI package name -attribute :package_name, kind_of: String, required: true +# use_inline_resources -# The source ISO SHA256 checksum -attribute :checksum, kind_of: String +action :install do + if dotnet_version_or_higher_is_installed?(new_resource.version) + Chef::Log.info( + ".NET Framework #{new_resource.version} or higher is already installed" + ) + else + converge_by("Installing .NET Framework #{new_resource.version}") do + setup_exe = ::File.basename(new_resource.source) + setup_log_path = + win_friendly_path(::File.join(::Dir.tmpdir, "#{setup_exe}.html")) + + windows_package new_resource.package_name do # ~FC009 + source new_resource.source + checksum new_resource.checksum + installer_type :custom + options "/q /norestart /log \"#{setup_log_path}\"" + action :install + returns [0, 3010] + end + end + end +end + +def dotnet_version_or_higher_is_installed?(expected_version) + reg_path = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' + require 'win32/registry' + ::Win32::Registry::HKEY_LOCAL_MACHINE.open(reg_path) do |reg| + reg_version = reg['Version'] + return Gem::Version.new(reg_version) >= Gem::Version.new(expected_version) + end +rescue ::Win32::Registry::Error + false +end From 9f99481968c9d21f09300afadf06db05430e5a66 Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:02:16 -0500 Subject: [PATCH 2/8] add new versions, clean up formatting --- attributes/default.rb | 135 ++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 220e399..5003935 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -19,102 +19,111 @@ # limitations under the License. # -# rubocop:disable VariableNumber # Allows the cookbook the compile without error on Linux if RUBY_PLATFORM =~ /mswin|mingw32|windows/ require 'chef/win32/version' windows_version = Chef::ReservedNames::Win32::Version.new - is_2012r2_or_8_1 = \ - windows_version.windows_server_2012_r2? || windows_version.windows_8_1? + is_2012r2_or_8_1 = windows_version.windows_server_2012_r2? || windows_version.windows_8_1? else is_2012r2_or_8_1 = true end # Override to install different .NET versions -# 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1 +# 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.7.0, 4.7.1, 4.7.2, 4.8.0 default['dotnetframework']['version'] = '4.5.2' +# Reference: https://answers.microsoft.com/en-us/windows/forum/all/list-of-net-framework-direct-downloading-links-for/5eb424ab-1ee0-4e13-8f2c-aeb61896d3ff # .NET 4.0 -default['dotnetframework']['4.0']['package_name'] = - 'Microsoft .NET Framework 4 Extended' +default['dotnetframework']['4.0']['package_name'] = 'Microsoft .NET Framework 4 Extended' default['dotnetframework']['4.0']['version'] = '4.0.30319' -default['dotnetframework']['4.0']['checksum'] = +default['dotnetframework']['4.0']['checksum'] = '65e064258f2e418816b304f646ff9e87af101e4c9552ab064bb74d281c38659f' -default['dotnetframework']['4.0']['url'] = - 'http://download.microsoft.com/download/9/5/A/' \ - '95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/' \ - 'dotNetFx40_Full_x86_x64.exe' +default['dotnetframework']['4.0']['url'] = 'http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe' # .NET 4.5 -default['dotnetframework']['4.5']['package_name'] = - 'Microsoft .NET Framework 4.5' +default['dotnetframework']['4.5']['package_name'] = 'Microsoft .NET Framework 4.5' default['dotnetframework']['4.5']['version'] = '4.5.50709' -default['dotnetframework']['4.5']['checksum'] = +default['dotnetframework']['4.5']['checksum'] = 'a04d40e217b97326d46117d961ec4eda455e087b90637cb33dd6cc4a2c228d83' -default['dotnetframework']['4.5']['url'] = - 'http://download.microsoft.com/download/b/a/4/' \ - 'ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/' \ - 'dotnetfx45_full_x86_x64.exe' +default['dotnetframework']['4.5']['url'] = + 'http://download.microsoft.com/download/b/a/4/ba4a7e71-2906-4b2d-a0e1-80cf16844f5f/dotnetfx45_full_x86_x64.exe' # .NET 4.5.1 -default['dotnetframework']['4.5.1']['package_name'] = - 'Microsoft .NET Framework 4.5.1' -if is_2012r2_or_8_1 - default['dotnetframework']['4.5.1']['version'] = '4.5.51641' -else - default['dotnetframework']['4.5.1']['version'] = '4.5.50938' -end -default['dotnetframework']['4.5.1']['checksum'] = +default['dotnetframework']['4.5.1']['package_name'] = 'Microsoft .NET Framework 4.5.1' +default['dotnetframework']['4.5.1']['version'] = if is_2012r2_or_8_1 + '4.5.51641' + else + '4.5.50938' + end +default['dotnetframework']['4.5.1']['checksum'] = '5ded8628ce233a5afa8e0efc19ad34690f05e9bb492f2ed0413508546af890fe' -default['dotnetframework']['4.5.1']['url'] = - 'http://download.microsoft.com/download/1/6/7/' \ - '167F0D79-9317-48AE-AEDB-17120579F8E2/' \ - 'NDP451-KB2858728-x86-x64-AllOS-ENU.exe' +default['dotnetframework']['4.5.1']['url'] = + 'http://download.microsoft.com/download/1/6/7/167F0D79-9317-48AE-AEDB-17120579F8E2/NDP451-KB2858728-x86-x64-AllOS-ENU.exe' # .NET 4.5.2 -default['dotnetframework']['4.5.2']['package_name'] = - 'Microsoft .NET Framework 4.5.2' -if is_2012r2_or_8_1 - default['dotnetframework']['4.5.2']['version'] = '4.5.51650' -else - default['dotnetframework']['4.5.2']['version'] = '4.5.51209' -end -default['dotnetframework']['4.5.2']['checksum'] = +default['dotnetframework']['4.5.2']['package_name'] = 'Microsoft .NET Framework 4.5.2' +default['dotnetframework']['4.5.2']['version'] = if is_2012r2_or_8_1 + '4.5.51650' + else + '4.5.51209' + end +default['dotnetframework']['4.5.2']['checksum'] = '6c2c589132e830a185c5f40f82042bee3022e721a216680bd9b3995ba86f3781' -default['dotnetframework']['4.5.2']['url'] = - 'http://download.microsoft.com/download/E/2/1/' \ - 'E21644B5-2DF2-47C2-91BD-63C560427900/' \ - 'NDP452-KB2901907-x86-x64-AllOS-ENU.exe' +default['dotnetframework']['4.5.2']['url'] = + 'http://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe' # .NET 4.6 -default['dotnetframework']['4.6']['package_name'] = - 'Microsoft .NET Framework 4.6' +default['dotnetframework']['4.6']['package_name'] = 'Microsoft .NET Framework 4.6' default['dotnetframework']['4.6']['version'] = '4.6.00081' -default['dotnetframework']['4.6']['checksum'] = +default['dotnetframework']['4.6']['checksum'] = 'b21d33135e67e3486b154b11f7961d8e1cfd7a603267fb60febb4a6feab5cf87' -default['dotnetframework']['4.6']['url'] = - 'http://download.microsoft.com/download/C/3/A/' \ - 'C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/' \ - 'NDP46-KB3045557-x86-x64-AllOS-ENU.exe' +default['dotnetframework']['4.6']['url'] = + 'http://download.microsoft.com/download/C/3/A/C3A5200B-D33C-47E9-9D70-2F7C65DAAD94/NDP46-KB3045557-x86-x64-AllOS-ENU.exe' # .NET 4.6.1 -default['dotnetframework']['4.6.1']['package_name'] = - 'Microsoft .NET Framework 4.6.1' +default['dotnetframework']['4.6.1']['package_name'] = 'Microsoft .NET Framework 4.6.1' default['dotnetframework']['4.6.1']['version'] = '4.6.01038' -default['dotnetframework']['4.6.1']['checksum'] = +default['dotnetframework']['4.6.1']['checksum'] = 'beaa901e07347d056efe04e8961d5546c7518fab9246892178505a7ba631c301' -default['dotnetframework']['4.6.1']['url'] = - 'http://download.microsoft.com/download/E/4/1/' \ - 'E4173890-A24A-4936-9FC9-AF930FE3FA40/' \ - 'NDP461-KB3102436-x86-x64-AllOS-ENU.exe' +default['dotnetframework']['4.6.1']['url'] = + 'http://download.microsoft.com/download/E/4/1/E4173890-A24A-4936-9FC9-AF930FE3FA40/NDP461-KB3102436-x86-x64-AllOS-ENU.exe' # .NET 4.6.2 -default['dotnetframework']['4.6.2']['package_name'] = - 'Microsoft .NET Framework 4.6.2' +default['dotnetframework']['4.6.2']['package_name'] = 'Microsoft .NET Framework 4.6.2' default['dotnetframework']['4.6.2']['version'] = '4.6.01590' -default['dotnetframework']['4.6.2']['checksum'] = +default['dotnetframework']['4.6.2']['checksum'] = '28886593e3b32f018241a4c0b745e564526dbb3295cb2635944e3a393f4278d4' -default['dotnetframework']['4.6.2']['url'] = - 'https://download.microsoft.com/download/F/9/4/' \ - 'F942F07D-F26F-4F30-B4E3-EBD54FABA377/' \ - 'NDP462-KB3151800-x86-x64-AllOS-ENU.exe' +default['dotnetframework']['4.6.2']['url'] = + 'https://download.microsoft.com/download/F/9/4/F942F07D-F26F-4F30-B4E3-EBD54FABA377/NDP462-KB3151800-x86-x64-AllOS-ENU.exe' + +# .NET 4.7.0 +default['dotnetframework']['4.7.0']['package_name'] = 'Microsoft .NET Framework 4.7.0' +default['dotnetframework']['4.7.0']['version'] = '4.7.2053.0' +default['dotnetframework']['4.7.0']['checksum'] = + '24762159579EC9763BAEC8C23555464360BD31677EE8894A58BDB67262E7E470' +default['dotnetframework']['4.7.0']['url'] = + 'https://download.microsoft.com/download/D/D/3/DD35CC25-6E9C-484B-A746-C5BE0C923290/NDP47-KB3186497-x86-x64-AllOS-ENU.exe' + +# .NET 4.7.1 +default['dotnetframework']['4.7.1']['package_name'] = 'Microsoft .NET Framework 4.7.1' +default['dotnetframework']['4.7.1']['version'] = '4.7.2558.0' +default['dotnetframework']['4.7.1']['checksum'] = + '63DC850DF091F3F137B5D4392F47917F847F8926DC8AF1DA9BFBA6422E495805' +default['dotnetframework']['4.7.1']['url'] = + 'https://download.microsoft.com/download/9/E/6/9E63300C-0941-4B45-A0EC-0008F96DD480/NDP471-KB4033342-x86-x64-AllOS-ENU.exe' + +# .NET 4.7.2 +default['dotnetframework']['4.7.2']['package_name'] = 'Microsoft .NET Framework 4.7.2' +default['dotnetframework']['4.7.2']['version'] = '4.7.3081.0' +default['dotnetframework']['4.7.2']['checksum'] = + 'C908F0A5BEA4BE282E35ACBA307D0061B71B8B66CA9894943D3CBB53CAD019BC' +default['dotnetframework']['4.7.2']['url'] = + 'https://download.microsoft.com/download/6/E/4/6E48E8AB-DC00-419E-9704-06DD46E5F81D/NDP472-KB4054530-x86-x64-AllOS-ENU.exe' + +# .NET 4.8.0 +default['dotnetframework']['4.8.0']['package_name'] = 'Microsoft .NET Framework 4.8.0' +default['dotnetframework']['4.8.0']['version'] = '4.8.3928.0' +default['dotnetframework']['4.8.0']['checksum'] = + '9B1F71CD1B86BB6EE6303F7BE6FBBE71807A51BB913844C85FC235D5978F3A0F' +default['dotnetframework']['4.8.0']['url'] = + 'https://dotnet.microsoft.com/download/thank-you/net48-offline' From ee63b505f228a859be2a34e5020a1c4e3db37c2d Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:04:30 -0500 Subject: [PATCH 3/8] unit and integration tests --- Berksfile | 2 - TESTING.md | 35 +++++++++++++++ files/default/tests/minitest/default_test.rb | 41 ------------------ .kitchen.yml => kitchen.yml | 6 ++- spec/unit/recipes/default_spec.rb | 45 ++++++++++++++++++++ spec/unit/recipes/regiis_spec.rb | 41 ++++++++++++++++++ test/integration/default/default_test.rb | 24 +++++++++++ test/integration/default/regiis_test.rb | 8 ++++ 8 files changed, 158 insertions(+), 44 deletions(-) create mode 100644 TESTING.md delete mode 100644 files/default/tests/minitest/default_test.rb rename .kitchen.yml => kitchen.yml (91%) create mode 100644 spec/unit/recipes/default_spec.rb create mode 100644 spec/unit/recipes/regiis_spec.rb create mode 100644 test/integration/default/default_test.rb create mode 100644 test/integration/default/regiis_test.rb diff --git a/Berksfile b/Berksfile index 3bb74f7..34fea21 100644 --- a/Berksfile +++ b/Berksfile @@ -1,5 +1,3 @@ source 'https://supermarket.chef.io' -# rubocop:disable Metrics/LineLength metadata -cookbook 'minitest-handler', git: 'https://github.com/b-dean/minitest-handler-cookbook', branch: 'chef-13-fix' diff --git a/TESTING.md b/TESTING.md new file mode 100644 index 0000000..ab5a116 --- /dev/null +++ b/TESTING.md @@ -0,0 +1,35 @@ +# TESTING # + +The [ChefDK](https://docs.chef.io/about_chefdk.html) contains all the tools required to test and develop for this cookbook. A `project.toml` file is provided so that all testing commands can be run using the `delivery local` cli that comes with ChefDK. + +### Style Testing ### +Run `delivery local lint` to run cookstyle and `delivery local syntax` to run foodcritic. + +### Spec Testing ### +Run `delivery local unit` to run [ChefSpec](https://github.com/chefspec/chefspec) tests. + +### Combined Style + Spec Testing ### +All cookstyle, foodcritic and Chefspec tests can be run in a single command using `delivery local verify` + +### Integration Testing ### +Integration testing with [Test Kitchen](https://docs.chef.io/kitchen.html) can also be done using the delivery cli. To execute all stages of testing with test kitchen you can run either `delivery local acceptance` or `kitchen test` + +Test Kitchen is configured to use vagrant by default and uses [inspec](https://www.inspec.io/) to verify. + +## Private Images + +Some operating systems have specific licenses that prevent us from making those images available freely. We either comment these the .kitchen.yml or create a separate .kitchen.vmware.yml file for Chef internal use. + +Images include: + +- Windows Server 2008 +- Windows Server 2012 +- Windows Server 2016 +- Windows Server 2019 +- Windows 7 Professional +- Windows 8.1 Professional +- Mac OS X 10.7-10.12 +- SLES 12 / 12SP1 +- Solaris 10.11 + +Windows Images: https://atlas.hashicorp.com/boxes/search?order=desc&page=1&provider=virtualbox&q=windows&sort=updated&utf8=%E2%9C%93 \ No newline at end of file diff --git a/files/default/tests/minitest/default_test.rb b/files/default/tests/minitest/default_test.rb deleted file mode 100644 index 21d4c2f..0000000 --- a/files/default/tests/minitest/default_test.rb +++ /dev/null @@ -1,41 +0,0 @@ -# encoding: UTF-8 - -require 'minitest/spec' -require 'win32/registry' - -# Tests to ensure .NET 4 is installed -class TestDotNet4Install < MiniTest::Chef::TestCase - def test_framework_dir_exists - # all .NET versions are installed to the same v4.0.30319 folder - dir = File.join(ENV['WINDIR'], 'Microsoft.Net\\Framework64\\v4.0.30319') - assert Dir.exist?(dir) - end - - # Determining installed .NET versions - # http://support.microsoft.com/kb/318785 - # https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx - def test_framework_version - expected_version = expected_dotnet_version - reg_version = installed_dotnet_version - flunk('Could not find a .NET version in the registry') unless reg_version - assert( - Gem::Version.new(reg_version) >= Gem::Version.new(expected_version), - "Expected .NET version #{expected_version} or higher, " \ - "but only found #{reg_version}" - ) - end - - def expected_dotnet_version - major_version = node['dotnetframework']['version'] - node['dotnetframework'][major_version]['version'] - end - - def installed_dotnet_version - path = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' - Win32::Registry::HKEY_LOCAL_MACHINE.open(path) do |reg| - return reg['Version'] - end - rescue ::Win32::Registry::Error - return nil - end -end diff --git a/.kitchen.yml b/kitchen.yml similarity index 91% rename from .kitchen.yml rename to kitchen.yml index fbef9ab..930c5ef 100644 --- a/.kitchen.yml +++ b/kitchen.yml @@ -23,6 +23,9 @@ transport: username: <%= ENV['WIN_USER'] %> password: <%= ENV['WIN_PASS'] %> +verifier: + name: inspec + platforms: - name: windows @@ -32,7 +35,8 @@ suites: encrypted_data_bag_secret_key_path: <%= ENV['CHEF_SECRET_FILE'] %> run_list: - recipe[<%= ENV['COOKBOOK'] %>::default] - - recipe[minitest-handler] + inspec_tests: + - test/integration/default attributes: daptiv_site: version: <%= ENV['LATEST_PPM_PACKAGE'] %> diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..7b6bad2 --- /dev/null +++ b/spec/unit/recipes/default_spec.rb @@ -0,0 +1,45 @@ +# +# Cookbook:: dotnetframework +# Spec:: default +# +# Copyright:: 2020, The Authors, All Rights Reserved. + +require 'spec_helper' + +RSpec.shared_examples 'dotnetframework::default' do |platform, version| + context "when run on #{platform} #{version}" do + let(:chef_run) do + ChefSpec::SoloRunner.new( + os: 'windows', + platform: platform, + version: version, + step_into: ['dotnetframework::default'] + ).converge(described_recipe) + end + + describe 'nothing reboot resouce' do + it { is_expected.to nothing_reboot('dotnetframework_install') } + end + + describe 'install .NET Framework' do + it { is_expected.to install_dotnetframework_version('4.5.51650') } + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end +end + +RSpec.describe 'dotnetframework::default' do + platforms = { + 'windows' => %w(2012R2 2016 2019), + } + + platforms.each do |platform, versions| + versions = versions.is_a?(String) ? [versions] : versions + versions.each do |version| + include_examples 'dotnetframework::default', platform, version + end + end +end diff --git a/spec/unit/recipes/regiis_spec.rb b/spec/unit/recipes/regiis_spec.rb new file mode 100644 index 0000000..e2c9b29 --- /dev/null +++ b/spec/unit/recipes/regiis_spec.rb @@ -0,0 +1,41 @@ +# +# Cookbook:: dotnetframework +# Spec:: regiis +# +# Copyright:: 2020, The Authors, All Rights Reserved. + +require 'spec_helper' + +RSpec.shared_examples 'dotnetframework::regiis' do |platform, version| + context "when run on #{platform} #{version}" do + let(:chef_run) do + ChefSpec::SoloRunner.new( + os: 'windows', + platform: platform, + version: version, + step_into: ['dotnetframework::regiis'] + ).converge(described_recipe) + end + + describe 'run appcmd.exe' do + it { is_expected.to run_execute('aspnet_regiis') } + end + + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end + end +end + +RSpec.describe 'dotnetframework::regiis' do + platforms = { + 'windows' => %w(2012R2 2016 2019), + } + + platforms.each do |platform, versions| + versions = versions.is_a?(String) ? [versions] : versions + versions.each do |version| + include_examples 'dotnetframework::regiis', platform, version + end + end +end diff --git a/test/integration/default/default_test.rb b/test/integration/default/default_test.rb new file mode 100644 index 0000000..53f2fc1 --- /dev/null +++ b/test/integration/default/default_test.rb @@ -0,0 +1,24 @@ +# InSpec test for recipe dotnetframework::default + +# The InSpec reference, with examples and extensive documentation, can be +# found at https://www.inspec.io/docs/reference/resources/ + +dir = File.join(ENV['WINDIR'], '\\Microsoft.Net\\Framework64\\v4.0.30319') +describe directory(dir) do + it { should exist } +end + +if os['release'] < '10' + describe registry_key('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full') do + its('Version') { should match '4.5.51650' } + it { should exist } + end +end + +# Windows 2019 has 4.7 already installed +if os['release'] > '10' + describe registry_key('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full') do + its('Version') { should include '4.7' } + it { should exist } + end +end diff --git a/test/integration/default/regiis_test.rb b/test/integration/default/regiis_test.rb new file mode 100644 index 0000000..2686daf --- /dev/null +++ b/test/integration/default/regiis_test.rb @@ -0,0 +1,8 @@ +# InSpec test for recipe dotnetframework::regiis + +# The InSpec reference, with examples and extensive documentation, can be +# found at https://www.inspec.io/docs/reference/resources/ + +describe 'install aspnet regiis' do + its('stdout') { should eq 0 } +end From 9fa56c3155554cc203dd810b910819ae6a2fc691 Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:05:06 -0500 Subject: [PATCH 4/8] rubocop edits --- .rubocop.yml | 1 + .rubocop_todo.yml | 60 +++++++++++++++++++++++++++++++++++++++++++++++ rakefile.rb | 9 ++++--- recipes/regiis.rb | 1 - 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc32da4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..ceff252 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,60 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-04-10 13:40:46 -0500 using RuboCop version 0.55.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 2 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/BlockLength: + Max: 32 + +# Offense count: 2 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: snake_case, normalcase, non_integer +Naming/VariableNumber: + Exclude: + - 'attributes/default.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Style/Encoding: + Exclude: + - 'Vagrantfile' + - 'attributes/default.rb' + - 'files/default/tests/minitest/default_test.rb' + - 'libraries/matchers.rb' + - 'recipes/default.rb' + - 'resources/version.rb' + +# Offense count: 2 +Style/MixinUsage: + Exclude: + - 'providers/version.rb' + - 'resources/version.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'rakefile.rb' + - 'spec/unit/recipes/default_spec.rb' + - 'spec/unit/recipes/regiis_spec.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'spec/unit/recipes/default_spec.rb' + - 'spec/unit/recipes/regiis_spec.rb' + +# Offense count: 30 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 116 diff --git a/rakefile.rb b/rakefile.rb index 70c512e..5eb3b44 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -1,6 +1,5 @@ -# rubocop:disable Metrics/BlockLength -task default: %i[version rubocop foodcritic spec kitchen cleanup] -task nokitchen: %i[version rubocop foodcritic spec] +task default: %i((version) (rubocop) (foodcritic) (spec) (kitchen) (cleanup)) +task nokitchen: %i((version) (rubocop) (foodcritic) (spec)) desc 'Set cookbook version.' task :version do @@ -32,11 +31,11 @@ end desc 'Test Kitchen.' -task :kitchen, [:type] => %i[check_env_vars assume_role] do |_t, args| +task :kitchen, [:type] => %i((check_env_vars) (assume_role)) do |_t, args| task_thread = [] kitchen_complete = false start_time = Time.now - %w[kitchen assume_role].each do |task| + %w[(kitchen assume_role)].each do |task| task_thread << Thread.new do case task when 'kitchen' diff --git a/recipes/regiis.rb b/recipes/regiis.rb index fa3fa3b..198b42b 100644 --- a/recipes/regiis.rb +++ b/recipes/regiis.rb @@ -17,7 +17,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# rubocop:disable Method/LineLength # C:\Windows\System32\inetsrv>appcmd list config /section:isapiCgiRestriction # # From 2abc7dcc8033cb66b454dc19087116e8e45bc1e1 Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:05:19 -0500 Subject: [PATCH 5/8] delivery framework --- .delivery/project.toml | 1 + .github/workflows/delivery.yml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .delivery/project.toml create mode 100644 .github/workflows/delivery.yml diff --git a/.delivery/project.toml b/.delivery/project.toml new file mode 100644 index 0000000..d0f90d3 --- /dev/null +++ b/.delivery/project.toml @@ -0,0 +1 @@ +remote_file = "https://raw.githubusercontent.com/chef-cookbooks/community_cookbook_tools/master/delivery/project.toml" \ No newline at end of file diff --git a/.github/workflows/delivery.yml b/.github/workflows/delivery.yml new file mode 100644 index 0000000..4b5c467 --- /dev/null +++ b/.github/workflows/delivery.yml @@ -0,0 +1,16 @@ +name: delivery + +on: [push, pull_request] + +jobs: + delivery: + + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@master + - name: Run Chef Delivery + uses: actionshub/chef-delivery@master + env: + CHEF_LICENSE: accept-no-persist \ No newline at end of file From a894b17729a3e47bebea8716dbb699721fcca9f1 Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:05:27 -0500 Subject: [PATCH 6/8] update ignore files --- .gitignore | 49 +++++++++++++++++++++++++++++++++++++++++-------- chefignore | 40 ++++++++++++++++------------------------ 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index e93a7ad..8f93e57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,49 @@ -.vagrant -.kitchen +*.rbc +.config +coverage +InstalledFiles +lib/bundler/man +pkg +rdoc +spec/reports +test/tmp +test/version_tmp +tmp +_Store *~ *# .#* \#*# .*.sw[a-z] *.un~ -/cookbooks -version.txt -Berksfile.lock +*.tmp +*.bk +*.bkup + +# ruby/bundler files +.ruby-version +.ruby-gemset +.rvmrc +Gemfile.lock +.bundle +*.gem -# Bundler -bin/* -.bundle/* +# YARD artifacts +.yardoc +_yardoc +doc/ +.idea + +# chef stuff +Berksfile.lock +.kitchen +kitchen.local.yml +vendor/ +.coverage/ +.zero-knife.rb +Policyfile.lock.json +# vagrant stuff +.vagrant/ +.vagrant.d/ +.kitchen/ diff --git a/chefignore b/chefignore index a586a3b..b2065c3 100644 --- a/chefignore +++ b/chefignore @@ -1,5 +1,5 @@ # Put files/directories that should be ignored in this file when uploading -# or sharing to the community site. +# to a chef-server or supermarket. # Lines that start with '# ' are comments. # OS generated files # @@ -45,14 +45,20 @@ a.out # Testing # ########### -.watchr .rspec spec/* spec/fixtures/* test/* features/* -Guardfile +examples/* Procfile +kitchen* +.kitchen* +.rubocop.yml +spec/* +.travis.yml +.foodcritic +appveyor.yml # SCM # ####### @@ -74,28 +80,14 @@ Berksfile.lock cookbooks/* tmp +# Policyfile # +############## +Policyfile.rb +Policyfile.lock.json + # Cookbooks # ############# -CONTRIBUTING +CONTRIBUTING* CHANGELOG* +TESTING* -# Strainer # -############ -Colanderfile -Strainerfile -.colander -.strainer - -# Vagrant # -########### -.vagrant -Vagrantfile - -# Travis # -########## -.travis.yml - -# daptiv # -########## -vagrant.yaml -.tailor From 80248ed24ebff2cc4b9593489bf1250484fa7c9a Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:05:42 -0500 Subject: [PATCH 7/8] update README.md --- README.md | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index df21de7..329838a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Dotnetframework cookbook -Installs and configures the .NET framework 4, 4.5, 4.5.1, 4.5.2, or 4.6 runtime +Installs and configures the .NET framework 4 family runtime. -# Requirements +## Requirements Tested on Windows Server 2008 R2 and Windows Server 2012R2. The selected .NET runtime should work on versions of Windows supported by the associated .NET @@ -12,48 +12,46 @@ installer. * Windows 2008 R2 * Windows 2012 * Windows 2012 R2 +* Windows 2016 +* Windows 2019 -# Usage +## Usage Include the default recipe in your run list. The default recipe will install the specified .NET framework version. -# Attributes +## Attributes -## default +### default * `node['dotnetframework']['version']` - defaults to '4.5.2' Acceptable values: -'4.0', '4.5', '4.5.1', '4.5.2', '4.6', '4.6.1', '4.6.2'. +'4.0', '4.5', '4.5.1', '4.5.2', '4.6', '4.6.1', '4.6.2', '4.7', '4.7.1', '4.7.2', '4.8' -# Recipes +## Recipes -## default +### default Installs the .NET Framework. -## regiis +### regiis This recipe register .NET with IIS so that IIS can host .NET application -associated with the specified intalled .NET version. This recipe currently +associated with the specified installed .NET version. This recipe currently does not support Windows 2012 or higher. For Windows 2012 or newer its recommended that you use the IIS cookbook to register the .NET version. -## mini-tests +## Testing -You can include the mini-tests in your runlist to verify .NET was successfully -installed, however .NET will not work until you reboot. +For more details look at the [TESTING.md](./TESTING.md). -.NET 4.6 minitests will fail until you reboot, so its best to run Chef with -only dotnetframework in your runlist, reboot, then include dotnetframework -again with the minitest-handler. +## TODO -# TODO +* Install .NET using the windows_feature resource if the current OS supports it. +* Support older versions of .NET < 4.0. +* Support installation over WinRM (i.e. native scheduled task support). +* Abstract .NET installation to a Chef resource. -- Install .NET using the windows_feature resource if the current OS supports it. -- Support older versions of .NET < 4.0. -- Support installation over WinRM (i.e. native scheduled task support). -- Abstract .NET installation to a Chef resource. - -# Author +## Author Author:: Shawn Neal (sneal@sneal.net) + Derek Groh (derekgroh@github.com) From 00dacf67b71e37fc00bd8e2c24a3aba874219676 Mon Sep 17 00:00:00 2001 From: Derek Groh Date: Fri, 10 Apr 2020 14:08:13 -0500 Subject: [PATCH 8/8] version 3.0.0 - changelog, metadata --- CHANGELOG.md | 6 ++++++ metadata.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 845c80f..7a6f7b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ This file is used to list changes made in each version of dotnetframework. +## 3.0.0 +- update cookbook to Chef14 custom resources +- unit and integration tests +- add kitchen testing +- add delivery framework and github integration + ## 2.0.0 - ChefDK 2.5.3 rubocop and foodcritic updates - Remove `node.set` for Chef 13 compatiblity diff --git a/metadata.rb b/metadata.rb index 5b70280..1488f3f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ description 'Installs/Configures .NET Framework' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) ver_path = File.join(File.dirname(__FILE__), 'version.txt') -version File.exist?(ver_path) ? IO.read(ver_path).chomp : '2.0.0' +version File.exist?(ver_path) ? IO.read(ver_path).chomp : '3.0.0' chef_version '>= 13.0' if respond_to?(:chef_version) issues_url 'https://github.com/daptiv/dotnetframework/issues' source_url 'https://github.com/daptiv/dotnetframework/'