Added Vagrant images to run CSIT.
authorBen Eze <beze@inocybe.ca>
Thu, 18 Jun 2015 14:20:55 +0000 (10:20 -0400)
committerFlavio Fernandes <ffernand@redhat.com>
Fri, 19 Jun 2015 00:46:59 +0000 (20:46 -0400)
Change-Id: I147cb90878f8f8af6d535b2b15988e9221777a4c
Signed-off-by: Gabriel Robitaille-Montpetit <grmontpetit@inocybe.com>
Signed-off-by: Ben Eze <beze@inocybe.ca>
resources/robot/README.md [new file with mode: 0644]
resources/robot/Vagrantfile [new file with mode: 0644]
resources/robot/puppet/manifests/dependencies.pp [new file with mode: 0644]
resources/robot/puppet/manifests/ovsnode.pp [new file with mode: 0644]
resources/robot/puppet/manifests/ovsnode_build.pp [new file with mode: 0644]
resources/robot/puppet/scripts/clear_ovs.sh [new file with mode: 0755]
resources/robot/puppet/scripts/setup_defaults.sh [new file with mode: 0644]

diff --git a/resources/robot/README.md b/resources/robot/README.md
new file mode 100644 (file)
index 0000000..55872b7
--- /dev/null
@@ -0,0 +1,14 @@
+# Purpose
+Creates VMs running CentOS 7.0 x64 with OpenVSwitch.
+Please use the Vagrant environment variable OVS_NODES to set the number of VMs that would be created. Default value is 2 (ovs1 and ovs2).
+
+# About the included OVS rpm
+To improve provisioning time, "openvswitch-2.3.1-1.x86_64.rpm" is pulled from dropbox. You can add rpm files for other OVS version if desired. Default ovs version is 2.3.1.
+
+To build ovs for the VMs from source, open the vagrant file and make changes to :
+
+Line 19: ovsversion = "<desired_ovs_release>"
+Line 50: puppet.manifest_file  = "ovsnode_build.pp"
+
+
+
diff --git a/resources/robot/Vagrantfile b/resources/robot/Vagrantfile
new file mode 100644 (file)
index 0000000..3bedd17
--- /dev/null
@@ -0,0 +1,63 @@
+# -*- mode: ruby -*-
+# # vi: set ft=ruby :
+
+# Specify minimum Vagrant version and Vagrant API version
+Vagrant.require_version ">= 1.6.0"
+VAGRANTFILE_API_VERSION = "2"
+
+# Create boxes
+Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
+
+    # Get the number of OVS VMs to create
+    num_ovs_vms = (ENV['OVS_NODES'] || 2).to_i
+
+    base_name = "ovs"
+    base_ip = "192.168.100."
+    controller_ip = "192.168.100.10"
+    os = "puppetlabs/centos-7.0-64-puppet"
+    ram = "512"
+    ovsversion = "2.3.1"
+    ovs_node_ips = num_ovs_vms.times.collect { |n| base_ip + "#{n+21}" }
+
+    num_ovs_vms.times do |n|
+    config.vm.define base_name + "#{n+1}", autostart: true do |srv|
+          ## Extract yaml variables
+          hostname = base_name + "#{n+1}"
+          local_ip = ovs_node_ips[n]
+
+              srv.vm.hostname = hostname
+          srv.vm.box = os
+          srv.vm.network "private_network", ip: local_ip
+          srv.vm.provider :virtualbox do |vb|
+        vb.name = hostname
+        vb.memory = ram
+          end # vb
+
+          # Set guest environment variables
+          command1 = 'export CONTROLLER=\"' + controller_ip + '\"'
+          command2 = 'export LOCAL_IP=\"' + local_ip + '\"'
+          srv.vm.provision :shell, privileged: true, inline: 'echo ' + command1 + ' >> /etc/profile'
+          srv.vm.provision :shell, privileged: true, inline: 'echo ' + command2 + ' >> /etc/profile'
+          srv.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
+
+          ## SSH config
+          srv.ssh.forward_x11 = false
+
+          ## puppet
+          srv.vm.provision "puppet" do |puppet|
+        puppet.working_directory = "/vagrant/puppet"
+        puppet.manifests_path = "puppet/manifests"
+        puppet.manifest_file  = "ovsnode.pp"
+        puppet.options = "--verbose --debug"
+        puppet.facter = {
+          "ovsversion" => ovsversion,
+        }
+          end # puppet
+
+
+          #process setup commands for ovs
+          srv.vm.provision "shell", path: "puppet/scripts/setup_defaults.sh"
+
+        end # srv
+    end #end num_ovs_vms
+end # config
diff --git a/resources/robot/puppet/manifests/dependencies.pp b/resources/robot/puppet/manifests/dependencies.pp
new file mode 100644 (file)
index 0000000..c264b40
--- /dev/null
@@ -0,0 +1,21 @@
+  $base_packages = [
+    "kernel-headers",
+    "kernel-devel",
+    "gcc",
+    "make",
+    "python-devel",
+    "openssl-devel",
+    "graphviz",
+    "kernel-debug-devel",
+    "automake",
+    "rpm-build",
+    "redhat-rpm-config",
+    "libtool",
+    "git"
+  ]
+
+  package { $base_packages:
+    ensure => installed,
+  }
+
+  notice("Dependencies are ready!")
diff --git a/resources/robot/puppet/manifests/ovsnode.pp b/resources/robot/puppet/manifests/ovsnode.pp
new file mode 100644 (file)
index 0000000..400442e
--- /dev/null
@@ -0,0 +1,39 @@
+  notice("specified ovs version to install: ${ovsversion}")
+
+  exec { "mktarget":
+    command => "/bin/mkdir -p /vagrant/shared/",
+    cwd     => "/",
+  }
+
+  file { [
+           "/vagrant/shared/",
+         ]:
+    ensure => directory,
+  }
+
+  exec { "download_ovs":
+    command => "/usr/bin/wget https://www.dropbox.com/s/v34fbw6t0mvtoi8/openvswitch-${ovsversion}-1.x86_64.rpm?dl=0 -O /vagrant/shared/openvswitch-${ovsversion}-1.x86_64.rpm",
+    cwd     => "/root",
+    creates => "/vagrant/shared/openvswitch-${ovsversion}-1.x86_64.rpm",
+    require => [
+                  Exec["mktarget"],
+               ],
+  }
+
+  exec { "install_ovs":
+    command => "yum localinstall -y /vagrant/shared/openvswitch-${ovsversion}-1.x86_64.rpm",
+    cwd => "/root",
+    path    => ["/bin", "/usr/bin"],
+    require => [
+                  Exec["download_ovs"],
+               ],
+  }
+
+  exec { "start_ovs":
+    command => "systemctl start openvswitch.service",
+    require => [
+                  Exec["install_ovs"],
+               ],
+    cwd => "/root",
+    path    => ["/bin", "/usr/bin"],
+  }
diff --git a/resources/robot/puppet/manifests/ovsnode_build.pp b/resources/robot/puppet/manifests/ovsnode_build.pp
new file mode 100644 (file)
index 0000000..8fe0050
--- /dev/null
@@ -0,0 +1,88 @@
+  import 'dependencies.pp'
+
+  notice("specified ovs version to install: ${ovsversion}")
+
+  exec { "mksource":
+    command => "/bin/mkdir -p /rpmbuild/SOURCES/",
+    cwd     => "/",
+  }
+
+  file { [
+           "/rpmbuild/",
+           "/rpmbuild/SOURCES/",
+         ]:
+    ensure => directory,
+  }
+
+  exec { "download_ovs":
+    command => "wget http://openvswitch.org/releases/openvswitch-${ovsversion}.tar.gz -O /root/openvswitch-${ovsversion}.tar.gz",
+    creates => "/root/openvswitch-${ovsversion}.tar.gz",
+    cwd    => "/root",
+    path    => ["/bin", "/usr/bin"],
+  }
+
+  exec { "check_presence":
+    command => "true",
+    onlyif  => "/usr/bin/test -e /rpmbuild/SOURCES",
+    path    => ["/bin", "/usr/bin"],
+  }
+
+  exec { "copy_archive":
+    command => "cp /root/openvswitch-${ovsversion}.tar.gz /rpmbuild/SOURCES/openvswitch-${ovsversion}.tar.gz",
+    require => [
+                  Exec["mksource"],
+                  Exec["download_ovs"],
+                  Exec["check_presence"],
+               ],
+    cwd    => "/root",
+    creates => "/rpmbuild/SOURCES/openvswitch-${ovsversion}.tar.gz",
+    path    => ["/bin", "/usr/bin"],
+  }
+
+  exec { "extract_ovs":
+    command => "tar xvfz /root/openvswitch-${ovsversion}.tar.gz",
+    require => [
+                  Exec["copy_archive"],
+               ],
+    path    => ["/bin", "/usr/bin"],
+    cwd     => "/root",
+    creates => "/root/openvswitch-${ovsversion}/README",
+  }
+
+  exec { "custom_sed":
+    command => "sed 's/openvswitch-kmod, //g' /root/openvswitch-${ovsversion}/rhel/openvswitch.spec > /root/openvswitch-${ovsversion}/rhel/openvswitch_no_kmod.spec",
+    require => [
+                  Exec["extract_ovs"],
+               ],
+    cwd => "/root",
+    path    => ["/bin", "/usr/bin"],
+  }
+
+  exec { "build_ovs":
+    command => "rpmbuild -bb --nocheck /root/openvswitch-${ovsversion}/rhel/openvswitch_no_kmod.spec",
+    cwd => "/root",
+    path    => ["/bin", "/usr/bin"],
+    require => [
+                  Exec["custom_sed"],
+               ],
+    timeout     => 0,
+    creates => "/root/rpmbuild/RPMS/x86_64/openvswitch-${ovsversion}-1.x86_64.rpm",
+  }
+
+  exec { "install_ovs":
+    command => "yum localinstall -y /rpmbuild/RPMS/x86_64/openvswitch-${ovsversion}-1.x86_64.rpm",
+    cwd => "/root",
+    path    => ["/bin", "/usr/bin"],
+    require => [
+                  Exec["build_ovs"],
+               ],
+  }
+
+  exec { "start_ovs":
+    command => "systemctl start openvswitch.service",
+    require => [
+                  Exec["install_ovs"],
+               ],
+    cwd => "/root",
+    path    => ["/bin", "/usr/bin"],
+  }
diff --git a/resources/robot/puppet/scripts/clear_ovs.sh b/resources/robot/puppet/scripts/clear_ovs.sh
new file mode 100755 (executable)
index 0000000..e48d6d6
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+#
+
+sudo service openvswitch-switch stop
+sudo rm -rf /var/log/openvswitch/*
+sudo rm -rf /etc/openvswitch/conf.db
+sudo service openvswitch-switch start
+
diff --git a/resources/robot/puppet/scripts/setup_defaults.sh b/resources/robot/puppet/scripts/setup_defaults.sh
new file mode 100644 (file)
index 0000000..577ff48
--- /dev/null
@@ -0,0 +1,11 @@
+# add a bridge
+sudo ovs-vsctl add-br ovs-br0
+
+# add a port to the bridge
+#sudo ovs-vsctl add-port ovs-br0 eth1
+
+# link the bridge the controller
+sudo ovs-vsctl set-controller ovs-br0 tcp:$CONTROLLER:6633
+
+# link the controller as a manager
+sudo ovs-vsctl set-manager tcp:$CONTROLLER:6640