help="Run all default steps")
parser.add_option("-l","--list",action="store_true",dest="list_steps", default=False,
help="List known steps")
- parser.add_option("-s","--state",action="store",dest="dbname",default=None,
- help="Used by db_dump and db_restore")
- parser.add_option("-d","--display", action="store", dest="display", default='bellami.inria.fr:0.0',
- help="Set DISPLAY for vmplayer")
parser.add_option("-i","--ip",action="callback", callback=TestMain.optparse_list, dest="ips",
nargs=1,type="string",
help="Specify the set of IP addresses to use in vserver mode (disable scanning)")
+ parser.add_option("-s","--small",action="store_true",dest="small_test",default=False,
+ help="run a small test -- typically only one node")
+ parser.add_option("-d","--dbname",action="store",dest="dbname",default=None,
+ help="Used by db_dump and db_restore")
parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False,
help="Run in verbose mode")
parser.add_option("-q","--quiet", action="store_true", dest="quiet", default=False,
class TestMapper:
- def __init__ (self,plcs,mapper,options):
+ def __init__ (self,plcs,options):
self.plcs=plcs
- self.mapper=mapper
self.options=options
@staticmethod
o=obj
for step in path[:-1]:
if not o.has_key(step):
- utils.header ("WARNING : cannot apply step %s in path %s on %s %s"%(
+ o[step]={}
+ utils.header ("WARNING : created step %s in path %s on %s %s"%(
step,path,type,name))
- return
- o=obj[step]
+ o=o[step]
# last step is the one for side-effect
step=path[-1]
if not o.has_key(step):
- utils.header ("WARNING : cannot apply step %s in path %s on %s %s"%(
+ utils.header ("WARNING : inserting key %s for path %s on %s %s"%(
step,path,type,name))
- return
- # apply formatting if found
+ # apply formatting if '%s' found in the value
if v.find('%s')>=0:
v=v%obj[k]
if self.options.verbose:
# only apply first rule
return
- def map (self):
+ def node_names (self):
+ result=[]
+ for plc in self.plcs:
+ for site in plc['sites']:
+ for node in site['nodes']:
+ result.append(node['node_fields']['hostname'])
+ return result
- plc_maps = self.mapper['plc']
+ def map (self,mapper):
+
+ try:
+ plc_maps = mapper['plc']
+ except:
+ plc_maps = []
+ try:
+ node_maps = mapper['node']
+ except:
+ node_maps = []
for plc in self.plcs:
name=TestMapper.plc_name(plc)
self.apply_first_map ('plc',name,plc,plc_maps)
- node_maps = self.mapper['node']
-
for site in plc['sites']:
for node in site['nodes']:
nodename = TestMapper.node_name(node)
self.apply_first_map('node',nodename,node,node_maps)
return self.plcs
-
-
self.node_spec=node_spec
def name(self):
- return self.node_spec['node_fields']['hostname']
+ return self.node_spec['name']
@staticmethod
def is_qemu_model (model):
def locate_node (self,nodename):
for site in self.plc_spec['sites']:
for node in site['nodes']:
- if node['node_fields']['hostname'] == nodename:
+ if node['name'] == nodename:
return (site,node)
raise Exception,"Cannot locate node %s"%nodename
--- /dev/null
+#
+# Thierry Parmentelat - INRIA Sophia Antipolis
+#
+# pool class
+#
+# allows to pick an available IP among a pool
+#
+# input is expressed as a list of tuples ('hostname_or_ip',user_data)
+# can be searched iteratively
+# e.g.
+# pool = [ (hostname1,ip1,user_data1), (hostname2,ip2,user_data2),
+# (hostname3,ip3,user_data2), (hostname4,ip4,user_data4) ]
+# assuming that ip1 and ip3 are taken (pingable), then we'd get
+# pool=TestPool(pool)
+# pool.next_free() -> entry2
+# pool.next_free() -> entry4
+# pool.next_free() -> None
+# that is, even if ip2 is not busy/pingable when the second next_free() is issued
+
+import commands
+import utils
+
+class TestPool:
+
+ def __init__ (self, pool, options):
+ self.pool=pool
+ self.options=options
+ self.busy=[]
+
+ def locate (self, hostname_or_ip):
+ for (h,i,u) in self.pool:
+ if h==hostname_or_ip or i==hostname_or_ip:
+ return (h,i,u)
+ return None
+
+ def next_free (self):
+ # if preferred is provided, let's re-order
+ for (host,ip,user_data) in self.pool:
+ if host in self.busy:
+ continue
+ utils.header('TestPool : checking %s'%host)
+ if not TestPool.check_ping (host):
+ utils.header('%s is available'%host)
+ self.busy.append(host)
+ return (host,ip,user_data)
+ else:
+ self.busy.append(host)
+ return None
+
+# OS-dependent ping option (support for macos, for convenience)
+ ping_timeout_option = None
+# checks whether a given hostname/ip responds to ping
+ @staticmethod
+ def check_ping (hostname):
+ if not TestPool.ping_timeout_option:
+ (status,osname) = commands.getstatusoutput("uname -s")
+ if status != 0:
+ raise Exception, "TestPool: Cannot figure your OS name"
+ if osname == "Linux":
+ TestPool.ping_timeout_option="-w"
+ elif osname == "Darwin":
+ TestPool.ping_timeout_option="-t"
+
+ command="ping -c 1 %s 1 %s"%(TestPool.ping_timeout_option,hostname)
+ (status,output) = commands.getstatusoutput(command)
+ return status == 0
--- /dev/null
+#
+from TestMapper import TestMapper
+
+# using mapper to do the reallocation job
+
+target = 'testbox32.one-lab.org'
+
+def config (plcs, options):
+
+ mapper = {'plc': [ ('*' , {'hostname':target,
+ 'PLC_DB_HOST':target,
+ 'PLC_API_HOST':target,
+ 'PLC_BOOT_HOST':target,
+ 'PLC_WWW_HOST':target,
+ 'name':'%s32' } ) ],
+ 'node': [ ('*' , {'host_box': target } ) ],
+ }
+
+ return TestMapper(plcs,options).map(mapper)
--- /dev/null
+#
+from TestMapper import TestMapper
+
+# using mapper to do the reallocation job
+
+def config (plcs, options):
+
+ mapper = {'plc': [ ('*' , {'hostname':target,
+ 'PLC_DB_HOST':target,
+ 'PLC_API_HOST':target,
+ 'PLC_BOOT_HOST':target,
+ 'PLC_WWW_HOST':target,
+ 'name':'%s64' } ) ],
+ 'node': [ ('*' , {'host_box': target } ) ],
+ }
+
+ return TestMapper(plcs,options).map(mapper)
--- /dev/null
+# map all nodes onto the avail. pool
+
+from TestMapper import TestMapper
+from TestPool import TestPool
+
+onelab_plcs_pool = [
+ ( 'vnode%02d.inria.fr'%i, '138.96.250.22%d'%i, 'ab:cd:ef:00:01:%02d'%i) for i in range(1,10) ]
+site_dict = {
+ 'network_fields:gateway':'138.96.248.250',
+ 'network_fields:network':'138.96.0.0',
+ 'network_fields:broadcast':'138.96.255.255',
+ 'network_fields:netmask':'255.255.0.0',
+ 'network_fields:dns1': '138.96.0.10',
+ 'network_fields:dns2': '138.96.0.11',
+}
+
+def config (plcs, options):
+
+ test_pool = TestPool (onelab_plcs_pool,options)
+ test_mapper = TestMapper (plcs, options)
+
+ all_nodenames = test_mapper.node_names()
+ maps = []
+ for nodename in all_nodenames:
+ (hostname,ip,mac) = test_pool.next_free()
+ node_dict= {'node_fields:hostname':hostname,
+ 'network_fields:ip':ip,
+ 'network_fields:mac':mac}
+ node_dict.update(site_dict)
+ maps.append ( ( nodename, node_dict) )
+
+ plc_map = [ ( '*' , { 'PLC_NET_DNS1' : site_dict [ 'network_fields:dns1' ],
+ 'PLC_NET_DNS2' : site_dict [ 'network_fields:dns2' ], } ) ]
+
+ return test_mapper.map ({'node': maps, 'plc' : plc_map } )
--- /dev/null
+import utils
+import os.path
+from TestPool import TestPool
+
+# the pool of IP addresses available - from 01 to 09
+onelab_plcs_pool = [
+ ( 'vplc%02d.inria.fr'%i, '138.96.250.13%d'%i, 'ab:cd:ef:00:00:%02d'%i) for i in range(1,10) ]
+
+# let's be flexible
+def locate (user_provided):
+ global available
+ for (hostname,ip,mac) in available:
+ if hostname.find(user_provided) >=0 or ip.find(user_provided) >=0:
+ return (hostname,ip)
+
+def config (plcs,options):
+
+ utils.header ("Turning configuration into a vserver-based one for onelab")
+
+ test_pool = TestPool (onelab_plcs_pool,options)
+
+ if len(options.ips) != 0:
+ utils.header('Using user-provided IPS:\nips=%r'%options.ips)
+ options.ips.reverse()
+
+ plc_counter=0
+ for plc in plcs:
+ try:
+ if len (options.ips != 0):
+ (hostname,ip,mac)=test_pool.locate(options.ips.pop())
+ else:
+ (hostname,ip,mac)=test_pool.next_free()
+
+ ### rewrite fields in plc
+ # compute a helpful vserver name - remove domain in hostname
+ simplehostname=hostname.split('.')[0]
+ # myplc rpm basename, without .rpm
+ vservername = os.path.basename(options.myplc_url)
+ vservername = vservername.replace(".rpm","")
+ # vservername
+ vservername = vservername.replace("myplc","vtest")
+ if len(plcs) == 1 :
+ vservername = "%s-%s" % (vservername,simplehostname)
+ else:
+ plc_counter += 1
+ vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
+ # apply
+ plc['vservername']=vservername
+ plc['vserverip']=ip
+ plc['name'] = "%s_%s"%(plc['name'],simplehostname)
+ utils.header("Attaching plc %s to vserver %s (%s)"%(
+ plc['name'],plc['vservername'],plc['vserverip']))
+ for key in [ 'PLC_DB_HOST', 'PLC_API_HOST', 'PLC_WWW_HOST', 'PLC_BOOT_HOST',]:
+ plc[key] = hostname
+
+ except:
+ raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
+
+ return plcs
# (**) TestMain options field
# (*) and that returns the new set of plc_specs
-onelab="one-lab.org"
+# values like 'hostname', 'ip' and the like my be rewritten later with a TestPool object
-# host_box is taken as 'localhost' if omitted (should be a direct field in the node spec)
-def nodes():
- nodes= [{'node_fields': {'hostname': 'vnode01.inria.fr',
+def nodes(options):
+ nodes= [{'name':'node1',
+ 'node_fields': {'hostname': 'deferred01',
'model':'qemu/minhw', } ,
'host_box': 'testbox1.one-lab.org',
'owner' : 'pi',
'network_fields': { 'method':'static',
'type':'ipv4',
- 'ip':'138.96.250.221',
- 'gateway':'138.96.248.250',
- 'network':'138.96.0.0',
- 'broadcast':'138.96.255.255',
- 'netmask':'255.255.0.0',
- 'dns1': '138.96.0.10',
- 'dns2': '138.96.0.11',
+ 'ip':'xx-deferred-xxx',
+ 'gateway':'xx-deferred-xxx',
+ 'network':'xx-deferred-xxx',
+ 'broadcast':'xx-deferred-xxx',
+ 'netmask':'xx-deferred-xxx',
+ 'dns1': 'xx-deferred-xxx',
+ 'dns2': 'xx-deferred-xxx',
+ },
+ },
+ {'name':'node2',
+ 'node_fields': {'hostname': 'deferred02',
+ 'model':'qemu/minhw', } ,
+ 'host_box': 'testbox1.one-lab.org',
+ 'owner' : 'pi',
+ 'network_fields': { 'method':'static',
+ 'type':'ipv4',
+ 'ip':'xx-deferred-xxx',
+ 'gateway':'xx-deferred-xxx',
+ 'network':'xx-deferred-xxx',
+ 'broadcast':'xx-deferred-xxx',
+ 'netmask':'xx-deferred-xxx',
+ 'dns1': 'xx-deferred-xxx',
+ 'dns2': 'xx-deferred-xxx',
},
},
- #{'node_fields': {'hostname': 'vnode02.inria.fr',
- # 'model':'qemu/minhw', } ,
- # 'host_box': 'testbox1.one-lab.org',
- # 'owner' : 'pi',
- # 'network_fields': { 'method':'static',
- # 'type':'ipv4',
- # 'ip':'138.96.250.222',
- # 'gateway':'138.96.248.250',
- # 'network':'138.96.0.0',
- # 'broadcast':'138.96.255.255',
- # 'netmask':'255.255.0.0',
- # 'dns1': '138.96.0.10',
- # 'dns2': '138.96.0.11',
- # },
- # },
]
- return nodes
+ if options.small_test:
+ return [nodes[0]]
+ else:
+ return nodes
-def all_nodenames ():
- return [ node['node_fields']['hostname'] for node in nodes()]
+def all_nodenames (options):
+ return [ node['name'] for node in nodes(options)]
-def users (domain=onelab) :
+def users (options) :
+ domain="one-lab.org"
return [ {'name' : 'pi', 'keynames' : [ 'key1' ],
'user_fields' : {'first_name':'PI', 'last_name':'PI',
'enabled':'True',
'roles':['pi','tech']},
]
-def all_usernames ():
- return [ user['name'] for user in users()]
+def all_usernames (options):
+ return [ user['name'] for user in users(options)]
-def sites ():
+def sites (options):
return [ {'site_fields' : {'name':'mainsite',
'login_base':'main',
'abbreviated_name':'PLanettest',
'postalcode':'06600',
'country':'france',
},
- 'users' : users(),
- 'nodes': nodes(),
+ 'users' : users(options),
+ 'nodes': nodes(options),
}]
##########
-----END RSA PRIVATE KEY-----
"""
-def keys ():
+def keys (options):
return [ {'name': 'key1',
'private' : private_key,
'key_fields' : {'key_type':'ssh',
'key': public_key}}
]
-def initscripts():
- return [ { 'initscript_fields' : { 'enabled' : True,
- 'name':'script1',
- 'script' : '#! /bin/sh\n (echo Starting test initscript: Stage 1; date) > /tmp/initscript1.log \n ',
- }},
- { 'initscript_fields' : { 'enabled' : True,
- 'name':'script2',
- 'script' : '#! /bin/sh\n (echo Starting test initscript: Stage 2; date) > /tmp/initscript2.log \n ',
- }},
- ]
+def initscripts(options):
+ initscripts= [ { 'initscript_fields' : { 'enabled' : True,
+ 'name':'script1',
+ 'script' : '#! /bin/sh\n (echo Starting test initscript: Stage 1; date) > /tmp/initscript1.log \n ',
+ }},
+ { 'initscript_fields' : { 'enabled' : True,
+ 'name':'script2',
+ 'script' : '#! /bin/sh\n (echo Starting test initscript: Stage 2; date) > /tmp/initscript2.log \n ',
+ }},
+ ]
+ if options.small_test:
+ return [initscripts[0]]
+ else:
+ return initscripts
-def slices ():
+def slices (options):
both = [ { 'slice_fields': {'name':'main_slicetest1',
'instantiation':'plc-instantiated',
'url':'http://foo@ffo.com',
'max_nodes':2
},
'usernames' : [ 'pi','tech','techuser' ],
- 'nodenames' : all_nodenames(),
+ 'nodenames' : all_nodenames(options),
'initscriptname' : 'script1',
'sitename' : 'main',
'owner' : 'pi',
'max_nodes':100
},
'usernames' : [ 'user', 'pitech' ],
- 'nodenames' : all_nodenames(),
+ 'nodenames' : all_nodenames(options),
'initscriptname' : 'script2',
'sitename' : 'main',
'owner' : 'pi',
}]
- return both
+ if options.small_test:
+ return [both[0]]
+ else:
+ return both
-def all_slicenames ():
- return [ slice['slice_fields']['name'] for slice in slices()]
-#def tcp_param():
-# param = [{ 'tcp_fields' : {'peer_name' : 'server',
-# 'slice_name' :all_slicenames()[0],
-# 'server_name': all_nodenames()[0]
-# },
-#
-# },
-# { 'tcp_fields':{'peer_name' : 'client',
-# 'slice_name' :all_slicenames()[1],
-# 'client_name': all_nodenames()[1],
-# 'peer_server' : all_nodenames()[0],
-# 'server_port' : 22
-# },
-# },
-#
-# ]
-# return param
+def all_slicenames (options):
+ return [ slice['slice_fields']['name'] for slice in slices(options)]
+
+def tcp_param (options):
+ try:
+ return [{ 'tcp_fields' : {'peer_name' : 'server',
+ 'slice_name' :all_slicenames(options)[0],
+ 'server_name': all_nodenames()[0]
+ },
+
+ },
+ { 'tcp_fields':{'peer_name' : 'client',
+ 'slice_name' :all_slicenames()[1],
+ 'client_name': all_nodenames()[1],
+ 'peer_server' : all_nodenames()[0],
+ 'server_port' : 22
+ },
+ },
+
+ ]
+ except:
+ return None
-def plc () :
+def plc (options) :
return {
- 'name' : 'onelabtest',
+ 'name' : 'onetest',
# as of yet, not sure we can handle foreign hosts, but this is required though
- 'hostname' : 'testbox1.one-lab.org',
+ 'hostname' : 'xx-deferred-xxx',
# set these two items to run within a vserver
# 'vservername': '138.96.250.131'
# 'vserverip': '138.96.250.131'
'PLC_API_HOST' : 'test.one-lab.org',
'PLC_WWW_HOST' : 'test.one-lab.org',
'PLC_BOOT_HOST' : 'test.one-lab.org',
- 'PLC_NET_DNS1' : '138.96.0.10',
- 'PLC_NET_DNS2' : '138.96.0.11',
- 'sites' : sites(),
- 'keys' : keys(),
- 'initscripts': initscripts(),
- 'slices' : slices(),
- #'tcp_param' : tcp_param(),
+ 'PLC_NET_DNS1' : 'xx-deferred-xxx',
+ 'PLC_NET_DNS2' : 'xx-deferred-xxx',
+ 'sites' : sites(options),
+ 'keys' : keys(options),
+ 'initscripts': initscripts(options),
+ 'slices' : slices(options),
+ 'tcp_param' : tcp_param(options),
}
def config (plc_specs,options):
- return plc_specs + [ plc() ]
+ return plc_specs + [ plc(options) ]
+++ /dev/null
-#
-from TestMapper import TestMapper
-
-# using mapper to do the reallocation job
-
-def config (plcs, options):
-
- mapper = {'plc': [ ('*' , {'hostname':'testbox32.one-lab.org',
- 'name':'%s2' } ) ],
- 'node': [ ('*' , {'host_box':'testbox32.one-lab.org'} ) ],
- }
-
- return TestMapper(plcs,mapper,options).map()
+++ /dev/null
-#
-from TestMapper import TestMapper
-
-# using mapper to do the reallocation job
-
-def config (plcs, options):
-
- mapper = {'plc': [ ('*' , {'hostname':'testbox64.one-lab.org',
- 'name':'%s2' } ) ],
- 'node': [ ('*' , {'host_box':'testbox64.one-lab.org'} ) ],
- }
-
- return TestMapper(plcs,mapper,options).map()
+++ /dev/null
-import utils
-import os.path
-
-# the pool of IP addresses available
-# from 01 to 09
-available = [ ( 'vplc%02d.inria.fr'%i, '138.96.250.13%d'%i, 'ab:cd:ef:00:00:%02d'%i) for i in range(1,10) ]
-
-# let's be flexible
-def locate (user_provided):
- global available
- for (hostname,ip,mac) in available:
- if hostname.find(user_provided) >=0 or ip.find(user_provided) >=0:
- return (hostname,ip)
-
-def config (plcs,options):
- global available
- available.reverse()
- if len(options.ips) != 0:
- options.ips.reverse()
- plc_counter=0
- for plc in plcs:
- if len(options.ips) != 0:
- utils.header('ips=%r'%options.ips)
- user_provided = options.ips.pop()
- utils.header('vserver IP assignment : using user-provided %s'%user_provided)
- (hostname,ip) = locate(user_provided)
- else:
- ### locating the next available hostname (using ping)
- while True:
- try:
- (hostname,ip,mac)=available.pop()
- utils.header('vserver IP assignment : scanning IP %s'%ip)
- if not utils.check_ping(hostname):
- utils.header('IP %s is OK'%ip)
- break
- except:
- raise Exception('Cannot find an available IP for %s - exiting'%plc['name'])
- # compute a helpful vserver name
- plc_counter += 1
- simplehostname=hostname.split('.')[0]
- vservername = os.path.basename(options.myplc_url)
- vservername = vservername.replace(".rpm","")
- vservername = vservername.replace("myplc","vtest")
- if len(plcs) == 1 :
- vservername = "%s-%s" % (vservername,simplehostname)
- else:
- vservername = "%s-%d-%s" % (vservername,plc_counter,simplehostname)
- plc['vservername']=vservername
- plc['vserverip']=ip
- plc['name'] = "%s_%s"%(plc['name'],simplehostname)
- utils.header("Attaching plc %s to vserver %s (%s)"%\
- (plc['name'],plc['vservername'],plc['vserverip']))
- for key in [ 'PLC_DB_HOST',
- 'PLC_API_HOST',
- 'PLC_WWW_HOST',
- 'PLC_BOOT_HOST',
- ]:
- plc[key] = hostname
-
- return plcs
# use a model that contains "vmware" to get the node actually started
def nodes():
- node02 = {'node_fields': {'hostname': 'wlab02.inria.fr', 'model':'Dell Latitude 830'},
+ node02 = {'name':'wlab02',
+ 'node_fields': {'hostname': 'wlab02.inria.fr', 'model':'Dell Latitude 830'},
'owner' : 'pi',
'nodegroups' : 'wifi',
'network_fields': { 'method':'dhcp', 'type' : 'ipv4', 'ip':'138.96.250.162',},
},
],
}
- node05 = {'node_fields': {'hostname': 'wlab05.inria.fr', 'model':'Dell Latitude 830'},
+ node05 = {'name':'wlab05',
+ 'node_fields': {'hostname': 'wlab05.inria.fr', 'model':'Dell Latitude 830'},
'owner' : 'pi',
'nodegroups' : 'wifi',
'network_fields': { 'method':'dhcp', 'type' : 'ipv4', 'ip':'138.96.250.165',},
},
],
}
- node17 = {'node_fields': {'hostname': 'wlab17.inria.fr', 'model':'Dell Latitude 830'},
+ node17 = {'name':'wlab17',
+ 'node_fields': {'hostname': 'wlab17.inria.fr', 'model':'Dell Latitude 830'},
'owner' : 'pi',
'nodegroups' : ['wifi','x86_64'] ,
'network_fields': { 'method':'dhcp', 'type' : 'ipv4', 'ip':'138.96.250.177',},
return [ node02 , node05 , node17 ]
def all_nodenames ():
- return [ node['node_fields']['hostname'] for node in nodes()]
+ return [ node['name'] for node in nodes()]
def users (domain=onelab) :
return [ {'name' : 'pi', 'keynames' : [ 'key1' ],
# $Id$
import time
import os
-import commands
from pprint import PrettyPrinter
# how could this accept a list again ?
print "+",now,':',command
return os.system("set -x; " + command)
-# checks whether a given hostname/ip responds to ping
-ping_timeout_option = None
-def check_ping (hostname):
- # check OS (support for macos)
- global ping_timeout_option
- if not ping_timeout_option:
- (status,osname) = commands.getstatusoutput("uname -s")
- if status != 0:
- raise Exception, "Cannot figure your OS name"
- if osname == "Linux":
- ping_timeout_option="-w"
- elif osname == "Darwin":
- ping_timeout_option="-t"
-
- command="ping -c 1 %s 1 %s"%(ping_timeout_option,hostname)
- (status,output) = commands.getstatusoutput(command)
- return status == 0