Commit cc58dcca authored by Benjamin Blanc's avatar Benjamin Blanc

testnode: delete scalability instance older than 2 days

parent 1582bfeb
...@@ -114,8 +114,8 @@ class ScalabilityTestRunner(): ...@@ -114,8 +114,8 @@ class ScalabilityTestRunner():
instance_title = "Scalability-" instance_title = "Scalability-"
instance_title += "("+test_suite_title+")-" instance_title += "("+test_suite_title+")-"
instance_title += str(self.involved_nodes_computer_guid).replace("'","") instance_title += str(self.involved_nodes_computer_guid).replace("'","")
instance_title += "-" instance_title += "-"+str(datetime.now().isoformat())+"-"
instance_title += time.strftime('%d/%m/%y_%H:%M:%S',time.localtime()) instance_title += "timestamp="+str(time.time())
return instance_title return instance_title
def _generateInstanceXML(self, software_configuration, def _generateInstanceXML(self, software_configuration,
...@@ -417,6 +417,9 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -417,6 +417,9 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
self.slapos_controler.stopInstance(self.instance_title) self.slapos_controler.stopInstance(self.instance_title)
self._waitInstance(self.instance_title, 'stopped') self._waitInstance(self.instance_title, 'stopped')
#self.slapos_controler.destroyInstance(self.instance_title) #self.slapos_controler.destroyInstance(self.instance_title)
# Delete old instances
self._cleanUpOldInstance()
if error: if error:
test_result_proxy.fail() test_result_proxy.fail()
...@@ -425,7 +428,32 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -425,7 +428,32 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
#test_result_proxy.stop() #test_result_proxy.stop()
return {'status_code' : 0} return {'status_code' : 0}
def _cleanUpOldInstance(self):
# Get link list of instances to delete
instance_dict = self.slapos_communicator.getHostingSubscriptionDict()
instance_to_delete_list = []
outdated_date = datetime.fromtimestamp(time.time()) - timedelta(days=2)
for title,link in instance_dict.items():
if "Scalability-" in title and "timestamp=" in title:
foo, timestamp = title.split("timestamp=")
creation_date = datetime.fromtimestamp(timestamp)
if creation_date < outdated_date:
instance_to_delete_list.append((title,link))
for title,link in instance_to_delete_list:
# Get instance information
instance_information_dict = self.slapos_communicator.getHostingSubscriptionInformation(link)
# Delete instance
if instance_information_dict:
self.slapos_controler.request(
instance_information_dict['title'],
instance_information_dict['software_url'],
software_type=instance_information_dict['software_type'],
computer_guid=instance_information_dict['computer_guid'],
state='destroyed'
)
def _cleanUpNodesInformation(self): def _cleanUpNodesInformation(self):
self.involved_nodes_computer_guid = [] self.involved_nodes_computer_guid = []
self.launcher_nodes_computer_guid = [] self.launcher_nodes_computer_guid = []
......
...@@ -151,7 +151,6 @@ class SlapOSControler(object): ...@@ -151,7 +151,6 @@ class SlapOSControler(object):
""" """
self.log('SlapOSControler : request-->SlapOSMaster') self.log('SlapOSControler : request-->SlapOSMaster')
import pdb; pdb.set_trace()
current_intance_config = {'software_type':software_type, current_intance_config = {'software_type':software_type,
'software_configuration':software_configuration, 'software_configuration':software_configuration,
'computer_guid':computer_guid, 'computer_guid':computer_guid,
...@@ -180,6 +179,8 @@ class SlapOSControler(object): ...@@ -180,6 +179,8 @@ class SlapOSControler(object):
filter_kw = filter_kw, filter_kw = filter_kw,
state = state) state = state)
self.instance_config[reference]['partition'] = partition self.instance_config[reference]['partition'] = partition
if state == 'destroyed':
del self.instance_config[reference]
except: except:
self.log("SlapOSControler.request, \ self.log("SlapOSControler.request, \
exception in registerOpenOrder", exc_info=sys.exc_info()) exception in registerOpenOrder", exc_info=sys.exc_info())
...@@ -200,7 +201,6 @@ class SlapOSControler(object): ...@@ -200,7 +201,6 @@ class SlapOSControler(object):
self.log('SlapOSControler : delete instance') self.log('SlapOSControler : delete instance')
try: try:
self._requestSpecificState(reference, 'destroyed') self._requestSpecificState(reference, 'destroyed')
del self.instance_config[reference]
except: except:
raise ValueError("Can't delete instance '%s' (instance may not been created?)" %reference) raise ValueError("Can't delete instance '%s' (instance may not been created?)" %reference)
...@@ -227,7 +227,7 @@ class SlapOSControler(object): ...@@ -227,7 +227,7 @@ class SlapOSControler(object):
self.log('SlapOSControler : updateInstanceXML will request same' self.log('SlapOSControler : updateInstanceXML will request same'
'instance with new XML configuration...') 'instance with new XML configuration...')
try: try:
self.request(reference, self.request(reference,
self.instance_config[reference]['software_url'], self.instance_config[reference]['software_url'],
self.instance_config[reference]['software_type'], self.instance_config[reference]['software_type'],
......
...@@ -101,7 +101,7 @@ class SlapOSMasterCommunicator(object): ...@@ -101,7 +101,7 @@ class SlapOSMasterCommunicator(object):
hosting_subscription = self._curl(hosting_subscription_link) hosting_subscription = self._curl(hosting_subscription_link)
self.hosting_subcriptions_dict.update({hosting_subscription['title']:hosting_subscription_link}) self.hosting_subcriptions_dict.update({hosting_subscription['title']:hosting_subscription_link})
self.visited_hosting_subcriptions_link_list.append(hosting_subscription_link) self.visited_hosting_subcriptions_link_list.append(hosting_subscription_link)
def _getRelatedInstanceLink(self, hosting_subscription_title): def _getRelatedInstanceLink(self, hosting_subscription_title):
""" """
Return a list of all related instance_url from an hosting_subscription_title Return a list of all related instance_url from an hosting_subscription_title
...@@ -171,11 +171,34 @@ class SlapOSMasterCommunicator(object): ...@@ -171,11 +171,34 @@ class SlapOSMasterCommunicator(object):
return True return True
return False return False
def getAliveHostingSubscription(self, prefix_title): def getHostingSubscriptionDict(self):
""" """
Return list of dict information of alive hosting subscrtion Return the dict of hosting subcription.
""" """
return [] return self.hosting_subcriptions_dict
def getHostingSubscriptionInformationDict(self, title):
\ No newline at end of file """
Return a dict with informations about Hosting subscription
"""
related_instance_link_list = self._getRelatedInstanceLink(title)
related_instance_link = None
# Get root instance
for link in related_instance_link_list:
instance = self._curl(link)
if tile == instance['title']:
related_instance_link = link
break
# Return information dict
if related_instance_link:
related_instance = self._curl(related_instance_link)
return {
'title': related_instance['title'],
'status': related_instance['status'],
'software_url': related_instance['_links']['http://slapos.org/reg/release'],
'software_type': related_instance['software_type'],
'computer_guid': related_instance['sla']['computer_guid']
}
else:
return None
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment