Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
include cf_remote/nt-discovery.sh
include cf_remote/Vagrantfile
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
include cf_remote/Vagrantfile
include cf_remote/Vagrantfile

65 changes: 65 additions & 0 deletions cf_remote/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'json'

config_path = File.expand_path("../config.json", __FILE__)
if !File.file?(config_path)
abort "Need a config file for this host at " + config_path
end
config = JSON.parse(File.read(config_path))

VM_BOX = config['box']
VM_COUNT = config['count']
VM_MEMORY = config['memory']
VM_CPUS = config['cpus']
VM_PROVISION = File.expand_path(config['provision'], __FILE__)
VM_NAME = config['name']
SYNC_FOLDER = config['sync_folder']

Vagrant.configure("2") do |config|

(1..VM_COUNT).each do |i|

config.vm.define "#{VM_NAME}-#{i}" do |node|
node.vm.hostname = "#{VM_NAME}-#{i}"
node.vm.network "private_network", ip: "192.168.56.#{9 + i}"
node.vm.box = VM_BOX

node.vm.provision "shell" do |s|
ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
s.inline = <<-SHELL
echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
SHELL
end
node.vm.provision "bootstrap", type: "shell", path: VM_PROVISION
node.vm.synced_folder ".", "/vagrant",
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--links"]
node.vm.synced_folder "#{SYNC_FOLDER}", "/synched_folder",
rsync__args: ["--verbose", "--archive", "--delete", "-z", "--links"]

# https://bugs.launchpad.net/cloud-images/+bug/1874453
NOW = Time.now.strftime("%d.%m.%Y.%H:%M:%S")
FILENAME = "serial-debug-%s.log" % NOW
node.vm.provider "virtualbox" do |vb|
vb.memory = VM_MEMORY
vb.cpus = VM_CPUS
vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding time and dns you might need to include this snippet from jenkins-vms that handles darwin/macos

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L104

vb.customize [ "modifyvm", :id, "--uart1", "0x3F8", "4" ]
vb.customize [ "modifyvm", :id, "--uartmode1", "file",
File.join(Dir.pwd, FILENAME) ]
end

node.vm.provider :libvirt do |v, override|
v.memory = VM_MEMORY
v.cpus = VM_CPUS
# Fedora 30+ uses QEMU sessions by default, breaking pretty much all
# previously working Vagrantfiles:
# https://fedoraproject.org/wiki/Changes/Vagrant_2.2_with_QEMU_Session#Upgrade.2Fcompatibility_impact
v.qemu_use_session = false
override.vm.synced_folder "./", "/vagrant", type: :rsync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

synced folders are also tricky for older distributions like debian-9:

here are some workarounds for centos-7 and old debians:

https://gitlab.com/Northern.tech/CFEngine/jenkins-vms/-/blob/master/scripts/common.rb?ref_type=heads#L151

override.vm.synced_folder "#{SYNC_FOLDER}", "/synched_folder", type: :rsync
end
end
end
end
48 changes: 41 additions & 7 deletions cf_remote/aramid.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,22 @@ def from_str(cls, method_str):
raise ValueError("Invalid or unsupported method '%s' given" % method_str)


def _get_put_method_args(method, host, src, dst):
def _get_put_method_args(method, host, src, dst, config):
port_args = []

config_args = []
if config:
config_args += ["-F", config]

if method == PutMethod.SCP:
if host.port != _DEFAULT_SSH_PORT:
port_args += ["-P", str(host.port)]
return (
["scp", "-r"] + DEFAULT_SSH_ARGS + port_args + [src, host.login + ":" + dst]
["scp", "-r"]
+ config_args
+ DEFAULT_SSH_ARGS
+ port_args
+ [src, host.login + ":" + dst]
)
elif method == PutMethod.RSYNC:
if host.port != _DEFAULT_SSH_PORT:
Expand All @@ -100,7 +109,10 @@ def _get_put_method_args(method, host, src, dst):
"rsync",
"-a",
"-e",
"ssh " + " ".join(DEFAULT_SSH_ARGS + port_args + host.extra_ssh_args),
"ssh "
+ " ".join(
config_args + DEFAULT_SSH_ARGS + port_args + host.extra_ssh_args
),
] + [src, host.login + ":" + dst]
else:
raise ValueError("Invalid or unsupported method '%s' given" % method)
Expand Down Expand Up @@ -302,6 +314,7 @@ def execute(
ignore_failed=False,
echo=True,
echo_cmd=False,
config=None,
): # TODO: parallel=False
"""Execute command on remote hosts (in parallel)
Expand Down Expand Up @@ -337,8 +350,12 @@ def execute(
port_args = []
if host.port != _DEFAULT_SSH_PORT:
port_args += ["-p", str(host.port)]
config_args = []
if config:
config_args += ["-F", config]
proc = subprocess.Popen(
["ssh", host.login]
+ config_args
+ DEFAULT_SSH_ARGS
+ port_args
+ host.extra_ssh_args
Expand All @@ -362,6 +379,7 @@ def execute_commands(
ignore_failed=False,
echo=True,
echo_cmd=True,
config=None,
): # TODO: parallel=False
"""A more flexible version of the :func:`execute` function
Expand Down Expand Up @@ -393,8 +411,12 @@ def execute_commands(
port_args = []
if host.port != _DEFAULT_SSH_PORT:
port_args += ["-p", str(host.port)]
config_args = []
if not config:
config_args += ["-F", config]
proc = subprocess.Popen(
["ssh", host.login]
+ config_args
+ DEFAULT_SSH_ARGS
+ port_args
+ host.extra_ssh_args
Expand All @@ -411,7 +433,13 @@ def execute_commands(


def put(
hosts, src, dst=None, method=PutMethod.SCP, ignore_failed=False, echo=True
hosts,
src,
dst=None,
method=PutMethod.SCP,
ignore_failed=False,
echo=True,
config=None,
): # TODO: parallel=False
"""Copy files to remote hosts
Expand Down Expand Up @@ -451,7 +479,7 @@ def put(
hosts = _hosts_to_host_specs(hosts)
for host in hosts:
proc = subprocess.Popen(
_get_put_method_args(method, host, src, dst),
_get_put_method_args(method, host, src, dst, config),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
Expand All @@ -464,7 +492,13 @@ def put(


def put_to_hosts(
hosts, data, get_src_dst_fn, method=PutMethod.SCP, ignore_failed=False, echo=True
hosts,
data,
get_src_dst_fn,
method=PutMethod.SCP,
ignore_failed=False,
echo=True,
config=None,
):
"""A more flexible version of the :func:`put` function
Expand All @@ -490,7 +524,7 @@ def put_to_hosts(
src, dst = src_dst
dst = dst or src # `dst` defaults to `src`
proc = subprocess.Popen(
_get_put_method_args(method, host, src, dst),
_get_put_method_args(method, host, src, dst, config),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
Expand Down
Loading