kitchen-hyperv 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e5069fa03e4ad0ae44ac50547e6d2e72a78e15c
4
- data.tar.gz: ffc236de0552e5d2a05a823e5940cf71d08d39b2
3
+ metadata.gz: 00ebbd881261a4c181dd20609af6dbe637e31a9f
4
+ data.tar.gz: f72840dd9fe7aa7656f587a308f2083ad367f3be
5
5
  SHA512:
6
- metadata.gz: 256beb5a5e5162a66ef21e27ef0c9545f983e9ccefadafbff39e76b580e3a6fe9f15bd74deadbbe5636cd0c93c78613410b7b280b9ecf5bf91228afcbb90c54c
7
- data.tar.gz: 840a6623091d82276080c80589438500dd56031efc0f81e33f32b41f704d596136688124c8671a6c2fafdfbebd5a2a7bf3943e476ec07c44be4b2ba05774ee03
6
+ metadata.gz: 3570223eaed7e14b5de2d3882e5c92db9ed7794253c5fcece900cd5285cd4a623188fe493342201431961a6e8742406f59c92015a61843ae35bb257ab0095e86
7
+ data.tar.gz: 96186575c571efaae757e730d5eb6c674cdd6414264bdd386a97d66a1a0220dca8a361541976028d96e7e791cae85f2649232b25e73c4f5d767998a76d384d57
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.1.8 / 12-03-2015
2
+
3
+ * [PR #15](https://github.com/test-kitchen/kitchen-hyperv/pull/15) : Dynamic Memory support
4
+ * [PR #17](https://github.com/test-kitchen/kitchen-hyperv/pull/17) : File copy support
5
+ * [PR #19](https://github.com/test-kitchen/kitchen-hyperv/pull/19) : Explict import of hyper-v module and delay in getting ip (wait for DHCP)
6
+ * [PR #20](https://github.com/test-kitchen/kitchen-hyperv/pull/20) : Doc the required WinRM Settings
7
+
1
8
  # 0.1.7 / 07-14-2015
2
9
 
3
10
  * [PR #8](https://github.com/test-kitchen/kitchen-hyperv/pull/8) : Add support for 64 bit ruby
data/README.md CHANGED
@@ -33,6 +33,10 @@ driver:
33
33
  * amount of RAM to assign to each virtual machine. Defaults to 536,870,912.
34
34
  * processor_count
35
35
  * number of virtual processors to assign to each virtual machine. Defaults to 2.
36
+ * dynamic_memory
37
+ * if true, the amount of memory allocated to a virtual machine is adjusted by Hyper-V dynamically. Defaults to false.
38
+ * dynamic_memory_min_bytes / dynamic_memory_max_bytes
39
+ * The minimum and maximum amount of memory Hyper-V will allocate to a virtual machine if dynamic_memory is enabled. Defaults to 536,870,912 and 2,147,483,648 (512MB-2GB)
36
40
  * ip_address
37
41
  * IP address for the virtual machine. If the VM is not on a network with DHCP, this can be used to assign an IP that can be reached from the host machine.
38
42
  * vm_switch
@@ -44,6 +48,17 @@ driver:
44
48
  * disk_type
45
49
  * The type of virtual disk to create, .VHD or .VHDX. Defaults to the file extension of the parent virtual hard drive.
46
50
 
51
+ ## Image Configuration
52
+
53
+ The following changes need to be made to a Windows image that is going to be used for testing. This is not an exhaustive list and, your milage may vary.
54
+
55
+ #### WinRM
56
+
57
+ ```powershell
58
+ winrm set winrm/config/client/auth @{Basic="true"}
59
+ winrm set winrm/config/service/auth @{Basic="true"}
60
+ winrm set winrm/config/service @{AllowUnencrypted="true"}
61
+ ```
47
62
  ## Contributing
48
63
 
49
64
  1. Fork it ( https://github.com/[my-github-username]/kitchen-hyperv/fork )
@@ -37,12 +37,15 @@ module Kitchen
37
37
  default_config :parent_vhd_folder
38
38
  default_config :parent_vhd_name
39
39
  default_config :memory_startup_bytes, 536_870_912
40
+ default_config :dynamic_memory_min_bytes, 536_870_912
41
+ default_config :dynamic_memory_max_bytes, 2_147_483_648
42
+ default_config :dynamic_memory, false
40
43
  default_config :processor_count, 2
41
44
  default_config :ip_address
42
45
  default_config :vm_switch
43
46
  default_config :iso_path
44
47
  default_config :vm_generation, 1
45
- default_config :disk_type do |driver|
48
+ default_config :disk_type do |driver|
46
49
  File.extname(driver[:parent_vhd_name])
47
50
  end
48
51
 
@@ -56,6 +59,7 @@ module Kitchen
56
59
  update_state
57
60
  mount_virtual_machine_iso
58
61
  instance.transport.connection(@state).wait_until_ready
62
+ copy_vm_files
59
63
  info("Hyper-V instance #{instance.to_str} created.")
60
64
  end
61
65
 
@@ -80,6 +84,13 @@ module Kitchen
80
84
  def validate_vm_settings
81
85
  raise "Missing parent_vhd_folder" unless config[:parent_vhd_folder]
82
86
  raise "Missing parent_vhd_name" unless config[:parent_vhd_name]
87
+ if config[:dynamic_memory]
88
+ startup_bytes = config[:memory_startup_bytes]
89
+ min = config[:dynamic_memory_min_bytes]
90
+ max = config[:dynamic_memory_max_bytes]
91
+ memory_valid = startup_bytes.between?(min, max)
92
+ raise "memory_startup_bytes (#{startup_bytes}) must fall within dynamic memory range (#{min}-#{max})" unless memory_valid
93
+ end
83
94
  return if config[:vm_switch]
84
95
  config[:vm_switch] = (run_ps vm_default_switch_ps)['Name']
85
96
  end
@@ -100,8 +111,9 @@ module Kitchen
100
111
  info('Checking for existing virtual machine.')
101
112
  return false unless @state.key?(:id) && !@state[:id].nil?
102
113
  existing_vm = run_ps ensure_vm_running_ps
114
+ return false if existing_vm.nil? || existing_vm['Id'].nil?
103
115
  info("Found an exising VM with an ID: #{existing_vm['Id']}")
104
- return true unless existing_vm.nil? || existing_vm['Id'].nil?
116
+ return true
105
117
  #fail('Failed to start existing VM.')
106
118
  end
107
119
 
@@ -131,6 +143,16 @@ module Kitchen
131
143
  @state[:id] = new_vm_object['Id']
132
144
  info("Created virtual machine for #{instance.name}.")
133
145
  end
146
+
147
+ def copy_vm_files
148
+
149
+ return if config[:copy_vm_files].nil?
150
+ info("Copying files to virtual machine")
151
+ config[:copy_vm_files].each do |file_info|
152
+ run_ps copy_vm_file_ps(file_info[:source], file_info[:dest])
153
+ end
154
+ info("Copied files to virtual machine")
155
+ end
134
156
 
135
157
  def update_state
136
158
  vm_details
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Kitchen
19
19
  module Driver
20
- HYPERV_VERSION = '0.1.7'
20
+ HYPERV_VERSION = '0.1.8'
21
21
  end
22
22
  end
@@ -99,6 +99,9 @@ module Kitchen
99
99
  VHDPath = "#{differencing_disk_path}"
100
100
  SwitchName = "#{config[:vm_switch]}"
101
101
  ProcessorCount = #{config[:processor_count]}
102
+ UseDynamicMemory = "#{config[:dynamic_memory]}"
103
+ DynamicMemoryMinBytes = #{config[:dynamic_memory_min_bytes]}
104
+ DynamicMemoryMaxBytes = #{config[:dynamic_memory_max_bytes]}
102
105
  }
103
106
  New-KitchenVM @NewVMParams | ConvertTo-Json
104
107
  NEWVM
@@ -141,6 +144,41 @@ module Kitchen
141
144
  mount-vmiso -id "#{@state[:id]}" -Path #{config[:iso_path]}
142
145
  MOUNTISO
143
146
  end
147
+
148
+ def copy_vm_file_ps(source, dest)
149
+ <<-FILECOPY
150
+ Function CopyFile ($VM, [string]$SourcePath, [string]$DestPath) {
151
+ #Write-Host "Copying file to VM - Source: $SourcePath Destination $DestPath"
152
+ $VM | Copy-VMFile -SourcePath $SourcePath -DestinationPath $DestPath -CreateFullPath -FileSource Host -Force
153
+ }
154
+
155
+ $sourceLocation = '#{source}'
156
+ $destinationLocation = '#{dest}'
157
+ $vmId = '#{@state[:id]}'
158
+ If (Test-Path $sourceLocation) {
159
+ $vm = Get-VM -ID $vmId
160
+ $service = 'Guest Service Interface'
161
+
162
+ If ((Get-VMIntegrationService -Name $service -VM $vm).Enabled -ne $true) {
163
+ Enable-VMIntegrationService -Name $service -VM $vm
164
+ Start-Sleep -Seconds 3
165
+ }
166
+
167
+ If ((Get-Item $sourceLocation) -is [System.IO.DirectoryInfo]) {
168
+ ForEach ($item in (Get-ChildItem -Path $sourceLocation -File)) {
169
+ $destFullPath = (Join-Path $destinationLocation $item.Name)
170
+ CopyFile $vm $item.FullName $destFullPath
171
+ }
172
+ }
173
+ Else {
174
+ CopyFile $vm $sourceLocation $destinationLocation
175
+ }
176
+ }
177
+ else {
178
+ Write-Error "Source file path does not exist: $sourceLocation"
179
+ }
180
+ FILECOPY
181
+ end
144
182
  end
145
183
  end
146
184
  end
data/support/hyperv.ps1 CHANGED
@@ -1,60 +1,90 @@
1
+ #requires -Version 2 -Modules Hyper-V
1
2
 
2
- $ProgressPreference = "SilentlyContinue"
3
+ #implicitly import hyperv module to avoid powercli cmdlets
4
+ if((Get-Module -Name hyperv) -ne $null)
5
+ {
6
+ Remove-Module -Name hyperv
7
+ Import-Module -Name hyperv
8
+ }
9
+ else
10
+ {
11
+ Import-Module -Name hyperv
12
+ }
13
+
14
+ $ProgressPreference = 'SilentlyContinue'
3
15
 
4
16
 
5
17
  function New-DifferencingDisk
6
18
  {
7
- [cmdletbinding()]
8
- param ([string[]]$Path, [string]$ParentPath)
9
- if (-not (test-path $Path))
19
+ [cmdletbinding()]
20
+ param ([string[]]$Path, [string]$ParentPath)
21
+ if (-not (Test-Path $Path))
10
22
  {
11
- $null = new-vhd @psboundparameters -Differencing
23
+ $null = new-vhd @psboundparameters -Differencing
12
24
  }
13
25
  }
14
26
 
15
27
  function Assert-VmRunning
16
28
  {
17
- [cmdletbinding()]
18
- param([string]$Id)
29
+ [cmdletbinding()]
30
+ param([string]$Id)
19
31
 
20
- if ([string]::IsNullOrEmpty($ID))
32
+ if ([string]::IsNullOrEmpty($Id))
21
33
  {
22
- $Output = [pscustomobject]@{Name = '';State =''}
34
+ $Output = [pscustomobject]@{
35
+ Name = ''
36
+ State = ''
37
+ }
23
38
  }
24
39
  else
25
40
  {
26
- $Output = Get-VM -Id $ID |
27
- foreach {
28
- if ($_.State -notlike 'Running')
29
- {
30
- $_ | start-vm -passthru
31
- }
32
- else
33
- {
34
- $_
35
- }
41
+ $Output = Get-VM -Id $Id |
42
+ ForEach-Object -Process {
43
+ if ($_.State -notlike 'Running')
44
+ {
45
+ $_ |
46
+ Start-VM -passthru
47
+ }
48
+ else
49
+ {
50
+ $_
51
+ }
36
52
  } |
37
- select Name, Id, State
53
+ Select-Object -Property Name, Id, State
38
54
  }
39
- $output
55
+ $Output
40
56
  }
41
57
 
42
58
  function New-KitchenVM
43
59
  {
44
- [cmdletbinding()]
45
- param (
46
- $Generation = 1,
60
+ [cmdletbinding()]
61
+ param (
62
+ $Generation = 1,
47
63
  $MemoryStartupBytes,
48
64
  $Name,
49
65
  $Path,
50
66
  $VHDPath,
51
67
  $SwitchName,
52
- $ProcessorCount
68
+ $ProcessorCount,
69
+ $UseDynamicMemory,
70
+ $DynamicMemoryMinBytes,
71
+ $DynamicMemoryMaxBytes
53
72
  )
54
73
  $null = $psboundparameters.remove('ProcessorCount')
74
+ $null = $psboundparameters.remove('UseDynamicMemory')
75
+ $null = $psboundparameters.remove('DynamicMemoryMinBytes')
76
+ $null = $psboundparameters.remove('DynamicMemoryMaxBytes')
77
+ $UseDynamicMemory = [Convert]::ToBoolean($UseDynamicMemory)
78
+
55
79
  $vm = new-vm @psboundparameters |
56
80
  Set-Vm -ProcessorCount $ProcessorCount -passthru
57
- $vm | Set-VMMemory -DynamicMemoryEnabled $false
81
+ if ($UseDynamicMemory) {
82
+ $vm | Set-VMMemory -DynamicMemoryEnabled $true -MinimumBytes $DynamicMemoryMinBytes -MaximumBytes $DynamicMemoryMaxBytes
83
+ }
84
+ else {
85
+ $vm | Set-VMMemory -DynamicMemoryEnabled $false
86
+ }
87
+
58
88
  $vm | Start-Vm -passthru |
59
89
  foreach {
60
90
  $vm = $_
@@ -68,9 +98,12 @@ function New-KitchenVM
68
98
 
69
99
  function Get-VmIP($vm)
70
100
  {
71
- $vm.networkadapters.ipaddresses |
72
- where {$_ -match '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'} |
73
- select -first 1
101
+ start-sleep -seconds 10
102
+ $vm.networkadapters.ipaddresses |
103
+ Where-Object {
104
+ $_ -match '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$'
105
+ } |
106
+ Select-Object -First 1
74
107
  }
75
108
 
76
109
  Function Set-VMNetworkConfiguration
@@ -79,18 +112,24 @@ Function Set-VMNetworkConfiguration
79
112
  Param (
80
113
  [parameter(valuefrompipeline)]
81
114
  [object]$NetworkAdapter,
82
- [String[]]$IPAddress=@(),
83
- [String[]]$Subnet=@()
115
+ [String[]]$IPAddress = @(),
116
+ [String[]]$Subnet = @()
84
117
  )
85
118
 
86
- $VM = Get-WmiObject -Namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' | Where-Object { $_.ElementName -eq $NetworkAdapter.VMName }
87
- $VMSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object { $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized' }
119
+ $vm = Get-WmiObject -Namespace 'root\virtualization\v2' -Class 'Msvm_ComputerSystem' | Where-Object {
120
+ $_.ElementName -eq $NetworkAdapter.VMName
121
+ }
122
+ $VMSettings = $vm.GetRelated('Msvm_VirtualSystemSettingData') | Where-Object {
123
+ $_.VirtualSystemType -eq 'Microsoft:Hyper-V:System:Realized'
124
+ }
88
125
  $VMNetAdapters = $VMSettings.GetRelated('Msvm_SyntheticEthernetPortSettingData')
89
126
 
90
127
  $NetworkSettings = @()
91
- foreach ($NetAdapter in $VMNetAdapters) {
92
- if ($NetAdapter.Address -eq $NetworkAdapter.MacAddress) {
93
- $NetworkSettings = $NetworkSettings + $NetAdapter.GetRelated("Msvm_GuestNetworkAdapterConfiguration")
128
+ foreach ($NetAdapter in $VMNetAdapters)
129
+ {
130
+ if ($NetAdapter.Address -eq $NetworkAdapter.MacAddress)
131
+ {
132
+ $NetworkSettings = $NetworkSettings + $NetAdapter.GetRelated('Msvm_GuestNetworkAdapterConfiguration')
94
133
  }
95
134
  }
96
135
 
@@ -100,53 +139,65 @@ Function Set-VMNetworkConfiguration
100
139
  $NetworkSettings[0].DHCPEnabled = $false
101
140
 
102
141
 
103
- $Service = Get-WmiObject -Class "Msvm_VirtualSystemManagementService" -Namespace "root\virtualization\v2"
104
- $setIP = $Service.SetGuestNetworkAdapterConfiguration($VM, $NetworkSettings[0].GetText(1))
142
+ $Service = Get-WmiObject -Class 'Msvm_VirtualSystemManagementService' -Namespace 'root\virtualization\v2'
143
+ $setIP = $Service.SetGuestNetworkAdapterConfiguration($vm, $NetworkSettings[0].GetText(1))
105
144
 
106
- if ($setip.ReturnValue -eq 4096) {
107
- $job=[WMI]$setip.job
145
+ if ($setIP.ReturnValue -eq 4096)
146
+ {
147
+ $job = [WMI]$setIP.job
108
148
 
109
- while ($job.JobState -eq 3 -or $job.JobState -eq 4) {
110
- start-sleep 1
111
- $job=[WMI]$setip.job
149
+ while ($job.JobState -eq 3 -or $job.JobState -eq 4)
150
+ {
151
+ Start-Sleep 1
152
+ $job = [WMI]$setIP.job
112
153
  }
113
154
 
114
- if ($job.JobState -ne 7) {
155
+ if ($job.JobState -ne 7)
156
+ {
115
157
  $job.GetError()
116
158
  }
117
159
  }
118
- (Get-VM -id $NetworkAdapter.VmId).NetworkAdapter | select Name, IpAddress
160
+ (Get-VM -Id $NetworkAdapter.VmId).NetworkAdapter | Select-Object Name, IpAddress
119
161
  }
120
162
 
121
163
  function Get-VmDetail
122
164
  {
123
- [cmdletbinding()]
124
- param($Id)
165
+ [cmdletbinding()]
166
+ param($Id)
167
+
168
+ Get-VM -Id $Id |
169
+ ForEach-Object {
170
+ $vm = $_
171
+ do
172
+ {
173
+ Start-Sleep -Seconds 1
174
+ }
175
+ while (-not (Get-VmIP $vm))
125
176
 
126
- get-vm -id $Id |
127
- foreach {
128
- $vm = $_
129
- do {
130
- start-sleep -seconds 1
131
- } while (-not (Get-VmIP $vm))
132
-
133
- [pscustomobject]@{
134
- Name = $vm.name
135
- Id = $vm.ID
136
- IpAddress = (Get-VmIP $vm)
137
- }
138
- }
177
+ [pscustomobject]@{
178
+ Name = $vm.name
179
+ Id = $vm.ID
180
+ IpAddress = (Get-VmIP $vm)
181
+ }
182
+ }
139
183
  }
140
184
 
141
185
  function Get-DefaultVMSwitch
142
186
  {
143
- Get-VMSwitch | Select -First 1 | Select Name, Id
187
+ Get-VMSwitch |
188
+ Select-Object -First 1 |
189
+ Select-Object Name, Id
144
190
  }
145
191
 
146
- function Mount-VMISO {
192
+ function Mount-VMISO
193
+ {
147
194
  [cmdletbinding()]
148
195
  param($Id, $Path)
149
196
 
197
+ <<<<<<< HEAD
198
+ set-VMDvdDrive -VMName (Get-VM -Id $Id).Name -Path $Path
199
+ =======
150
200
  set-VMDvdDrive -VMName (get-vm -id $Id).Name -Path $Path
151
201
 
152
- }
202
+ >>>>>>> brantb/dynamic-memory
203
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-hyperv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Murawski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  requirements: []
167
167
  rubyforge_project:
168
- rubygems_version: 2.4.4
168
+ rubygems_version: 2.4.8
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: Hyper-V Driver for Test-Kitchen