From: Thierry Parmentelat Date: Sun, 13 Jun 2010 17:56:31 +0000 (+0200) Subject: add leases to the default config, applicale only with reservable nodes, which is... X-Git-Tag: tests-5.0-6~11 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=72dfe45e8b716c1c599f8b50299db5ad8b898fd0;p=tests.git add leases to the default config, applicale only with reservable nodes, which is the prupose of config_resa --- diff --git a/system/TestApiserver.py b/system/TestApiserver.py index 0ad8935..93a24bb 100644 --- a/system/TestApiserver.py +++ b/system/TestApiserver.py @@ -38,6 +38,8 @@ server_methods = [ ('GetNodes' , []), ('AddPersonKey' , True), ('GetPlcRelease', {'build': {'target-arch':'i386'}}), ('GetSites', []), + ('GetLeaseGranularity', 180), + ('AddLeases', True), ] class TestApiserver: diff --git a/system/TestPlc.py b/system/TestPlc.py index d61212d..cf8d9f8 100644 --- a/system/TestPlc.py +++ b/system/TestPlc.py @@ -87,7 +87,7 @@ class TestPlc: '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 @@ -657,6 +657,39 @@ class TestPlc: "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 @@ -728,10 +761,16 @@ class TestPlc: 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 minutes nothing gets printed def nodes_check_boot_state (self, target_boot_state, timeout_minutes, silent_minutes,period=15): diff --git a/system/config_default.py b/system/config_default.py index 37a740f..e1a3a75 100644 --- a/system/config_default.py +++ b/system/config_default.py @@ -7,6 +7,8 @@ # 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, @@ -145,18 +147,18 @@ def initscripts(options,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)] @@ -183,7 +185,21 @@ def tcp_tests (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, @@ -206,13 +222,14 @@ def plc (options,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) : @@ -284,5 +301,5 @@ def sfa_slice_rspec(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 diff --git a/system/config_resa.py b/system/config_resa.py new file mode 100644 index 0000000..02f485e --- /dev/null +++ b/system/config_resa.py @@ -0,0 +1,22 @@ +# 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 +