Skip to content

Commit 73e9bd8

Browse files
committed
Added vagrant vm spawning provider
Ticket: ENT-5725 Signed-off-by: Victor Moene <victor.moene@northern.tech>
1 parent 0617c6d commit 73e9bd8

File tree

10 files changed

+557
-155
lines changed

10 files changed

+557
-155
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
include cf_remote/nt-discovery.sh
2+
include cf_remote/Vagrantfile

cf_remote/Vagrantfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
require 'json'
4+
5+
config_path = File.expand_path("../config.json", __FILE__)
6+
if !File.file?(config_path)
7+
abort "Need a config file for this host at " + config_path
8+
end
9+
config = JSON.parse(File.read(config_path))
10+
11+
VM_BOX = config['box']
12+
VM_COUNT = config['count']
13+
VM_MEMORY = config['memory']
14+
VM_CPUS = config['cpus']
15+
VM_PROVISION = File.expand_path(config['provision'], __FILE__)
16+
VM_NAME = config['name']
17+
SYNC_FOLDER = config['sync_folder']
18+
19+
Vagrant.configure("2") do |config|
20+
21+
(1..VM_COUNT).each do |i|
22+
23+
config.vm.define "#{VM_NAME}-#{i}" do |node|
24+
node.vm.hostname = "#{VM_NAME}-#{i}"
25+
node.vm.network "private_network", ip: "192.168.56.#{9 + i}"
26+
node.vm.box = VM_BOX
27+
28+
node.vm.provision "shell" do |s|
29+
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
30+
s.inline = <<-SHELL
31+
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
32+
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
33+
SHELL
34+
end
35+
node.vm.provision "bootstrap", type: "shell", path: VM_PROVISION
36+
node.vm.synced_folder ".", "/vagrant",
37+
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--links"]
38+
node.vm.synced_folder "#{SYNC_FOLDER}", "/synched_folder",
39+
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--links"]
40+
41+
# https://bugs.launchpad.net/cloud-images/+bug/1874453
42+
NOW = Time.now.strftime("%d.%m.%Y.%H:%M:%S")
43+
FILENAME = "serial-debug-%s.log" % NOW
44+
node.vm.provider "virtualbox" do |vb|
45+
vb.memory = VM_MEMORY
46+
vb.cpus = VM_CPUS
47+
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
48+
vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
49+
vb.customize [ "modifyvm", :id, "--uartmode1", "file",
50+
File.join(Dir.pwd, FILENAME) ]
51+
end
52+
53+
node.vm.provider :libvirt do |v, override|
54+
v.memory = VM_MEMORY
55+
v.cpus = VM_CPUS
56+
# Fedora 30+ uses QEMU sessions by default, breaking pretty much all
57+
# previously working Vagrantfiles:
58+
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact
59+
v.qemu_use_session = false
60+
override.vm.synced_folder "./", "/vagrant", type: :rsync
61+
override.vm.synced_folder "#{SYNC_FOLDER}", "/synched_folder", type: :rsync
62+
end
63+
end
64+
end
65+
end

cf_remote/aramid.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,22 @@ def from_str(cls, method_str):
8585
raise ValueError("Invalid or unsupported method '%s' given" % method_str)
8686

8787

88-
def _get_put_method_args(method, host, src, dst):
88+
def _get_put_method_args(method, host, src, dst, config):
8989
port_args = []
90+
91+
config_args = []
92+
if config:
93+
config_args += ["-F", config]
94+
9095
if method == PutMethod.SCP:
9196
if host.port != _DEFAULT_SSH_PORT:
9297
port_args += ["-P", str(host.port)]
9398
return (
94-
["scp", "-r"] + DEFAULT_SSH_ARGS + port_args + [src, host.login + ":" + dst]
99+
["scp", "-r"]
100+
+ config_args
101+
+ DEFAULT_SSH_ARGS
102+
+ port_args
103+
+ [src, host.login + ":" + dst]
95104
)
96105
elif method == PutMethod.RSYNC:
97106
if host.port != _DEFAULT_SSH_PORT:
@@ -100,7 +109,10 @@ def _get_put_method_args(method, host, src, dst):
100109
"rsync",
101110
"-a",
102111
"-e",
103-
"ssh " + " ".join(DEFAULT_SSH_ARGS + port_args + host.extra_ssh_args),
112+
"ssh "
113+
+ " ".join(
114+
config_args + DEFAULT_SSH_ARGS + port_args + host.extra_ssh_args
115+
),
104116
] + [src, host.login + ":" + dst]
105117
else:
106118
raise ValueError("Invalid or unsupported method '%s' given" % method)
@@ -302,6 +314,7 @@ def execute(
302314
ignore_failed=False,
303315
echo=True,
304316
echo_cmd=False,
317+
config=None,
305318
): # TODO: parallel=False
306319
"""Execute command on remote hosts (in parallel)
307320
@@ -337,8 +350,12 @@ def execute(
337350
port_args = []
338351
if host.port != _DEFAULT_SSH_PORT:
339352
port_args += ["-p", str(host.port)]
353+
config_args = []
354+
if config:
355+
config_args += ["-F", config]
340356
proc = subprocess.Popen(
341357
["ssh", host.login]
358+
+ config_args
342359
+ DEFAULT_SSH_ARGS
343360
+ port_args
344361
+ host.extra_ssh_args
@@ -362,6 +379,7 @@ def execute_commands(
362379
ignore_failed=False,
363380
echo=True,
364381
echo_cmd=True,
382+
config=None,
365383
): # TODO: parallel=False
366384
"""A more flexible version of the :func:`execute` function
367385
@@ -393,8 +411,12 @@ def execute_commands(
393411
port_args = []
394412
if host.port != _DEFAULT_SSH_PORT:
395413
port_args += ["-p", str(host.port)]
414+
config_args = []
415+
if not config:
416+
config_args += ["-F", config]
396417
proc = subprocess.Popen(
397418
["ssh", host.login]
419+
+ config_args
398420
+ DEFAULT_SSH_ARGS
399421
+ port_args
400422
+ host.extra_ssh_args
@@ -411,7 +433,13 @@ def execute_commands(
411433

412434

413435
def put(
414-
hosts, src, dst=None, method=PutMethod.SCP, ignore_failed=False, echo=True
436+
hosts,
437+
src,
438+
dst=None,
439+
method=PutMethod.SCP,
440+
ignore_failed=False,
441+
echo=True,
442+
config=None,
415443
): # TODO: parallel=False
416444
"""Copy files to remote hosts
417445
@@ -451,7 +479,7 @@ def put(
451479
hosts = _hosts_to_host_specs(hosts)
452480
for host in hosts:
453481
proc = subprocess.Popen(
454-
_get_put_method_args(method, host, src, dst),
482+
_get_put_method_args(method, host, src, dst, config),
455483
stdout=subprocess.PIPE,
456484
stderr=subprocess.PIPE,
457485
universal_newlines=True,
@@ -464,7 +492,13 @@ def put(
464492

465493

466494
def put_to_hosts(
467-
hosts, data, get_src_dst_fn, method=PutMethod.SCP, ignore_failed=False, echo=True
495+
hosts,
496+
data,
497+
get_src_dst_fn,
498+
method=PutMethod.SCP,
499+
ignore_failed=False,
500+
echo=True,
501+
config=None,
468502
):
469503
"""A more flexible version of the :func:`put` function
470504
@@ -490,7 +524,7 @@ def put_to_hosts(
490524
src, dst = src_dst
491525
dst = dst or src # `dst` defaults to `src`
492526
proc = subprocess.Popen(
493-
_get_put_method_args(method, host, src, dst),
527+
_get_put_method_args(method, host, src, dst, config),
494528
stdout=subprocess.PIPE,
495529
stderr=subprocess.PIPE,
496530
universal_newlines=True,

0 commit comments

Comments
 (0)