fab_release_test.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. #Airtime install/upgrade infrastructure
  2. #author martin.konecny@sourcefabric.org
  3. #Documentation for this page:
  4. #http://wiki.sourcefabric.org/x/OwCD
  5. import os
  6. import time
  7. import sys
  8. from fabric.api import *
  9. from fabric.contrib.files import comment, sed, append
  10. from xml.dom.minidom import parse
  11. from xml.dom.minidom import Node
  12. from xml.dom.minidom import Element
  13. env.user = 'martin'
  14. env.password = 'test'
  15. env.hosts = []
  16. env.host_string
  17. env.warn_only = True
  18. env.vm_download_url = "http://host.sourcefabric.org/vms/VirtualBox"
  19. #fab -f fab_setup.py ubuntu_lucid_64 airtime_182_tar airtime_190_tar
  20. def do_sudo(command):
  21. result = sudo(command)
  22. if result.return_code != 0:
  23. print "Error running command: %s" %command
  24. shutdown()
  25. sys.exit(1)
  26. else:
  27. return result
  28. def do_run(command):
  29. result = run(command)
  30. if result.return_code != 0:
  31. print "Error running command: %s" %command
  32. shutdown()
  33. sys.exit(1)
  34. else:
  35. return result
  36. def do_local(command, capture=True):
  37. result = local(command, capture)
  38. if result.return_code != 0:
  39. print "Error running command: %s" %command
  40. shutdown()
  41. sys.exit(1)
  42. else:
  43. return result
  44. def pause():
  45. raw_input("--> Press Enter to continue...")
  46. def shutdown():
  47. do_sudo("poweroff")
  48. time.sleep(45)
  49. def test():
  50. x = do_sudo('airtime-check-system')
  51. print x.failed
  52. print x.succeeded
  53. print x.return_code
  54. def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file):
  55. if not os.path.exists(vdi_dir):
  56. os.makedirs(vdi_dir)
  57. if os.path.exists(os.path.join(vdi_dir, vm_vdi_file)):
  58. print "File %s already exists. No need to re-download" % os.path.join(vdi_dir, vm_vdi_file)
  59. else:
  60. print "File %s not found. Downloading" % vm_vdi_file
  61. tmpPath = do_local("mktemp", capture=True)
  62. do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, tmpPath))
  63. os.rename(tmpPath, os.path.join(vdi_dir, vm_vdi_file))
  64. if os.path.exists(os.path.join(xml_dir, vm_xml_file)):
  65. print "File %s already exists. No need to re-download" % os.path.join(xml_dir, vm_xml_file)
  66. else:
  67. do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_xml_file, os.path.join(xml_dir, vm_xml_file)))
  68. def create_fresh_os(vm_name, lucid=False, debian=False, icecast2_config=False):
  69. """
  70. remove known_hosts because if two virtual machines get the same ip address,
  71. then they will most likey have a different host key, and ssh will fail, warning
  72. about a possible man in the middle attack.
  73. """
  74. do_local("rm -f ~/.ssh/known_hosts")
  75. vm_vdi_file = '%s.vdi'%vm_name
  76. vm_xml_file = '%s.xml'%vm_name
  77. vdi_dir = os.path.expanduser('~/tmp/vms/%s'%vm_name)
  78. vdi_snapshot_dir = os.path.expanduser('~/tmp/vms/%s/Snapshots'%vm_name)
  79. xml_dir = os.path.expanduser('~/.VirtualBox')
  80. vm_xml_path = os.path.join(xml_dir, vm_xml_file)
  81. download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file)
  82. if not os.path.exists("%s/vm_registered"%vdi_dir):
  83. do_local("VBoxManage registervm %s"%os.path.join(xml_dir, vm_xml_file), capture=True)
  84. do_local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name)
  85. do_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)))
  86. do_local("VBoxManage modifyvm %s --snapshotfolder %s"%(vm_name, vdi_snapshot_dir))
  87. do_local("VBoxManage snapshot %s take fresh_install"%vm_name)
  88. do_local("touch %s/vm_registered"%vdi_dir)
  89. do_local('VBoxManage snapshot %s restore fresh_install'%vm_name)
  90. do_local('VBoxManage modifyvm "%s" --bridgeadapter1 eth0'%vm_name)
  91. do_local('VBoxManage startvm %s'%vm_name)
  92. print "Please wait while attempting to acquire IP address"
  93. time.sleep(30)
  94. try_again = True
  95. while try_again:
  96. ret = do_local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name, capture=True)
  97. triple = ret.partition(':')
  98. ip_addr = triple[2].strip(' \r\n')
  99. print "Address found %s"%ip_addr
  100. try_again = (len(ip_addr) == 0)
  101. time.sleep(1)
  102. env.hosts.append(ip_addr)
  103. env.host_string = ip_addr
  104. if lucid:
  105. print "Lucid detected - updating python virtualenv"
  106. do_sudo('apt-get update')
  107. do_sudo('apt-get install -y python-setuptools')
  108. do_sudo('wget http://apt.sourcefabric.org/pool/main/p/python-virtualenv/python-virtualenv_1.4.9-3_all.deb')
  109. do_sudo('dpkg -i python-virtualenv_1.4.9-3_all.deb')
  110. #supress rabbitmq bug that makes an upgrade warning pop-up even though it hasn't been
  111. #installed before.
  112. do_sudo('echo "rabbitmq-server rabbitmq-server/upgrade_previous note" | debconf-set-selections')
  113. if debian:
  114. append('/etc/apt/sources.list', "deb http://backports.debian.org/debian-backports squeeze-backports main", use_sudo=True)
  115. if icecast2_config:
  116. print "Updating icecast2 setup settings"
  117. do_sudo('echo "icecast2 icecast2/icecast-setup boolean false" | debconf-set-selections')
  118. def ubuntu_lucid_32(fresh_os=True):
  119. if (fresh_os):
  120. create_fresh_os('Ubuntu_10.04_32', lucid=True)
  121. def ubuntu_lucid_64(fresh_os=True):
  122. if (fresh_os):
  123. create_fresh_os('Ubuntu_10.04_64', lucid=True)
  124. def ubuntu_maverick_32(fresh_os=True):
  125. if (fresh_os):
  126. create_fresh_os('Ubuntu_10.10_32')
  127. def ubuntu_maverick_64(fresh_os=True):
  128. if (fresh_os):
  129. create_fresh_os('Ubuntu_10.10_64')
  130. def ubuntu_natty_32(fresh_os=True):
  131. if (fresh_os):
  132. create_fresh_os('Ubuntu_11.04_32')
  133. def ubuntu_natty_64(fresh_os=True):
  134. if (fresh_os):
  135. create_fresh_os('Ubuntu_11.04_64')
  136. def ubuntu_oneiric_32(fresh_os=True):
  137. if (fresh_os):
  138. create_fresh_os('Ubuntu_11.10_32')
  139. def ubuntu_oneiric_64(fresh_os=True):
  140. if (fresh_os):
  141. create_fresh_os('Ubuntu_11.10_64')
  142. def ubuntu_precise_32(fresh_os=True):
  143. if (fresh_os):
  144. create_fresh_os('Ubuntu_12.04_32', icecast2_config=True)
  145. def ubuntu_precise_64(fresh_os=True):
  146. if (fresh_os):
  147. create_fresh_os('Ubuntu_12.04_64', icecast2_config=True)
  148. def ubuntu_quantal_32(fresh_os=True):
  149. if (fresh_os):
  150. create_fresh_os('Ubuntu_12.10_32', icecast2_config=True)
  151. def ubuntu_quantal_64(fresh_os=True):
  152. if (fresh_os):
  153. create_fresh_os('Ubuntu_12.10_64', icecast2_config=True)
  154. def ubuntu_raring_32(fresh_os=True):
  155. if (fresh_os):
  156. create_fresh_os('Ubuntu_13.04_32', icecast2_config=True)
  157. def ubuntu_raring_64(fresh_os=True):
  158. if (fresh_os):
  159. create_fresh_os('Ubuntu_13.04_64', icecast2_config=True)
  160. def ubuntu_saucy_32(fresh_os=True):
  161. if (fresh_os):
  162. create_fresh_os('Ubuntu_13.10_32', icecast2_config=True)
  163. def ubuntu_saucy_64(fresh_os=True):
  164. if (fresh_os):
  165. create_fresh_os('Ubuntu_13.10_64', icecast2_config=True)
  166. def debian_squeeze_32(fresh_os=True):
  167. if (fresh_os):
  168. create_fresh_os('Debian_Squeeze_32', debian=True)
  169. def debian_squeeze_64(fresh_os=True):
  170. if (fresh_os):
  171. create_fresh_os('Debian_Squeeze_64', debian=True)
  172. def debian_wheezy_32(fresh_os=True):
  173. if (fresh_os):
  174. create_fresh_os('Debian_Wheezy_32', icecast2_config=True)
  175. def debian_wheezy_64(fresh_os=True):
  176. if (fresh_os):
  177. create_fresh_os('Debian_Wheezy_64', icecast2_config=True)
  178. def airtime_180_tar():
  179. airtime_18x_tar("airtime", "1.8.0")
  180. def airtime_181_tar():
  181. airtime_18x_tar("airtime", "1.8.1")
  182. def airtime_182_tar():
  183. airtime_18x_tar("airtime-1.8.2", "1.8.2")
  184. def airtime_18x_tar(root_dir, version):
  185. do_sudo('apt-get update')
  186. do_sudo('apt-get install -y --force-yes tar gzip unzip apache2 php5-pgsql libapache2-mod-php5 ' + \
  187. 'php-pear php5-gd postgresql odbc-postgresql python python-configobj poc-streamer ' + \
  188. 'lame daemontools daemontools-run python-mutagen libsoundtouch-ocaml sudo ' + \
  189. 'libtaglib-ocaml libao-ocaml libmad-ocaml libesd0 icecast2 oggvideotools ' + \
  190. 'libportaudio2 libsamplerate0 libcamomile-ocaml-dev ecasound php5-curl mpg123 ' + \
  191. 'python-setuptools python-pip rabbitmq-server libvorbis-ocaml-dev libmp3lame-dev flac')
  192. do_sudo('pip install kombu')
  193. do_sudo('pip install poster')
  194. do_sudo('mkdir -p /tmp/pear/cache')
  195. do_sudo('pear channel-discover pear.phing.info || true')
  196. do_sudo('pear install phing/phing-2.4.2 || true')
  197. do_sudo('ln -sf /etc/apache2/mods-available/php5.* /etc/apache2/mods-enabled')
  198. do_sudo('ln -sf /etc/apache2/mods-available/rewrite.* /etc/apache2/mods-enabled')
  199. sed('/etc/php5/apache2/php.ini', ";upload_vdi_dir =", "upload_vdi_dir = /tmp", use_sudo=True)
  200. sed('/etc/php5/apache2/php.ini', ";date.timezone =", 'date.timezone = "America/Toronto"', use_sudo=True)
  201. put('airtime.vhost', '/etc/apache2/sites-available/airtime', use_sudo=True)
  202. do_sudo('a2dissite default')
  203. do_sudo('ln -sf /etc/apache2/sites-available/airtime /etc/apache2/sites-enabled/airtime')
  204. do_sudo('a2enmod rewrite')
  205. do_sudo('service apache2 restart')
  206. sed('/etc/default/icecast2', 'ENABLE=false', 'ENABLE=true', use_sudo=True)
  207. do_sudo('service icecast2 start')
  208. #these are do_sudo instead of do_run because in Debian we would be working with different home directores (/home/martin and /root in debian)
  209. do_sudo('wget http://downloads.sourceforge.net/project/airtime/%s/airtime-%s.tar.gz' % (version, version))
  210. do_sudo('tar xfz airtime-%s.tar.gz' % version)
  211. #do_sudo('cd ~/%s/install && php airtime-install.php' % root_dir)
  212. do_sudo('php ~/%s/install/airtime-install.php' % root_dir)
  213. #need to reboot because of daemon-tools.
  214. reboot(45)
  215. do_sudo('airtime-check-system')
  216. def airtime_190_tar():
  217. #1.9.0 doesn't do apt-get update during install, and therefore the package index
  218. #files are not resynchronized. Need to do this here.
  219. do_sudo('apt-get update')
  220. do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.0/airtime-1.9.0.tar.gz')
  221. do_run('tar xfz airtime-1.9.0.tar.gz')
  222. do_sudo('cd /home/martin/airtime-1.9.0/install_full/ubuntu && ./airtime-full-install')
  223. def airtime_191_tar():
  224. #1.9.0 doesn't do apt-get update during install, and therefore the package index
  225. #files are not resynchronized. Need to do this here.
  226. do_sudo('apt-get update')
  227. do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.1/airtime-1.9.1.tar.gz')
  228. do_run('tar xfz airtime-1.9.1.tar.gz')
  229. do_sudo('cd /home/martin/airtime-1.9.1/install_full/ubuntu && ./airtime-full-install')
  230. def airtime_192_tar():
  231. #1.9.2 doesn't do apt-get update during install, and therefore the package index
  232. #files are not resynchronized. Need to do this here.
  233. do_sudo('apt-get update')
  234. do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.2/airtime-1.9.2.tar.gz')
  235. do_run('tar xfz airtime-1.9.2.tar.gz')
  236. do_sudo('cd /home/martin/airtime-1.9.2/install_full/ubuntu && ./airtime-full-install')
  237. def airtime_193_tar():
  238. #1.9.3 doesn't do apt-get update during install, and therefore the package index
  239. #files are not resynchronized. Need to do this here.
  240. do_sudo('apt-get update')
  241. do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.3/airtime-1.9.3.tar.gz')
  242. do_run('tar xfz airtime-1.9.3.tar.gz')
  243. do_sudo('cd /home/martin/airtime-1.9.3/install_full/ubuntu && ./airtime-full-install')
  244. def airtime_194_tar():
  245. #1.9.4 doesn't do apt-get update during install, and therefore the package index
  246. #files are not resynchronized. Need to do this here.
  247. do_sudo('apt-get update')
  248. do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.4/airtime-1.9.4.tar.gz')
  249. do_run('tar xfz airtime-1.9.4.tar.gz')
  250. do_sudo('cd /home/martin/airtime-1.9.4/install_full/ubuntu && ./airtime-full-install')
  251. def airtime_195_tar():
  252. do_run('wget http://downloads.sourceforge.net/project/airtime/1.9.5/airtime-1.9.5.tar.gz')
  253. do_run('tar xfz airtime-1.9.5.tar.gz')
  254. do_sudo('cd /home/martin/airtime-1.9.5/install_full/ubuntu && ./airtime-full-install')
  255. def airtime_200_tar():
  256. do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.0/airtime-2.0.0.tar.gz')
  257. do_run('tar xfz airtime-2.0.0.tar.gz')
  258. do_sudo('cd /home/martin/airtime-2.0.0/install_full/ubuntu && ./airtime-full-install')
  259. def airtime_201_tar():
  260. do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.1/airtime-2.0.1.tar.gz')
  261. do_run('tar xfz airtime-2.0.1.tar.gz')
  262. do_sudo('cd /home/martin/airtime-2.0.1/install_full/ubuntu && ./airtime-full-install')
  263. def airtime_202_tar():
  264. do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.2/airtime-2.0.2.tar.gz')
  265. do_run('tar xfz airtime-2.0.2.tar.gz')
  266. do_sudo('cd /home/martin/airtime-2.0.2/install_full/ubuntu && ./airtime-full-install')
  267. def airtime_203_tar():
  268. do_run('wget http://downloads.sourceforge.net/project/airtime/2.0.3/airtime-2.0.3.tar.gz')
  269. do_run('tar xfz airtime-2.0.3.tar.gz')
  270. do_sudo('cd /home/martin/airtime-2.0.3/install_full/ubuntu && ./airtime-full-install')
  271. def airtime_210_tar():
  272. do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.0/airtime-2.1.0.tar.gz')
  273. do_run('tar xfz airtime-2.1.0.tar.gz')
  274. do_sudo('cd /home/martin/airtime-2.1.0/install_full/ubuntu && ./airtime-full-install')
  275. def airtime_211_tar():
  276. do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.1/airtime-2.1.1.tar.gz')
  277. do_run('tar xfz airtime-2.1.1.tar.gz')
  278. do_sudo('cd /home/martin/airtime-2.1.1/install_full/ubuntu && ./airtime-full-install')
  279. def airtime_212_tar():
  280. do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.2/airtime-2.1.2.tar.gz')
  281. do_run('tar xfz airtime-2.1.2.tar.gz')
  282. do_sudo('cd /home/martin/airtime-2.1.2/install_full/ubuntu && ./airtime-full-install')
  283. def airtime_213_tar():
  284. do_run('wget http://downloads.sourceforge.net/project/airtime/2.1.3/airtime-2.1.3.tar.gz')
  285. do_run('tar xfz airtime-2.1.3.tar.gz')
  286. do_sudo('cd /home/martin/airtime-2.1.3/install_full/ubuntu && ./airtime-full-install')
  287. def airtime_220_tar():
  288. do_run('wget http://downloads.sourceforge.net/project/airtime/2.2.0/airtime-2.2.0.tar.gz')
  289. do_run('tar xfz airtime-2.2.0.tar.gz')
  290. do_sudo('cd /home/martin/airtime-2.2.0/install_full/ubuntu && ./airtime-full-install')
  291. def airtime_221_tar():
  292. do_run('wget http://downloads.sourceforge.net/project/airtime/2.2.1/airtime-2.2.1.tar.gz')
  293. do_run('tar xfz airtime-2.2.1.tar.gz')
  294. do_sudo('cd /home/martin/airtime-2.2.1/install_full/ubuntu && ./airtime-full-install')
  295. def airtime_230_tar():
  296. do_run('wget http://downloads.sourceforge.net/project/airtime/2.3.0/airtime-2.3.0.tar.gz')
  297. do_run('tar xfz airtime-2.3.0.tar.gz')
  298. do_sudo('cd /home/martin/airtime-2.3.0/install_full/ubuntu && ./airtime-full-install')
  299. def airtime_231_tar():
  300. do_run('wget http://downloads.sourceforge.net/project/airtime/2.3.1/airtime-2.3.1-ga.tar.gz')
  301. do_run('tar xfz airtime-2.3.1-ga.tar.gz')
  302. do_sudo('cd /home/martin/airtime-2.3.1/install_full/ubuntu && ./airtime-full-install')
  303. def airtime_240_tar():
  304. do_run('wget http://sourceforge.net/projects/airtime/files/2.4.0/airtime-2.4.0-ga.tar.gz')
  305. do_run('tar xfz airtime-2.4.0-ga.tar.gz')
  306. do_sudo('cd /home/martin/airtime-2.4.0/install_full/ubuntu && ./airtime-full-install')
  307. def airtime_241_tar():
  308. do_run('wget http://sourceforge.net/projects/airtime/files/2.4.1/airtime-2.4.1-ga.tar.gz')
  309. do_run('tar xfz airtime-2.4.1-ga.tar.gz')
  310. do_sudo('cd /home/martin/Airtime-airtime-2.4.1-ga/install_full/ubuntu && ./airtime-full-install')
  311. def airtime_latest_deb():
  312. append('/etc/apt/sources.list', "deb http://apt.sourcefabric.org/ lucid main", use_sudo=True)
  313. append('/etc/apt/sources.list', "deb http://archive.ubuntu.com/ubuntu/ lucid multiverse", use_sudo=True)
  314. do_sudo('apt-get update')
  315. do_sudo('apt-get install -y --force-yes sourcefabric-keyring')
  316. do_sudo('apt-get install -y postgresql')
  317. do_sudo('apt-get install -y icecast2')
  318. do_sudo('apt-get purge -y pulseaudio')
  319. do_sudo('apt-get install -y --force-yes airtime')
  320. def airtime_git_branch(branch="2.5.x"):
  321. do_sudo('apt-get update')
  322. do_sudo('apt-get install -y git-core')
  323. do_run('git clone https://github.com/sourcefabric/Airtime.git ~/airtime_git')
  324. do_sudo('cd /home/martin/airtime_git && git checkout %s && install_full/ubuntu/airtime-full-install || true' % branch)
  325. #def airtime_200():
  326. # pass