2 import time, os, re, glob
3 from pprint import PrettyPrinter
7 def init_options(options_arg):
11 # how could this accept a list again ?
13 now=time.strftime("%H:%M:%S", time.localtime())
14 print "*",now,'--',message
16 def pprint(message,spec,depth=2):
17 now=time.strftime("%H:%M:%S", time.localtime())
18 print ">",now,"--",message
19 PrettyPrinter(indent=8,depth=depth).pprint(spec)
21 # quick & dirty - should probably use the parseroption object instead
22 # and move to TestMain as well
23 exclude_options_keys = [ 'ensure_value' , 'read_file', 'read_module' ]
24 def show_options (message,options):
25 now=time.strftime("%H:%M:%S", time.localtime())
26 print ">",now,"--",message
27 for k in dir(options):
28 if k.find("_")==0: continue
29 if k in exclude_options_keys: continue
30 print " ",k,":",getattr(options,k)
32 def show_site_spec (site):
33 print '* ======== site',site['site_fields']['name']
34 for (k,v) in site.iteritems():
37 print '* \t\t','nodes : ',
39 print node['node_fields']['hostname'],'',
43 print '* \t\tusers : ',
45 print user['name'],'',
47 elif k == 'site_fields':
48 print '* \t\tlogin_base',':',v['login_base']
49 elif k == 'address_fields':
53 PrettyPrinter(indent=8,depth=2).pprint(v)
55 def show_initscript_spec (initscript):
56 print '* ======== initscript',initscript['initscript_fields']['name']
58 def show_key_spec (key):
59 print '* ======== key',key['name']
61 def show_slice_spec (slice):
62 print '* ======== slice',slice['slice_fields']['name']
63 for (k,v) in slice.iteritems():
66 print '* \t\tnodes : ',
72 print '* \t\tusers : ',
76 elif k=='slice_fields':
77 print '* \t\tfields',':',
78 print 'max_nodes=',v['max_nodes'],
83 def show_test_spec (message,all_plc_specs):
84 now=time.strftime("%H:%M:%S", time.localtime())
85 print "*",now,"--",message
86 for plc_spec in all_plc_specs:
87 show_test_spec_pass (plc_spec,1)
88 show_test_spec_pass (plc_spec,2)
90 def show_test_spec_pass (plc_spec,passno):
91 for (key,val) in plc_spec.iteritems():
96 elif key=='initscripts':
97 for initscript in val:
98 show_initscript_spec (initscript)
101 show_slice_spec (slice)
106 if key not in ['sites','initscripts','slices','keys']:
107 print '* \t',key,':',val
109 def system(command,background=False):
110 if background: command += " &"
112 print 'dry_run:',command
115 return os.system("set -x; " + command)
117 ### WARNING : this ALWAYS does its job, even in dry_run mode
118 def output_of (command):
120 # if options.dry_run:
121 # print 'dry_run',command
122 # return (0,'[[dry-run - fake output]]')
124 (code,string) = commands.getstatusoutput(command)
127 # convenience: translating shell-like pattern into regexp
128 def match (string, pattern):
129 # tmp - there's probably much simpler
130 # rewrite * into .*, ? into .
131 pattern=pattern.replace("*",".*")
132 pattern=pattern.replace("?",".")
133 return re.compile(pattern).match(string)
135 def locate_sanity_scripts (message,path,extensions):
136 print message,'searching',path,'for extensions',extensions
138 for ext in extensions:
139 scripts += glob.glob (path+'/*.'+ext)