-
Notifications
You must be signed in to change notification settings - Fork 107
/
Vagrantfile
93 lines (84 loc) · 3.31 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'yaml'
Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
def extract_id(env)
id = env.map do |env_var|
env_var[/^SALT_NODE_ID=(?<node_id>.+)$/, "node_id"]
end.compact
id[0]
end
def is_salt_master(id)
# The ideal way of doing this would be to ask Salt, which minions will
# execute the `salt/master.sls` state file during a highstate? However,
# it is not possible to do that from Vagrant outside the VM, and parsing
# the top.sls is also not a good idea because there are Salt intracacies
# like compound matching. Hence, simply hardcode this regex for now.
# This should be kept in sync with the top.sls file.
!id.match(/servo-master\d+/).nil?
end
# Need Vagrant >= 2.0.0 for `salt_call_args`
Vagrant.require_version('>= 2.0.0')
Vagrant.configure(2) do |config|
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :machine
end
dir = File.dirname(__FILE__)
test_pillars_path = File.join(dir, '.travis', 'test_pillars')
YAML.load_file(File.join(dir, '.travis.yml'))['matrix']['include'].map do |node|
node_config = case node['os']
when 'linux'
case node['dist']
when 'trusty'
{ id: extract_id(node['env']), os: node['os'], box: 'ubuntu/trusty64' }
when 'xenial'
{ id: extract_id(node['env']), os: node['os'], box: 'ubuntu/xenial64' }
when 'bionic'
{ id: extract_id(node['env']), os: node['os'], box: 'ubuntu/bionic64' }
end
end
if node_config.nil?
if ENV['VAGRANT_LOG'] == 'debug'
version = node.has_key?('dist') ? ', version' + node['dist'] : ''
os_and_version = node['os'] + version
puts "OS #{os_and_version} is not yet supported"
end
elsif node_config[:id] != 'test'
node_config
end
end.compact.uniq.each do |node|
config.vm.define node[:id] do |machine|
machine.vm.box = node[:box]
machine.vm.provider :virtualbox do |vbox|
# Need extra memory for downloading large files (e.g. Android SDK)
vbox.memory = 1024
vbox.linked_clone = true
end
if is_salt_master(node[:id])
# Salt master directories are hardcoded because we'd need to run Salt
# to resolve the configuration stored in the salt/map.jinja file.
# Make sure to keep these values in sync with that file.
# Note that because gitfs always reflects the master branch on GitHub,
# the states dir is synced to the override location instead to allow
# testing out changes locally.
machine.vm.synced_folder dir, '/tmp/salt-testing-root/saltfs'
machine.vm.synced_folder test_pillars_path, '/srv/pillar'
end
machine.vm.provision :salt do |salt|
salt.bootstrap_script = File.join(dir, '.travis', 'install_salt.sh')
salt.install_args = node[:os] # Pass OS type to bootstrap script
salt.masterless = true
salt.minion_config = File.join(dir, '.travis', 'minion')
# hack to provide additional options to salt-call
salt.minion_id = node[:id]
salt.salt_call_args = [
'--file-root=/vagrant',
'--pillar-root=/vagrant/.travis/test_pillars',
'--retcode-passthrough'
]
salt.run_highstate = true
salt.verbose = true
salt.log_level = 'info'
salt.colorize = true
end
end
end
end