From e21df5950dec74fa6bea8d4b3b4c328cb6db4b6f Mon Sep 17 00:00:00 2001 From: Baptiste Courtois Date: Thu, 26 Nov 2015 12:56:22 +0100 Subject: [PATCH] Tests --- Berksfile | 2 ++ recipes/powershell2.rb | 38 ++++++++++------------- recipes/powershell3.rb | 9 +++--- recipes/powershell4.rb | 8 +++-- recipes/powershell5.rb | 7 ++--- spec/recipes/powershell2_spec.rb | 1 - spec/recipes/powershell3_spec.rb | 1 - spec/recipes/powershell4_spec.rb | 1 - spec/recipes/powershell5_spec.rb | 1 - spec/recipes/winrm_spec.rb | 1 - toto | 53 ++++++++++++++++++++++++++++++++ 11 files changed, 85 insertions(+), 37 deletions(-) create mode 100644 toto diff --git a/Berksfile b/Berksfile index 099d9f1..b2ca716 100644 --- a/Berksfile +++ b/Berksfile @@ -2,6 +2,8 @@ source 'https://supermarket.chef.io' metadata +cookbook 'ms_dotnet', git: 'https://github.com/criteo-cookbooks/ms_dotnet.git', branch: 'no_use_of_win32_module' + group :integration do cookbook 'minimal', path: './test/cookbooks/minimal' end diff --git a/recipes/powershell2.rb b/recipes/powershell2.rb index 57d2a43..990e319 100644 --- a/recipes/powershell2.rb +++ b/recipes/powershell2.rb @@ -24,36 +24,32 @@ case node['platform'] when 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new + # 0x0C Server Datacenter (core installation) + # 0x27 Server Datacenter without Hyper-V (core installation) + # 0x0E Server Enterprise (core installation) + # 0x29 Server Enterprise without Hyper-V (core installation) + # 0x0D Server Standard (core installation) + # 0x28 Server Standard without Hyper-V (core installation) + # 0x1D Web Server (core installation) + is_core = [0x0C, 0x27, 0x0E, 0x29, 0x0D, 0x28, 0x1D].include? node['kernel']['os_info']['operating_system_sku'] + nt_version = node['platform_version'].to_f - if (windows_version.windows_server_2012? || windows_version.windows_8?) && windows_version.core? - # Windows Server 2012 Core does not come with Powershell 2.0 enabled - windows_feature 'MicrosoftWindowsPowerShellV2' do - action :install - end - windows_feature 'MicrosoftWindowsPowerShellV2-WOW64' do - action :install - only_if { node['kernel']['machine'] == 'x86_64' } - end + include_recipe 'ms_dotnet::ms_dotnet2' - elsif (windows_version.windows_server_2008_r2? || windows_version.windows_7?) && windows_version.core? - # Windows Server 2008 R2 Core does not come with .NET or Powershell 2.0 enabled - include_recipe 'ms_dotnet::ms_dotnet2' + if is_core && nt_version.between?(6.1, 6.2) + feature_suffix = 'V2' if nt_version == 6.2 - windows_feature 'MicrosoftWindowsPowerShell' do + windows_feature "MicrosoftWindowsPowerShell#{feature_suffix}" do action :install end - windows_feature 'MicrosoftWindowsPowerShell-WOW64' do + + windows_feature "MicrosoftWindowsPowerShell#{feature_suffix}-WOW64" do action :install only_if { node['kernel']['machine'] == 'x86_64' } end - elsif windows_version.windows_server_2008? || windows_version.windows_server_2003_r2? || - windows_version.windows_server_2003? || windows_version.windows_xp? - - include_recipe 'ms_dotnet::ms_dotnet2' - + # WMF 2.0 is required for XP and Windows Server 2003 + elsif nt_version.between?(5.1, 5.2) # Reboot if user specifies doesn't specify no_reboot include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot' diff --git a/recipes/powershell3.rb b/recipes/powershell3.rb index 977594d..ad1b843 100644 --- a/recipes/powershell3.rb +++ b/recipes/powershell3.rb @@ -24,10 +24,11 @@ case node['platform'] when 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new - - if windows_version.windows_server_2008? || windows_version.windows_server_2008_r2? || windows_version.windows_7? + nt_version = node['platform_version'].to_f + # Powershell 3.0 is only compatible with: + # * Windows NT 6.0 server (Windows Server 2008 SP2 not vista) + # * Windows NT 6.1 (Windows Server 2008R2 & Windows 7.1) + if (nt_version == 6.0 && node['kernel']['os_info']['product_type'] != 0x1) || nt_version == 6.1 # For Windows Server 2008 ensure that Powershell 2 is already installed and so is BITS 4.0 if windows_version.windows_server_2008? diff --git a/recipes/powershell4.rb b/recipes/powershell4.rb index 7f3bea2..9520c0e 100644 --- a/recipes/powershell4.rb +++ b/recipes/powershell4.rb @@ -22,10 +22,12 @@ # http://www.microsoft.com/en-us/download/details.aspx?id=40855 if node['platform'] == 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new - if windows_version.windows_server_2008_r2? || windows_version.windows_7? || windows_version.windows_server_2012? + nt_version = node['platform_version'].to_f + # WMF 4.0 is only compatible with: + # * Windows NT 6.1 (Windows Server 2008R2 & Windows 7.1) + # * Windows NT 6.2 Server (Windows Server 2012 not Windows 8) + if nt_version == 6.1 || (nt_version == 6.2 && node['kernel']['os_info']['product_type'] != 0x1) # Ensure .NET 4.5 is installed or installation will fail silently per Microsoft. fail 'Attribute ms_dotnet.v4.version is not configured to install .NET4.5 as required for Powershell4' if node.default['ms_dotnet']['v4']['version'] < '4.5' diff --git a/recipes/powershell5.rb b/recipes/powershell5.rb index 2ccda0f..c819c2e 100644 --- a/recipes/powershell5.rb +++ b/recipes/powershell5.rb @@ -26,11 +26,10 @@ case node['platform'] when 'windows' - require 'chef/win32/version' - windows_version = Chef::ReservedNames::Win32::Version.new - - if windows_version.windows_server_2012_r2? || windows_version.windows_8_1? + nt_version = node['platform_version'].to_f + # Handle WMFC install on 2012R2 and 8.1 only (yet) + if nt_version == 6.3 include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot' windows_package 'Windows Management Framework Core 5.0' do diff --git a/spec/recipes/powershell2_spec.rb b/spec/recipes/powershell2_spec.rb index 3e7940d..3ca516c 100644 --- a/spec/recipes/powershell2_spec.rb +++ b/spec/recipes/powershell2_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'chef/win32/version' describe 'powershell::powershell2' do let(:chef_run) do diff --git a/spec/recipes/powershell3_spec.rb b/spec/recipes/powershell3_spec.rb index fe798c2..b3ba8e9 100644 --- a/spec/recipes/powershell3_spec.rb +++ b/spec/recipes/powershell3_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'chef/win32/version' describe 'powershell::powershell3' do let(:chef_run) do diff --git a/spec/recipes/powershell4_spec.rb b/spec/recipes/powershell4_spec.rb index 17b62a2..f9d52e3 100644 --- a/spec/recipes/powershell4_spec.rb +++ b/spec/recipes/powershell4_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'chef/win32/version' describe 'powershell::powershell4' do context 'when installation_reboot_mode is no_reboot' do diff --git a/spec/recipes/powershell5_spec.rb b/spec/recipes/powershell5_spec.rb index b69ef4d..c60d725 100644 --- a/spec/recipes/powershell5_spec.rb +++ b/spec/recipes/powershell5_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'chef/win32/version' describe 'powershell::powershell5' do let(:chef_run) do diff --git a/spec/recipes/winrm_spec.rb b/spec/recipes/winrm_spec.rb index 6bdb490..71efb29 100644 --- a/spec/recipes/winrm_spec.rb +++ b/spec/recipes/winrm_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' -require 'chef/win32/version' describe 'powershell::winrm' do let(:chef_run) do diff --git a/toto b/toto new file mode 100644 index 0000000..a44e434 --- /dev/null +++ b/toto @@ -0,0 +1,53 @@ + PRODUCT_BUSINESS = 0x00000006 # Business + PRODUCT_BUSINESS_N = 0x00000010 # Business N + PRODUCT_CLUSTER_SERVER = 0x00000012 # HPC Edition + PRODUCT_DATACENTER_SERVER = 0x00000008 # Server Datacenter (full installation) + PRODUCT_DATACENTER_SERVER_CORE = 0x0000000C # Server Datacenter (core installation) + PRODUCT_DATACENTER_SERVER_CORE_V = 0x00000027 # Server Datacenter without Hyper-V (core installation) + PRODUCT_DATACENTER_SERVER_V = 0x00000025 # Server Datacenter without Hyper-V (full installation) + PRODUCT_ENTERPRISE = 0x00000004 # Enterprise + PRODUCT_ENTERPRISE_E = 0x00000046 # Not supported + PRODUCT_ENTERPRISE_N = 0x0000001B # Enterprise N + PRODUCT_ENTERPRISE_SERVER = 0x0000000A # Server Enterprise (full installation) + PRODUCT_ENTERPRISE_SERVER_CORE = 0x0000000E # Server Enterprise (core installation) + PRODUCT_ENTERPRISE_SERVER_CORE_V = 0x00000029 # Server Enterprise without Hyper-V (core installation) + PRODUCT_ENTERPRISE_SERVER_IA64 = 0x0000000F # Server Enterprise for Itanium-based Systems + PRODUCT_ENTERPRISE_SERVER_V = 0x00000026 # Server Enterprise without Hyper-V (full installation) + PRODUCT_HOME_BASIC = 0x00000002 # Home Basic + PRODUCT_HOME_BASIC_E = 0x00000043 # Not supported + PRODUCT_HOME_BASIC_N = 0x00000005 # Home Basic N + PRODUCT_HOME_PREMIUM = 0x00000003 # Home Premium + PRODUCT_HOME_PREMIUM_E = 0x00000044 # Not supported + PRODUCT_HOME_PREMIUM_N = 0x0000001A # Home Premium N + PRODUCT_HYPERV = 0x0000002A # Microsoft Hyper-V Server + PRODUCT_MEDIUMBUSINESS_SERVER_MANAGEMENT = 0x0000001E # Windows Essential Business Server Management Server + PRODUCT_MEDIUMBUSINESS_SERVER_MESSAGING = 0x00000020 # Windows Essential Business Server Messaging Server + PRODUCT_MEDIUMBUSINESS_SERVER_SECURITY = 0x0000001F # Windows Essential Business Server Security Server + PRODUCT_PROFESSIONAL = 0x00000030 # Professional + PRODUCT_PROFESSIONAL_E = 0x00000045 # Not supported + PRODUCT_PROFESSIONAL_N = 0x00000031 # Professional N + PRODUCT_SERVER_FOR_SMALLBUSINESS = 0x00000018 # Windows Server 2008 for Windows Essential Server Solutions + PRODUCT_SERVER_FOR_SMALLBUSINESS_V = 0x00000023 # Windows Server 2008 without Hyper-V for Windows Essential Server Solutions + PRODUCT_SERVER_FOUNDATION = 0x00000021 # Server Foundation + PRODUCT_HOME_PREMIUM_SERVER = 0x00000022 # Windows Home Server 2011 + PRODUCT_SB_SOLUTION_SERVER = 0x00000032 # Windows Small Business Server 2011 Essentials + PRODUCT_HOME_SERVER = 0x00000013 # Windows Storage Server 2008 R2 Essentials + PRODUCT_SMALLBUSINESS_SERVER = 0x00000009 # Windows Small Business Server + PRODUCT_SOLUTION_EMBEDDEDSERVER = 0x00000038 # Windows MultiPoint Server + PRODUCT_STANDARD_SERVER = 0x00000007 # Server Standard (full installation) + PRODUCT_STANDARD_SERVER_CORE = 0x0000000D # Server Standard (core installation) + PRODUCT_STANDARD_SERVER_CORE_V = 0x00000028 # Server Standard without Hyper-V (core installation) + PRODUCT_STANDARD_SERVER_V = 0x00000024 # Server Standard without Hyper-V (full installation) + PRODUCT_STARTER = 0x0000000B # Starter + PRODUCT_STARTER_E = 0x00000042 # Not supported + PRODUCT_STARTER_N = 0x0000002F # Starter N + PRODUCT_STORAGE_ENTERPRISE_SERVER = 0x00000017 # Storage Server Enterprise + PRODUCT_STORAGE_EXPRESS_SERVER = 0x00000014 # Storage Server Express + PRODUCT_STORAGE_STANDARD_SERVER = 0x00000015 # Storage Server Standard + PRODUCT_STORAGE_WORKGROUP_SERVER = 0x00000016 # Storage Server Workgroup + PRODUCT_UNDEFINED = 0x00000000 # An unknown product + PRODUCT_ULTIMATE = 0x00000001 # Ultimate + PRODUCT_ULTIMATE_E = 0x00000047 # Not supported + PRODUCT_ULTIMATE_N = 0x0000001C # Ultimate N + PRODUCT_WEB_SERVER = 0x00000011 # Web Server (full installation) + PRODUCT_WEB_SERVER_CORE = 0x0000001D # Web Server (core installation) \ No newline at end of file