source: misc/tools/acceptance_tests/test_utils.py @ 7276

Last change on this file since 7276 was 7276, checked in by ole, 15 years ago

Merged numpy branch back into the trunk.

In ~/sandpit/anuga/anuga_core/source
svn merge -r 6246:HEAD ../../branches/numpy .

In ~/sandpit/anuga/anuga_validation
svn merge -r 6417:HEAD ../branches/numpy_anuga_validation .

In ~/sandpit/anuga/misc
svn merge -r 6809:HEAD ../branches/numpy_misc .

For all merges, I used numpy version where conflicts existed

The suites test_all.py (in source/anuga) and validate_all.py passed using Python2.5 with numpy on my Ubuntu Linux box.

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