diff --git a/dev_tools/fabric/fab_setup.py b/dev_tools/fabric/fab_setup.py index e9f4be9a8..b6bc73d51 100644 --- a/dev_tools/fabric/fab_setup.py +++ b/dev_tools/fabric/fab_setup.py @@ -1,8 +1,20 @@ +#Airtime install/upgrade infrastructure +#author martin.konecny@sourcefabric.org + +#Documentation for this page: +#http://wiki.sourcefabric.org/x/OwCD + + import os import time +import sys from fabric.api import * from fabric.contrib.files import comment, sed, append +from xml.dom.minidom import parse +from xml.dom.minidom import Node +from xml.dom.minidom import Element + env.user = 'martin' env.password = 'test' @@ -26,11 +38,9 @@ def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file): if os.path.exists(os.path.join(vdi_dir, vm_vdi_file)): print "File %s already exists. No need to re-download" % os.path.join(vdi_dir, vm_vdi_file) - downloaded = False else: print "File %s not found. Downloading" % vm_vdi_file local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, os.path.join(vdi_dir, vm_vdi_file))) - downloaded = True if os.path.exists(os.path.join(xml_dir, vm_xml_file)): print "File %s already exists. No need to re-download" % os.path.join(xml_dir, vm_xml_file) @@ -38,7 +48,6 @@ def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file): print "File %s not found. Downloading" % vm_xml_file local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_xml_file, os.path.join(xml_dir, vm_xml_file))) - return downloaded def create_fresh_os(os_version, os_arch): @@ -48,19 +57,41 @@ def create_fresh_os(os_version, os_arch): vdi_dir = os.path.expanduser('~/tmp/vms/%s'%vm_name) vdi_snapshot_dir = os.path.expanduser('~/tmp/vms/%s/Snapshots'%vm_name) xml_dir = os.path.expanduser('~/.VirtualBox') + vm_xml_path = os.path.join(xml_dir, vm_xml_file) - downloaded = download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file) - if downloaded: + if not os.path.exists("%s/vm_registered"%vdi_dir) and os.path.exists(vm_xml_path): + #vm_xml file exists, but it wasn't registered. Did something go wrong on a previous attempt? + #Let's attempt to correct this by completely removing the virtual machine. + + dom = parse(vm_xml_path) + root = dom.childNodes[0] + rootChildren = root.childNodes + + #manually remove all snapshots before removing virtual machine + for rc in rootChildren: + if rc.nodeType == Node.ELEMENT_NODE and rc.localName == "Machine": + snapshotNodes = rc.getElementsByTagName("Snapshot") + for sn in snapshotNodes: + local("VBoxManage snapshot %s delete %s"% (vm_name, sn.getAttribute("uuid")[1:-1])) + + os.remove(vm_xml_path) + local("VBoxManage unregistervm %s --delete"% vm_name) + + download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file) + + if not os.path.exists("%s/vm_registered"%vdi_dir): local("VBoxManage registervm %s"%os.path.join(xml_dir, vm_xml_file), capture=True) local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name) - local('VBoxManage storageattach "%s" --storagectl "SATA Controller" --port 0 --type hdd --medium %s'%(vm_name, os.path.join(vdi_dir, vm_vdi_file))) - local("VBoxManage snapshot %s take fresh_install"%vm_name) + local('VBoxManage storageattach "%s" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium %s'%(vm_name, os.path.join(vdi_dir, vm_vdi_file))) local("VBoxManage modifyvm %s --snapshotfolder %s"%(vm_name, vdi_snapshot_dir)) - #else: - # local('VBoxManage snapshot %s restore fresh_install'%vm_name) - + local("VBoxManage snapshot %s take fresh_install"%vm_name) + local("touch %s/vm_registered"%vdi_dir) + + + local('VBoxManage snapshot %s restore fresh_install'%vm_name) local('VBoxManage startvm %s'%vm_name) + print "Please wait while attempting to acquire IP address" time.sleep(30) @@ -71,6 +102,16 @@ def create_fresh_os(os_version, os_arch): print "Address found %s"%ip_addr env.hosts.append(ip_addr) env.host_string = ip_addr + + if os_version == "10.04": + print "Lucid detected - updating python virtualenv" + sudo('apt-get update') + sudo('apt-get install -y python-setuptools') + sudo('wget http://apt.sourcefabric.org/pool/main/p/python-virtualenv/python-virtualenv_1.4.9-3_all.deb') + #sudo('echo "Y" | gdebi python-virtualenv_1.4.9-3_all.deb') + + #for some weird reason have to run dpkg after gdebi for the package to be configured :/ + sudo('dpkg -i python-virtualenv_1.4.9-3_all.deb') def ubuntu_lucid_32(fresh_os=True): if (fresh_os): @@ -123,6 +164,7 @@ def airtime_182_tar(): run('tar xfz airtime-1.8.2.tar.gz') sudo('cd ~/airtime-1.8.2/install && php airtime-install.php') + #need to reboot because of daemon-tools. reboot(45) sudo('airtime-check-system') @@ -131,10 +173,10 @@ def airtime_194_tar(): run('tar xfz airtime-1.9.4.tar.gz') sudo('cd ~/airtime-1.9.4/install_full/ubuntu && ./airtime-full-install') -def airtime_195_RC1_tar(): - run('wget http://downloads.sourceforge.net/project/airtime/1.9.5-RC1/airtime-1.9.5-RC1.tar.gz') - run('tar xfz airtime-1.9.5-RC1.tar.gz') - sudo('cd ~/airtime-1.9.5-RC1/install_full/ubuntu && ./airtime-full-install') +def airtime_195_tar(): + run('wget http://downloads.sourceforge.net/project/airtime/1.9.5-RC3/airtime-1.9.5-RC3.tar.gz') + run('tar xfz airtime-1.9.5-RC3.tar.gz') + sudo('cd ~/airtime-1.9.5/install_full/ubuntu && ./airtime-full-install') def airtime_latest_deb(): append('/etc/apt/sources.list', "deb http://apt.sourcefabric.org/ lucid main", use_sudo=True) @@ -146,11 +188,11 @@ def airtime_latest_deb(): sudo('apt-get purge -y pulseaudio') sudo('apt-get install -y --force-yes airtime') -def airtime_devel(): +def airtime_git_branch(branch="devel"): sudo('apt-get update') sudo('apt-get install -y git-core') run('git clone https://github.com/sourcefabric/Airtime.git ~/airtime') - sudo('cd ~/airtime && git checkout devel && install_full/ubuntu/airtime-full-install || true') + sudo('cd ~/airtime && git checkout %s && install_full/ubuntu/airtime-full-install || true' % branch) def airtime_200(): diff --git a/dev_tools/fabric/run.sh b/dev_tools/fabric/run.sh new file mode 100755 index 000000000..920f36bf7 --- /dev/null +++ b/dev_tools/fabric/run.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +exec 2>&1 + +target="airtime_195_tar" +airtime_versions=("" "airtime_182_tar" "airtime_194_tar") +ubuntu_versions=("ubuntu_lucid_32" "ubuntu_natty_32") + + +num1=${#ubuntu_versions[@]} +num2=${#airtime_versions[@]} + + +for i in $(seq 0 $(($num1 -1))); +do + for j in $(seq 0 $(($num2 -1))); + do + echo fab -f fab_setup.py ${ubuntu_versions[$i]} ${airtime_versions[$j]} $target 2>&1 | tee $LOG + fab -f fab_setup.py ${ubuntu_versions[$i]} ${airtime_versions[$j]} $target 2>&1 | tee $LOG + done +done