method for booting nodes
authorTony Mack <tmack@cs.princeton.edu>
Tue, 15 Jan 2008 21:48:35 +0000 (21:48 +0000)
committerTony Mack <tmack@cs.princeton.edu>
Tue, 15 Jan 2008 21:48:35 +0000 (21:48 +0000)
qaapi/qa/modules/plc/boot_node.py [new file with mode: 0644]

diff --git a/qaapi/qa/modules/plc/boot_node.py b/qaapi/qa/modules/plc/boot_node.py
new file mode 100644 (file)
index 0000000..cae230c
--- /dev/null
@@ -0,0 +1,47 @@
+import os,sys
+import base64
+from qa.Test import Test
+from qa import utils
+
+class boot_node(Test):
+
+    def call(self, hostname, disk_size = "500M"):
+       api = self.config.api
+       auth = self.config.auth
+       
+       # validate hostname
+       nodes = api.GetNodes(auth, [hostname], ['hostname'])
+       if not nodes:
+           raise Exception, "No such node %s" 
+
+       bootimage = api.GetBootMedium(auth, hostname, 'node-iso', '')
+       bootimage_path = '/tmp/%(hostname)s-bootcd.iso' % locals()
+
+       if self.config.verbose:
+            utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals())  
+       # Create a temporary bootcd file
+       file = open(bootimage_path, 'w')
+       file.write(base64.b64decode(bootimage))
+       file.close()
+       
+       # Create a temporary disk image
+       diskimage_path = "/tmp/%(hostname)s-hda.img" % locals() 
+       qemu_img_cmd = "qemu-img create %(diskimage_path)s %(disk_size)s" % locals()
+       (stdin, stdout, stderr) = os.popen3(qemu_img_cmd)
+       self.errors = stderr.readlines()
+       if self.errors: 
+           raise Exception, "Unable to create disk image\n" + \
+                           "\n".join(self.errors)
+
+       if self.config.verbose:
+            utils.header("Booting %(hostname)s" % locals())
+       # Attempt to boot this node image
+       bootcmd = "qemu -kernel-kqemu -hda %(diskimage_path)s -cdrom %(bootimage_path)s" % \
+                 locals()
+       (stdin, stdout, stderr) = os.popen3(bootcmd)
+       self.errors = stderr.readlines()
+       if self.errors:
+            raise Exception, "Unable to boot node image\n" + \
+                            "\n".join(self.errors)     
+        
+       return True