kitchen-hyperv 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +25 -15
- data/LICENSE +13 -0
- data/Rakefile +50 -32
- data/kitchen-hyperv.gemspec +26 -32
- data/lib/kitchen/driver/hyperv.rb +297 -279
- data/lib/kitchen/driver/hyperv_version.rb +22 -22
- data/lib/kitchen/driver/powershell.rb +23 -16
- data/support/hyperv.ps1 +3 -0
- metadata +33 -89
- data/.cane +0 -2
- data/.gitignore +0 -15
- data/.rubocop.yml +0 -5
- data/CHANGELOG.md +0 -126
- data/LICENSE.txt +0 -22
- data/README.md +0 -122
- data/spec/kitchen/driver/hyperv_spec.rb +0 -70
- data/spec/spec_helper.rb +0 -43
- data/spec/support/hyperv.Tests.ps1 +0 -194
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2015 Steven Murawski
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/kitchen-hyperv.svg)](http://badge.fury.io/rb/kitchen-hyperv)
|
2
|
-
# Kitchen::Hyperv
|
3
|
-
|
4
|
-
TODO: Write a gem description
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Add this line to your application's Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'kitchen-hyperv'
|
12
|
-
```
|
13
|
-
|
14
|
-
## Usage
|
15
|
-
|
16
|
-
In the .kitchen.yml
|
17
|
-
|
18
|
-
```yaml
|
19
|
-
driver:
|
20
|
-
name: 'hyperv'
|
21
|
-
```
|
22
|
-
|
23
|
-
### Required parameters:
|
24
|
-
|
25
|
-
* parent_vhd_folder
|
26
|
-
* Location of the base vhd files
|
27
|
-
* parent_vhd_name
|
28
|
-
* Vhd file name for the base vhd file
|
29
|
-
|
30
|
-
### Optional parameters:
|
31
|
-
|
32
|
-
* memory_startup_bytes
|
33
|
-
* amount of RAM to assign to each virtual machine. Defaults to 536,870,912.
|
34
|
-
* processor_count
|
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)
|
40
|
-
* ip_address
|
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.
|
42
|
-
* subnet
|
43
|
-
* The subnet of the virtual machine. Defaults to `255.255.255.0`
|
44
|
-
* gateway
|
45
|
-
* The default gateway of the virtual machine.
|
46
|
-
* dns_servers
|
47
|
-
* A list of DNS Servers that can be reached on the virtual network.
|
48
|
-
* vm_switch
|
49
|
-
* The virtual switch to attach the guest VMs. Defaults to the first switch returned from Get-VMSwitch.
|
50
|
-
* vm_vlan_id
|
51
|
-
* The VLAN ID to assign the virtual network adapter on the VM (Valid values: 1-4094). Defaults to untagged.
|
52
|
-
* iso_path
|
53
|
-
* Path on the host to the ISO to mount on the VMs.
|
54
|
-
* boot_iso_path
|
55
|
-
* Path on the host to the ISO to mount before starting the VMs.
|
56
|
-
* vm_generation
|
57
|
-
* The generation for the hyper-v VM. Defaults to 1.
|
58
|
-
* disable_secureboot
|
59
|
-
* Boolean. If true, will disable secure boot for the VM. Only applies if `vm_generation=2`. Defaults to false.
|
60
|
-
* enable_guest_services
|
61
|
-
* Enable the Hyper-V Integration Guest services for the VM before starting it. Hyper-V defauls is false (true|false)
|
62
|
-
* disk_type
|
63
|
-
* The type of virtual disk to create, .VHD or .VHDX. Defaults to the file extension of the parent virtual hard drive.
|
64
|
-
* resize_vhd
|
65
|
-
* Resize the disk to the specified size. Leave empty to keep the original size. Only works on newly created VM's. Defaults to empty.
|
66
|
-
* additional_disks
|
67
|
-
* An array of hashes (`name`,`size_gb`, and `type`) of additional disks to attach to the VM.
|
68
|
-
* **Required parameters:**
|
69
|
-
* name
|
70
|
-
* Unique name for the virtual disk.
|
71
|
-
* **Optional parameters:**
|
72
|
-
* size_gb
|
73
|
-
* Integer. If not provided, will default to 5.
|
74
|
-
* type
|
75
|
-
* The type of virtual disk to create, .VHD or .VHDX. Defaults to the file extension of the parent virtual hard drive.
|
76
|
-
* Example:
|
77
|
-
|
78
|
-
```yaml
|
79
|
-
driver:
|
80
|
-
name: hyperv
|
81
|
-
parent_vhd_folder: 'D:\Hyper-V\Virtual Hard Disks'
|
82
|
-
parent_vhd_name: tk_test.vhdx
|
83
|
-
additional_disks:
|
84
|
-
- name: disk1
|
85
|
-
size_gb: 10
|
86
|
-
- name: disk2
|
87
|
-
size_gb: 50
|
88
|
-
type: .VHD
|
89
|
-
```
|
90
|
-
* vm_note
|
91
|
-
* A note to add to the VM's note field. Defaults to empty.
|
92
|
-
* copy_vm_files
|
93
|
-
* An array of hashes (`source` and `dest`) of files or directories to copy over to the sytem under test.
|
94
|
-
* example:
|
95
|
-
|
96
|
-
```
|
97
|
-
driver:
|
98
|
-
name: hyperv
|
99
|
-
copy_vm_files:
|
100
|
-
- source: c:/users/steven/downloads/chef-client-12.19.36-1-x64.msi
|
101
|
-
dest: c:/users/administrator/appdata/local/temp/chef-client-12.19.36-1-x64.msi
|
102
|
-
```
|
103
|
-
|
104
|
-
* static_mac_address
|
105
|
-
* String value specifying a static MAC Address to be set at virtual machine creation time.
|
106
|
-
* Hyper-V will automatically assign a valid dynamic address if your input doesn't give a valid MAC Address.
|
107
|
-
* example: `static_mac_address: '00155d123456'`
|
108
|
-
|
109
|
-
|
110
|
-
## Image Configuration
|
111
|
-
|
112
|
-
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.
|
113
|
-
|
114
|
-
* Guest VMs should have the latest Integration Components installed. See https://support.microsoft.com/en-us/help/3063109/hyper-v-integration-components-update-for-windows-virtual-machines-that-are-running-on-a-windows-10-based-host
|
115
|
-
|
116
|
-
## Contributing
|
117
|
-
|
118
|
-
1. Fork it ( https://github.com/[my-github-username]/kitchen-hyperv/fork )
|
119
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
120
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
121
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
122
|
-
5. Create a new Pull Request
|
@@ -1,70 +0,0 @@
|
|
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
|
data/spec/spec_helper.rb
DELETED
@@ -1,43 +0,0 @@
|
|
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,194 +0,0 @@
|
|
1
|
-
. $PSScriptRoot\..\..\support\hyperv.ps1
|
2
|
-
|
3
|
-
describe 'New-DifferencingDisk' {
|
4
|
-
mock new-vhd -Verifiable -MockWith {}
|
5
|
-
|
6
|
-
context 'mandatory parameters' {
|
7
|
-
mock Test-Path -MockWith {}
|
8
|
-
|
9
|
-
$command = get-command new-differencingDisk
|
10
|
-
|
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
|
-
}
|
17
|
-
}
|
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
|
-
}
|
41
|
-
}
|
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
|
56
|
-
|
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
|
-
}
|
64
|
-
|
65
|
-
Context "When VlanId is specified" {
|
66
|
-
$testVlanId = 1
|
67
|
-
New-KitchenVM -VlanId $testVlanId
|
68
|
-
|
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
|
-
}
|
76
|
-
}
|
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
|
94
|
-
|
95
|
-
It "Should not add additional disks to the VM" {
|
96
|
-
Assert-MockCalled Add-VMHardDiskDrive -Times 0
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
Context "When AdditionalDisks is specified" {
|
101
|
-
$AdditionalDisks = @(".\test1.vhd", ".\test2.vhdx")
|
102
|
-
New-KitchenVM -AdditionalDisks $AdditionalDisks
|
103
|
-
|
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
|
-
}
|
110
|
-
}
|
111
|
-
}
|
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
|
-
}
|
161
|
-
|
162
|
-
Describe "New-KitchenVM with StaticMacAddress" {
|
163
|
-
function New-VM {}
|
164
|
-
function Set-VM {}
|
165
|
-
function Set-VMMemory {}
|
166
|
-
function Set-VMNetworkAdapter {param ($VM, $StaticMacAddress)}
|
167
|
-
function Start-VM {}
|
168
|
-
|
169
|
-
Mock New-VM
|
170
|
-
Mock Set-VM
|
171
|
-
Mock Set-VMMemory
|
172
|
-
Mock Set-VMNetworkAdapter
|
173
|
-
Mock Start-VM
|
174
|
-
|
175
|
-
Context "When StaticMacAddress is not specified" {
|
176
|
-
New-KitchenVM -StaticMacAddress ""
|
177
|
-
|
178
|
-
It "Should not set the StaticMacAddress for the VM" {
|
179
|
-
Assert-MockCalled Set-VMNetworkAdapter -Times 1
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
Context "When StaticMacAddress is specified" {
|
184
|
-
$testStaticMacAddress = "00155D01B532"
|
185
|
-
New-KitchenVM -StaticMacAddress $testStaticMacAddress
|
186
|
-
|
187
|
-
It "Should set the StaticMacAddress for the VM" {
|
188
|
-
Assert-MockCalled Set-VMNetworkAdapter -Times 1 -ParameterFilter {
|
189
|
-
$VM -eq $VM.VMName -and
|
190
|
-
$StaticMacAddress -eq $testStaticMacAddress
|
191
|
-
}
|
192
|
-
}
|
193
|
-
}
|
194
|
-
}
|