('AddPersonKey' , True),
('GetPlcRelease', {'build': {'target-arch':'i386'}}),
('GetSites', []),
+ ('GetLeaseGranularity', 180),
+ ('AddLeases', True),
]
class TestApiserver:
'display', 'resources_pre', SEP,
'delete_vs','create_vs','install', 'configure', 'start', SEP,
'fetch_keys', 'store_keys', 'clear_known_hosts', SEP,
- 'initscripts', 'sites', 'nodes', 'slices', 'nodegroups', SEP,
+ 'initscripts', 'sites', 'nodes', 'slices', 'nodegroups', 'leases', SEP,
'reinstall_node', 'init_node','bootcd', 'configure_qemu', 'export_qemu',
'kill_all_qemus', 'start_node', SEP,
# better use of time: do this now that the nodes are taking off
"delete nodegroups with PLCAPI"
return self.do_nodegroups("delete")
+ YEAR = 365*24*3600
+ @staticmethod
+ def translate_timestamp (start,timestamp):
+ if timestamp < TestPlc.YEAR: return start+timestamp
+ else: return timestamp
+
+ @staticmethod
+ def timestamp_printable (timestamp):
+ return time.strftime('%m-%d %H:%M UTC',time.gmtime(timestamp))
+
+ def leases(self):
+ now=time.time()
+ grain=self.apiserver.GetLeaseGranularity(self.auth_root())
+ round=(int(now)/grain)*grain
+ start=round+grain
+ # find out all nodes that are reservable
+ nodes=self.all_reservable_nodenames()
+ if not nodes:
+ utils.header ("No reservable node found - proceeding without leases")
+ return True
+ ok=True
+ # attach them to the leases as specified in plc_specs
+ # this is where the 'leases' field gets interpreted as relative of absolute
+ for lease_spec in self.plc_spec['leases']:
+ lease_spec['t_from']=TestPlc.translate_timestamp(start,lease_spec['t_from'])
+ lease_spec['t_until']=TestPlc.translate_timestamp(start,lease_spec['t_until'])
+ if self.apiserver.AddLeases(self.auth_root(),nodes,
+ lease_spec['slice'],lease_spec['t_from'],lease_spec['t_until']):
+ utils.header('Leases on nodes %r from %s until %s'%(nodes,lease_spec['t_from'],lease_spec['t_until']))
+ else:
+ ok=False
+ return ok
+
# create nodegroups if needed, and populate
def do_nodegroups (self, action="add"):
# 1st pass to scan contents
node_infos = []
for site_spec in self.plc_spec['sites']:
node_infos += [ (node_spec['node_fields']['hostname'],node_spec['host_box']) \
- for node_spec in site_spec['nodes'] ]
+ for node_spec in site_spec['nodes'] ]
return node_infos
def all_nodenames (self): return [ x[0] for x in self.all_node_infos() ]
+ def all_reservable_nodenames (self):
+ res=[]
+ for site_spec in self.plc_spec['sites']:
+ res += [ node_spec['hostname'] for node_spec in site_spec['nodes']
+ if 'node_type' in node_spec and node_spec['node_type'] == 'reservable' ]
+ return res
# silent_minutes : during the first <silent_minutes> minutes nothing gets printed
def nodes_check_boot_state (self, target_boot_state, timeout_minutes, silent_minutes,period=15):
# values like 'hostname', 'ip' and the like are rewritten later with a TestPool object
+reservation_granularity=180
+
def nodes(options,index):
return [{'name':'node%d'%index,
'node_fields': {'hostname': 'deferred-nodename%d'%index,
return initscripts
def slices (options,index):
- return [ { 'slice_fields': {'name':'main_pslc%d'%index,
+ return [ { 'slice_fields': {'name':'main_pslc%d'%i,
'instantiation':'plc-instantiated',
- 'url':'http://foo%d@foo.com'%index,
- 'description':'testslice number %d'%index,
+ 'url':'http://foo.com',
+ 'description':'testslice number %d'%i,
'max_nodes':2,
},
'usernames' : [ 'pi','tech','techuser' ],
'nodenames' : all_nodenames(options,index),
- 'initscriptname' : 'script%d'%index,
+ 'initscriptname' : 'script%d'%i,
'sitename' : 'main',
'owner' : 'pi',
- }]
+ } for i in range (2*index-1,2*index+1) ]
def all_slicenames (options,index):
return [ slice['slice_fields']['name'] for slice in slices(options,index)]
]
else:
return []
-
+
+# the semantic for 't_from' and 't_until' here is:
+# if they are smaller than one year, they are relative to the current time
+# otherwise they are absolute
+def leases (options, index):
+ leases=[]
+ counter=0
+ slices=all_slicenames(options,index)
+ slice_sequence = slices[:1] + slices + [None,]
+ for iterator in range(100):
+ for slice in slice_sequence:
+ leases += { 'slice' : slice, 't_from':counter,'t_until':counter+reservation_granularity}
+ counter += reservation_granularity
+ return leases
+
def plc (options,index) :
return {
'name' : 'onetest%d'%index,
'PLC_BOOT_HOST' : 'deferred-myplc-hostname',
'PLC_NET_DNS1' : 'deferred-dns-1',
'PLC_NET_DNS2' : 'deferred-dns-2',
- 'PLC_RESERVATION_GRANULARITY':300,
+ 'PLC_RESERVATION_GRANULARITY':reservation_granularity,
'sites' : sites(options,index),
'keys' : keys(options,index),
'initscripts': initscripts(options,index),
'slices' : slices(options,index),
'tcp_test' : tcp_tests(options,index),
'sfa' : sfa(options,index),
+ 'leases' : leases (options, index),
}
def sfa (options,index) :
def config (plc_specs,options):
result=plc_specs
for i in range (options.size):
- result += [ plc(options,i+1) ]
+ result.append(plc(options,i+1))
return result
--- /dev/null
+# a configuration module is expected:
+# (*) to define a config method
+# (*) that takes two arguments
+# (**) the current set of plc_specs as output by the preceding config modules
+# (**) TestMain options field
+# (*) and that returns the new set of plc_specs
+
+# values like 'hostname', 'ip' and the like are rewritten later with a TestPool object
+
+import config_default
+
+def config (plc_specs, options):
+ result=plc_specs
+ for i in range (options.size):
+ plc = config_default.plc(options,i+1)
+ for site in plc['sites']:
+ for node in site['nodes']:
+ node['node_fields']['node_type']='reservable'
+ result.append(plc)
+
+ return result
+