Description fpr planetflow2
[tests.git] / qaapi / qa / tests / get_boot_state.py
1 #!/usr/bin/python
2 import os, sys
3 import time
4 from qa import utils
5 from Test import Test
6
7 class get_boot_state(Test):
8     """
9     Continually checks the boot_state of the specified node until
10     either the node reaches boot, the node reaches debug or the 
11     timeout is reached. 
12
13     Timeout represents the ammout of time (in minutes) we should 
14     continue trying before quitting.
15
16     Sleep represnet the ammount of time (in seconds) to wait in 
17     between checks.
18
19     Returns the boot state of the node.
20     """
21     def call(self, hostname, timeout = 5, sleep = 30):
22         exit = False
23         api = self.config.api
24         auth = self.config.auth
25         
26         # Validate hostname
27         nodes = api.GetNodes(auth, [hostname], ['hostname'])
28         if not nodes:
29             raise Exception, "No such hostname %(hostname)s" % locals()
30         
31         start_time = time.time()
32         end_time = start_time + (timeout * 60)
33         
34         while not exit:
35             nodes = api.GetNodes(auth, [hostname], ['boot_state'])
36             node = nodes[0]
37             boot_state = node['boot_state']
38             if self.config.verbose:
39                 utils.header("%(hostname)s boot_state is %(boot_state)s" % locals()) 
40
41             if boot_state in ['boot', 'debug']:
42                 exit = True
43             elif time.time() < end_time:
44                 time.sleep(sleep)
45             else:
46                 exit = True
47
48
49         if self.config.verbose:
50             if boot_state in ['boot']:
51                 utils.header("%(hostname)s correctly installed and booted" % locals())
52             else:
53                 utils.header("%(hostname)s not fully booted" % locals())
54
55         return boot_state
56
57 if __name__  == '__main__':
58     args = tuple(sys.argv[1:])
59     get_boot_state()(*args)