-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
321 lines (288 loc) · 12.7 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# frozen_string_literal: true
# -*- mode: ruby -*-
# vi: set ft=ruby :
##############################################################################
# Copyright (c)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
no_proxy = ENV["NO_PROXY"] || ENV["no_proxy"] || "127.0.0.1,localhost"
(1..254).each do |i|
no_proxy += ",10.0.2.#{i}"
end
mirror_ip_address = "192.168.123.3"
ci_ip_address = "192.168.123.4"
cloud_ip_address = "192.168.123.5"
cloud_vip_address = "192.168.123.6"
public_nic = `ip r get 1.1.1.1`.split[4] || "eth0"
cloud_public_cidr = `ip r | grep "dev $(ip r get 1.1.1.1 | awk 'NR==1{print $5}') .* scope link" | awk '{print $1}'`.strip! || "192.168.0.0/24"
cloud_public_gw = `ip r | grep "^default" | awk 'NR==1{print $3}'`.strip! || "192.168.0.1"
fly_version = ENV["PKG_FLY_VERSION"] || "7.7.1"
kubectl_version = "v1.20.7"
kolla_build = ENV.fetch("RELENG_KOLLA_BUILD", nil)
k8s_type = ENV["RELENG_K8S_TYPE"] || "krd"
ci_type = ENV["RELENG_CI_TYPE"] || "tekton"
debug = ENV["RELENG_DEBUG"] || "false"
ci_setup_enabled = "false"
mirror_svc_list = ENV["RELENG_MIRROR_SERVICE_LIST"] || "k8s,devpi,kolla"
mirror_file = ENV["RELENG_MIRROR_FILE"] || "mirror_releng.list"
releng_folder = "/opt/releng/"
def which(cmd)
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
vb_public_nic = `VBoxManage list bridgedifs | grep "^Name:.*#{public_nic}" | awk -F "Name:[ ]*" '{ print $2}'`.strip! if which "VBoxManage"
Vagrant.configure("2") do |config|
config.vm.provider :libvirt
config.vm.provider :virtualbox
config.vm.box = "generic/ubuntu2004"
config.vm.box_check_update = false
config.vm.box_version = "4.3.12"
config.vm.provider "virtualbox" do |v|
v.gui = false
# VirtualBox's NAT gateway will accept DNS traffic from the guest and
# forward it to the resolver used by the host
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
# https://docs.oracle.com/en/virtualization/virtualbox/6.0/user/network_performance.html
v.customize ["modifyvm", :id, "--nictype1", "virtio", "--cableconnected1", "on"]
v.customize ["modifyvm", :id, "--nictype2", "virtio", "--cableconnected2", "on"]
# https://bugs.launchpad.net/cloud-images/+bug/1829625/comments/2
v.customize ["modifyvm", :id, "--uart1", "0x3F8", "4"]
v.customize ["modifyvm", :id, "--uartmode1", "file", File::NULL]
# Enable nested paging for memory management in hardware
v.customize ["modifyvm", :id, "--nestedpaging", "on"]
# Use large pages to reduce Translation Lookaside Buffers usage
v.customize ["modifyvm", :id, "--largepages", "on"]
# Use virtual processor identifiers to accelerate context switching
v.customize ["modifyvm", :id, "--vtxvpid", "on"]
end
config.vm.provider :libvirt do |v|
v.management_network_address = "10.0.2.0/24"
# Administration - Provides Internet access for all nodes and is
# used for administration to install software packages
v.management_network_name = "administration"
v.cpu_mode = "host-passthrough"
v.disk_device = "sda"
v.disk_bus = "sata"
end
if !ENV["http_proxy"].nil? && !ENV["https_proxy"].nil? && Vagrant.has_plugin?("vagrant-proxyconf")
config.proxy.http = ENV["http_proxy"] || ENV["HTTP_PROXY"] || ""
config.proxy.https = ENV["https_proxy"] || ENV["HTTPS_PROXY"] || ""
config.proxy.no_proxy = no_proxy
config.proxy.enabled = { docker: false }
end
config.vm.synced_folder "./common", "#{releng_folder}common", type: "nfs", nfs_version: ENV.fetch("VAGRANT_NFS_VERSION", 4)
config.vm.define :mirror do |mirror|
mirror.vm.hostname = "mirror"
mirror.vm.network :private_network, ip: mirror_ip_address, libvirt__network_name: "management", virtualbox__intnet: true
mirror.vm.synced_folder "./mirror", "/vagrant"
mirror.vm.network :public_network, dev: public_nic, bridge: vb_public_nic
%i[virtualbox libvirt].each do |provider|
mirror.vm.provider provider do |p|
p.cpus = ENV["CPUS"] || 1
p.memory = ENV["MEMORY"] || 512
end
end
# Mirror's volumes
mirror.vm.disk :disk, name: "packages", size: "250GB"
mirror.vm.disk :disk, name: "images", size: "10GB"
mirror.vm.disk :disk, name: "pypi", size: "10GB"
mirror.vm.provider :libvirt do |v, override|
override.vm.synced_folder "./mirror", "/vagrant", type: "nfs", nfs_version: ENV.fetch("VAGRANT_NFS_VERSION", 4)
v.storage :file, bus: "sata", device: "sdb", size: "350G"
v.storage :file, bus: "sata", device: "sdc", size: "10G"
v.storage :file, bus: "sata", device: "sdd", size: "10G"
end
{
"sdb" => "/var/local/packages",
"sdc" => "/var/local/images",
"sdd" => "/var/local/pypi_packages"
}.each do |device, mount_path|
mirror.vm.provision "shell" do |s|
s.path = "pre-install.sh"
s.args = [device, mount_path]
end
end
mirror.vm.provision "shell", privileged: false do |sh|
sh.env = {
PKG_FLY_VERSION: fly_version,
PKG_KUBECTL_VERSION: kubectl_version,
MIRROR_FILENAME: mirror_file,
SVC_LIST: mirror_svc_list,
RELENG_DEBUG: debug,
RELENG_K8S_TYPE: k8s_type,
RELENG_FOLDER: releng_folder,
RELENG_KOLLA_BUILD: kolla_build
}
sh.inline = <<-SHELL
set -o errexit
set -o pipefail
echo "export MIRROR_FILENAME=#{mirror_file}" | sudo tee --append /etc/environment
# Prefer IPv4 over IPv6 in dual-stack environment
sudo sed -i "s|^#precedence ::ffff:0:0/96 100$|precedence ::ffff:0:0/96 100|g" /etc/gai.conf
cd /vagrant/
./install.sh | tee ~/install.log
./deploy.sh | tee ~/deploy.log
for svc in ${SVC_LIST//,/ }; do
./setup_$svc.sh | tee "$HOME/setup_${svc}.log"
done
./post-install.sh | tee ~/post-install.log
curl -s -X GET http://localhost:5000/v2/_catalog
SHELL
end
end
config.vm.define :ci, primary: true, autostart: false do |ci|
ci.vm.hostname = "ci"
ci.vm.network :private_network, ip: ci_ip_address, libvirt__network_name: "management", virtualbox__intnet: true
ci.vm.network :forwarded_port, guest: 80, host: 8080
ci.vm.synced_folder "./ci", "/vagrant"
ci.vm.synced_folder "./", "/opt/releng"
ci.vm.synced_folder "./apt/", "/etc/apt/" if File.exist?("#{File.dirname(__FILE__)}./apt/sources.list")
%i[virtualbox libvirt].each do |provider|
ci.vm.provider provider do |p|
p.cpus = ENV["CPUS"] || 4
p.memory = ENV["MEMORY"] || 16_384
end
end
ci.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--nested-hw-virt", "on"]
end
# CI's volumes
ci.vm.disk :disk, name: "postgresql", size: "10GB"
ci.vm.disk :disk, name: "worker0", size: "25GB"
ci.vm.disk :disk, name: "containers", size: "100GB"
ci.vm.provider :libvirt do |v, override|
override.vm.synced_folder "./ci", "/vagrant", type: "nfs", nfs_version: ENV.fetch("VAGRANT_NFS_VERSION", 4)
v.nested = true
v.storage :file, bus: "sata", device: "sdb", size: "10G"
v.storage :file, bus: "sata", device: "sdc", size: "25G"
v.storage :file, bus: "sata", device: "sdd", size: "100G"
end
{
"sdb" => "/mnt/disks/postgresql",
"sdc" => "/mnt/disks/worker0",
"sdd" => "/var/lib/containers/storage"
}.each do |device, mount_path|
ci.vm.provision "shell" do |s|
s.path = "pre-install.sh"
s.args = [device, mount_path]
end
end
ci.vm.provision "shell", privileged: false do |sh|
sh.env = {
RELENG_DEVPI_HOST: mirror_ip_address,
RELENG_NTP_SERVER: mirror_ip_address
}
sh.path = "install.sh"
end
ci.vm.provision "shell", privileged: false do |sh|
sh.env = {
PKG_DOCKER_REGISTRY_MIRRORS: "\"http://#{mirror_ip_address}:5000\"",
PKG_FLY_VERSION: fly_version,
PKG_KUBECTL_VERSION: kubectl_version,
RELENG_K8S_TYPE: k8s_type,
RELENG_CI_TYPE: ci_type,
RELENG_DEBUG: debug,
RELENG_NTP_SERVER: mirror_ip_address
}
sh.inline = <<-SHELL
set -o errexit
set -o pipefail
for os_var in $(printenv | grep RELENG_); do echo "export $os_var" | sudo tee --append /etc/environment ; done
cd /vagrant/
./provision_${RELENG_K8S_TYPE:-kind}_cluster.sh | tee ~/provision_cluster.log
cd ${RELENG_CI_TYPE}
./deploy.sh | tee ~/deploy.log
if [ "#{ci_setup_enabled}" == "true" ]; then
./setup.sh | tee ~/setup.log
fi
kubectl describe nodes
SHELL
end
end
config.vm.define :cloud, autostart: false do |cloud|
cloud.vm.hostname = "cloud"
# Management/API - Used for communication between the OpenStack
# services.
cloud.vm.network :private_network, ip: cloud_ip_address, libvirt__network_name: "management", virtualbox__intnet: true
cloud.vm.network :forwarded_port, guest_ip: cloud_vip_address, guest: 80, host: 9090
cloud.vm.network :forwarded_port, guest_ip: cloud_vip_address, guest: 6080, host: 6080
cloud.vm.synced_folder "./cloud/openstack", "/opt/openstack-multinode"
# Public - Provides external access to OpenStack services. For
# instances, it provides the route out to the external network and
# the IP addresses to enable inbound connections to the instances.
# This network can also provide the public API endpoints to
# connect to OpenStack services.
cloud.vm.network :public_network, dev: public_nic, bridge: vb_public_nic, auto_config: false
%i[virtualbox libvirt].each do |provider|
cloud.vm.provider provider do |p|
p.cpus = ENV["CPUS"] || 4
p.memory = ENV["MEMORY"] || 32_768
end
end
cloud.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--nested-hw-virt", "on"]
# Cable connected enables you to temporarily disconnect a
# virtual network interface, as if a network cable had been
# pulled from a real network card.
# Performance-wise the virtio network adapter is preferable over
# Intel PRO/1000 emulated adapters.
v.customize ["modifyvm", :id, "--nictype1", "virtio", "--cableconnected1", "on"]
v.customize ["modifyvm", :id, "--nictype2", "virtio", "--cableconnected2", "on"]
v.customize ["modifyvm", :id, "--nictype3", "virtio", "--cableconnected3", "on"]
v.customize ["modifyvm", :id, "--nic3", "natnetwork", "--nat-network3", "public", "--nicpromisc3", "allow-all"]
end
cloud.vm.disk :disk, name: "cinder", size: "50GB"
cloud.vm.provider :libvirt do |v, override|
override.vm.synced_folder "./cloud/openstack", "/opt/openstack-multinode", type: "nfs", nfs_version: ENV.fetch("VAGRANT_NFS_VERSION", 4)
v.nested = true
v.storage :file, bus: "sata", device: "sdb", size: "50G"
end
cloud.vm.provision 'shell', privileged: false, inline: <<-SHELL
set -o errexit
set -o pipefail
cd /opt/openstack-multinode
./node.sh -c /dev/sdb
SHELL
cloud.vm.provision "shell", privileged: false do |sh|
sh.env = {
PKG_DOCKER_REGISTRY_MIRRORS: "\"http://#{mirror_ip_address}:5000\"",
RELENG_DEBUG: debug,
RELENG_CINDER_VOLUME: "/dev/sdb",
RELENG_ENABLE_CINDER: "yes",
RELENG_INTERNAL_VIP_ADDRESS: cloud_vip_address,
RELENG_NETWORK_INTERFACE: "eth1",
RELENG_NEUTRON_EXTERNAL_INTERFACE: "eth2",
RELENG_NTP_SERVER: mirror_ip_address,
RELENG_DEVPI_HOST: mirror_ip_address,
RELENG_FOLDER: releng_folder,
OS_KOLLA_NEUTRON_EXTERNAL_INTERFACE: "eth2",
EXT_NET_RANGE: "start=#{cloud_public_cidr.sub('0/24', '50')},end=#{cloud_public_cidr.sub('0/24', '100')}",
EXT_NET_CIDR: cloud_public_cidr.to_s,
EXT_NET_GATEWAY: cloud_public_gw.to_s
}
sh.inline = <<-SHELL
set -o errexit
set -o pipefail
sudo ip link set $RELENG_NEUTRON_EXTERNAL_INTERFACE promisc on
echo "127.0.0.1 localhost" | sudo tee /etc/hosts
for os_var in $(printenv | grep "RELENG_|EXT_NET_" ); do
echo "export $os_var" | sudo tee --append /etc/environment
done
source /etc/os-release || source /usr/lib/os-release
export OS_KOLLA_KOLLA_BASE_DISTRO=${ID,,}
echo "127.0.0.1 localhost" | sudo tee /etc/hosts
cd /opt/openstack-multinode
./install.sh
SHELL
end
end
end