Merge "Refactoring build system to support Fuel 6.1"
authorStefan K. Berg <stefan.k.berg@ericsson.com>
Mon, 14 Sep 2015 11:47:17 +0000 (11:47 +0000)
committerGerrit Code Review <gerrit@172.30.200.206>
Mon, 14 Sep 2015 11:47:18 +0000 (11:47 +0000)
foreman/ci/Vagrantfile
foreman/ci/deploy.sh
foreman/ci/opnfv_ksgen_settings.yml
foreman/ci/opnfv_ksgen_settings_no_HA.yml
foreman/ci/resize_lvm.sh [new file with mode: 0755]
foreman/ci/resize_partition.sh [new file with mode: 0755]
foreman/ci/vm_nodes_provision.sh

index 5550976..c7dfc03 100644 (file)
@@ -80,10 +80,11 @@ Vagrant.configure(2) do |config|
   #   sudo apt-get update
   #   sudo apt-get install -y apache2
   # SHELL
-  
+
   config.ssh.username = 'root'
   config.ssh.password = 'vagrant'
   config.ssh.insert_key = 'true'
+  config.vm.provision :shell, path: "resize_partition.sh"
   config.vm.provision "ansible" do |ansible|
      ansible.playbook = "reload_playbook.yml"
   end
@@ -97,4 +98,5 @@ Vagrant.configure(2) do |config|
     config.vm.provision :shell, :inline => "systemctl stop dhcpd"
     config.vm.provision :shell, :inline => "systemctl disable dhcpd"
   end
+  config.vm.provision :shell, path: "resize_lvm.sh"
 end
index 29ad83c..83d1b81 100755 (executable)
@@ -29,6 +29,8 @@ declare -A controllers_ip_arr
 declare -A admin_ip_arr
 declare -A public_ip_arr
 
+vagrant_box_dir=~/.vagrant.d/boxes/opnfv-VAGRANTSLASH-centos-7.0/1.0.0/virtualbox/
+vagrant_box_vmdk=box-disk1.vmdk
 vm_dir=/var/opt/opnfv
 script=`realpath $0`
 ##END VARS
@@ -509,7 +511,8 @@ configure_network() {
     echo "${blue}Detecting network configuration...${reset}"
     ##detect host 1 or 3 interface configuration
     #output=`ip link show | grep -E "^[0-9]" | grep -Ev ": lo|tun|virbr|vboxnet" | awk '{print $2}' | sed 's/://'`
-    output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
+    #output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | cut -d " " -f10`
+    output=`/bin/ls -l /sys/class/net | tail -n +2 | grep -v virtual | awk {'print $9'}`
   fi
 
   if [ ! "$output" ]; then
@@ -1023,6 +1026,19 @@ start_virtual_nodes() {
       node_type=config_nodes_${node}_type
       node_type=$(eval echo \$$node_type)
 
+      ##modify memory and cpu
+      node_memory=$(eval echo \${config_nodes_${node}_memory})
+      node_vcpus=$(eval echo \${config_nodes_${node}_cpus})
+      node_storage=$(eval echo \${config_nodes_${node}_disk})
+
+      sed -i 's/^.*vb.memory =.*$/     vb.memory = '"$node_memory"'/' Vagrantfile
+      sed -i 's/^.*vb.cpus =.*$/     vb.cpus = '"$node_vcpus"'/' Vagrantfile
+
+      if ! resize_vagrant_disk $node_storage; then
+        echo "${red}Error while resizing vagrant box to size $node_storage for $node! ${reset}"
+        exit 1
+      fi
+
       ##trozet test make compute nodes wait 20 minutes
       if [ "$compute_wait_completed" = false ] && [ "$node_type" != "controller" ]; then
         echo "${blue}Waiting 20 minutes for Control nodes to install before continuing with Compute nodes..."
@@ -1091,8 +1107,12 @@ start_virtual_nodes() {
 
       ##modify provisioning to do puppet install, config, and foreman check-in
       ##substitute host_name and dns_server in the provisioning script
-      host_string=config_nodes_${node}_hostname
-      host_name=$(eval echo \$$host_string)
+      host_string=config_nodes_${node}_short_name
+      short_host_name=$(eval echo \$$host_string)
+      ##substitute domain_name
+      domain_name=$config_domain_name
+      sed -i 's/^domain_name=REPLACE/domain_name='$domain_name'/' vm_nodes_provision.sh
+      host_name=${short_host_name}.${domain_name}
       sed -i 's/^host_name=REPLACE/host_name='$host_name'/' vm_nodes_provision.sh
       ##dns server should be the foreman server
       sed -i 's/^dns_server=REPLACE/dns_server='${interface_ip_arr[0]}'/' vm_nodes_provision.sh
@@ -1101,11 +1121,6 @@ start_virtual_nodes() {
       sed -i 's/bootstrap.sh/vm_nodes_provision.sh/' Vagrantfile
       ## modify default_gw to be node_default_gw
       sed -i 's/^.*default_gw =.*$/  default_gw = '\""$node_default_gw"\"'/' Vagrantfile
-      ## modify VM memory to be 4gig
-      ##if node type is controller
-      if [ "$node_type" == "controller" ]; then
-        sed -i 's/^.*vb.memory =.*$/     vb.memory = 4096/' Vagrantfile
-      fi
       echo "${blue}Starting Vagrant Node $node! ${reset}"
       ##stand up vagrant
       if ! vagrant up; then
@@ -1226,6 +1241,77 @@ check_baremetal_nodes() {
   fi
 }
 
+##resizes vagrant disk (cannot shrink)
+##params: size in GB
+##usage: resize_vagrant_disk 100
+resize_vagrant_disk() {
+  if [[ "$1" < 40 ]]; then
+    echo "${blue}Warn: Requested disk size cannot be less than 40, using 40 as new size${reset}"
+    new_size_gb=40
+  else
+    new_size_gb=$1
+  fi
+
+  if ! vagrant box list | grep opnfv; then
+    vagrant box remove -f opnfv/centos-7.0
+    if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
+      echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
+      exit 1
+    fi
+  fi
+
+  pushd $vagrant_box_dir
+
+  # Close medium to make sure we can modify it
+  vboxmanage closemedium disk $vagrant_box_vmdk
+
+  cur_size=$(vboxmanage showhdinfo $vagrant_box_vmdk | grep -i capacity | grep -Eo [0-9]+)
+  cur_size_gb=$((cur_size / 1024))
+
+  if [ "$cur_size_gb" -eq "$new_size_gb" ]; then
+    echo "${blue}Info: Disk size already ${cur_size_gb} ${reset}"
+    popd
+    return
+  elif [[ "$new_size_gb" < "$cur_size_gb" ]] ; then
+    echo "${blue}Info: Requested disk is less than ${cur_size_gb} ${reset}"
+    echo "${blue}Re-adding vagrant box${reset}"
+    if vagrant box list | grep opnfv; then
+      popd
+      vagrant box remove -f opnfv/centos-7.0
+      if ! vagrant box add opnfv/centos-7.0 --provider virtualbox; then
+        echo "${red}Unable to reclone vagrant box! Exiting...${reset}"
+        exit 1
+      fi
+      pushd $vagrant_box_dir
+    fi
+  fi
+
+  new_size=$((new_size_gb * 1024))
+  if ! vboxmanage clonehd $vagrant_box_vmdk tmp-disk.vdi --format vdi; then
+    echo "${red}Error: Unable to clone ${vagrant_box_vmdk}${reset}"
+    popd
+    return 1
+  fi
+
+  if ! vboxmanage modifyhd tmp-disk.vdi --resize $new_size; then
+    echo "${red}Error: Unable modify tmp-disk.vdi to ${new_size}${reset}"
+    popd
+    return 1
+  fi
+
+  if  ! vboxmanage clonehd tmp-disk.vdi resized-disk.vmdk --format vmdk; then
+    echo "${red}Error: Unable clone tmp-disk.vdi to vmdk${reset}"
+    popd
+    return 1
+  fi
+
+  vboxmanage closemedium disk tmp-disk.vdi --delete
+  rm -f tmp-disk.vdi $vagrant_box_vmdk
+  cp -f resized-disk.vmdk $vagrant_box_vmdk
+  vboxmanage closemedium disk resized-disk.vmdk --delete
+  popd
+}
+
 ##END FUNCTIONS
 
 main() {
index b41a41b..a6d2207 100644 (file)
@@ -45,6 +45,7 @@ global_params:
 network_type: multi_network
 default_gw:
 no_dhcp: false
+domain_name: opnfv.com
 foreman:
   seed_values:
     - { name: heat_cfn, oldvalue: true, newvalue: false }
@@ -100,8 +101,8 @@ workaround_vif_plugging: false
 openstack_packstack_rpm: http://REPLACE_ME/brewroot/packages/openstack-puppet-modules/2013.2/9.el6ost/noarch/openstack-puppet-modules-2013.2-9.el6ost.noarch.rpm
 nodes:
   compute:
-    name: oscompute11.opnfv.com
-    hostname: oscompute11.opnfv.com
+    name: oscompute11.{{ domain_name }}
+    hostname: oscompute11.{{ domain_name }}
     short_name: oscompute11
     type: compute
     host_type: baremetal
@@ -114,6 +115,9 @@ nodes:
     admin_ip: compute_admin
     ansible_ssh_pass: "Op3nStack"
     admin_password: ""
+    cpus: 2
+    memory: 2048
+    disk: 40
     groups:
     - compute
     - foreman_nodes
@@ -121,8 +125,8 @@ nodes:
     - rdo
     - neutron
   controller1:
-    name: oscontroller1.opnfv.com
-    hostname: oscontroller1.opnfv.com
+    name: oscontroller1.{{ domain_name }}
+    hostname: oscontroller1.{{ domain_name }}
     short_name: oscontroller1
     type: controller
     host_type: baremetal
@@ -137,6 +141,9 @@ nodes:
     private_mac: "10:23:45:67:87:AC"
     ansible_ssh_pass: "Op3nStack"
     admin_password: "octopus"
+    cpus: 2
+    memory: 4096
+    disk: 40
     groups:
     - controller
     - foreman_nodes
@@ -144,8 +151,8 @@ nodes:
     - rdo
     - neutron
   controller2:
-    name: oscontroller2.opnfv.com
-    hostname: oscontroller2.opnfv.com
+    name: oscontroller2.{{ domain_name }}
+    hostname: oscontroller2.{{ domain_name }}
     short_name: oscontroller2
     type: controller
     host_type: baremetal
@@ -160,6 +167,9 @@ nodes:
     private_mac: "10:23:45:67:87:AD"
     ansible_ssh_pass: "Op3nStack"
     admin_password: "octopus"
+    cpus: 2
+    memory: 4096
+    disk: 40
     groups:
     - controller
     - foreman_nodes
@@ -167,8 +177,8 @@ nodes:
     - rdo
     - neutron
   controller3:
-    name: oscontroller3.opnfv.com
-    hostname: oscontroller3.opnfv.com
+    name: oscontroller3.{{ domain_name }}
+    hostname: oscontroller3.{{ domain_name }}
     short_name: oscontroller3
     type: controller
     host_type: baremetal
@@ -183,6 +193,9 @@ nodes:
     private_mac: "10:23:45:67:87:AE"
     ansible_ssh_pass: "Op3nStack"
     admin_password: "octopus"
+    cpus: 2
+    memory: 4096
+    disk: 40
     groups:
     - controller
     - foreman_nodes
index 79db257..71d3108 100644 (file)
@@ -12,6 +12,7 @@ global_params:
 network_type: multi_network
 default_gw:
 no_dhcp: false
+domain_name: opnfv.com
 foreman:
   seed_values:
     - { name: heat_cfn, oldvalue: true, newvalue: false }
@@ -67,8 +68,8 @@ workaround_vif_plugging: false
 openstack_packstack_rpm: http://REPLACE_ME/brewroot/packages/openstack-puppet-modules/2013.2/9.el6ost/noarch/openstack-puppet-modules-2013.2-9.el6ost.noarch.rpm
 nodes:
   compute:
-    name: oscompute11.opnfv.com
-    hostname: oscompute11.opnfv.com
+    name: oscompute11.{{ domain_name }}
+    hostname: oscompute11.{{ domain_name }}
     short_name: oscompute11
     type: compute
     host_type: baremetal
@@ -81,6 +82,9 @@ nodes:
     admin_ip: compute_admin
     ansible_ssh_pass: "Op3nStack"
     admin_password: ""
+    cpus: 2
+    memory: 2048
+    disk: 40
     groups:
     - compute
     - foreman_nodes
@@ -88,8 +92,8 @@ nodes:
     - rdo
     - neutron
   controller1:
-    name: oscontroller1.opnfv.com
-    hostname: oscontroller1.opnfv.com
+    name: oscontroller1.{{ domain_name }}
+    hostname: oscontroller1.{{ domain_name }}
     short_name: oscontroller1
     type: controller
     host_type: baremetal
@@ -104,6 +108,9 @@ nodes:
     private_mac: "10:23:45:67:87:AC"
     ansible_ssh_pass: "Op3nStack"
     admin_password: "octopus"
+    cpus: 2
+    memory: 4096
+    disk: 40
     groups:
     - controller
     - foreman_nodes
diff --git a/foreman/ci/resize_lvm.sh b/foreman/ci/resize_lvm.sh
new file mode 100755 (executable)
index 0000000..64a9c62
--- /dev/null
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+
+#script for resizing volumes in Foreman/QuickStack VM
+#author: Tim Rozet (trozet@redhat.com)
+#
+#Uses Vagrant and VirtualBox
+#VagrantFile uses resize_partition.sh
+#
+#Pre-requisties:
+#Vagrant box disk size already resized
+#Partition already resized
+
+##VARS
+reset=`tput sgr0`
+blue=`tput setaf 4`
+red=`tput setaf 1`
+green=`tput setaf 2`
+
+##END VARS
+
+echo "${blue}Resizing physical volume${reset}"
+if ! pvresize /dev/sda2; then
+  echo "${red}Unable to resize physical volume${reset}"
+  exit 1
+else
+  new_part_size=`pvdisplay | grep -Eo "PV Size\s*[0-9]+\." | awk {'print $3'} | tr -d .`
+  echo "${blue}New physical volume size: ${new_part_size}${reset}"
+fi
+
+echo "${blue}Resizing logical volume${reset}"
+if ! lvextend /dev/mapper/centos-root -r -l +100%FREE; then
+  echo "${red}Unable to resize logical volume${reset}"
+  exit 1
+else
+  new_fs_size=`df -h | grep centos-root | awk '{print $2}'`
+  echo "${blue}Filesystem resized to: ${new_fs_size}${reset}"
+fi
diff --git a/foreman/ci/resize_partition.sh b/foreman/ci/resize_partition.sh
new file mode 100755 (executable)
index 0000000..4c5581d
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+#script for extending disk partition in Foreman/QuickStack VM
+#author: Tim Rozet (trozet@redhat.com)
+#
+#Uses Vagrant and VirtualBox
+#VagrantFile uses resize_partition.sh
+#
+#Pre-requisties:
+#Vagrant box disk size already resized
+
+##VARS
+reset=`tput sgr0`
+blue=`tput setaf 4`
+red=`tput setaf 1`
+green=`tput setaf 2`
+
+##END VARS
+
+echo "${blue}Extending partition...${reset}"
+echo "d
+2
+n
+p
+
+
+
+p
+t
+2
+8e
+w
+"|fdisk /dev/sda; true
index e64c0ad..0754e31 100755 (executable)
@@ -19,6 +19,7 @@ green=`tput setaf 2`
 host_name=REPLACE
 dns_server=REPLACE
 host_ip=REPLACE
+domain_name=REPLACE
 ##END VARS
 
 ##set hostname
@@ -35,7 +36,7 @@ fi
 ##modify /etc/resolv.conf to point to foreman
 echo "${blue} Configuring resolv.conf with DNS: $dns_server ${reset}"
 cat > /etc/resolv.conf << EOF
-search ci.com opnfv.com
+search ci.com $domain_name
 nameserver $dns_server
 nameserver 8.8.8.8
 
@@ -94,10 +95,10 @@ pluginsync      = true
 report          = true
 ignoreschedules = true
 daemon          = false
-ca_server       = foreman-server.opnfv.com
+ca_server       = foreman-server.$domain_name
 certname        = $host_name
 environment     = production
-server          = foreman-server.opnfv.com
+server          = foreman-server.$domain_name
 runinterval     = 600
 
 EOF
@@ -105,13 +106,13 @@ EOF
 # Setup puppet to run on system reboot
 /sbin/chkconfig --level 345 puppet on
 
-/usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server foreman-server.opnfv.com --no-daemonize
+/usr/bin/puppet agent --config /etc/puppet/puppet.conf -o --tags no_such_tag --server foreman-server.$domain_name --no-daemonize
 
 sync
 
 # Inform the build system that we are done.
 echo "Informing Foreman that we are built"
-wget -q -O /dev/null --no-check-certificate http://foreman-server.opnfv.com:80/unattended/built
+wget -q -O /dev/null --no-check-certificate http://foreman-server.$domain_name:80/unattended/built
 
 echo "Starting puppet"
 systemctl start puppet