blob: 3ffa6a36890cf23d8494c7a8148272bfde597fae [file] [log] [blame]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +01001# -*- mode: ruby -*-
2# -*- coding: utf-8 -*-
3
4host_ip = "192.168.121.1"
5operator_key = "${HOME}/.ssh/onap-key"
6vagrant_user = "vagrant"
7vagrant_password = "vagrant"
8synced_folder_main = "/vagrant"
9synced_folder_config = "#{synced_folder_main}/config"
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +010010synced_folder_tools_config = "#{synced_folder_main}/tools/config"
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +010011os_config = "#{synced_folder_config}/local.conf"
Pawel Wieczorek0d01b782019-12-09 16:20:45 +010012os_env = "#{synced_folder_config}/dot_env"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010013cluster_yml = "cluster.yml"
14apt_prefs_dir = "/etc/apt/apt.conf.d"
15apt_prefs = "95silent-approval"
16
Pawel Wieczorek3cb78212019-12-09 16:00:47 +010017vm_memory = 1 * 1024
Pawel Wieczorek73862e42020-01-24 11:58:07 +010018vm_memory_os = 4 * 1024
19vm_memory_onap = 20 * 1024
Pawel Wieczorek3cb78212019-12-09 16:00:47 +010020vm_cpu = 1
Pawel Wieczorek73862e42020-01-24 11:58:07 +010021vm_cpus = 4
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010022vm_box = "generic/ubuntu1804"
Pawel Wieczorek3fbeaf02020-01-24 17:52:23 +010023vm_disk = 32
24vm_disk_onap = 64
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010025
Pawel Wieczorek3fbeaf02020-01-24 17:52:23 +010026operation = {
27 name: 'operator',
28 hostname: 'operator',
29 ip: '172.17.4.254',
30 cpus: vm_cpu,
31 memory: vm_memory,
32 disk: vm_disk
33}
34devstack = {
35 name: 'devstack',
36 hostname: 'devstack',
37 ip: '172.17.4.200',
38 cpus: vm_cpu,
39 memory: vm_memory_os,
40 disk: vm_disk
41}
42control = {
43 name: 'control',
44 hostname: 'control',
45 ip: '172.17.4.100',
46 cpus: vm_cpu,
47 memory: vm_memory,
48 disk: vm_disk
49}
50worker = {
51 name: 'worker',
52 hostname: 'worker',
53 ip: '172.17.4.101',
54 cpus: vm_cpus,
55 memory: vm_memory_onap,
56 disk: vm_disk_onap
57}
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010058
Pawel Wieczorek3cb78212019-12-09 16:00:47 +010059cluster = [] << control << worker
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +010060all = cluster.dup << operation << devstack
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010061
Pawel Wieczorek0d01b782019-12-09 16:20:45 +010062operation_post_msg = "Run: \"vagrant provision #{operation[:name]} --provision-with=rke_up,setup_kubectl,setup_helm_cluster,setup_helm_repo,deploy_onap\" to complete ONAP deployment"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010063
64$replace_dns = <<-SCRIPT
65 HOST_IP="$1"
66 rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved
67 echo nameserver "$HOST_IP" | tee /etc/resolv.conf
68SCRIPT
69
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +010070$enable_ipv6 = <<-SCRIPT
71 sed -i'' 's/net.ipv6.conf.all.disable_ipv6.*$/net.ipv6.conf.all.disable_ipv6 = 0/' /etc/sysctl.conf
72 sysctl -p
73SCRIPT
74
75$setup_devstack = <<-SCRIPT
76 CONFIG="$1"
77 git clone https://opendev.org/openstack/devstack
78 cd devstack
79 cp "$CONFIG" .
80 ./stack.sh
81SCRIPT
82
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +010083$add_to_docker_group = <<-SCRIPT
84 USER="$1"
85 echo "Adding ${USER} to 'docker' group"
86 usermod -aG docker "$USER"
87SCRIPT
88
89$setup_debconf = <<-SCRIPT
90 echo "Setting debconf frontend to noninteractive"
91 sed -i'.orig' '/^Config:/a Frontend: noninteractive' /etc/debconf.conf
92SCRIPT
93
94$install_sshpass = <<-SCRIPT
95 apt-get update
96 echo "Installing 'sshpass'"
97 apt-get install sshpass
98SCRIPT
99
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100100$install_make = <<-SCRIPT
101 apt-get update
102 echo "Installing 'make'"
103 apt-get install make
104SCRIPT
105
Pawel Wieczorek3fbeaf02020-01-24 17:52:23 +0100106$resize_disk = <<-SCRIPT
107 DEV=${1:-sda}
108 PART=${2:-3}
109 echo ", +" | sfdisk -N "$PART" "/dev/$DEV" --no-reread
110 partprobe
111 resize2fs "/dev/${DEV}${PART}"
112SCRIPT
113
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100114$generate_key = <<-SCRIPT
115 KEY_FILE="$1"
116 echo "Generating SSH key (${KEY_FILE})"
117 ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N ""
118SCRIPT
119
120$deploy_key = <<-SCRIPT
121 KEY="$1"
122 USER="$2"
123 PASS="$PASSWORD"
124 IPS="$3"
125 echo "Deploying ${KEY} for ${USER}"
126 for ip in $IPS; do
127 echo "on ${ip}"
128 sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}"
129 done
130SCRIPT
131
132$link_dotfiles = <<-SCRIPT
133 SYNC_DIR="$1"
134 for rc in ${SYNC_DIR}/dot_*; do
135 src="$rc"
136 dst="${HOME}/.${rc##*dot_}"
137 echo "Symlinking ${src} to ${dst}"
138 ln -sf "$src" "$dst"
139 done
140SCRIPT
141
142$link_file = <<-SCRIPT
143 SYNC_DIR="$1"
144 FILE="$2"
145 src="${SYNC_DIR}/${FILE}"
146 dst="$3"
147 echo "Symlinking ${src} to ${dst}"
148 ln -sf "$src" "$dst"
149SCRIPT
150
151$rke_up = "rke up"
Pawel Wieczorek33649802020-01-27 17:32:20 +0100152$rke_down = "rke remove --force || true" # best effort
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100153
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100154$get_oom = <<-SCRIPT
155 BRANCH="${1:-5.0.1-ONAP}"
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100156 REPO="${2:-https://git.onap.org/oom}"
157 git clone -b "$BRANCH" "$REPO" --recurse-submodules
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100158SCRIPT
159
Pawel Wieczorek6efe9412020-01-07 15:28:55 +0100160$get_helm_plugins = "mkdir -p ${HOME}/.helm && cp -R ${HOME}/oom/kubernetes/helm/plugins/ ${HOME}/.helm"
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100161
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100162$setup_helm_cluster = <<-SCRIPT
163 export KUBECONFIG="${HOME}/.kube/config.onap"
164 kubectl config use-context onap
165 kubectl -n kube-system create serviceaccount tiller
166 kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
167 helm init --service-account tiller
168 kubectl -n kube-system rollout status deploy/tiller-deploy
169SCRIPT
170
171# FIXME: replace sleep command with helm repo readiness probe
172$setup_helm_repo = <<-SCRIPT
173 helm serve &
174 sleep 3
175 helm repo add local http://127.0.0.1:8879
176 make -C ${HOME}/oom/kubernetes all
177 make -C ${HOME}/oom/kubernetes onap
178SCRIPT
179
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100180$deploy_onap = <<-SCRIPT
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100181 OVERRIDE="${1:-${HOME}/oom/kubernetes/onap/resources/environments/minimal-onap.yaml}"
182
183 ENV="${2:-#{os_env}}"
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100184 export $(cat "$ENV" | xargs)
185
186 encrypt () {
187 KEY="${HOME}/oom/kubernetes/so/resources/config/mso/encryption.key"
188 echo -n "$1" \
189 | openssl aes-128-ecb -e -K `cat "$KEY"` -nosalt \
190 | xxd -c 256 -p
191 }
192
193 export OPENSTACK_ENCRYPTED_PASSWORD="$(encrypt $OPENSTACK_PASSWORD)"
194
195 export KUBECONFIG="${HOME}/.kube/config.onap"
196
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100197 helm deploy minimal local/onap --namespace onap -f "$OVERRIDE" --verbose --timeout 900
198SCRIPT
199
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100200Vagrant.configure('2') do |config|
201 all.each do |machine|
202 config.vm.define machine[:name] do |config|
203 config.vm.box = vm_box
204 config.vm.hostname = machine[:hostname]
205
206 config.vm.provider :virtualbox do |v|
207 v.name = machine[:name]
Pawel Wieczorek3cb78212019-12-09 16:00:47 +0100208 v.memory = machine[:memory]
209 v.cpus = machine[:cpus]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100210 end
211
212 config.vm.provider :libvirt do |v|
Pawel Wieczorek3cb78212019-12-09 16:00:47 +0100213 v.memory = machine[:memory]
214 v.cpus = machine[:cpus]
Pawel Wieczorek3fbeaf02020-01-24 17:52:23 +0100215 v.machine_virtual_size = machine[:disk] # set at VM creation
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100216 end
217
218 config.vm.network :private_network, ip: machine[:ip]
219 config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip
220
Pawel Wieczorekdf0edea2019-11-29 16:18:36 +0100221 if machine[:name] == 'devstack'
222 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile"
223
224 config.vm.provision "enable_ipv6", type: :shell, run: "always", inline: $enable_ipv6
225 config.vm.provision "setup_devstack", type: :shell, privileged: false, inline: $setup_devstack, args: os_config
226 end
227
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100228 if machine[:name] == 'control'
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100229 config.vm.provision "customize_control", type: :shell, path: "tools/imported/openstack-k8s-controlnode.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100230 config.vm.provision "fix_groups_control", type: :shell, inline: $add_to_docker_group, args: vagrant_user
231 end
232
233 if machine[:name] == 'worker'
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100234 config.vm.provision "customize_worker", type: :shell, path: "tools/imported/openstack-k8s-workernode.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100235 config.vm.provision "fix_group_worker", type: :shell, inline: $add_to_docker_group, args: vagrant_user
Pawel Wieczorek3fbeaf02020-01-24 17:52:23 +0100236 config.vm.provision "resize_disk", type: :shell, inline: $resize_disk
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100237 end
238
239 if machine[:name] == 'operator'
Pawel Wieczorekba88f292020-01-27 17:34:05 +0100240 config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: ["Vagrantfile", "operator"]
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100241 config.vm.synced_folder "~/.ssh", "/home/#{vagrant_user}/.ssh", type: "rsync", rsync__exclude: "authorized_keys"
Pawel Wieczorekb0accc32020-01-16 16:21:02 +0100242 config.vm.synced_folder "./operator", "/home/#{vagrant_user}", type: "sshfs", reverse: true, sshfs_opts_append: "-o nonempty"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100243
244 config.vm.provision "setup_debconf", type: :shell, inline: $setup_debconf
245 config.vm.provision "link_apt_prefs", type: :shell, run: "always" do |s|
246 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100247 s.args = [synced_folder_tools_config, apt_prefs, apt_prefs_dir]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100248 end
249 config.vm.provision "link_dotfiles_root", type: :shell, run: "always" do |s|
250 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100251 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100252 end
253 config.vm.provision "link_dotfiles_user", type: :shell, run: "always" do |s|
254 s.privileged = false
255 s.inline = $link_dotfiles
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100256 s.args = synced_folder_tools_config
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100257 end
258
259 config.vm.provision "install_sshpass", type: :shell, inline: $install_sshpass
260 config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: operator_key
261
262 ips = ""
263 cluster.each { |node| ips << node[:ip] << " " }
264 config.vm.provision "deploy_key", type: :shell do |s|
265 s.privileged = false
266 s.inline = $deploy_key
267 s.args = [operator_key, vagrant_user, ips]
268 s.env = {'PASSWORD': vagrant_password}
269 end
270
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100271 config.vm.provision "get_rke", type: :shell, path: "tools/get_rke.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100272 config.vm.provision "link_cluster_yml", type: :shell, run: "always" do |s|
273 s.privileged = false
274 s.inline = $link_file
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100275 s.args = [synced_folder_config, cluster_yml, "$HOME"]
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100276 end
277
278 config.vm.post_up_message = operation_post_msg
279 config.vm.provision "rke_up", type: :shell, run: "never", privileged: false, inline: $rke_up
280 config.trigger.before :destroy do |trigger|
281 trigger.warn = "Removing cluster"
282 trigger.run_remote = {privileged: false, inline: $rke_down}
283 end
284
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100285 config.vm.provision "get_kubectl", type: :shell, path: "tools/get_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100286 config.vm.provision "setup_kubectl", type: :shell, run: "never" do |s|
287 s.privileged = false
Pawel Wieczorek55c0c9d2019-11-29 15:23:43 +0100288 s.path = "tools/setup_kubectl.sh"
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100289 end
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100290 config.vm.provision "get_helm", type: :shell, path: "tools/get_helm.sh"
Pawel Wieczorekdc298f12020-01-23 17:55:17 +0100291 config.vm.provision "get_oom", type: :shell do |s|
292 s.privileged = false
293 s.inline = $get_oom
294 end
Pawel Wieczorekf1176da2019-12-05 13:45:45 +0100295 config.vm.provision "get_helm_plugins", type: :shell, privileged: false, inline: $get_helm_plugins
Pawel Wieczorek0664ac42019-12-09 16:16:48 +0100296 config.vm.provision "install_make", type: :shell, inline: $install_make
297 config.vm.provision "setup_helm_cluster", type: :shell, run: "never", privileged: false, inline: $setup_helm_cluster
298 config.vm.provision "setup_helm_repo", type: :shell, run: "never", privileged: false, inline: $setup_helm_repo
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100299 config.vm.provision "deploy_onap", type: :shell, run: "never" do |s|
300 s.privileged = false
301 s.inline = $deploy_onap
Pawel Wieczorek0d01b782019-12-09 16:20:45 +0100302 end
Pawel Wieczorek216bd6a2019-11-29 15:15:51 +0100303 end
304 end
305 end
306end