kitchen-vcenter 2.11.12 → 2.12.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: 2814ca94153dd996897c1d357d2f538f07e699f47798d6bf8ca34b04d501ed8f
4
- data.tar.gz: d1174b70520da7fcb424089ffc06928ef5bb272535640cad62cea16bca8d79cb
3
+ metadata.gz: e78c67ec9092a28c7a0c4ca7c58f480c8f712b6c8cefcbd6e114fbe337d6ea15
4
+ data.tar.gz: 0bd6b279c05a22f489c0fb5a7c7dde3de1c06aeaa0b0eb08793c756e59aaa8bf
5
5
  SHA512:
6
- metadata.gz: 12002adacfb368da1769950918f716a78b2b0a5533889d6541d473104572882c77ff0d2b48cfb16539eaf6ea027069de552e3c7e10e2ddf8782780c5ca8aa602
7
- data.tar.gz: 3ff08fe608203a098b0b944e278c99c693a902cca9fcdc50154d25603ee515a755931aaedd2c99969bd55eaeaa4cfdd59451bdf5ec2823880862344435da423d
6
+ metadata.gz: a636d115b71f1fb65dbc607c41b20c09f39b975d3b6c8ce2d60fd2aaa93f5c98a0f0f058ba1b8179e5e7db0f6dca8812c141438469430e2ee5e00edb7e827719
7
+ data.tar.gz: dbe33aabab07e01a092da7215e25a718a4c74cdeba037c59a5164ef552221b2df69f45a053e17d4e8b53c88cafad0ff95fc3743d446973a4d8fb782350d94858
@@ -56,6 +56,7 @@ module Kitchen
56
56
  default_config :clone_type, :full
57
57
  default_config :cluster, nil
58
58
  default_config :network_name, nil
59
+ default_config :networks, []
59
60
  default_config :tags, nil
60
61
  default_config :vm_wait_timeout, 90
61
62
  default_config :vm_wait_interval, 2.0
@@ -94,6 +95,11 @@ module Kitchen
94
95
  The `customize` setting was renamed to `vm_customization` and will
95
96
  be removed in future versions.
96
97
  MSG
98
+ deprecate_config_for :network_name, Util.outdent!(<<-MSG)
99
+ The `network_name` setting is deprecated and will be removed in the
100
+ future version. Please use the new settings `networks` and refer
101
+ documentation for the usage.
102
+ MSG
97
103
 
98
104
  # The main create method
99
105
  #
@@ -145,7 +151,7 @@ module Kitchen
145
151
  config[:targethost] = get_host(config[:targethost], datacenter, cluster_id)
146
152
 
147
153
  # Check if network exists, if to be changed
148
- network_exists?(config[:network_name]) unless config[:network_name].nil?
154
+ config[:networks].each { |network| network_exists?(network[:name]) }
149
155
 
150
156
  # Same thing needs to happen with the folder name if it has been set
151
157
  unless config[:folder].nil?
@@ -172,7 +178,7 @@ module Kitchen
172
178
  folder: config[:folder],
173
179
  resource_pool: config[:resource_pool],
174
180
  clone_type: config[:clone_type].to_sym,
175
- network_name: config[:network_name],
181
+ networks: config[:networks],
176
182
  interface: config[:interface],
177
183
  wait_timeout: config[:vm_wait_timeout],
178
184
  wait_interval: config[:vm_wait_interval],
@@ -286,6 +292,13 @@ module Kitchen
286
292
  config[:vm_username] = config[:aggressive_username] unless config[:aggressive_username].nil?
287
293
  config[:vm_password] = config[:aggressive_password] unless config[:aggressive_password].nil?
288
294
  config[:vm_customization] = config[:customize] unless config[:customize].nil?
295
+ validate_network_parameters
296
+ end
297
+
298
+ def validate_network_parameters
299
+ return if config[:network_name].nil?
300
+
301
+ config[:networks] = [{ name: config[:network_name], operation: "edit" }]
289
302
  end
290
303
 
291
304
  # A helper method to validate the state
@@ -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.12"
23
+ VERSION = "2.12.0"
24
24
  end
@@ -173,12 +173,37 @@ class Support
173
173
  options[:vm_os].downcase.to_sym == :linux
174
174
  end
175
175
 
176
+ # Network configured to update the existing one in the template
177
+ #
178
+ def networks_to_update
179
+ options[:networks].select { |n| n[:operation] == "edit" }
180
+ end
181
+
182
+ # New networks that needs to be attached to newly created vm
183
+ #
184
+ def networks_to_add
185
+ options[:networks].select { |n| [nil, "add"].include?(n[:operation]) }
186
+ end
187
+
188
+ # A network should update if there is a network_device available in the template
189
+ # and the user configured a new network with edit operation.
190
+ #
176
191
  def update_network?(network_device)
177
- options[:network_name] && network_device
192
+ networks_to_update.any? && network_device
178
193
  end
179
194
 
180
- def add_network?(network_device)
181
- options[:network_name] && network_device.nil?
195
+ # Checks whether any networks configured for addition
196
+ def add_network?
197
+ networks_to_add.any?
198
+ end
199
+
200
+ # TODO: Remove this method and its invocations after the deprecation of `network_name` config
201
+ # For backward compatibility
202
+ # If the template doesn't have any NIC and the user use the old
203
+ # configuration(network_name), then that network should be attached to the vm.
204
+ #
205
+ def attach_new_network?(network_device)
206
+ network_device.nil? && networks_to_update.any?
182
207
  end
183
208
 
184
209
  def network_device(vm)
@@ -477,13 +502,13 @@ class Support
477
502
  #
478
503
  # @return Network object
479
504
  #
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?
505
+ def fetch_network(datacenter, network_name)
506
+ networks = datacenter.network.select { |n| n.name == network_name }
507
+ raise Support::CloneError, format("Could not find network named %s", network_name) if networks.empty?
483
508
 
484
509
  if networks.count > 1
485
510
  Kitchen.logger.warn(
486
- format("Found %d networks named %s, picking first one", networks.count, options[:network_name])
511
+ format("Found %d networks named %s, picking first one", networks.count, network_name)
487
512
  )
488
513
  end
489
514
  networks.first
@@ -493,7 +518,7 @@ class Support
493
518
  # to add a new network device or update the existing network device
494
519
  #
495
520
  # The network_obj will be used as a backing for the network_device.
496
- def network_change_spec(network_device, network_obj, operation: :edit)
521
+ def network_change_spec(network_device, network_obj, network_name, operation: :edit)
497
522
  if network_obj.is_a? RbVmomi::VIM::DistributedVirtualPortgroup
498
523
  Kitchen.logger.info format("Assigning network %s...", network_obj.pretty_path)
499
524
 
@@ -507,39 +532,42 @@ class Support
507
532
  )
508
533
  )
509
534
  elsif network_obj.is_a? RbVmomi::VIM::Network
510
- Kitchen.logger.info format("Assigning network %s...", options[:network_name])
535
+ Kitchen.logger.info format("Assigning network %s...", network_name)
511
536
 
512
537
  network_device.backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(
513
- deviceName: options[:network_name]
538
+ deviceName: network_name
514
539
  )
515
540
  else
516
- raise Support::CloneError, format("Unknown network type %s for network name %s", network_obj.class.to_s, options[:network_name])
541
+ raise Support::CloneError, format("Unknown network type %s for network name %s", network_obj.class.to_s, network_name)
517
542
  end
518
543
 
519
- [
520
- RbVmomi::VIM.VirtualDeviceConfigSpec(
521
- operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation(operation),
522
- device: network_device
523
- ),
524
- ]
544
+ RbVmomi::VIM.VirtualDeviceConfigSpec(
545
+ operation: RbVmomi::VIM::VirtualDeviceConfigSpecOperation(operation),
546
+ device: network_device
547
+ )
525
548
  end
526
549
 
527
550
  # This method can be used to add new network device to the target vm
528
551
  # This fill find the network which defined in kitchen.yml in network_name configuration
529
552
  # 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
- )
553
+ def add_new_network_device(datacenter, networks)
554
+ device_change = []
555
+ networks.each do |network|
556
+ network_obj = fetch_network(datacenter, network[:name])
557
+ network_device = RbVmomi::VIM.VirtualVmxnet3(
558
+ key: 0,
559
+ deviceInfo: {
560
+ label: network[:name],
561
+ summary: network[:name],
562
+ }
563
+ )
564
+
565
+ device_change << network_change_spec(network_device, network_obj, network[:name], operation: :add)
566
+ end
539
567
 
540
568
  config_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
541
569
  {
542
- deviceChange: network_change_spec(network_device, network_obj, operation: :add),
570
+ deviceChange: device_change,
543
571
  }
544
572
  )
545
573
 
@@ -592,8 +620,12 @@ class Support
592
620
  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
593
621
 
594
622
  if update_network?(network_device)
595
- network_obj = fetch_network(dc)
596
- relocate_spec.deviceChange = network_change_spec(network_device, network_obj)
623
+ network_spec = []
624
+ networks_to_update.each do |network|
625
+ network_obj = fetch_network(dc, network[:name])
626
+ network_spec << network_change_spec(network_device, network_obj, network[:name])
627
+ end
628
+ relocate_spec.deviceChange = network_spec
597
629
  end
598
630
 
599
631
  # Set the folder to use
@@ -678,7 +710,10 @@ class Support
678
710
 
679
711
  vm_customization if options[:vm_customization]
680
712
 
681
- add_new_network_device(dc) if add_network?(network_device)
713
+ # TODO: Remove this line after the deprecation of `network_name` config
714
+ add_new_network_device(dc, networks_to_update) if attach_new_network?(network_device)
715
+
716
+ add_new_network_device(dc, networks_to_add) if add_network?
682
717
 
683
718
  # Start only if specified or customizations wanted; no need for instant clones as they start in running state
684
719
  if options[:poweron] && !options[:vm_customization].nil? && !instant_clone?
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.12
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-17 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ping
@@ -31,12 +31,12 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: rbvmomi
34
+ name: rbvmomi2
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '1.11'
39
+ version: 3.5.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '4.0'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '1.11'
49
+ version: 3.5.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '4.0'
@@ -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.6'
112
+ version: '2.7'
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="