Merge branch 'master' of git://git.pcp.io/kenj/pcp into kenj-merge
[pcp.git] / Vagrantfile
blob09b8efdfcf1f3cbbfba64c12496cb2216b394bc9
1 # -*- mode: ruby -*-
2 # vi: set ft=ruby :
4 # Leave this alone
5 VAGRANTFILE_API_VERSION = "2"
7 # VM Configs
8 VM_MEM = "1024"
9 VM_CPU = "1"
11 # QA Flags
12 QA_FLAGS = ""
13 #QA_FLAGS = "022"
14 #QA_FLAGS = "-g pmda.linux"
17 # Arch Specific Config Files
19 ############################################################
20 # CentOS
21 ############################################################
22 $script_centos = <<SCRIPT
24 # Setup EPEL
25 cat <<EOM >/etc/yum.repos.d/epel-bootstrap.repo
26 [epel]
27 name=Bootstrap EPEL
28 mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-\\\$releasever&arch=\\\$basearch
29 failovermethod=priority
30 enabled=0
31 gpgcheck=0
32 EOM
34 yum --enablerepo=epel -y install epel-release
35 rm -f /etc/yum.repos.d/epel-bootstrap.repo
37 yum -y groupinstall 'Development Tools'
38 yum -y install git ncurses-devel readline-devel man libmicrohttpd-devel qt4-devel python26 python26-devel perl-JSON sysstat perl-TimeDate \
39                 perl-XML-TokeParser perl-ExtUtils-MakeMaker perl-Time-HiRes systemd-devel bc cairo-devel cyrus-sasl-devel \
40                 systemd-devel libibumad-devel libibmad-devel papi-devel libpfm-devel rpm-devel perl-Spreadsheet-WriteExcel \
41                 perl-Text-CSV_XS bind-utils httpd python-devel nspr-devel nss-devel python-ctypes nss-tools perl-Spreadsheet-XLSX \
42                 ed cpan valgrind time xdpyinfo rrdtool-perl
44 # Lots of avahi errors on Centos511, likely due to my environment
45 # avahi-devel
47 cd /vagrant
48 sudo -H -u vagrant env PYTHON=python2.6 ./Makepkgs
49 rpm -ivh  pcp-*/build/rpm/*.rpm
51 # Doesn't start automatically on all distributions
52 /sbin/service pmcd start
54 echo 'pcpqa   ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
56 SCRIPT
58 ############################################################
59 # SUSE
60 ############################################################
61 $script_suse = <<SCRIPT
62 zypper -n in -t pattern devel_basis devel_C_C++ devel_rpm_build
63 zypper -n in git ncurses-devel readline-devel man libmicrohttpd-devel libqt4-devel perl-JSON sysstat perl-TimeDate perl-ExtUtils-MakeMaker bc \
64                 cyrus-sasl-devel systemd-devel avahi-devel rpm-devel  perl-Text-CSV_XS \
65                 bind-utils python-devel python-curses
67 # These dont have the right "provides" in opensuse
68 # libibumad-devel libibmad-devel papi-devel libpfm-devel
70 #SUSE doesn't get the right perms in /vagrant, hmm
71 chown -R vagrant /vagrant
73 cd /vagrant
74 sudo -H -u vagrant ./Makepkgs
75 rpm -ivh  pcp-*/build/rpm/*.rpm
77 # Doesn't start automatically on all distributions
78 /sbin/service pmcd start
80 echo 'pcpqa   ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
82 SCRIPT
84 ############################################################
85 # Ubuntu
86 ############################################################
87 $script_ubuntu = <<SCRIPT
88 apt-get update
89 # Use a regex for some of the more obscure packages so apt doesn't exit if missing
90 # Trying to not have one script per box
91 apt-get install -y  '^(libreadline|libpapi|libpfm4|libcoin80|libicu)-dev$' \
92         bc bison curl flex  git  g++  dpkg-dev  pkg-config  debhelper chrpath \
93         python-all  python-all-dev  libnspr4-dev  libnss3-dev  libsasl2-dev  libmicrohttpd-dev  libavahi-common-dev \
94         libqt4-dev  autotools-dev  autoconf  gawk  libxml-tokeparser-perl  libspreadsheet-read-perl gdb sysv-rc-conf \
95         libcairo2-dev sysstat valgrind apache2 realpath unbound \
96         libibumad-dev libsoqt-dev libsoqt-dev-common libnss3-tools libibmad-dev x11-utils
98 cd /vagrant
99 sudo -H -u vagrant ./Makepkgs
100 dpkg -i build/deb/*.deb
102 echo 'pcpqa   ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
104 SCRIPT
106 ############################################################
107 # Ubuntu EOL
108 ############################################################
109 $script_EOLubuntu = <<SCRIPT
111 # Fix the repo names
112 sed -i.bak -r 's/(us.)?(archive|security).ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
114 apt-get update
115 apt-get install  -y '^(libreadline|libpapi|libpfm4|libcoin80|libicu)-dev$' \
116         bc bison curl flex  git  g++  dpkg-dev  pkg-config  debhelper chrpath \
117         python-all  python-all-dev  libnspr4-dev  libnss3-dev  libsasl2-dev  libmicrohttpd-dev  libavahi-common-dev \
118         libqt4-dev  autotools-dev  autoconf  gawk  libxml-tokeparser-perl  libspreadsheet-read-perl gdb sysv-rc-conf \
119         libcairo2-dev sysstat valgrind apache2 realpath unbound \
120         libibumad-dev libsoqt-dev libsoqt-dev-common libnss3-tools libibmad-dev x11-utils
122 cd /vagrant
123 sudo -H -u vagrant ./Makepkgs
124 dpkg -i build/deb/*.deb
126 echo 'pcpqa   ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
128 SCRIPT
130 ############################################################
131 # Debian
132 ############################################################
133 $script_debian = <<SCRIPT
134 apt-get update
135 apt-get install -y '^(libreadline|libpapi|libpfm4|libcoin80)-dev$' \
136                 bc bison  flex  git  g++  dpkg-dev  pkg-config  debhelper chrpath \
137                 python-all  python-all-dev  libnspr4-dev  libnss3-dev  libsasl2-dev  libmicrohttpd-dev  libavahi-common-dev \
138                 libqt4-dev  autotools-dev  autoconf  gawk  libxml-tokeparser-perl libspreadsheet-read-perl ed gdb sysv-rc-conf \
139                 libcairo2-dev libibumad-dev libibmad-dev sysstat valgrind apache2 realpath unbound libsoqt-dev \
140                 libsoqt-dev-common libnss3-tools x11-utils
142 cd /vagrant
143 sudo -H -u vagrant ./Makepkgs
144 dpkg -i build/deb/*.deb
146 echo 'pcpqa   ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
148 SCRIPT
150 ############################################################
151 # Fedora
152 ############################################################
153 $script_fedora = <<SCRIPT
155 # For sudo to work from a script
156 sed -i '/requiretty/d' /etc/sudoers 
158 yum -y group install 'Development Tools' 'C Development Tools and Libraries' 'RPM Development Tools'
159 yum -y install perl-ExtUtils-MakeMaker bison flex libmicrohttpd-devel qt-devel fedora-packager systemd-devel perl-JSON \
160                 sysstat perl-Digest-MD5 bc ed cpan cairo-devel cyrus-sasl-devel libibumad-devel libibmad-devel avahi-devel \
161                 papi-devel libpfm-devel rpm-devel perl-TimeDate perl-XML-TokeParser perl-Spreadsheet-WriteExcel \
162                 perl-Text-CSV_XS bind-utils httpd python-devel nspr-devel nss-devel perl-Spreadsheet-XLSX time xorg-x11-utils
164 # Remove too old libraries
165 pfmvers=`rpm -q --qf "%{VERSION}\n" libpfm`
166 [ "$pfmvers" = "`echo -e "$pfmvers\n4.3.9" | sort -V | head -n1`" ] && rpm -e libpfm libpfm-devel papi papi-devel
168 cd /vagrant
169 sudo -H -u vagrant ./Makepkgs
170 rpm -ivh  pcp-*/build/rpm/*.rpm
172 # Doesn't start automatically on all distributions
173 /sbin/service pmcd start
175 echo 'pcpqa   ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
177 SCRIPT
179 ############################################################
180 # Host Definititions
181 ############################################################
183 pcp_hosts = {
184         :ubuntu1204 => {
185                 :hostname => "ubuntu1204",
186                 :ipaddress => "10.100.10.10",
187                 :box => "ubuntu/precise64",
188                 :script => "#{$script_ubuntu}"
189         },
190         :ubuntu1304 => {
191                 :hostname => "ubuntu1304",
192                 :ipaddress => "10.100.10.11",
193                 :box => "chef/ubuntu-13.04",
194                 :script => "#{$script_EOLubuntu}"
195         },
196         :ubuntu1404 => {
197                 :hostname => "ubuntu1404",
198                 :ipaddress => "10.100.10.12",
199                 :box => "ubuntu/trusty64",
200                 :script => "#{$script_ubuntu}"
201         },
202         :centos511 => {
203                 :hostname => "centos511",
204                 :ipaddress => "10.100.10.20",
205                 :box => "chef/centos-5.11",
206                 :script => "#{$script_centos}"
207         },
208         :centos511_32 => {
209                 :hostname => "centos511-32",
210                 :ipaddress => "10.100.10.21",
211                 :box => "chef/centos-5.11-i386",
212                 :script => "#{$script_centos}"
213         },
214         :centos65 => {
215                 :hostname => "centos65",
216                 :ipaddress => "10.100.10.22",
217                 :box => "chef/centos-6.5",
218                 :script => "#{$script_centos}"
219         },
220         :centos7 => {
221                 :hostname => "centos7",
222                 :ipaddress => "10.100.10.23",
223                 :box => "chef/centos-7.0",
224                 :script => "#{$script_centos}"
225         },
226         :fedora19 => {
227                 :hostname => "fedora19",
228                 :ipaddress => "10.100.10.30",
229                 :box => "chef/fedora-19",
230                 :script => "#{$script_fedora}"
231         },
232         :fedora20 => {
233                 :hostname => "fedora20",
234                 :ipaddress => "10.100.10.31",
235                 :box => "chef/fedora-20",
236                 :script => "#{$script_fedora}"
237         },
238         :debian76 => {
239                 :hostname => "debian76",
240                 :ipaddress => "10.100.10.40",
241                 :box => "chef/debian-7.6",
242                 :script => "#{$script_debian}"
243         }
244 # Built locally from : https://github.com/opscode/bento
245 # NAT comes up but not the host interface
246 #        :opensuse132 => {
247 #                :hostname => "opensuse132",
248 #                :ipaddress => "10.100.10.51",
249 #                :box => "minnus-opensuse-13.2",
250 #                :script => "#{$script_suse}"
251 #        }
252 # Networking wont come up
253 #        :opensuse131 => {
254 #                :hostname => "opensuse131",
255 #                :ipaddress => "10.100.10.50",
256 #                :box => "chef/opensuse-13.1",
257 #                :script => "#{$script_suse}"
258 #        }
261 ############################################################
262 # Common Config Setup, hostnames, etc
263 # So VMs could talk to each other if we wanted
264 ############################################################
266 $script_common = ""
268 # We set our own IP
269 $script_common << "sed -i '/127.0.1.1/d' /etc/hosts\n"
270 # Fix bogus entries that some os use
271 $script_common << "sed -i '/127.0.0.1/d' /etc/hosts\n"
272 $script_common << "echo \"127.0.0.1 localhost.localdomain localhost\" >> /etc/hosts\n"
274 pcp_hosts.each_pair do |name, options|
275         ipaddr = options[:ipaddress]
276         hostname = options[:hostname]
277         $script_common << "echo \"#{ipaddr} #{hostname} #{hostname}.localdomain\" >> /etc/hosts\n"
280 $script_common << "domainname localdomain"
282 ############################################################
283 # QA run script
284 ############################################################
286 $script_qa = <<SCRIPT
288 touch /tmp/runqa.sh
289 echo "#!/bin/sh" >> /tmp/runqa.sh
290 echo "cd /var/lib/pcp/testsuite" >> /tmp/runqa.sh
291 echo "./check #{QA_FLAGS} >/tmp/runqa.out 2>&1" >> /tmp/runqa.sh
292 echo "cp /tmp/runqa.out /qaresults" >> /tmp/runqa.sh
293 echo "cp /var/lib/pcp/testsuite/*.bad /qaresults" >> /tmp/runqa.sh
295 chmod 777 /tmp/runqa.sh
296 sudo -b -H -u pcpqa sh -c '/tmp/runqa.sh'
298 SCRIPT
300 ############################################################
301 # Main Vagrant Init : Loop over Host configs
302 ############################################################
304 Vagrant.configure(VAGRANTFILE_API_VERSION) do |global_config|
306   global_config.ssh.forward_x11 = true
307   global_config.ssh.forward_agent = true
308   global_config.ssh.insert_key = false
311   if Vagrant.has_plugin?("vagrant-cachier")
312     global_config.cache.scope = :box
313   end
315   # Global shared folder for pcp source.  Copy it so we have our own to muck around in
316   global_config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync_auto: false, :rsync__exclude => ["qaresults/"]
318   pcp_hosts.each_pair do |name, options|
320         global_config.vm.define name do |config|
322            config.vm.provider "virtualbox" do |v|
323                 v.name = "Vagrant PCP - #{name}"
324                 v.customize ["modifyvm", :id, "--groups", "/VagrantPCP", "--memory", VM_MEM, "--cpus", VM_CPU]
325            end
327            config.vm.box = options[:box]
328            
329            # VM specific shared folder for qa results
330            config.vm.synced_folder "./qaresults/#{name}", "/qaresults", mount_options: ["dmode=777", "fmode=666"], create: true
332            #config.vm.hostname = "#{name}"
333            config.vm.hostname = "#{options[:hostname]}"
334            config.vm.network :private_network, ip: options[:ipaddress]
336            # Setup networking etc
337            config.vm.provision :shell, :inline => $script_common
339            # Do platfrom specifics: install packages, etc
340            config.vm.provision :shell, :inline => options[:script]
342            # Run QA and copy results back to host
343            config.vm.provision :shell, :inline => $script_qa
344         end
345   end