vagrant-ovirt4 2.1.0 → 2.1.3

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: 032a8a924b7d7f1870fc319f4d4ed13f33910d0bb6bccde70fce977f25c8cafd
4
- data.tar.gz: d3495cebef0d0daf9c5d2d9bbd09a3c271844844c4a334258049dc55a0f31062
3
+ metadata.gz: 7f8d267202b71616a27bf1a4b721fe29264a7128d7643d0059a0558a3a6d76c8
4
+ data.tar.gz: 4dfc4ee00d4dfef59a9a9acf0e4639bdcd86bf4f030de479e6e0c526eb088441
5
5
  SHA512:
6
- metadata.gz: 9b04cf43df3269c745ffb0bb7d503f9f192da7e3b7939d2b2428e3597684e4ed6dbebca051c16ff20529415f4a85ea506070658d84089e47bf9fbf9e16ae8c28
7
- data.tar.gz: e6f60e4dbb661bcfa8cc39f8cd0fcb4633949490abf8910a5fc8f792c9ef45451aff4d6aed449e4e52e7d1cb020f6327a1dcf2d4743a1a342463263cf114782c
6
+ metadata.gz: 013cbee883c91387751dcb150c4cae7af3e73275845d67f9019e6b508564ad756adc48d8d6d84b721188bd631e006511a58928c3e44b34b0086deac8a50d2d74
7
+ data.tar.gz: b281f7740fbc84ca12bc8c81a95a6b1ebfeeaa4246c0726384b389a0130716291bf3d859650fcc697a22a7f97a671e114745e403a0b5bb27137b24197e6dc3a5
data/CHANGELOG CHANGED
@@ -1,3 +1,22 @@
1
+ v2.1.2
2
+ 79a0074 Fix lock file
3
+
4
+ v2.1.1
5
+ 605663e Bump nokogiri from 1.13.3 to 1.13.4
6
+ 2981f5c Default to disabling run-once mode
7
+ f048313 Enable oVirt conn debugging when VAGRANT_LOG=info
8
+ 3555e36 Add safe connection closing methods
9
+ cdb765c Support :timeout and :timeout_connect options
10
+ tomeon/test-all-vmtype-andvmaffinity-values
11
+ 2a9a653 Rakefile: add RSpec task
12
+ 7641780 test all valid VmType and VmAffinity values
13
+ 54efcde Add tests for vmname and hostname settings
14
+ dc3ab3e Add "vmname" provider option
15
+ 233e4bb read_ssh_info: return nil on IPv4 lookup failure
16
+ fcff147 Bump nokogiri from 1.12.5 to 1.13.3
17
+ da44f24 Bump nokogiri from 1.11.4 to 1.12.5
18
+ 9025f4e Bump nokogiri from 1.11.3 to 1.11.4
19
+
1
20
  v2.1.0
2
21
  41b8c63 Move where rspec-mocks is included.
3
22
  0015c45 Update engine binding.
data/Gemfile.lock CHANGED
@@ -28,7 +28,7 @@ GIT
28
28
  PATH
29
29
  remote: .
30
30
  specs:
31
- vagrant-ovirt4 (2.1.0)
31
+ vagrant-ovirt4 (2.1.3)
32
32
  filesize (~> 0)
33
33
  nokogiri (~> 1)
34
34
  ovirt-engine-sdk (~> 4)
@@ -41,26 +41,27 @@ GEM
41
41
  byebug (11.1.3)
42
42
  childprocess (4.0.0)
43
43
  coderay (1.1.3)
44
- concurrent-ruby (1.1.8)
45
- diff-lcs (1.4.4)
44
+ concurrent-ruby (1.1.10)
45
+ diff-lcs (1.5.0)
46
46
  domain_name (0.5.20190701)
47
47
  unf (>= 0.0.5, < 1.0.0)
48
48
  ed25519 (1.2.4)
49
49
  erubi (1.10.0)
50
- ffi (1.15.0)
50
+ ffi (1.15.5)
51
51
  filesize (0.2.0)
52
52
  gssapi (1.3.1)
53
53
  ffi (>= 1.0.1)
54
- gyoku (1.3.1)
54
+ gyoku (1.4.0)
55
55
  builder (>= 2.1.2)
56
+ rexml (~> 3.0)
56
57
  hashicorp-checkpoint (0.1.5)
57
- http-cookie (1.0.3)
58
+ http-cookie (1.0.4)
58
59
  domain_name (~> 0.5)
59
60
  httpclient (2.8.3)
60
- i18n (1.8.10)
61
+ i18n (1.10.0)
61
62
  concurrent-ruby (~> 1.0)
62
- json (2.5.1)
63
- listen (3.5.1)
63
+ json (2.6.1)
64
+ listen (3.7.1)
64
65
  rb-fsevent (~> 0.10, >= 0.10.3)
65
66
  rb-inotify (~> 0.9, >= 0.9.10)
66
67
  little-plugger (1.1.4)
@@ -70,10 +71,9 @@ GEM
70
71
  multi_json (~> 1.14)
71
72
  method_source (1.0.0)
72
73
  mime (0.4.4)
73
- mime-types (3.3.1)
74
+ mime-types (3.4.1)
74
75
  mime-types-data (~> 3.2015)
75
- mime-types-data (3.2021.0225)
76
- mini_portile2 (2.5.0)
76
+ mime-types-data (3.2022.0105)
77
77
  multi_json (1.15.0)
78
78
  net-scp (1.2.1)
79
79
  net-ssh (>= 2.6.5)
@@ -81,49 +81,49 @@ GEM
81
81
  net-ssh (>= 5.0.0, < 7.0.0)
82
82
  net-ssh (6.1.0)
83
83
  netrc (0.11.0)
84
- nokogiri (1.11.3)
85
- mini_portile2 (~> 2.5.0)
84
+ nokogiri (1.13.4-x86_64-darwin)
86
85
  racc (~> 1.4)
87
86
  nori (2.6.0)
88
87
  ovirt-engine-sdk (4.4.1)
89
88
  json (>= 1, < 3)
90
- pry (0.14.1)
89
+ pry (0.13.1)
91
90
  coderay (~> 1.1)
92
91
  method_source (~> 1.0)
93
- pry-byebug (3.8.0)
92
+ pry-byebug (3.9.0)
94
93
  byebug (~> 11.0)
95
- pry (~> 0.10)
96
- racc (1.5.2)
97
- rake (13.0.3)
94
+ pry (~> 0.13.0)
95
+ racc (1.6.0)
96
+ rake (13.0.6)
98
97
  rake-release (1.3.0)
99
98
  bundler (>= 1.11, < 3)
100
- rb-fsevent (0.10.4)
99
+ rb-fsevent (0.11.1)
101
100
  rb-inotify (0.10.1)
102
101
  ffi (~> 1.0)
103
- rb-kqueue (0.2.6)
102
+ rb-kqueue (0.2.8)
104
103
  ffi (>= 0.5.0)
105
104
  rest-client (2.0.2)
106
105
  http-cookie (>= 1.0.2, < 2.0)
107
106
  mime-types (>= 1.16, < 4.0)
108
107
  netrc (~> 0.8)
109
- rspec-core (3.10.1)
110
- rspec-support (~> 3.10.0)
111
- rspec-expectations (3.10.1)
108
+ rexml (3.2.5)
109
+ rspec-core (3.11.0)
110
+ rspec-support (~> 3.11.0)
111
+ rspec-expectations (3.11.0)
112
112
  diff-lcs (>= 1.2.0, < 2.0)
113
- rspec-support (~> 3.10.0)
113
+ rspec-support (~> 3.11.0)
114
114
  rspec-its (1.3.0)
115
115
  rspec-core (>= 3.0.0)
116
116
  rspec-expectations (>= 3.0.0)
117
- rspec-mocks (3.10.2)
117
+ rspec-mocks (3.11.1)
118
118
  diff-lcs (>= 1.2.0, < 2.0)
119
- rspec-support (~> 3.10.0)
120
- rspec-support (3.10.2)
119
+ rspec-support (~> 3.11.0)
120
+ rspec-support (3.11.0)
121
121
  ruby_dep (1.3.1)
122
122
  rubyntlm (0.6.3)
123
- rubyzip (2.3.0)
123
+ rubyzip (2.3.2)
124
124
  unf (0.1.4)
125
125
  unf_ext
126
- unf_ext (0.0.7.7)
126
+ unf_ext (0.0.8.1)
127
127
  vagrant_cloud (2.0.3)
128
128
  rest-client (~> 2.0.2)
129
129
  wdm (0.1.1)
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [OvirtSDK4::Connection#initialize]: https://rubydoc.info/gems/ovirt-engine-sdk/OvirtSDK4%2FConnection:initialize
2
+
1
3
  # Vagrant oVirt v4 Provider
2
4
 
3
5
  This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that adds an
@@ -76,8 +78,12 @@ Vagrant.configure("2") do |config|
76
78
  ovirt.password = "password"
77
79
  ovirt.insecure = true
78
80
  ovirt.debug = true
81
+ ovirt.timeout = 120 # seconds
82
+ ovirt.connect_timeout = 30 # seconds
79
83
  ovirt.filtered_api = true #see http://www.ovirt.org/develop/release-management/features/infra/user-portal-permissions/
80
84
  ovirt.cluster = 'Default'
85
+ ovirt.vmname = 'my-vm'
86
+ ovirt.run_once = false
81
87
  ovirt.template = 'Vagrant-Centos7-test'
82
88
  ovirt.console = 'vnc'
83
89
  ovirt.disk_size = '15 GiB' # only growing is supported. works the same way as below memory settings
@@ -105,8 +111,8 @@ end
105
111
  ### Configuration options
106
112
 
107
113
  1. Vagrant specific
108
- 1. `config.vm.hostname` => Sets the hostname of the VM
109
- a. Is the 'name' in the Virtual Machine tab of the UI
114
+ 1. `config.vm.hostname` => Sets the hostname of the VM. Optional. String.
115
+ Default is `"vagrant"`.
110
116
  a. Is the 'hostname' of the VM configured by `cloud-init`
111
117
  1. `config.vm.network` => Sets the network information of the VM.
112
118
  a. Note: `:ip` => is ignored, but `:ovirt__ip` is used and merged with `:ip`
@@ -118,7 +124,22 @@ end
118
124
  1. `username` => The username for the API. Required. String. No default value.
119
125
  1. `password` => The password for the API. Required. String. No default value.
120
126
  1. `insecure` => Allow connecting to SSL sites without certificates. Optional. Bool. Default is `false`
121
- 1. `debug` => Turn on additional log statements. Optional. Bool. Default is `false`.
127
+ 1. `debug` => Turn on additional log statements. Optional. Bool. Default is
128
+ `true` if Vagrant's logging verbosity is set to `info` or above
129
+ (`VAGRANT_LOG={info,debug,...}`); otherwise, the default is `false`.
130
+ 1. `timeout` => Per [the oVirt SDK docs][OvirtSDK4::Connection#initialize],
131
+ "The maximun (_sic_) total time to wait for the response, in seconds. A value of
132
+ zero (the default) means wait for ever." Optional. Integer. Uses the
133
+ `OvirtSDK4::Connection` default if omitted; as of the time of writing,
134
+ this is `0` (i.e. wait forever).
135
+ 1. `connect_timeout` => Per [the oVirt SDK docs][OvirtSDK4::Connection#initialize],
136
+ "The maximun (_sic_) time to wait for connection establishment, in
137
+ seconds." Optional. Integer. Uses the `OvirtSDK4::Connection` default if
138
+ omitted; as of the time of writing, this is `300`.
139
+ 1. `vmname` => Sets the name of the VM. Optional. String. Default is
140
+ `config.vm.hostname`, if defined, otherwise `"vagrant"`.
141
+ a. Is the 'name' in the Virtual Machine tab of the UI
142
+ 1. `run_once` => Launch VM in run-once mode. Optional. Default is `false`.
122
143
  1. `template` => The name of the template to use for creation. Required. String. No Default value.
123
144
  1. `cluster` => The name of the ovirt cluster to create within. Required. String. No Default value.
124
145
  1. `console` => The type of remote viewing protocol to use. Required. String. No Default value.
data/Rakefile CHANGED
@@ -14,3 +14,7 @@ Dir.chdir(File.expand_path("../", __FILE__))
14
14
  # This installs the tasks that help with gem creation and
15
15
  # publishing.
16
16
  Bundler::GemHelper.install_tasks
17
+
18
+ RSpec::Core::RakeTask.new
19
+
20
+ task :default => [:spec]
@@ -19,9 +19,19 @@ module VagrantPlugins
19
19
  conn_attr[:url] = "#{config.url}"
20
20
  conn_attr[:username] = config.username if config.username
21
21
  conn_attr[:password] = config.password if config.password
22
- conn_attr[:debug] = config.debug if config.debug
23
22
  conn_attr[:insecure] = true if config.insecure
24
23
  conn_attr[:headers] = {'Filter' => true} if config.filtered_api
24
+ conn_attr[:timeout] = config.timeout unless config.timeout.nil?
25
+ conn_attr[:connect_timeout] = config.connect_timeout unless config.connect_timeout.nil?
26
+
27
+ # Respect VAGRANT_LOG setting -- any level at least as verbose as
28
+ # "info" will result in logging oVirt connection debugging messages
29
+ # (read: libcurl verbose output).
30
+ conn_attr[:debug] = config.debug or @logger.info?
31
+
32
+ # Inject our own logger so that messages are namespaced under
33
+ # "connect_ovirt"
34
+ conn_attr[:log] = @logger
25
35
 
26
36
  @logger.info("Connecting to oVirt (#{config.url}) ...")
27
37
  ovirt_connection = OvirtSDK4::Connection.new(conn_attr)
@@ -1,10 +1,14 @@
1
1
  require 'log4r'
2
+ require 'vagrant-ovirt4/util/connection'
3
+ require 'vagrant-ovirt4/util/machine_names'
2
4
  require 'vagrant/util/retryable'
3
5
 
4
6
  module VagrantPlugins
5
7
  module OVirtProvider
6
8
  module Action
7
9
  class CreateVM
10
+ include Util::Connection
11
+ include Util::MachineNames
8
12
  include Vagrant::Util::Retryable
9
13
 
10
14
  def initialize(app, env)
@@ -16,12 +20,11 @@ module VagrantPlugins
16
20
  # Get config.
17
21
  config = env[:machine].provider_config
18
22
 
19
- hostname = env[:machine].config.vm.hostname
20
- hostname = 'vagrant' if hostname.nil?
23
+ vmname = machine_vmname(env[:machine])
21
24
 
22
25
  # Output the settings we're going to use to the user
23
26
  env[:ui].info(I18n.t("vagrant_ovirt4.creating_vm"))
24
- env[:ui].info(" -- Name: #{hostname}")
27
+ env[:ui].info(" -- Name: #{vmname}")
25
28
  env[:ui].info(" -- Cluster: #{config.cluster}")
26
29
  env[:ui].info(" -- Template: #{config.template}")
27
30
  env[:ui].info(" -- Console Type: #{config.console}")
@@ -46,7 +49,7 @@ module VagrantPlugins
46
49
 
47
50
  # Create oVirt VM.
48
51
  attr = {
49
- :name => hostname,
52
+ :name => vmname,
50
53
  :description => config.description,
51
54
  :comment => config.comment,
52
55
  :cpu => {
@@ -127,7 +130,7 @@ module VagrantPlugins
127
130
  OvirtSDK4::DiskAttachment.new(
128
131
  disk: {
129
132
  name: disk[:name],
130
- description: '#{hostname} storage disk',
133
+ description: "#{vmname} storage disk",
131
134
  format: disk[:type] == 'qcow2' ? OvirtSDK4::DiskFormat::COW : OvirtSDK4::DiskFormat::RAW,
132
135
  provisioned_size: disk[:size],
133
136
  storage_domains: [{
@@ -192,7 +195,7 @@ module VagrantPlugins
192
195
  destroy_env[:config_validate] = false
193
196
  destroy_env[:force_confirm_destroy] = true
194
197
  env[:action_runner].run(Action.action_destroy, destroy_env)
195
- env[:connection].close()
198
+ safe_close_connection_standard!(env)
196
199
  end
197
200
  end
198
201
  end
@@ -1,10 +1,13 @@
1
1
  require 'log4r'
2
2
  require 'ovirtsdk4'
3
+ require 'vagrant-ovirt4/util/connection'
3
4
 
4
5
  module VagrantPlugins
5
6
  module OVirtProvider
6
7
  module Action
7
8
  class DisconnectOVirt
9
+ include Util::Connection
10
+
8
11
  def initialize(app, env)
9
12
  @logger = Log4r::Logger.new("vagrant_ovirt4::action::disconnect_ovirt")
10
13
  @app = app
@@ -14,7 +17,7 @@ module VagrantPlugins
14
17
 
15
18
  # Get config options for ovirt provider.
16
19
  @logger.info("Disconnecting oVirt connection")
17
- env[:connection].close()
20
+ safe_close_connection_standard!(env)
18
21
 
19
22
  @app.call(env)
20
23
  end
@@ -17,31 +17,31 @@ module VagrantPlugins
17
17
  @app.call(env)
18
18
  end
19
19
 
20
+ # This method powers OVirtProvider::Provider#ssh_info. It returns a
21
+ # hash of SSH connection information if and only if at least one IPv4
22
+ # address associated with the machine in question could be retrieved
23
+ # from the oVirt API. Otherwise, it returns nil.
20
24
  def read_ssh_info(env)
21
25
  vms_service, machine = env[:vms_service], env[:machine]
22
- return :not_created if machine.id.nil?
26
+ return nil if machine.id.nil?
23
27
 
24
28
  # Find the machine
25
29
  server = vms_service.vm_service(machine.id)
26
30
  begin
27
31
  if server.get.nil?
28
32
  machine.id = nil
29
- return :not_created
33
+ return nil
30
34
  end
31
35
  rescue Exception => e
32
36
  machine.id = nil
33
- return :not_created
34
- raise e
37
+ return nil
35
38
  end
36
39
 
37
40
  nics_service = server.nics_service
38
41
  nics = nics_service.list
39
- begin
40
- ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
41
- rescue
42
- # for backwards compatibility with ovirt 4.3
43
- ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
44
- end
42
+ ip_addr = first_active_ipv4_address(env, nics)
43
+
44
+ return nil if ip_addr.nil?
45
45
 
46
46
  # Return the info
47
47
  # TODO: Some info should be configurable in Vagrantfile
@@ -54,7 +54,16 @@ module VagrantPlugins
54
54
  :forward_x11 => machine.config.ssh.forward_x11,
55
55
  }
56
56
 
57
- end
57
+ end
58
+
59
+ private
60
+
61
+ def first_active_ipv4_address(env, nics)
62
+ nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
63
+ rescue
64
+ # for backwards compatibility with ovirt 4.3
65
+ nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
66
+ end
58
67
  end
59
68
  end
60
69
  end
@@ -1,4 +1,6 @@
1
1
  require 'log4r'
2
+ require 'vagrant-ovirt4/errors'
3
+ require 'vagrant-ovirt4/util/machine_names'
2
4
  require 'vagrant/util/scoped_hash_override'
3
5
 
4
6
  module VagrantPlugins
@@ -7,6 +9,7 @@ module VagrantPlugins
7
9
 
8
10
  # Just start the VM.
9
11
  class StartVM
12
+ include Util::MachineNames
10
13
  include Vagrant::Util::ScopedHashOverride
11
14
 
12
15
  def initialize(app, env)
@@ -26,8 +29,7 @@ module VagrantPlugins
26
29
  end
27
30
 
28
31
  # FIX MULTIPLE NETWORK INTERFACES
29
- hostname = env[:machine].config.vm.hostname
30
- hostname = 'vagrant' if hostname.nil?
32
+ hostname = machine_hostname(env[:machine])
31
33
 
32
34
  initialization = {
33
35
  host_name: hostname,
@@ -81,6 +83,7 @@ module VagrantPlugins
81
83
  vm_configuration = {
82
84
  initialization: initialization,
83
85
  placement_policy: {},
86
+ run_once: config.run_once
84
87
  }
85
88
 
86
89
  vm_configuration[:placement_policy][:hosts] = [{ :name => config.placement_host }] unless config.placement_host.nil?
@@ -29,7 +29,11 @@ module VagrantPlugins
29
29
  attr_accessor :optimized_for
30
30
  attr_accessor :description
31
31
  attr_accessor :comment
32
+ attr_accessor :vmname
32
33
  attr_accessor :disks
34
+ attr_accessor :timeout
35
+ attr_accessor :connect_timeout
36
+ attr_accessor :run_once
33
37
 
34
38
  def initialize
35
39
  @url = UNSET_VALUE
@@ -55,6 +59,10 @@ module VagrantPlugins
55
59
  @optimized_for = UNSET_VALUE
56
60
  @description = UNSET_VALUE
57
61
  @comment = UNSET_VALUE
62
+ @vmname = UNSET_VALUE
63
+ @timeout = UNSET_VALUE
64
+ @connect_timeout = UNSET_VALUE
65
+ @run_once = UNSET_VALUE
58
66
  @disks = []
59
67
 
60
68
  end
@@ -109,6 +117,10 @@ module VagrantPlugins
109
117
  @optimized_for = nil if @optimized_for == UNSET_VALUE
110
118
  @description = '' if @description == UNSET_VALUE
111
119
  @comment = '' if @comment == UNSET_VALUE
120
+ @vmname = nil if @vmname == UNSET_VALUE
121
+ @timeout = nil if @timeout == UNSET_VALUE
122
+ @connect_timeout = nil if @connect_timeout == UNSET_VALUE
123
+ @run_once = @run_once == UNSET_VALUE ? false : !!@run_once
112
124
 
113
125
  unless optimized_for.nil?
114
126
  raise "Invalid 'optimized_for'. Must be one of #{OvirtSDK4::VmType.constants.map { |s| "'#{s.downcase}'" }.join(' ')}" unless OvirtSDK4::VmType.constants.include? optimized_for.upcase.to_sym
@@ -133,6 +145,24 @@ module VagrantPlugins
133
145
  rescue ArgumentError
134
146
  raise "Not able to parse either `memory_size` or `memory_guaranteed`. Please verify and check again."
135
147
  end
148
+
149
+ unless timeout.nil?
150
+ begin
151
+ @timeout = Integer(@timeout)
152
+ raise ArgumentError if @timeout < 0
153
+ rescue ArgumentError, TypeError
154
+ raise "`timeout` argument #{@timeout.inspect} is not a valid nonnegative integer"
155
+ end
156
+ end
157
+
158
+ unless connect_timeout.nil?
159
+ begin
160
+ @connect_timeout = Integer(@connect_timeout)
161
+ raise ArgumentError if @connect_timeout < 0
162
+ rescue ArgumentError, TypeError
163
+ raise "`connect_timeout` argument #{@connect_timeout.inspect} is not a valid nonnegative integer"
164
+ end
165
+ end
136
166
  end
137
167
 
138
168
  end
@@ -0,0 +1,40 @@
1
+ require 'ovirtsdk4'
2
+ require 'ovirtsdk4/connection'
3
+
4
+ module VagrantPlugins
5
+ module OVirtProvider
6
+ module Util
7
+ module Connection
8
+ # Use OVirtSDK4::ConnectionError if available; SDK versions older than
9
+ # 4.2.0 used the generic OVirtSDK4::Error.
10
+ ERROR_CLASSES = (OvirtSDK4.const_defined?(:ConnectionError) ? [OvirtSDK4::ConnectionError, OvirtSDK4::Error] : [OvirtSDK4::Error]).freeze
11
+
12
+ module_function
13
+
14
+ # Close a connection, suppressing errors generated by the SDK. Yield
15
+ # the error to the caller to re-raise if appropriate (or log, or do
16
+ # whatever).
17
+ def safe_close_connection!(conn)
18
+ conn.close
19
+ rescue *ERROR_CLASSES => e
20
+ yield e if block_given?
21
+ rescue StandardError => e
22
+ yield e if block_given?
23
+ raise e
24
+ end
25
+
26
+ # Wrapper for "#safe_close_connection" that issues a warning message
27
+ # with diagnostic information about the exception raised.
28
+ def safe_close_connection_with_warning!(conn, ui)
29
+ safe_close_connection!(conn) { |e| ui.warn("Encountered exception of class #{e.class}: #{e.message}") }
30
+ end
31
+
32
+ # Wrapper for "#safe_close_connection_with_warning" that extracts the
33
+ # connection and UI from a Vagrant environment.
34
+ def safe_close_connection_standard!(env)
35
+ safe_close_connection_with_warning!(env[:connection], env[:ui])
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module OVirtProvider
3
+ module Util
4
+ module MachineNames
5
+ DEFAULT_NAME = 'vagrant'.freeze
6
+
7
+ module_function
8
+
9
+ def machine_hostname(machine)
10
+ machine.config.vm.hostname || DEFAULT_NAME
11
+ end
12
+
13
+ def machine_vmname(machine)
14
+ machine.provider_config.vmname || machine_hostname(machine)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  module OVirtProvider
3
- VERSION = '2.1.0'
3
+ VERSION = '2.1.3'
4
4
  end
5
5
  end
6
6
 
data/spec/spec_helper.rb CHANGED
@@ -1 +1,3 @@
1
1
  require 'vagrant'
2
+
3
+ require_relative 'support/shared_context'
@@ -0,0 +1,39 @@
1
+ require 'vagrant-ovirt4/config'
2
+
3
+ shared_context 'provider:action' do
4
+ let(:app) { double('app') }
5
+
6
+ let(:env) {
7
+ {
8
+ connection: double('connection',
9
+ system_service: double('system_service', disks_service: double('disks_service'))
10
+ ),
11
+ machine: double('machine',
12
+ provider: double('provider'),
13
+ provider_config: VagrantPlugins::OVirtProvider::Config.new,
14
+ name: 'machname',
15
+ id: 'ID',
16
+ config: double('config',
17
+ vm: double('vm_config',
18
+ networks: [],
19
+ ),
20
+ ),
21
+ ),
22
+ ui: double('ui'),
23
+ vms_service: double('vms_service'),
24
+ }
25
+ }
26
+
27
+ let(:vm_service) {
28
+ double('vm_service',
29
+ disk_attachments_service: double('disk_attachments_service', list: []),
30
+ get: double('get'),
31
+ )
32
+ }
33
+
34
+ before do
35
+ allow(app).to receive(:call)
36
+ allow(env[:vms_service]).to receive(:vm_service).with(env[:machine].id).and_return(vm_service)
37
+ env[:machine].provider_config.finalize!
38
+ end
39
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-ovirt4/action/create_vm'
3
+ require 'vagrant-ovirt4/config'
4
+
5
+ describe VagrantPlugins::OVirtProvider::Action::CreateVM do
6
+ include_context 'provider:action'
7
+
8
+ let(:vm) { double('vm', id: 'ID') }
9
+
10
+ subject(:action) { described_class.new(app, env) }
11
+
12
+ before do
13
+ allow(env[:ui]).to receive(:info)
14
+ allow(env[:machine]).to receive(:"id=").with(vm.id)
15
+ allow(vm_service.get).to receive(:status).and_return('down')
16
+ end
17
+
18
+ context 'given a custom vmname' do
19
+ let(:vmname) { 'VMNAME' }
20
+
21
+ it 'uses that as the name for machine creation' do
22
+ env[:machine].provider_config.vmname = vmname
23
+ expect(env[:vms_service]).to receive(:add).with(hash_including(name: vmname)).and_return(vm)
24
+ action.call(env)
25
+ end
26
+ end
27
+
28
+ context 'given no custom vmname' do
29
+ context 'given a custom hostname' do
30
+ let(:hostname) { 'HOSTNAME' }
31
+
32
+ it 'uses that as the name for machine creation' do
33
+ expect(env[:machine].config.vm).to receive(:hostname).and_return(hostname)
34
+ expect(env[:vms_service]).to receive(:add).with(hash_including(name: hostname)).and_return(vm)
35
+ action.call(env)
36
+ end
37
+ end
38
+
39
+ context 'given no custom hostname' do
40
+ it 'uses a default name for machine creation' do
41
+ expect(env[:machine].config.vm).to receive(:hostname)
42
+ expect(env[:vms_service]).to receive(:add).with(hash_including(name: 'vagrant')).and_return(vm)
43
+ action.call(env)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -17,7 +17,7 @@ describe VagrantPlugins::OVirtProvider::Action::ReadSSHInfo do
17
17
  expect(action).to receive(:call).with(env)
18
18
  action.call(env)
19
19
  end
20
-
20
+
21
21
  context 'unknown API error' do
22
22
  before do
23
23
  allow(env.machine).to receive(:id).and_return('wat')
@@ -25,35 +25,35 @@ describe VagrantPlugins::OVirtProvider::Action::ReadSSHInfo do
25
25
  allow(env.vms_service.vm_service).to receive(:get).and_raise('boom')
26
26
 
27
27
  end
28
-
29
- it 'continues the middleware chain' do
28
+
29
+ it 'returns nil' do
30
30
  expect(app).to receive(:call).with(env)
31
31
  action.call(env)
32
- expect(env.machine_ssh_info).to eq(:not_created)
32
+ expect(env.machine_ssh_info).to be_nil
33
33
  end
34
-
35
34
  end
36
35
 
37
36
  context 'machine does not exist' do
38
37
  before do
39
38
  allow(env.machine).to receive(:id).and_return(nil)
40
39
  end
41
-
42
- it 'continues the middleware chain' do
40
+
41
+ it 'returns nil' do
43
42
  expect(app).to receive(:call).with(env)
44
43
  action.call(env)
45
- expect(env.machine_ssh_info).to eq(:not_created)
44
+ expect(env.machine_ssh_info).to be_nil
46
45
  end
47
-
48
46
  end
49
47
 
50
48
  context 'machine exists' do
49
+ let(:port) { 44 }
50
+
51
51
  before do
52
52
  allow(env.machine).to receive(:id).and_return('wat')
53
53
  allow(env.machine).to receive(:config).and_return(OpenStruct.new({
54
54
  ssh: OpenStruct.new({
55
- guest_port: 44,
56
- }),
55
+ guest_port: port
56
+ })
57
57
  }))
58
58
  allow(env.vms_service).to receive(:vm_service).and_return({})
59
59
  allow(env.vms_service.vm_service).to receive(:get).and_return({})
@@ -61,13 +61,27 @@ describe VagrantPlugins::OVirtProvider::Action::ReadSSHInfo do
61
61
  allow(env.vms_service.vm_service.nics_service).to receive(:list).and_return({})
62
62
  allow(env.vms_service.vm_service.get).to receive(:status).and_return('active')
63
63
  end
64
-
65
- it 'continues the middleware chain' do
66
- expect(app).to receive(:call).with(env)
67
- action.call(env)
68
- expect(env.machine_ssh_info).to eq({:host=>nil, :port=>44, :username=>nil, :private_key_path=>nil, :forward_agent=>nil, :forward_x11=>nil})
64
+
65
+ context 'with no IP addresses defined' do
66
+ it 'returns nil' do
67
+ expect(app).to receive(:call).with(env)
68
+ action.call(env)
69
+ expect(env.machine_ssh_info).to be_nil
70
+ end
69
71
  end
70
72
 
73
+ context 'with at least one IP address defined' do
74
+ let(:host) { '10.10.10.10' }
75
+
76
+ before do
77
+ allow(action).to receive(:first_active_ipv4_address).and_return(host)
78
+ end
79
+
80
+ it 'returns filled-out SSH information' do
81
+ expect(app).to receive(:call).with(env)
82
+ action.call(env)
83
+ expect(env.machine_ssh_info).to eq(host: host, port: port, username: nil, private_key_path: nil, forward_agent: nil, forward_x11: nil)
84
+ end
85
+ end
71
86
  end
72
87
  end
73
-
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-ovirt4/action/start_vm'
3
+ require 'vagrant-ovirt4/config'
4
+
5
+ describe VagrantPlugins::OVirtProvider::Action::StartVM do
6
+ include_context 'provider:action'
7
+
8
+ subject(:action) { described_class.new(app, env) }
9
+
10
+ before do
11
+ allow(env[:ui]).to receive(:info)
12
+ allow(env[:machine].config.vm).to receive(:hostname)
13
+ allow(vm_service.get).to receive(:status).and_return('nominal')
14
+ allow(vm_service).to receive(:start)
15
+ end
16
+
17
+ def vm_initialization_hash_including_hostname(hostname)
18
+ hash_including(vm: hash_including(initialization: hash_including(host_name: hostname)))
19
+ end
20
+
21
+ context 'given a custom hostname' do
22
+ let(:hostname) { 'HOSTNAME' }
23
+
24
+ it 'uses that as the hostname for machine initialization' do
25
+ expect(env[:machine].config.vm).to receive(:hostname).and_return(hostname)
26
+ expect(vm_service).to receive(:start).with(vm_initialization_hash_including_hostname(hostname))
27
+ action.call(env)
28
+ end
29
+ end
30
+
31
+ context 'given no custom hostname' do
32
+ it 'uses a default value as the hostname for machine initialization' do
33
+ expect(vm_service).to receive(:start).with(vm_initialization_hash_including_hostname('vagrant'))
34
+ action.call(env)
35
+ end
36
+ end
37
+
38
+ context 'given a custom run_once setting' do
39
+ [true, false].each do |value|
40
+ it 'uses that setting' do
41
+ env[:machine].provider_config.run_once = value
42
+ expect(vm_service).to receive(:start).with(hash_including(vm: hash_including(run_once: value)))
43
+ action.call(env)
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'given no custom run_once setting' do
49
+ it 'defaults to false' do
50
+ expect(vm_service).to receive(:start).with(hash_including(vm: hash_including(run_once: false)))
51
+ action.call(env)
52
+ end
53
+ end
54
+ end
@@ -50,6 +50,7 @@ describe VagrantPlugins::OVirtProvider::Config do
50
50
  its("optimized_for") { should be_nil }
51
51
  its("description") { should == '' }
52
52
  its("comment") { should == '' }
53
+ its("run_once") { should be false }
53
54
 
54
55
  end
55
56
 
@@ -66,7 +67,9 @@ describe VagrantPlugins::OVirtProvider::Config do
66
67
 
67
68
  describe "overriding optimized_for" do
68
69
  [:optimized_for].each do |attribute|
69
- ['server', 'desktop'].each do |value|
70
+ OvirtSDK4::VmType.constants.each do |const|
71
+ value = const.to_s.downcase
72
+
70
73
  it "should accept #{value} for #{attribute}" do
71
74
  instance.send("#{attribute}=".to_sym, value)
72
75
  instance.finalize!
@@ -103,27 +106,77 @@ describe VagrantPlugins::OVirtProvider::Config do
103
106
 
104
107
  describe "overriding affinity defaults" do
105
108
  [:affinity].each do |attribute|
109
+ OvirtSDK4::VmAffinity.constants.each do |const|
110
+ value = const.to_s.downcase
111
+
112
+ it "should accept #{value} for #{attribute}" do
113
+ instance.send("#{attribute}=".to_sym, value)
114
+ instance.finalize!
115
+ instance.send(attribute).should == value
116
+ end
117
+ end
118
+
119
+ it "should reject a value for #{attribute} outside of the defined values" do
120
+ expect {
121
+ instance.send("#{attribute}=".to_sym, "foo")
122
+ instance.finalize!
123
+ }.to raise_error(RuntimeError)
124
+ end
125
+ end
106
126
 
107
- context 'valid value' do
108
- it "should not default #{attribute} if overridden" do
109
- instance.send("#{attribute}=".to_sym, "pinned")
127
+ end
128
+
129
+ describe "overriding timeout defaults" do
130
+ [:timeout, :connect_timeout].each do |attribute|
131
+ [0, 6, 1_000_000, 8.10, nil].each do |value|
132
+ it "should accept #{value.to_s} for #{attribute}" do
133
+ instance.send("#{attribute}=".to_sym, value)
110
134
  instance.finalize!
111
- instance.send(attribute).should == "pinned"
135
+
136
+ if value.nil?
137
+ instance.send(attribute).should be_nil
138
+ else
139
+ instance.send(attribute).should == Integer(value)
140
+ end
112
141
  end
113
142
  end
114
143
 
115
- context 'invalid value' do
116
- it "should error" do
144
+ ["foo", Object.new, -100].each do |value|
145
+ it "should reject a value for #{attribute} outside of the defined values" do
117
146
  expect {
118
- instance.send("#{attribute}=".to_sym, "foo")
147
+ instance.send("#{attribute}=".to_sym, value)
119
148
  instance.finalize!
120
- }.to raise_error(RuntimeError)
121
-
149
+ }.to raise_error { |error|
150
+ expect(error).to be_a(RuntimeError)
151
+ expect(error.message).to match(/nonnegative integer/)
152
+ }
122
153
  end
154
+ end
155
+ end
156
+
157
+ end
123
158
 
159
+ describe "overriding run_once defaults" do
160
+ context "given truthy values" do
161
+ [Object.new, {}, true, 1, 0].each do |value|
162
+ it "should convert #{value.inspect} to 'true'" do
163
+ instance.run_once = value
164
+ instance.finalize!
165
+ expect(instance.run_once).to be true
166
+ end
124
167
  end
168
+ end
125
169
 
170
+ context "given falsey values" do
171
+ [false, nil].each do |value|
172
+ it "should convert #{value.inspect} to 'false'" do
173
+ instance.run_once = value
174
+ instance.finalize!
175
+ expect(instance.run_once).to be false
176
+ end
177
+ end
126
178
  end
179
+
127
180
  end
128
181
 
129
182
  end
@@ -0,0 +1,80 @@
1
+ require 'vagrant-ovirt4/util/connection'
2
+
3
+ describe VagrantPlugins::OVirtProvider::Util::Connection do
4
+ class MockConnection
5
+ def initialize(exception)
6
+ @closed = false
7
+ @exception = exception
8
+ end
9
+
10
+ def close
11
+ raise @exception if @closed
12
+ @closed = true
13
+ end
14
+ end
15
+
16
+ let(:error_class) { described_class::ERROR_CLASSES.first }
17
+ let(:exception) { error_class.new('already closed') }
18
+ let(:conn) { MockConnection.new(exception) }
19
+
20
+ describe '#safe_close_connection!' do
21
+ context 'when called on an open connection' do
22
+ it 'does not raise an error' do
23
+ expect { described_class.safe_close_connection!(conn) }.not_to raise_error
24
+ end
25
+ end
26
+
27
+ context 'when called on an already-closed connection' do
28
+ context 'and the error pertains to double-closing' do
29
+ it 'yields the error' do
30
+ expect { described_class.safe_close_connection!(conn) }.not_to raise_error
31
+ expect { |b| described_class.safe_close_connection!(conn, &b) }.to yield_with_args(exception)
32
+ end
33
+ end
34
+
35
+ context 'and the error does not pertain to double-close' do
36
+ let(:exception) { RuntimeError.new('sorry, no') }
37
+
38
+ it 'yields and then raises the error' do
39
+ expect { described_class.safe_close_connection!(conn) }.not_to raise_error
40
+ expect { |b| described_class.safe_close_connection!(conn, &b) }.to yield_with_args(exception).and raise_error(exception)
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '#safe_connection_connection_standard!' do
47
+ let(:env) {
48
+ {
49
+ connection: conn,
50
+ ui: double('ui'),
51
+ }
52
+ }
53
+
54
+ context 'when called on an open connection' do
55
+ it 'does not raise an error' do
56
+ expect { described_class.safe_close_connection_standard!(env) }.not_to raise_error
57
+ end
58
+ end
59
+
60
+ context 'when called on an already-closed connection' do
61
+ context 'and the error pertains to double-closing' do
62
+ it 'logs a warning' do
63
+ expect { described_class.safe_close_connection_standard!(env) }.not_to raise_error
64
+ expect(env[:ui]).to receive(:warn).with(/^Encountered exception of class #{exception.class}: #{exception.message}/)
65
+ expect { described_class.safe_close_connection_standard!(env) }.not_to raise_error
66
+ end
67
+ end
68
+
69
+ context 'and the error does not pertain to double-close' do
70
+ let(:exception) { RuntimeError.new('sorry, no') }
71
+
72
+ it 'logs a warning and then raises the error' do
73
+ expect { described_class.safe_close_connection_standard!(env) }.not_to raise_error
74
+ expect(env[:ui]).to receive(:warn).with(/^Encountered exception of class #{exception.class}: #{exception.message}/)
75
+ expect { |b| described_class.safe_close_connection_standard!(env) }.to raise_error(exception)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-ovirt4
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Young
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-23 00:00:00.000000000 Z
11
+ date: 2022-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ovirt-engine-sdk
@@ -60,7 +60,6 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".github/FUNDING.yml"
63
- - ".github/workflows/release.yml"
64
63
  - ".gitignore"
65
64
  - ".rspec"
66
65
  - CHANGELOG
@@ -112,10 +111,14 @@ files:
112
111
  - lib/vagrant-ovirt4/provider.rb
113
112
  - lib/vagrant-ovirt4/util.rb
114
113
  - lib/vagrant-ovirt4/util/collection.rb
114
+ - lib/vagrant-ovirt4/util/connection.rb
115
+ - lib/vagrant-ovirt4/util/machine_names.rb
115
116
  - lib/vagrant-ovirt4/util/timer.rb
116
117
  - lib/vagrant-ovirt4/version.rb
117
118
  - locales/en.yml
118
119
  - spec/spec_helper.rb
120
+ - spec/support/shared_context.rb
121
+ - spec/vagrant-ovirt4/action/create_vm_spec.rb
119
122
  - spec/vagrant-ovirt4/action/is_created_spec.rb
120
123
  - spec/vagrant-ovirt4/action/is_running_spec.rb
121
124
  - spec/vagrant-ovirt4/action/message_already_up_spec.rb
@@ -126,7 +129,9 @@ files:
126
129
  - spec/vagrant-ovirt4/action/message_saving_state_spec.rb
127
130
  - spec/vagrant-ovirt4/action/read_ssh_info_spec.rb
128
131
  - spec/vagrant-ovirt4/action/read_state_spec.rb
132
+ - spec/vagrant-ovirt4/action/start_vm_spec.rb
129
133
  - spec/vagrant-ovirt4/config_spec.rb
134
+ - spec/vagrant-ovirt4/util/connection_spec.rb
130
135
  - templates/Vagrantfile.erb
131
136
  - tools/prepare_redhat_for_box.sh
132
137
  - vagrant-ovirt4.gemspec
@@ -134,7 +139,7 @@ homepage: https://github.com/myoung34/vagrant-ovirt4
134
139
  licenses:
135
140
  - MIT
136
141
  metadata: {}
137
- post_install_message:
142
+ post_install_message:
138
143
  rdoc_options: []
139
144
  require_paths:
140
145
  - lib
@@ -149,13 +154,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
154
  - !ruby/object:Gem::Version
150
155
  version: '0'
151
156
  requirements: []
152
- rubygems_version: 3.0.3
153
- signing_key:
157
+ rubygems_version: 3.0.3.1
158
+ signing_key:
154
159
  specification_version: 4
155
160
  summary: This vagrant plugin provides the ability to create, control, and destroy
156
161
  virtual machines under oVirt/RHEV
157
162
  test_files:
158
163
  - spec/spec_helper.rb
164
+ - spec/support/shared_context.rb
165
+ - spec/vagrant-ovirt4/action/create_vm_spec.rb
159
166
  - spec/vagrant-ovirt4/action/is_created_spec.rb
160
167
  - spec/vagrant-ovirt4/action/is_running_spec.rb
161
168
  - spec/vagrant-ovirt4/action/message_already_up_spec.rb
@@ -166,4 +173,6 @@ test_files:
166
173
  - spec/vagrant-ovirt4/action/message_saving_state_spec.rb
167
174
  - spec/vagrant-ovirt4/action/read_ssh_info_spec.rb
168
175
  - spec/vagrant-ovirt4/action/read_state_spec.rb
176
+ - spec/vagrant-ovirt4/action/start_vm_spec.rb
169
177
  - spec/vagrant-ovirt4/config_spec.rb
178
+ - spec/vagrant-ovirt4/util/connection_spec.rb
@@ -1,20 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- push:
5
- paths:
6
- - lib/vagrant-ovirt4/version.rb
7
- branches:
8
- - master
9
- jobs:
10
- build:
11
- runs-on: ubuntu-latest
12
- steps:
13
- - uses: actions/checkout@v2
14
- - uses: fregante/setup-git-user@v1
15
- - name: Release Gem
16
- uses: cadwallion/publish-rubygems-action@master
17
- env:
18
- GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
19
- RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
20
- RELEASE_COMMAND: rake release