no longer rely on plcsh. Config will either import PLC.Shell or use xmlrpc, so use...
[tests.git] / qaapi / qa / tests / boot_node.py
1 #!/usr/bin/python
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         api = self.config.api
17         auth = self.config.auth
18         tdir = "/tmp/"
19         
20         # validate hostname
21         nodes = api.GetNodes(auth, [hostname], ['hostname'])
22         if not nodes:
23             raise Exception, "No such node %(hostname)s" % locals() 
24
25         bootimage = api.GetBootMedium(auth, hostname, image_type, '')
26         bootimage_path = '/%(tdir)s/%(hostname)s-bootcd.iso' % locals()
27
28         if self.config.verbose:
29             utils.header("Creating bootcd for %(hostname)s at %(bootimage_path)s" % locals())   
30         # Create a temporary bootcd file
31         file = open(bootimage_path, 'w')
32         file.write(base64.b64decode(bootimage))
33         file.close()
34         
35         # Create a temporary disk image
36         diskimage_path = "/%(tdir)s/%(hostname)s-hda.img" % locals() 
37         qemu_img_cmd = "qemu-img create -f qcow2 %(diskimage_path)s %(disk_size)s" % locals()
38         (stdin, stdout, stderr) = os.popen3(qemu_img_cmd)
39         self.errors = stderr.readlines()
40         if self.errors: 
41             raise Exception, "Unable to create disk image\n" + \
42                             "\n".join(self.errors)
43
44         if self.config.verbose:
45             utils.header("Booting %(hostname)s" % locals())
46         # Attempt to boot this node image
47         bootcmd = "qemu -hda %(diskimage_path)s -cdrom %(bootimage_path)s -smp 1 -m 256 -monitor stdio" % \
48                   locals()
49         (stdin, stdout, stderr) = os.popen3(bootcmd)
50         self.errors = stderr.readlines()
51         if self.errors:
52             raise Exception, "Unable to boot node image\n" + \
53                             "\n".join(self.errors)      
54          
55         return 1
56
57 if __name__ == '__main__':
58     args = tuple(sys.argv[1:])
59     boot_node()(*args)  
60         
61