source: branches/numpy_misc/tools/acceptance_tests/test_utils.py @ 7026

Last change on this file since 7026 was 7026, checked in by rwilson, 15 years ago

Cosmetic changes to cluster info dictionary.

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/bin/env python
2
3'''Utility functions for the cluster acceptance test suite.'''
4
5import os
6import sys
7import time
8
9
10# information about each cluster.
11# 'node_stem' key defines a compute node name.
12# update this if adding a new cluster.
13# should get this from the machines_<cluster> file?
14Cluster_Info = {'cyclone': {'num_nodes': 23,
15                            'node_stem': 'compute-1-%d',
16                            'bad_nodes': [13, 22]},
17                # 13 bad - 'no route to host'
18                # 22 bad - forgets password, can't find file
19                'tornado': {'num_nodes': 20,
20                            'node_stem': 'compute-0-%d',
21                            'bad_nodes': []}
22               }
23
24
25def log(logfile, msg=''):
26    '''Write a message to the log file.'''
27
28    fd = open(logfile, 'a')
29    fd.write(msg)
30    fd.close()
31
32
33def log_nl(logfile, msg=''):
34    '''Write a message to the log file, with a newline added.'''
35
36    log(logfile, msg)
37    log(logfile, '\n')
38
39
40def log_print(logfile, msg=''):
41    '''Write a message to the log file and stdout.
42
43    The message doesn't have a '\n' added to it.
44    '''
45
46    log(logfile, msg)
47    print msg,
48    sys.stdout.flush()
49
50
51def log_print_nl(logfile, msg=''):
52    '''Write a message to the log file and stdout, with a newline added.
53
54    Appends '\n' to msg.
55    '''
56
57    log_nl(logfile, msg)
58    print msg
59    sys.stdout.flush()
60
61
62def header(logfile, module, msg):
63    '''Write testlet header to log and stdout.'''
64
65    # current time
66    time_now = time.strftime('%H:%M:%S %Y-%m-%d')
67
68    log_print_nl(logfile, '#' * 80)
69    log_print_nl(logfile, '# ' + time_now + ' - ' + msg)
70    log_print_nl(logfile, '# Module: %s' % module)
71    log_print_nl(logfile, '#' * 80)
72    log_print_nl(logfile)
73
74
75def footer(logfile, start_time=None):
76    '''Write testlet footer to log and stdout.'''
77
78    if start_time:
79        end_time = time.time()
80        msg = 'Test took %.1f s' % (end_time - start_time)
81    else:
82        msg = 'Finished at %s' % time.ctime()
83       
84    log_nl(logfile)
85    log_nl(logfile, '# ' + msg)
86    log_print_nl(logfile)
87
88
89def get_hostname():
90    '''Return (<host>, <domain>) for machine.
91
92    For example, on the GA cyclone main node, return ('cyclone', 'agso.gov.au').
93    '''
94
95    fd = os.popen('hostname')
96    hostname = fd.read()
97    fd.close()
98
99    try:
100        result = hostname.strip().split('.', 1)
101        if len(result) < 2:
102            result.append('')
103    except:
104        result = (hostname, '')
105
106    return result
107
108
109def get_cluster_info(cluster):
110    '''Get dictionary containing information for 'cluster'.
111
112    If 'cluster' is not recognized, return None.
113    '''
114
115    return Cluster_Info.get(cluster, None)
116
117
118def get_node_numbers(cluster, strip_bad_nodes=True):
119    '''Get a list of node numbers for the cluster.
120
121    If 'strip_bad_nodes' is True remove bad nodes from the result.
122    '''
123
124    result = []
125    info = Cluster_Info[cluster]
126    for n in xrange(info['num_nodes']):
127        if strip_bad_nodes:
128            if n in info['bad_nodes']:
129                continue
130        result.append(n)
131
132    return result
133
134
Note: See TracBrowser for help on using the repository browser.