use plcsh instead of xmlrpc
[tests.git] / qaapi / qa / tests / boot_node.py
1 #!/usr/bin/env /usr/share/plc_api/plcsh
2
3 import os,sys
4 import base64
5 from Test import Test
6 from qa import utils
7
8 image_types = ['node-iso', 'node-usb', 'generic-iso', 'generic-usb']
9
10 class boot_node(Test):
11     """
12     Attempts to boot the specified node using qemu. 
13     """
14
15     def call(self, hostname, image_type = 'node-iso', disk_size="4G"):
16         tdir = "/tmp/"
17         
18         # validate hostname
19         nodes = GetNodes([hostname], ['hostname'])
20         if not nodes:
21             raise Exception, "No such node %(hostname)s" % locals() 
22
23         bootimage = GetBootMedium(hostname, image_type, '')
24         bootimage_path = '/%(tdir)s/%(hostname)s-bootcd.iso' % locals()
25
26         if self.config.verbose:
27             utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals())   
28         # Create a temporary bootcd file
29         file = open(bootimage_path, 'w')
30         file.write(base64.b64decode(bootimage))
31         file.close()
32         
33         # Create a temporary disk image
34         diskimage_path = "/%(tdir)s/%(hostname)s-hda.img" % locals() 
35         qemu_img_cmd = "qemu-img create -f qcow2 %(diskimage_path)s %(disk_size)s" % locals()
36         (stdin, stdout, stderr) = os.popen3(qemu_img_cmd)
37         self.errors = stderr.readlines()
38         if self.errors: 
39             raise Exception, "Unable to create disk image\n" + \
40                             "\n".join(self.errors)
41
42         if self.config.verbose:
43             utils.header("Booting %(hostname)s" % locals())
44         # Attempt to boot this node image
45         bootcmd = "qemu -hda %(diskimage_path)s -cdrom %(bootimage_path)s -smp 1 -m 256 -monitor stdio" % \
46                   locals()
47         (stdin, stdout, stderr) = os.popen3(bootcmd)
48         self.errors = stderr.readlines()
49         if self.errors:
50             raise Exception, "Unable to boot node image\n" + \
51                             "\n".join(self.errors)      
52          
53         return 1
54
55 if __name__ == '__main__':
56     args = tuple(sys.argv[1:])
57     boot_node()(*args)  
58         
59