Skip to content

Commit

Permalink
extra: refactor 2nodes-qdevice-vip vagrant file
Browse files Browse the repository at this point in the history
  • Loading branch information
ioguix committed Sep 23, 2020
1 parent d55a96b commit 7ac317d
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 413 deletions.
26 changes: 8 additions & 18 deletions extra/vagrant/2nodes-qdevice-vip/Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
export VAGRANT_BOX_UPDATE_CHECK_DISABLE=1
export VAGRANT_CHECKPOINT_DISABLE=1

.PHONY: all create_vm pgsql-primary pgsql-replicas qdevice pacemaker cts prov clean validate
.PHONY: all up pgsql pacemaker cts clean check validate pcmk-stop

all: up

all: create_vm pgsql-replicas pacemaker

create_vm:
up:
vagrant up

pgsql-replicas: pcmk-stop pgsql-primary
vagrant up --provision-with=pgsql-replicas

qdevice:
vagrant up --provision-with=qdevice

pacemaker: qdevice
vagrant up --provision-with=pacemaker

pgsql-primary: pcmk-stop
vagrant up --provision-with=pgsql-primary
pgsql: pcmk-stop
vagrant provision --provision-with=pgsql

prov:
vagrant up --provision
pacemaker:
vagrant provision --provision-with=pacemaker

clean:
vagrant destroy -f
Expand All @@ -37,7 +27,7 @@ validate:
fi

cts:
vagrant up --provision-with=cts
vagrant provision --provision-with=cts

pcmk-stop:
vagrant ssh -c 'if [ -f "/etc/corosync/corosync.conf" ]; then sudo pcs cluster stop --all --wait; fi'
Expand Down
126 changes: 63 additions & 63 deletions extra/vagrant/2nodes-qdevice-vip/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ require 'ipaddr'
require 'yaml'

#ENV['VAGRANT_NO_PARALLEL'] = 'yes' # uncomment to forbid parallel execution
ENV["LANG"] = "C"
ENV["LC_ALL"] = "C"

boxname = 'centos/7' # vagrant box to use
pgver = '11' # pg version to use
hapass = 'hapass' # password for sys user hacluster
ssh_login = 'root' # ssh login to connect to the host when fencing a VM.
# put "./provision/id_rsa.pub" in your "~<ssh_login>/.ssh/authorized_keys"
master_ip = '10.20.30.105' # vIP assigned to master
pg_nodes = 'srv1', 'srv2' # first will be primary
qd_node = 'qd' # name of the node receiving logs
log_node = 'log-sink' # name of the node receiving logs
vm_prefix = 'paf_2nqd' # VM prefix in libvrit
rhel_user = '' # RHEL user account
rhel_pass = '' # RHEL user account password
ENV["LANG"] = "C"
ENV["LC_ALL"] = "C"

boxname = 'centos/7' # vagrant box to use
pgver = '12' # pg version to use
hapass = 'hapass' # password for sys user hacluster


base_ip = '10.20.30.40' # Base IP address to compute other ones
vm_prefix = 'paf_2nqd' # VM prefix in libvrit
rhel_user = '' # RHEL user account
rhel_pass = '' # RHEL user account password
pg_nodes = 'srv1', 'srv2' # first will be primary
log_node = 'log-sink' # name of the node receiving logs
qd_node = 'qd' # name of the qdevice node

if File.file?('vagrant.yml') and ( custom = YAML.load_file('vagrant.yml') )
boxname = custom['boxname'] if custom.has_key?('boxname')
pgver = custom['pgver'] if custom.has_key?('pgver')
hapass = custom['hapass'] if custom.has_key?('hapass')
ssh_login = custom['ssh_login'] if custom.has_key?('ssh_login')
master_ip = custom['master_ip'] if custom.has_key?('master_ip')

base_ip = custom['base_ip'] if custom.has_key?('base_ip')
pg_nodes = custom['pg_nodes'] if custom.has_key?('pg_nodes')
log_node = custom['log_node'] if custom.has_key?('log_node')
vm_prefix = custom['vm_prefix'] if custom.has_key?('vm_prefix')
Expand All @@ -33,16 +33,29 @@ end

Vagrant.configure(2) do |config|

############################################################################
# computes IPs

pgdata = "/var/lib/pgsql/#{pgver}/data"
next_ip = IPAddr.new(master_ip).succ
host_ip = (IPAddr.new(master_ip) & "255.255.255.0").succ.to_s
next_ip = IPAddr.new(base_ip).succ
host_ip = (IPAddr.new(base_ip) & "255.255.255.0").succ.to_s
nodes_ips = {}

( pg_nodes + [ qd_node, log_node ] ).each do |node|
( pg_nodes + [ log_node, qd_node ] ).each do |node|
nodes_ips[node] = next_ip.to_s
next_ip = next_ip.succ
end

############################################################################
# general vagrant setup

# RHEL registration when needed
if Vagrant.has_plugin?('vagrant-registration')
config.registration.unregister_on_halt = false
config.registration.username = rhel_user
config.registration.password = rhel_pass
end

# don't mind about insecure ssh key
config.ssh.insert_key = false

Expand All @@ -58,69 +71,56 @@ Vagrant.configure(2) do |config|
lv.qemu_use_session = false
end

# disable default share
# sync the root of sources
config.vm.synced_folder ".", "/vagrant", disabled: true

config.vm.synced_folder "../../..", "/vagrant", type: "rsync",
rsync__exclude: [ ".git/" ]

config.vm.define pg_nodes.first, primary: true

############################################################################
# system setup for all nodes
(pg_nodes + [qd_node, log_node]).each do |node|

config.vm.provision 'file', source: 'provision/id_rsa', destination: '/home/vagrant/.ssh/id_rsa'
config.vm.provision 'file', source: 'provision/id_rsa.pub', destination: '/home/vagrant/.ssh/id_rsa.pub'

(pg_nodes + [log_node, qd_node]).each do |node|
config.vm.define node do |conf|
conf.vm.network 'private_network', ip: nodes_ips[node]
conf.vm.provision 'system-setup', type: 'shell', path: 'provision/system.bash',
args: [ node, rhel_user, rhel_pass ] + nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
conf.vm.provision 'system', type: 'shell',
path: 'provision/system.bash',
args: [ node, pgver, base_ip, hapass, log_node, qd_node ] +
nodes_ips.keys.map {|n| "#{n}=#{nodes_ips[n]}"},
preserve_order: true
end
end

# setup rsyslog to collect logs from other node on log-sink
config.vm.define log_node do |conf|
conf.vm.provision 'rsyslog-setup', type: 'shell', path: 'provision/log_sink.bash'
end

# common postgresql+pacemaker installation and setup
############################################################################
# build pgsql instances
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'cluster-common', type: 'shell', path: 'provision/cluster-common.bash',
args: [ pgver, hapass, master_ip ],
conf.vm.provision 'pgsql', type: 'shell',
path: 'provision/pgsql.bash',
args: [ node, pgver, pgdata, base_ip, pg_nodes.first ],
preserve_order: true
end
end

# build primary pgsql instance
config.vm.define pg_nodes.first, primary:true do |conf|
conf.vm.provision 'pgsql-primary', type: 'shell',
path: 'provision/pgsql-primary.bash',
args: [ pgver, pgdata, master_ip, pg_nodes.first ],
run: 'never'
end

# replicas setup. Use "vagrant up --provision-with=pgsql-replicas"
pg_nodes[1..-1].each do |node|
config.vm.define node do |conf|
conf.vm.provision 'pgsql-replicas', type: 'shell', path: 'provision/pgsql-replicas.bash',
args: [ pgver, pgdata, master_ip, node ], run: 'never'
end
end

# cluster setup. Use "vagrant up --provision-with=qdevice"
config.vm.define qd_node do |conf|
conf.vm.provision 'qdevice', type: 'shell', path:'provision/qdevice.bash',
args: [ hapass ],
run: 'never'
end

# cluster setup. Use "vagrant up --provision-with=pacemaker"
############################################################################
# cluster setup
pg_nodes.each do |node|
config.vm.define node do |conf|
conf.vm.provision 'pacemaker', type: 'shell', path:'provision/pacemaker.bash',
args: [ pgver, hapass, master_ip, ssh_login,
vm_prefix, host_ip, pgdata, qd_node ] + pg_nodes,
run: 'never'
conf.vm.provision 'pacemaker', type: 'shell',
path: 'provision/pacemaker.bash',
args: [ pgver, hapass, base_ip, pgdata, qd_node ] +
pg_nodes,
preserve_order: true
end
end

# cluster test suite setup. Use "vagrant up --provision-with=cts"
config.vm.provision 'cts', type: 'shell', path: 'provision/cts.bash', run: 'never'
############################################################################
# cluster test suite setup. Use "vagrant provision --provision-with=cts"
config.vm.provision 'cts', type: 'shell',
path: 'provision/cts.bash',
run: 'never'
end
91 changes: 0 additions & 91 deletions extra/vagrant/2nodes-qdevice-vip/provision/cluster-common.bash

This file was deleted.

20 changes: 0 additions & 20 deletions extra/vagrant/2nodes-qdevice-vip/provision/log_sink.bash

This file was deleted.

Loading

0 comments on commit 7ac317d

Please sign in to comment.