kitchen-qemu 0.2.0 → 0.2.1
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 +4 -4
- data/lib/kitchen/driver/qemu.rb +30 -9
- data/lib/kitchen/driver/qemu_version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e90136f51889ebc9d9061dbbe2211746ef3d1f6
|
4
|
+
data.tar.gz: 3cc82a8034acdc525ae04d017b74f7aecc5a1fa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d93624e70a7c938103cab552902e656f7ff0f0e81f16d5c2a35a1bdb2eaeb69924d6548b6f0c03cff6acda2d9ba4c278118153f4ae60ebe8476eef8224d45c56
|
7
|
+
data.tar.gz: 81e0ed59f7c674b6d8feeb65cd3cf27b560491a08d054f310c6945381c91d3c4a105bb4eb796cb73a1db01a50cba84f895f2cee0cbd67b21088fc881d652ac55
|
data/lib/kitchen/driver/qemu.rb
CHANGED
@@ -15,6 +15,7 @@
|
|
15
15
|
# along with kitchen-qemu. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
|
17
17
|
require 'open3'
|
18
|
+
require 'socket'
|
18
19
|
|
19
20
|
require 'kitchen'
|
20
21
|
require 'kitchen/driver/qemu_version'
|
@@ -36,7 +37,8 @@ module Kitchen
|
|
36
37
|
default_config :arch, 'x86_64'
|
37
38
|
default_config :username, 'kitchen'
|
38
39
|
default_config :password, 'kitchen'
|
39
|
-
default_config :
|
40
|
+
default_config :port_min, 1025
|
41
|
+
default_config :port_max, 65535
|
40
42
|
default_config :display, 'none'
|
41
43
|
default_config :memory, '512'
|
42
44
|
default_config :nic_model, 'virtio'
|
@@ -134,12 +136,6 @@ module Kitchen
|
|
134
136
|
fqdn = config[:hostname] || instance.name
|
135
137
|
hostname = fqdn.match(/^([^.]+)/)[0]
|
136
138
|
|
137
|
-
state[:hostname] = 'localhost'
|
138
|
-
state[:port] = config[:port]
|
139
|
-
state[:username] = config[:username]
|
140
|
-
state[:password] = config[:password]
|
141
|
-
state[:acpi_poweroff] = config[:acpi_poweroff]
|
142
|
-
|
143
139
|
cmd = [
|
144
140
|
config[:binary], '-daemonize',
|
145
141
|
'-display', config[:display].to_s,
|
@@ -147,8 +143,6 @@ module Kitchen
|
|
147
143
|
'-mon', 'chardev=mon-qmp,mode=control,default',
|
148
144
|
'-serial', "mon:unix:path=#{serial_path},server,nowait",
|
149
145
|
'-m', config[:memory].to_s,
|
150
|
-
'-net', "nic,model=#{config[:nic_model]}",
|
151
|
-
'-net', "user,net=192.168.1.0/24,hostname=#{hostname},hostfwd=tcp::#{state[:port]}-:22",
|
152
146
|
]
|
153
147
|
|
154
148
|
kvm = config[:kvm]
|
@@ -193,6 +187,13 @@ module Kitchen
|
|
193
187
|
'-device', "virtio-9p-pci,fsdev=fsdev#{i},mount_tag=path#{i}")
|
194
188
|
end
|
195
189
|
|
190
|
+
port = config[:port]
|
191
|
+
port = random_free_port('127.0.0.1', config[:port_min], config[:port_max]) if port.nil?
|
192
|
+
cmd.push(
|
193
|
+
'-net', "nic,model=#{config[:nic_model]}",
|
194
|
+
'-net', "user,net=192.168.1.0/24,hostname=#{hostname},hostfwd=tcp::#{port}-:22",
|
195
|
+
)
|
196
|
+
|
196
197
|
info 'Spawning QEMU..'
|
197
198
|
error = nil
|
198
199
|
Open3.popen3({ 'QEMU_AUDIO_DRV' => 'none' }, *cmd) do |_, _, err, thr|
|
@@ -205,6 +206,12 @@ module Kitchen
|
|
205
206
|
raise ActionFailed, error
|
206
207
|
end
|
207
208
|
|
209
|
+
state[:hostname] = '127.0.0.1'
|
210
|
+
state[:port] = port
|
211
|
+
state[:username] = config[:username]
|
212
|
+
state[:password] = config[:password]
|
213
|
+
state[:acpi_poweroff] = config[:acpi_poweroff]
|
214
|
+
|
208
215
|
if hostname == fqdn
|
209
216
|
names = fqdn
|
210
217
|
else
|
@@ -318,6 +325,20 @@ tY4IM9IaSC2LuPFVc0Kx6TwObdeQScOokIxL3HfayfLKieTLC+w2
|
|
318
325
|
File.open(path, File::CREAT|File::TRUNC|File::RDWR, 0600) { |f| f.write(@@PRIVKEY) }
|
319
326
|
end
|
320
327
|
|
328
|
+
def random_free_port(host, min, max)
|
329
|
+
loop do
|
330
|
+
port = rand(max - min) + min
|
331
|
+
begin
|
332
|
+
serv = TCPServer.new(host, port)
|
333
|
+
rescue Errno::EADDRINUSE
|
334
|
+
# do nothing
|
335
|
+
else
|
336
|
+
serv.close
|
337
|
+
return port
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
321
342
|
def cleanup!
|
322
343
|
begin
|
323
344
|
File.delete(monitor_path)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-qemu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Renner Berthing
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|