diff --git a/dev_tools/fabric/fab_setup.py b/dev_tools/fabric/fab_setup.py index 86da750f8..e1d481d97 100644 --- a/dev_tools/fabric/fab_setup.py +++ b/dev_tools/fabric/fab_setup.py @@ -13,17 +13,9 @@ env.user = 'martin' env.hosts = [] env.host_string -""" -Main dispatcher function to be called from the command-line. Allows us to specify source and target version of Airtime, -to test upgrade scripts, along with whether we should load a fresh version of the OS (from a VM snapshot), the OS version -and architecture. -""" -def dispatcher(source_version="182", target_version="194", fresh_os=True, os_version='10.04', os_arch='32'): - if (fresh_os): - create_fresh_os(os_version, os_arch) - print env.hosts - globals()["airtime_%s"%source_version]() - globals()["airtime_%s"%target_version]() +env.vm_download_url = "http://host.sourcefabric.org/vms/VirtualBox" + +#fab -f fab_setup.py ubuntu_lucid_64 airtime_182_tar airtime_190_tar def test(): @@ -31,21 +23,47 @@ def test(): print x.failed print x.succeeded print x.return_code + +def download_if_needed(vdi_tmp_dir, xml_tmp_dir, vm_name, vm_vdi_file, vm_xml_file): + if not os.path.exists(vdi_tmp_dir): + os.makedirs(vdi_tmp_dir) + + if os.path.exists(os.path.join(vdi_tmp_dir, vm_vdi_file)): + print "File %s already exists. No need to re-download" % os.path.join(vdi_tmp_dir, vm_vdi_file) + 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_tmp_dir, vm_vdi_file))) + + if os.path.exists(os.path.join(xml_tmp_dir, vm_xml_file)): + print "File %s already exists. No need to re-download" % os.path.join(xml_tmp_dir, vm_xml_file) + else: + 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_tmp_dir, vm_xml_file))) def create_fresh_os(os_version, os_arch): - ret = local('VBoxManage snapshot Ubuntu_%s_%s restore fresh_install'%(os_version, os_arch), capture=True) - if (ret.failed): - print ret - print "Restoring snapshot failed, are you sure it's not already running?" + + vdi_tmp_dir = os.path.expanduser('~/tmp/vms/') + xml_tmp_dir = os.path.expanduser('~/.VirtualBox') + vm_name = 'Ubuntu_%s_%s'%(os_version, os_arch) + vm_vdi_file = 'Ubuntu_%s_%s.vdi'%(os_version, os_arch) + vm_xml_file = 'Ubuntu_%s_%s.xml'%(os_version, os_arch) + + downloaded = download_if_needed(vdi_tmp_dir, xml_tmp_dir, vm_name, vm_vdi_file, vm_xml_file) - ret = local('VBoxManage startvm Ubuntu_%s_%s'%(os_version, os_arch), capture=True) - if (ret.failed): - print ret - print "Starting Virtual Machine failed, are you sure it's not already running?" + local("VBoxManage registervm %s"%os.path.join(xml_tmp_dir, vm_xml_file)) + 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_tmp_dir, vm_vdi_file))) + + #if downloaded: + local('VBoxManage snapshot "%s" take "fresh_install_test2"'%vm_name) + #else: + # local('VBoxManage snapshot %s restore fresh_install'%vm_name) + + local('VBoxManage startvm %s'%vm_name) time.sleep(20) - ret = local('VBoxManage --nologo guestproperty get "Ubuntu_%s_%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%(os_version, os_arch), capture=True) + ret = local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name) triple = ret.partition(':') ip_addr = triple[2].strip(' \r\n') @@ -54,6 +72,19 @@ def create_fresh_os(os_version, os_arch): env.host_string = ip_addr +def ubuntu_lucid_32(fresh_os=True): + if (fresh_os): + create_fresh_os('10.04', '32') + +def ubuntu_lucid_64(fresh_os=True): + pass + +def ubuntu_natty_32(fresh_os=True): + pass + +def ubuntu_natty_64(fresh_os=True): + pass + def airtime_182(): sudo('apt-get update') sudo('apt-get install -y tar gzip unzip apache2 php5-pgsql libapache2-mod-php5 ' + \ @@ -73,7 +104,7 @@ def airtime_182(): sudo('ln -sf /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled') sudo('ln -sf /etc/apache2/mods-available/rewrite.* /etc/apache2/mods-enabled') - sed('/etc/php5/apache2/php.ini', ";upload_tmp_dir =", "upload_tmp_dir = /tmp", use_sudo=True) + sed('/etc/php5/apache2/php.ini', ";upload_vdi_tmp_dir =", "upload_vdi_tmp_dir = /tmp", use_sudo=True) sed('/etc/php5/apache2/php.ini', ";date.timezone =", 'date.timezone = "America/Toronto"', use_sudo=True) put('airtime.vhost', '/etc/apache2/sites-available/airtime', use_sudo=True)