kitchen-vcenter 2.11.0 → 2.11.9

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: 67058560fd24551eec490d96384db30c85da728655bde6495320c142582b82db
4
- data.tar.gz: 3b7d9ff608825c060e51bcbc1937848d7a3764435898d28e031d5a49f22006a9
3
+ metadata.gz: 0531d4a30ba60e32b1f7a86df17e1dcf1caa611b5c9cd87372fb4364cb19fa48
4
+ data.tar.gz: a20d1df383cbfb37faf41fd2c85166f394bd37200a0f29bece61270037557a0a
5
5
  SHA512:
6
- metadata.gz: 51483886c3582d2761ec89033a452ee2c369bace2f0ede2d89d3b9000656190a368775b27a3620ede8948f8913af6fa5b0062f84998361f0034353953d6ef5f1
7
- data.tar.gz: 4e3ebba36a422d3e5b7a8a5692e825fa78e79735755f2015ee3db2bd92955c5984ec515e341ec6dc04eb622cc298b05ace2b0f090c4d7b203b6dcc5ae36a3a4e
6
+ metadata.gz: b41c0ebc3486ff91b56bfce5ef3e219554a53e5a491f74da60cae4d0df45dca22ef172b95ee2d712ea59d3d10cac39e075c4e192604a53b61dd9c02f7de7a4fe
7
+ data.tar.gz: e7dca5a3b4ff2f93e9a78cab79361b48015f43a652784dd4ccf705a446c5e314aa4af35a0bf80fb396804522289f457075b2eadffb3a7c2a5c91a0e9413f7c4d
@@ -20,5 +20,5 @@
20
20
  # The main kitchen-vcenter module
21
21
  module KitchenVcenter
22
22
  # The version of this version of test-kitchen we assume enterprises want.
23
- VERSION = "2.11.0"
23
+ VERSION = "2.11.9"
24
24
  end
@@ -173,6 +173,14 @@ class Support
173
173
  options[:vm_os].downcase.to_sym == :linux
174
174
  end
175
175
 
176
+ def update_network?(network_device)
177
+ options[:network_name] && network_device
178
+ end
179
+
180
+ def add_network?(network_device)
181
+ options[:network_name] && network_device.nil?
182
+ end
183
+
176
184
  def network_device(vm)
177
185
  all_network_devices = vm.config.hardware.device.select do |device|
178
186
  device.is_a?(RbVmomi::VIM::VirtualEthernetCard)
@@ -184,6 +192,8 @@ class Support
184
192
 
185
193
  def reconnect_network_device(vm)
186
194
  network_device = network_device(vm)
195
+ return unless network_device
196
+
187
197
  network_device.connectable = RbVmomi::VIM.VirtualDeviceConnectInfo(
188
198
  allowGuestControl: true,
189
199
  startConnected: true,
@@ -461,6 +471,82 @@ class Support
461
471
  ))
462
472
  end
463
473
 
474
+ # This method will fetch the network which is configured in the kitchen.yml file with
475
+ # network_name configuration.
476
+ # If there are multiple networks with the same name, first one will be used.
477
+ #
478
+ # @return Network object
479
+ #
480
+ def fetch_network(datacenter)
481
+ networks = datacenter.network.select { |n| n.name == options[:network_name] }
482
+ raise Support::CloneError, format("Could not find network named %s", options[:network_name]) if networks.empty?
483
+
484
+ if networks.count > 1
485
+ Kitchen.logger.warn(
486
+ format("Found %d networks named %s, picking first one", networks.count, options[:network_name])
487
+ )
488
+ end
489
+ networks.first
490
+ end
491
+
492
+ # This is a helper method that can be used to create the deviceChange spec which can be used
493
+ # to add a new network device or update the existing network device
494
+ #
495
+ # The network_obj will be used as a backing for the network_device.
496
+ def network_change_spec(network_device, network_obj, operation: :edit)
497
+ if network_obj.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
498
+ Kitchen.logger.info format("Assigning network %s...", network_obj.pretty_path)
499
+
500
+ vds_obj = network_obj.config.distributedVirtualSwitch
501
+ Kitchen.logger.info format("Using vDS '%s' for network connectivity...", vds_obj.name)
502
+
503
+ network_device.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
504
+ port: RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
505
+ portgroupKey: network_obj.key,
506
+ switchUuid: vds_obj.uuid
507
+ )
508
+ )
509
+ elsif network_obj.is_a? RbVmomi::VIM::Network
510
+ Kitchen.logger.info format("Assigning network %s...", options[:network_name])
511
+
512
+ network_device.backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
513
+ deviceName: options[:network_name]
514
+ )
515
+ else
516
+ raise Support::CloneError, format("Unknown network type %s for network name %s", network_obj.class.to_s, options[:network_name])
517
+ end
518
+
519
+ [
520
+ RbVmomi::VIM.VirtualDeviceConfigSpec(
521
+ operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation(operation),
522
+ device: network_device
523
+ ),
524
+ ]
525
+ end
526
+
527
+ # This method can be used to add new network device to the target vm
528
+ # This fill find the network which defined in kitchen.yml in network_name configuration
529
+ # and attach that to the target vm.
530
+ def add_new_network_device(datacenter)
531
+ network_obj = fetch_network(datacenter)
532
+ network_device = RbVmomi::VIM.VirtualVmxnet3(
533
+ key: 0,
534
+ deviceInfo: {
535
+ label: options[:network_name],
536
+ summary: options[:network_name],
537
+ }
538
+ )
539
+
540
+ config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
541
+ {
542
+ deviceChange: network_change_spec(network_device, network_obj, operation: :add),
543
+ }
544
+ )
545
+
546
+ task = vm.ReconfigVM_Task(spec: config_spec)
547
+ task.wait_for_completion
548
+ end
549
+
464
550
  def clone
465
551
  benchmark_start if benchmark?
466
552
 
@@ -502,42 +588,12 @@ class Support
502
588
  relocate_spec.pool = options[:resource_pool]
503
589
 
504
590
  # Change network, if wanted
505
- unless options[:network_name].nil?
506
- networks = dc.network.select { |n| n.name == options[:network_name] }
507
- raise Support::CloneError.new(format("Could not find network named %s", options[:network_name])) if networks.empty?
508
-
509
- Kitchen.logger.warn format("Found %d networks named %s, picking first one", networks.count, options[:network_name]) if networks.count > 1
510
- network_obj = networks.first
511
- network_device = network_device(src_vm)
512
-
513
- if network_obj.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
514
- Kitchen.logger.info format("Assigning network %s...", network_obj.pretty_path)
515
-
516
- vds_obj = network_obj.config.distributedVirtualSwitch
517
- Kitchen.logger.info format("Using vDS '%s' for network connectivity...", vds_obj.name)
518
-
519
- network_device.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(
520
- port: RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
521
- portgroupKey: network_obj.key,
522
- switchUuid: vds_obj.uuid
523
- )
524
- )
525
- elsif network_obj.is_a? RbVmomi::VIM::Network
526
- Kitchen.logger.info format("Assigning network %s...", options[:network_name])
591
+ network_device = network_device(src_vm)
592
+ Kitchen.logger.warn format("Source VM/template does not have any network device (use VMware IPPools and vsphere-gom transport or govc to access)") unless network_device
527
593
 
528
- network_device.backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
529
- deviceName: options[:network_name]
530
- )
531
- else
532
- raise Support::CloneError.new(format("Unknown network type %s for network name %s", network_obj.class.to_s, options[:network_name]))
533
- end
534
-
535
- relocate_spec.deviceChange = [
536
- RbVmomi::VIM.VirtualDeviceConfigSpec(
537
- operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit"),
538
- device: network_device
539
- ),
540
- ]
594
+ if update_network?(network_device)
595
+ network_obj = fetch_network(dc)
596
+ relocate_spec.deviceChange = network_change_spec(network_device, network_obj)
541
597
  end
542
598
 
543
599
  # Set the folder to use
@@ -572,19 +628,20 @@ class Support
572
628
  # MAC at least with 6.7.0 build 9433931
573
629
 
574
630
  # Disconnect network device, so wo don't get IP collisions on start
575
- network_device = network_device(src_vm)
576
- network_device.connectable = RbVmomi::VIM.VirtualDeviceConnectInfo(
577
- allowGuestControl: true,
578
- startConnected: true,
579
- connected: false,
580
- migrateConnect: "disconnect"
581
- )
582
- relocate_spec.deviceChange = [
583
- RbVmomi::VIM.VirtualDeviceConfigSpec(
584
- operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit"),
585
- device: network_device
586
- ),
587
- ]
631
+ if network_device
632
+ network_device.connectable = RbVmomi::VIM.VirtualDeviceConnectInfo(
633
+ allowGuestControl: true,
634
+ startConnected: true,
635
+ connected: false,
636
+ migrateConnect: "disconnect"
637
+ )
638
+ relocate_spec.deviceChange = [
639
+ RbVmomi::VIM.VirtualDeviceConfigSpec(
640
+ operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation("edit"),
641
+ device: network_device
642
+ ),
643
+ ]
644
+ end
588
645
 
589
646
  clone_spec = RbVmomi::VIM.VirtualMachineInstantCloneSpec(location: relocate_spec,
590
647
  name: vm_name)
@@ -621,6 +678,8 @@ class Support
621
678
 
622
679
  vm_customization if options[:vm_customization]
623
680
 
681
+ add_new_network_device(dc) if add_network?(network_device)
682
+
624
683
  # Start only if specified or customizations wanted; no need for instant clones as they start in running state
625
684
  if options[:poweron] && !options[:vm_customization].nil? && !instant_clone?
626
685
  task = vm.PowerOnVM_Task
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-vcenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.11.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2022-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ping
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - ">="
111
111
  - !ruby/object:Gem::Version
112
- version: '2.5'
112
+ version: '2.6'
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="