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