Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Annih committed Nov 26, 2015
1 parent 0d5e2f8 commit 82f3ab9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 30 deletions.
28 changes: 9 additions & 19 deletions recipes/powershell2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,24 @@

require 'chef/win32/version'
windows_version = Chef::ReservedNames::Win32::Version.new
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 windows_version.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'

Expand Down
9 changes: 5 additions & 4 deletions recipes/powershell3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
8 changes: 5 additions & 3 deletions recipes/powershell4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 3 additions & 4 deletions recipes/powershell5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
require 'chefspec'
require 'chefspec/berkshelf'
require 'helpers/matchers'

RSpec.configure do |config|
config.before :each do
allow(::Kernel).to receive('require').and_call_original
allow(::Kernel).to receive('require').with('chef/win32/api/system')
end
end

0 comments on commit 82f3ab9

Please sign in to comment.