kitchen-hyperv 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Kitchen
19
19
  module Driver
20
- HYPERV_VERSION = '0.3.0'.freeze
20
+ HYPERV_VERSION = '0.4.0'.freeze
21
21
  end
22
22
  end
@@ -91,6 +91,13 @@ module Kitchen
91
91
  DIFF
92
92
  end
93
93
 
94
+ def new_additional_disk_ps(disk_path, disk_size)
95
+ <<-ADDDISK
96
+
97
+ New-VHD -Path "#{disk_path}" -SizeBytes #{disk_size}GB | Out-Null
98
+ ADDDISK
99
+ end
100
+
94
101
  def ensure_vm_running_ps
95
102
  <<-RUNNING
96
103
 
@@ -103,17 +110,20 @@ module Kitchen
103
110
 
104
111
  $NewVMParams = @{
105
112
  Generation = #{config[:vm_generation]}
113
+ DisableSecureBoot = "#{config[:disable_secureboot]}"
106
114
  MemoryStartupBytes = #{config[:memory_startup_bytes]}
107
115
  Name = "#{instance.name}"
108
116
  Path = "#{kitchen_vm_path}"
109
117
  VHDPath = "#{differencing_disk_path}"
110
118
  SwitchName = "#{config[:vm_switch]}"
119
+ VlanId = #{config[:vm_vlan_id] || '$null'}
111
120
  ProcessorCount = #{config[:processor_count]}
112
121
  UseDynamicMemory = "#{config[:dynamic_memory]}"
113
122
  DynamicMemoryMinBytes = #{config[:dynamic_memory_min_bytes]}
114
123
  DynamicMemoryMaxBytes = #{config[:dynamic_memory_max_bytes]}
115
124
  boot_iso_path = "#{boot_iso_path}"
116
125
  EnableGuestServices = "#{config[:enable_guest_services]}"
126
+ AdditionalDisks = @("#{@additional_disk_objects.join('","') || ''}")
117
127
  }
118
128
  New-KitchenVM @NewVMParams | ConvertTo-Json
119
129
  NEWVM
@@ -159,6 +169,12 @@ module Kitchen
159
169
  MOUNTISO
160
170
  end
161
171
 
172
+ def resize_vhd
173
+ <<-VMNOTE
174
+ Resize-VHD -Path "#{parent_vhd_path}" -Size #{config[:resize_vhd]}
175
+ VMNOTE
176
+ end
177
+
162
178
  def set_vm_note
163
179
  <<-VMNOTE
164
180
  Set-VM -Name (Get-VM | Where-Object{ $_.ID -eq "#{@state[:id]}"}).Name -Note "#{config[:vm_note]}"
@@ -1,70 +1,70 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2015, Fletcher Nichol
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- require_relative "../../spec_helper"
20
-
21
- require "logger"
22
- require "stringio"
23
- require "kitchen"
24
- require 'kitchen/driver/hyperv_version'
25
- require "kitchen/driver/hyperv"
26
- require "kitchen/provisioner/dummy"
27
- require "kitchen/transport/dummy"
28
- require "kitchen/verifier/dummy"
29
-
30
- describe Kitchen::Driver::Hyperv do
31
-
32
- let(:logged_output) { StringIO.new }
33
- let(:logger) { Logger.new(logged_output) }
34
- let(:config) { { :kitchen_root => "c:/test_root" } }
35
- let(:platform) { Kitchen::Platform.new(:name => "fooos-99") }
36
- let(:suite) { Kitchen::Suite.new(:name => "suitey") }
37
- let(:verifier) { Kitchen::Verifier::Dummy.new }
38
- let(:provisioner) { Kitchen::Provisioner::Dummy.new }
39
- let(:transport) { Kitchen::Transport::Dummy.new }
40
- let(:state_file) { stub("state_file") }
41
- let(:state) { Hash.new }
42
- let(:env) { Hash.new }
43
-
44
- let(:driver_object) { Kitchen::Driver::Hyperv.new(config) }
45
-
46
- let(:driver) do
47
- d = driver_object
48
- instance
49
- d
50
- end
51
-
52
- let(:instance) do
53
- Kitchen::Instance.new(
54
- :verifier => verifier,
55
- :driver => driver_object,
56
- :logger => logger,
57
- :suite => suite,
58
- :platform => platform,
59
- :provisioner => provisioner,
60
- :transport => transport,
61
- :state_file => state_file
62
- )
63
- end
64
-
65
- #before { stub_const("ENV", env) }
66
-
67
- it 'driver api_version is 2' do
68
- driver.diagnose_plugin[:api_version].must_equal(2)
69
- end
70
- end
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2015, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative "../../spec_helper"
20
+
21
+ require "logger"
22
+ require "stringio"
23
+ require "kitchen"
24
+ require 'kitchen/driver/hyperv_version'
25
+ require "kitchen/driver/hyperv"
26
+ require "kitchen/provisioner/dummy"
27
+ require "kitchen/transport/dummy"
28
+ require "kitchen/verifier/dummy"
29
+
30
+ describe Kitchen::Driver::Hyperv do
31
+
32
+ let(:logged_output) { StringIO.new }
33
+ let(:logger) { Logger.new(logged_output) }
34
+ let(:config) { { :kitchen_root => "c:/test_root" } }
35
+ let(:platform) { Kitchen::Platform.new(:name => "fooos-99") }
36
+ let(:suite) { Kitchen::Suite.new(:name => "suitey") }
37
+ let(:verifier) { Kitchen::Verifier::Dummy.new }
38
+ let(:provisioner) { Kitchen::Provisioner::Dummy.new }
39
+ let(:transport) { Kitchen::Transport::Dummy.new }
40
+ let(:state_file) { stub("state_file") }
41
+ let(:state) { Hash.new }
42
+ let(:env) { Hash.new }
43
+
44
+ let(:driver_object) { Kitchen::Driver::Hyperv.new(config) }
45
+
46
+ let(:driver) do
47
+ d = driver_object
48
+ instance
49
+ d
50
+ end
51
+
52
+ let(:instance) do
53
+ Kitchen::Instance.new(
54
+ :verifier => verifier,
55
+ :driver => driver_object,
56
+ :logger => logger,
57
+ :suite => suite,
58
+ :platform => platform,
59
+ :provisioner => provisioner,
60
+ :transport => transport,
61
+ :state_file => state_file
62
+ )
63
+ end
64
+
65
+ #before { stub_const("ENV", env) }
66
+
67
+ it 'driver api_version is 2' do
68
+ driver.diagnose_plugin[:api_version].must_equal(2)
69
+ end
70
+ end
@@ -1,43 +1,43 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
- #
5
- # Copyright (C) 2012, Fletcher Nichol
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
-
19
- gem "minitest"
20
- gem "minitest-stub-const"
21
-
22
- if ENV["CODECLIMATE_REPO_TOKEN"]
23
- require "codeclimate-test-reporter"
24
- CodeClimate::TestReporter.start
25
- elsif ENV["COVERAGE"]
26
- require "simplecov"
27
- SimpleCov.profiles.define "gem" do
28
- command_name "Specs"
29
-
30
- add_filter ".gem/"
31
- add_filter "/spec/"
32
- add_filter "/lib/vendor/"
33
-
34
- add_group "Libraries", "/lib/"
35
- end
36
- SimpleCov.start "gem"
37
- end
38
-
39
- require 'minitest'
40
- require 'minitest/stub_const'
41
- require "minitest/autorun"
42
- require "mocha/setup"
43
- require "tempfile"
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>)
4
+ #
5
+ # Copyright (C) 2012, Fletcher Nichol
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ gem "minitest"
20
+ gem "minitest-stub-const"
21
+
22
+ if ENV["CODECLIMATE_REPO_TOKEN"]
23
+ require "codeclimate-test-reporter"
24
+ CodeClimate::TestReporter.start
25
+ elsif ENV["COVERAGE"]
26
+ require "simplecov"
27
+ SimpleCov.profiles.define "gem" do
28
+ command_name "Specs"
29
+
30
+ add_filter ".gem/"
31
+ add_filter "/spec/"
32
+ add_filter "/lib/vendor/"
33
+
34
+ add_group "Libraries", "/lib/"
35
+ end
36
+ SimpleCov.start "gem"
37
+ end
38
+
39
+ require 'minitest'
40
+ require 'minitest/stub_const'
41
+ require "minitest/autorun"
42
+ require "mocha/setup"
43
+ require "tempfile"
@@ -1,43 +1,160 @@
1
1
  . $PSScriptRoot\..\..\support\hyperv.ps1
2
2
 
3
3
  describe 'New-DifferencingDisk' {
4
- mock new-vhd -Verifiable -MockWith {}
4
+ mock new-vhd -Verifiable -MockWith {}
5
5
 
6
- context 'mandatory parameters' {
7
- mock Test-Path -MockWith {}
6
+ context 'mandatory parameters' {
7
+ mock Test-Path -MockWith {}
8
8
 
9
- $command = get-command new-differencingDisk
9
+ $command = get-command new-differencingDisk
10
10
 
11
- it 'Path is mandatory' {
12
- $Command.Parameters['Path'].Attributes.Mandatory | should be $true
11
+ it 'Path is mandatory' {
12
+ $Command.Parameters['Path'].Attributes.Mandatory | should be $true
13
+ }
14
+ it 'ParentPath is mandatory' {
15
+ $Command.Parameters['ParentPath'].Attributes.Mandatory | should be $true
16
+ }
13
17
  }
14
- it 'ParentPath is mandatory' {
15
- $Command.Parameters['ParentPath'].Attributes.Mandatory | should be $true
18
+
19
+ context 'when differencing disk exists' {
20
+ mock Test-Path -ParameterFilter {$Path -eq 'c:\.kitchen\diff.vhd'} -MockWith {$true}
21
+
22
+ new-differencingDisk -Path 'c:\.kitchen\diff.vhd' -parentpath 'c:\source.vhd'
23
+
24
+ it 'does not create a new vhd' {
25
+ Assert-MockCalled new-vhd -Times 0
26
+ }
27
+ }
28
+
29
+ context 'when a differencing disk does not exist' {
30
+ mock Test-Path -ParameterFilter {$Path -eq 'c:\.kitchen\diff.vhd'} -MockWith {$false}
31
+
32
+ new-differencingDisk -Path 'c:\.kitchen\diff.vhd' -parentpath 'c:\source.vhd'
33
+
34
+ it 'creates a new differencing disk' {
35
+ Assert-MockCalled new-vhd -Times 1 -ParameterFilter {
36
+ $Path -eq 'c:\.kitchen\diff.vhd' -and
37
+ $ParentPath -eq 'c:\source.vhd' -and
38
+ $Differencing -eq $true
39
+ }
40
+ }
16
41
  }
17
- }
42
+ }
43
+
44
+ Describe "New-KitchenVM with VlanId" {
45
+ function New-VM {}
46
+ function Set-VM {}
47
+ function Set-VMMemory {}
48
+ function Set-VMNetworkAdapterVlan {param ($VM, [Switch]$Access, $VlanId)}
49
+ function Start-VM {}
50
+
51
+ Mock New-VM
52
+ Mock Set-VM
53
+ Mock Set-VMMemory
54
+ Mock Set-VMNetworkAdapterVlan
55
+ Mock Start-VM
18
56
 
19
- context 'when differencing disk exists' {
20
- mock Test-Path -ParameterFilter {$Path -eq 'c:\.kitchen\diff.vhd'} -MockWith {$true}
57
+ Context "When VlanId is not specified" {
58
+ New-KitchenVM
59
+
60
+ It "Should not set the VlanId for the VM" {
61
+ Assert-MockCalled Set-VMNetworkAdapterVlan -Times 0
62
+ }
63
+ }
21
64
 
22
- new-differencingDisk -Path 'c:\.kitchen\diff.vhd' -parentpath 'c:\source.vhd'
65
+ Context "When VlanId is specified" {
66
+ $testVlanId = 1
67
+ New-KitchenVM -VlanId $testVlanId
23
68
 
24
- it 'does not create a new vhd' {
25
- Assert-MockCalled new-vhd -Times 0
69
+ It "Should set the VlanId for the VM" {
70
+ Assert-MockCalled Set-VMNetworkAdapterVlan -Times 1 -ParameterFilter {
71
+ $VM -eq $null -and
72
+ $Access -eq $true -and
73
+ $VlanId -eq $testVlanId
74
+ }
75
+ }
26
76
  }
27
- }
77
+ }
78
+
79
+ Describe "New-KitchenVM with AdditionalDisks" {
80
+ function New-VM {}
81
+ function Set-VM {}
82
+ function Set-VMMemory {}
83
+ function Add-VMHardDiskDrive {param ($Path)}
84
+ function Start-VM {}
85
+
86
+ Mock New-VM
87
+ Mock Set-VM
88
+ Mock Set-VMMemory
89
+ Mock Add-VMHardDiskDrive
90
+ Mock Start-VM
91
+
92
+ Context "When AdditionalDisks is not specified" {
93
+ New-KitchenVM
28
94
 
29
- context 'when a differencing disk does not exist' {
30
- mock Test-Path -ParameterFilter {$Path -eq 'c:\.kitchen\diff.vhd'} -MockWith {$false}
95
+ It "Should not add additional disks to the VM" {
96
+ Assert-MockCalled Add-VMHardDiskDrive -Times 0
97
+ }
98
+ }
31
99
 
32
- new-differencingDisk -Path 'c:\.kitchen\diff.vhd' -parentpath 'c:\source.vhd'
100
+ Context "When AdditionalDisks is specified" {
101
+ $AdditionalDisks = @(".\test1.vhd", ".\test2.vhdx")
102
+ New-KitchenVM -AdditionalDisks $AdditionalDisks
33
103
 
34
- it 'creates a new differencing disk' {
35
- Assert-MockCalled new-vhd -Times 1 -ParameterFilter {
36
- $Path -eq 'c:\.kitchen\diff.vhd' -and
37
- $ParentPath -eq 'c:\source.vhd' -and
38
- $Differencing -eq $true
39
- }
104
+ It "Should add additinoal disks to the VM" {
105
+ Assert-MockCalled Add-VMHardDiskDrive -Times $AdditionalDisks.Count -ParameterFilter {
106
+ $VM -eq $null -and
107
+ $Path -in $AdditionalDisks
108
+ }
109
+ }
40
110
  }
41
- }
42
111
  }
43
112
 
113
+ Describe "New-KitchenVM with DisableSecureBoot" {
114
+ function New-VM {}
115
+ function Set-VM {}
116
+ function Set-VMMemory {}
117
+ function Set-VMFirmware {param ($EnableSecureBoot)}
118
+ function Start-VM {}
119
+
120
+ Mock New-VM
121
+ Mock Set-VM
122
+ Mock Set-VMMemory
123
+ Mock Set-VMFirmware
124
+ Mock Start-VM
125
+
126
+ Context "When DisableSecureBoot is not specified" {
127
+ New-KitchenVM
128
+
129
+ It "Should not set firmware settings on the VM" {
130
+ Assert-MockCalled Set-VMFirmware -Times 0
131
+ }
132
+ }
133
+
134
+ Context "When DisableSecureBoot is False" {
135
+ New-KitchenVM -DisableSecureBoot $false
136
+
137
+ It "Should not set firmware settings on the VM" {
138
+ Assert-MockCalled Set-VMFirmware -Times 0
139
+ }
140
+ }
141
+
142
+ Context "When DisableSecureBoot is True and Generation is 1" {
143
+ New-KitchenVM -Generation 1 -DisableSecureBoot $true
144
+
145
+ It "Should not set firmware settings on the VM" {
146
+ Assert-MockCalled Set-VMFirmware -Times 0
147
+ }
148
+ }
149
+
150
+ Context "When DisableSecureBoot is True and Generation is 2" {
151
+ New-KitchenVM -Generation 2 -DisableSecureBoot $true
152
+
153
+ It "Should disable secure boot on the VM" {
154
+ Assert-MockCalled Set-VMFirmware -Times 1 -ParameterFilter {
155
+ $VM -eq $null -and
156
+ $EnableSecureBoot -eq "Off"
157
+ }
158
+ }
159
+ }
160
+ }