kitchen-hyperv 0.5.5 → 0.7.1

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
  SHA256:
3
- metadata.gz: 9258c479984814c2d9aaf91a3686a9c5d917f190cbc48627e65d69bd911a5b61
4
- data.tar.gz: 43a7870274649b11ca8597213fe6ec7c93ed18b16f5c4b90d1bfd80642fb5344
3
+ metadata.gz: 2081b5e1d3d52389d2136e68798b265bdbfef2fe0a3bea713e9eca1f595dfffb
4
+ data.tar.gz: b39c49767592691ef4783c5e4492c865d55712b5c0a6a7e7c0dc501010fac6d1
5
5
  SHA512:
6
- metadata.gz: ca0012d2cc41220779907a19b573f64ff69893f1cff7d28a68b41c80ab48ee52eb3a7d6ddb30d2c408139f2a4ec327479766ce207d65b64928b4e6dd393a21b0
7
- data.tar.gz: 2994a51e52ddde357eacca301732b7ec7af40accd963ae47c0484a3aaeb9c1245e15f352c8ab64ec6aa9661328a052c8213b4400a259fb00c0e24a30c5ae591f
6
+ metadata.gz: a017678ac18c138fc504b8169a9e662000280fe1a2a0c7dbe092b45c98e4beab978504b831b5f6e3afc4f15b46733ef58bde12a5f23b76cdb06f32cca658c3b4
7
+ data.tar.gz: 0eb92487319eef5e8f35ae3a4ff9826aae8dd463087091fd93f59efdc9365524352f6996e9bcba40c4b55831f91f3a7e59c4d2a90a2fd7af21330eee167ca735
data/Gemfile CHANGED
@@ -10,10 +10,6 @@ group :integration do
10
10
  gem "kitchen-vagrant"
11
11
  end
12
12
 
13
- group :changelog do
14
- gem "github_changelog_generator", "1.15.2"
15
- end
16
-
17
13
  group :debug do
18
14
  gem "pry"
19
15
  gem "pry-byebug"
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
 
@@ -27,7 +25,7 @@ desc "Run all quality tasks"
27
25
  task quality: :style
28
26
 
29
27
  begin
30
- require "yard"
28
+ require "yard" unless defined?(YARD)
31
29
  YARD::Rake::YardocTask.new
32
30
  rescue LoadError
33
31
  puts "yard is not available. (sudo) gem install yard to generate yard documentation."
@@ -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"
@@ -17,11 +16,14 @@ Gem::Specification.new do |spec|
17
16
  spec.files = %w{LICENSE kitchen-hyperv.gemspec Gemfile Rakefile support/hyperv.ps1} + Dir.glob("lib/**/*")
18
17
  spec.require_paths = ["lib"]
19
18
 
20
- spec.add_development_dependency "bundler"
19
+ spec.required_ruby_version = ">= 2.6"
20
+
21
21
  spec.add_development_dependency "rake"
22
- spec.add_development_dependency "minitest", "~> 5.3", "< 5.15"
22
+ spec.add_development_dependency "minitest", "~> 5.3", "< 5.16"
23
23
  spec.add_development_dependency "minitest-stub-const"
24
24
  spec.add_development_dependency "mocha", "~> 1.1"
25
25
 
26
- spec.add_dependency "test-kitchen", ">= 1.4", "< 3"
26
+ spec.add_dependency "test-kitchen", ">= 1.4", "< 4"
27
+ spec.add_dependency "train", "~> 3.5"
28
+ spec.add_dependency "train-winrm", "~> 0.2"
27
29
  end
@@ -20,9 +20,11 @@ require "kitchen"
20
20
  require "kitchen/driver"
21
21
  require_relative "hyperv_version"
22
22
  require_relative "powershell"
23
- require "mixlib/shellout"
24
- require "fileutils"
25
- require "json"
23
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
24
+ require "fileutils" unless defined?(FileUtils)
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,8 @@ 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?
174
+
163
175
  @state[:id] = new_vm_object["Id"]
164
176
  info("Created virtual machine for #{instance.name}.")
165
177
  end
@@ -244,6 +256,8 @@ module Kitchen
244
256
  end
245
257
 
246
258
  def remove_differencing_disk
259
+ return unless differencing_disk_exists
260
+
247
261
  info("Removing the differencing disk for #{instance.name}.")
248
262
  FileUtils.rm(differencing_disk_path)
249
263
  info("Removed the differencing disk for #{instance.name}.")
@@ -269,12 +283,18 @@ module Kitchen
269
283
  @kitchen_vm_path ||= File.join(config[:kitchen_root], ".kitchen/#{instance.name}")
270
284
  end
271
285
 
286
+ def remote_kitchen_vm_path
287
+ config[:remote_vm_path]
288
+ end
289
+
272
290
  def boot_iso_path
273
291
  @boot_iso_path ||= config[:boot_iso_path]
274
292
  end
275
293
 
276
294
  def differencing_disk_path
277
- @differencing_disk_path ||= File.join(kitchen_vm_path, "diff" + "#{config[:disk_type]}")
295
+ kitchen_vm_base = remote_hyperv ? remote_kitchen_vm_path : kitchen_vm_path
296
+
297
+ @differencing_disk_path ||= File.join(kitchen_vm_base, "diff" + "#{config[:disk_type]}")
278
298
  end
279
299
 
280
300
  def additional_disk_path(disk_name, disk_type)
@@ -292,6 +312,44 @@ module Kitchen
292
312
  def vhd?
293
313
  config[:parent_vhd_name] && File.exist?(parent_vhd_path)
294
314
  end
315
+
316
+ def remote_hyperv
317
+ !!config[:hyperv_server]
318
+ end
319
+
320
+ def connection
321
+ return @connection if @connection
322
+
323
+ backend = remote_hyperv ? "winrm" : "local"
324
+
325
+ train = Train.create(backend, {
326
+ host: config[:hyperv_server],
327
+ user: config[:hyperv_username],
328
+ password: config[:hyperv_password],
329
+ ssl: config[:hyperv_ssl],
330
+ self_signed: config[:hyperv_insecure],
331
+ })
332
+ @connection = train.connection
333
+
334
+ # Copy support PS1
335
+ @connection.upload(local_script_path, remote_script_path)
336
+
337
+ @connection
338
+ end
339
+
340
+ def base_script_path
341
+ return remote_script_path if remote_hyperv
342
+
343
+ local_script_path
344
+ end
345
+
346
+ def local_script_path
347
+ File.join(File.dirname(__FILE__), "/../../../support/hyperv.ps1")
348
+ end
349
+
350
+ def remote_script_path
351
+ File.join(config[:kitchen_root], "kitchen-hyperv", "hyperv.ps1")
352
+ end
295
353
  end
296
354
  end
297
355
  end
@@ -17,6 +17,6 @@
17
17
 
18
18
  module Kitchen
19
19
  module Driver
20
- HYPERV_VERSION = "0.5.5".freeze
20
+ HYPERV_VERSION = "0.7.1".freeze
21
21
  end
22
22
  end
@@ -15,9 +15,10 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require "mixlib/shellout"
19
- require "fileutils"
20
- require "json"
18
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
19
+ require "benchmark" unless defined?(Benchmark)
20
+ require "fileutils" unless defined?(FileUtils)
21
+ require "json" unless defined?(JSON)
21
22
 
22
23
  module Kitchen
23
24
  module Driver
@@ -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
@@ -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,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-hyperv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.7.1
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: 2020-05-17 00:00:00.000000000 Z
11
+ date: 2022-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -47,7 +33,7 @@ dependencies:
47
33
  version: '5.3'
48
34
  - - "<"
49
35
  - !ruby/object:Gem::Version
50
- version: '5.15'
36
+ version: '5.16'
51
37
  type: :development
52
38
  prerelease: false
53
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +43,7 @@ dependencies:
57
43
  version: '5.3'
58
44
  - - "<"
59
45
  - !ruby/object:Gem::Version
60
- version: '5.15'
46
+ version: '5.16'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: minitest-stub-const
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +81,7 @@ dependencies:
95
81
  version: '1.4'
96
82
  - - "<"
97
83
  - !ruby/object:Gem::Version
98
- version: '3'
84
+ version: '4'
99
85
  type: :runtime
100
86
  prerelease: false
101
87
  version_requirements: !ruby/object:Gem::Requirement
@@ -105,7 +91,35 @@ dependencies:
105
91
  version: '1.4'
106
92
  - - "<"
107
93
  - !ruby/object:Gem::Version
108
- version: '3'
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'
109
123
  description: Hyper-V Driver for Test-Kitchen
110
124
  email:
111
125
  - steven.murawski@gmail.com
@@ -125,7 +139,7 @@ homepage: https://github.com/test-kitchen/kitchen-hyperv
125
139
  licenses:
126
140
  - Apache-2.0
127
141
  metadata: {}
128
- post_install_message:
142
+ post_install_message:
129
143
  rdoc_options: []
130
144
  require_paths:
131
145
  - lib
@@ -133,15 +147,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
147
  requirements:
134
148
  - - ">="
135
149
  - !ruby/object:Gem::Version
136
- version: '0'
150
+ version: '2.6'
137
151
  required_rubygems_version: !ruby/object:Gem::Requirement
138
152
  requirements:
139
153
  - - ">="
140
154
  - !ruby/object:Gem::Version
141
155
  version: '0'
142
156
  requirements: []
143
- rubygems_version: 3.1.2
144
- signing_key:
157
+ rubygems_version: 3.3.7
158
+ signing_key:
145
159
  specification_version: 4
146
160
  summary: Hyper-V Driver for Test-Kitchen
147
161
  test_files: []