kitchen-hyperv 0.6.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77de7e7e7c1ef9e2beccf916a5d2cfa43944e21a20c5f20b7b05fdccf6fbe7f1
4
- data.tar.gz: 56e1414348b16545ca9352c2f8412f646357d722eb734ce6d63fba284ba0d70c
3
+ metadata.gz: 21905b2f2c54db8a9414e98231c4eaa08c66cfa8aab926bf41248a8159663b29
4
+ data.tar.gz: 2ae8c16b86ee2933635c59f5e8403c42507d9ea2461c4c581c3468e409967c89
5
5
  SHA512:
6
- metadata.gz: bc98efd324d739c4acbc8a8f94126af271e93b0b0221eed758011cbd6e62e7e208faa9db97d7af2a9bc636fdc0dcd01bc2e405e98794093c60603ae2f32043e7
7
- data.tar.gz: 7bf53cdba391cf217b1e178a3c6150c6a4aa69b8dc100aba62d2f8360c67e65973f83936ec15967e7bb95b7ed0ee0082f3f951499673097c3a199ec7ff3c72eb
6
+ metadata.gz: 171d1d798fad06869c129086e5b72a093b3457ed4149cfb0ddc971756e70590f5359149a042519bc0d208381b61c9ebffc6b2c5c16f28c63f128ee14edf8815c
7
+ data.tar.gz: c7ff58b26dda26b67289a8acf66ae3bbdd152862b85e6bb9b2ed592833b0c2e44e980e3c4b8e17d24d1a108fe734820ed1da241778713c6d74819c9cd04ad8e0
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
1
  require "bundler/gem_tasks"
4
2
  require "kitchen/driver/hyperv_version"
5
3
 
@@ -1,5 +1,4 @@
1
- # encoding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path("lib", __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
 
5
4
  require "kitchen/driver/hyperv_version"
@@ -23,4 +22,6 @@ Gem::Specification.new do |spec|
23
22
  spec.add_development_dependency "mocha", "~> 1.1"
24
23
 
25
24
  spec.add_dependency "test-kitchen", ">= 1.4", "< 4"
25
+ spec.add_dependency "train", "~> 3.5"
26
+ spec.add_dependency "train-winrm", "~> 0.2"
26
27
  end
@@ -23,6 +23,8 @@ require_relative "powershell"
23
23
  require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
24
24
  require "fileutils" unless defined?(FileUtils)
25
25
  require "json" unless defined?(JSON)
26
+ require "train" unless defined?(Train)
27
+ require "train-winrm" unless defined?(TrainPlugins::WinRM)
26
28
 
27
29
  module Kitchen
28
30
 
@@ -34,8 +36,9 @@ module Kitchen
34
36
  kitchen_driver_api_version 2
35
37
  plugin_version Kitchen::Driver::HYPERV_VERSION
36
38
 
37
- default_config :parent_vhd_folder
38
- default_config :parent_vhd_name
39
+ required_config :parent_vhd_folder
40
+ required_config :parent_vhd_name
41
+
39
42
  default_config :memory_startup_bytes, 536_870_912
40
43
  default_config :dynamic_memory_min_bytes, 536_870_912
41
44
  default_config :dynamic_memory_max_bytes, 2_147_483_648
@@ -60,6 +63,13 @@ module Kitchen
60
63
  File.extname(driver[:parent_vhd_name])
61
64
  end
62
65
 
66
+ default_config :hyperv_server, nil
67
+ default_config :hyperv_username, nil
68
+ default_config :hyperv_password, nil
69
+ default_config :hyperv_ssl, false
70
+ default_config :hyperv_insecure, true
71
+ default_config :remote_vm_path, 'C:\Users\Public\Documents\Hyper-V'
72
+
63
73
  include Kitchen::Driver::PowerShellScripts
64
74
 
65
75
  def create(state)
@@ -94,8 +104,8 @@ module Kitchen
94
104
  private
95
105
 
96
106
  def validate_vm_settings
97
- raise "Missing parent_vhd_folder" unless vhd_folder?
98
- raise "Missing parent_vhd_name" unless vhd?
107
+ raise "Missing parent_vhd_folder" unless vhd_folder? || remote_hyperv
108
+ raise "Missing parent_vhd_name" unless vhd? || remote_hyperv
99
109
 
100
110
  if config[:dynamic_memory]
101
111
  startup_bytes = config[:memory_startup_bytes]
@@ -160,6 +170,7 @@ module Kitchen
160
170
 
161
171
  info("Creating virtual machine for #{instance.name}.")
162
172
  new_vm_object = run_ps new_vm_ps
173
+ raise "Unable to create virtual machine for #{instance.name}." if new_vm_object.nil?
163
174
  @state[:id] = new_vm_object["Id"]
164
175
  info("Created virtual machine for #{instance.name}.")
165
176
  end
@@ -244,6 +255,8 @@ module Kitchen
244
255
  end
245
256
 
246
257
  def remove_differencing_disk
258
+ return unless differencing_disk_exists
259
+
247
260
  info("Removing the differencing disk for #{instance.name}.")
248
261
  FileUtils.rm(differencing_disk_path)
249
262
  info("Removed the differencing disk for #{instance.name}.")
@@ -269,12 +282,18 @@ module Kitchen
269
282
  @kitchen_vm_path ||= File.join(config[:kitchen_root], ".kitchen/#{instance.name}")
270
283
  end
271
284
 
285
+ def remote_kitchen_vm_path
286
+ config[:remote_vm_path]
287
+ end
288
+
272
289
  def boot_iso_path
273
290
  @boot_iso_path ||= config[:boot_iso_path]
274
291
  end
275
292
 
276
293
  def differencing_disk_path
277
- @differencing_disk_path ||= File.join(kitchen_vm_path, "diff" + "#{config[:disk_type]}")
294
+ kitchen_vm_base = remote_hyperv ? remote_kitchen_vm_path : kitchen_vm_path
295
+
296
+ @differencing_disk_path ||= File.join(kitchen_vm_base, "diff" + "#{config[:disk_type]}")
278
297
  end
279
298
 
280
299
  def additional_disk_path(disk_name, disk_type)
@@ -292,6 +311,44 @@ module Kitchen
292
311
  def vhd?
293
312
  config[:parent_vhd_name] && File.exist?(parent_vhd_path)
294
313
  end
314
+
315
+ def remote_hyperv
316
+ !!config[:hyperv_server]
317
+ end
318
+
319
+ def connection
320
+ return @connection if @connection
321
+
322
+ backend = remote_hyperv ? "winrm" : "local"
323
+
324
+ train = Train.create(backend, {
325
+ host: config[:hyperv_server],
326
+ user: config[:hyperv_username],
327
+ password: config[:hyperv_password],
328
+ ssl: config[:hyperv_ssl],
329
+ self_signed: config[:hyperv_insecure],
330
+ })
331
+ @connection = train.connection
332
+
333
+ # Copy support PS1
334
+ @connection.upload(local_script_path, remote_script_path)
335
+
336
+ @connection
337
+ end
338
+
339
+ def base_script_path
340
+ return remote_script_path if remote_hyperv
341
+
342
+ local_script_path
343
+ end
344
+
345
+ def local_script_path
346
+ File.join(File.dirname(__FILE__), "/../../../support/hyperv.ps1")
347
+ end
348
+
349
+ def remote_script_path
350
+ File.join(config[:kitchen_root], "kitchen-hyperv", "hyperv.ps1")
351
+ end
295
352
  end
296
353
  end
297
354
  end
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Kitchen
19
19
  module Driver
20
- HYPERV_VERSION = "0.6.0".freeze
20
+ HYPERV_VERSION = "0.7.0".freeze
21
21
  end
22
22
  end
@@ -16,6 +16,7 @@
16
16
  # limitations under the License.
17
17
 
18
18
  require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
19
+ require "benchmark" unless defined?(Benchmark)
19
20
  require "fileutils" unless defined?(FileUtils)
20
21
  require "json" unless defined?(JSON)
21
22
 
@@ -28,6 +29,8 @@ module Kitchen
28
29
  end
29
30
 
30
31
  def is_64bit?
32
+ return true if remote_hyperv
33
+
31
34
  os_arch = ENV["PROCESSOR_ARCHITEW6432"] || ENV["PROCESSOR_ARCHITECTURE"]
32
35
  ruby_arch = ["foo"].pack("p").size == 4 ? 32 : 64
33
36
  os_arch == "AMD64" && ruby_arch == 64
@@ -48,7 +51,6 @@ module Kitchen
48
51
  end
49
52
 
50
53
  def wrap_command(script)
51
- base_script_path = File.join(File.dirname(__FILE__), "/../../../support/hyperv.ps1")
52
54
  debug("Loading functions from #{base_script_path}")
53
55
  new_script = [ ". #{base_script_path}", "#{script}" ].join(";\n")
54
56
  debug("Wrapped script: #{new_script}")
@@ -71,11 +73,15 @@ module Kitchen
71
73
  end
72
74
 
73
75
  def execute_command(cmd, options = {})
74
- debug("#Local Command BEGIN (#{cmd})")
75
- sh = Mixlib::ShellOut.new(cmd, options)
76
- sh.run_command
77
- debug("Local Command END #{Util.duration(sh.execution_time)}")
78
- raise "Failed: #{sh.stderr}" if sh.error?
76
+ debug("#Command BEGIN (#{cmd})")
77
+
78
+ sh = nil
79
+ bm = Benchmark.measure do
80
+ sh = connection.run_command(cmd, options)
81
+ end
82
+
83
+ debug("Command END #{Util.duration(bm.total)}")
84
+ raise "Failed: #{sh.stderr}" if sh.exit_status != 0
79
85
 
80
86
  stdout = sanitize_stdout(sh.stdout)
81
87
  JSON.parse(stdout) if stdout.length > 2
@@ -113,7 +119,7 @@ module Kitchen
113
119
  Generation = #{config[:vm_generation]}
114
120
  DisableSecureBoot = "#{config[:disable_secureboot]}"
115
121
  MemoryStartupBytes = #{config[:memory_startup_bytes]}
116
- StaticMacAddress = "#{config[:static_mac_address]}"
122
+ StaticMacAddress = "#{config[:static_mac_address].to_s}"
117
123
  Name = "#{instance.name}"
118
124
  Path = "#{kitchen_vm_path}"
119
125
  VHDPath = "#{differencing_disk_path}"
@@ -139,6 +145,7 @@ module Kitchen
139
145
  EOH
140
146
  end
141
147
 
148
+ # TODO: Report if VM has no IP address instead of silently waiting forever
142
149
  def vm_details_ps
143
150
  <<-DETAILS
144
151
 
data/support/hyperv.ps1 CHANGED
@@ -18,8 +18,8 @@ function New-DifferencingDisk {
18
18
  [parameter(Mandatory)]
19
19
  [ValidateNotNullOrEmpty()]
20
20
  [string[]]$Path,
21
- [parameter(Mandatory)]
22
- [ValidateNotNullOrEmpty()]
21
+ [parameter(Mandatory)]
22
+ [ValidateNotNullOrEmpty()]
23
23
  [string]$ParentPath
24
24
  )
25
25
  if (-not (Test-Path $Path)) {
@@ -73,9 +73,9 @@ function New-KitchenVM {
73
73
  $EnableGuestServices,
74
74
  $AdditionalDisks
75
75
  )
76
- $null = $psboundparameters.remove('DisableSecureBoot')
76
+ $null = $psboundparameters.remove('DisableSecureBoot')
77
77
  $null = $psboundparameters.remove('ProcessorCount')
78
- $null = $psboundparameters.remove('StaticMacAddress')
78
+ $null = $psboundparameters.remove('StaticMacAddress')
79
79
  $null = $psboundparameters.remove('UseDynamicMemory')
80
80
  $null = $psboundparameters.remove('DynamicMemoryMinBytes')
81
81
  $null = $psboundparameters.remove('DynamicMemoryMaxBytes')
@@ -99,7 +99,7 @@ function New-KitchenVM {
99
99
  if (-not [string]::IsNullOrEmpty($boot_iso_path)) {
100
100
  Mount-VMISO -Id $vm.Id -Path $boot_iso_path
101
101
  }
102
- if ($StaticMacAddress -ne $null) {
102
+ if (-not [string]::IsNullOrEmpty($StaticMacAddress)) {
103
103
  Set-VMNetworkAdapter -VMName $vm.VMName -StaticMacAddress $StaticMacAddress
104
104
  }
105
105
  if ($EnableGuestServices -and (Get-command Enable-VMIntegrationService -ErrorAction SilentlyContinue)) {
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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Murawski
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -92,6 +92,34 @@ dependencies:
92
92
  - - "<"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '4'
95
+ - !ruby/object:Gem::Dependency
96
+ name: train
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '3.5'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '3.5'
109
+ - !ruby/object:Gem::Dependency
110
+ name: train-winrm
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.2'
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.2'
95
123
  description: Hyper-V Driver for Test-Kitchen
96
124
  email:
97
125
  - steven.murawski@gmail.com
@@ -111,7 +139,7 @@ homepage: https://github.com/test-kitchen/kitchen-hyperv
111
139
  licenses:
112
140
  - Apache-2.0
113
141
  metadata: {}
114
- post_install_message:
142
+ post_install_message:
115
143
  rdoc_options: []
116
144
  require_paths:
117
145
  - lib
@@ -126,8 +154,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
154
  - !ruby/object:Gem::Version
127
155
  version: '0'
128
156
  requirements: []
129
- rubygems_version: 3.2.15
130
- signing_key:
157
+ rubygems_version: 3.0.3
158
+ signing_key:
131
159
  specification_version: 4
132
160
  summary: Hyper-V Driver for Test-Kitchen
133
161
  test_files: []