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():
instance_title = "Scalability-"
instance_title += "("+test_suite_title+")-"
instance_title += str(self.involved_nodes_computer_guid).replace("'","")
instance_title += "-"
instance_title += time.strftime('%d/%m/%y_%H:%M:%S',time.localtime())
instance_title += "-"+str(datetime.now().isoformat())+"-"
instance_title += "timestamp="+str(time.time())
return instance_title
def _generateInstanceXML(self, software_configuration,
......@@ -417,6 +417,9 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
self.slapos_controler.stopInstance(self.instance_title)
self._waitInstance(self.instance_title, 'stopped')
#self.slapos_controler.destroyInstance(self.instance_title)
# Delete old instances
self._cleanUpOldInstance()
if error:
test_result_proxy.fail()
......@@ -425,7 +428,32 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
#test_result_proxy.stop()
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):
self.involved_nodes_computer_guid = []
self.launcher_nodes_computer_guid = []
......
......@@ -151,7 +151,6 @@ class SlapOSControler(object):
"""
self.log('SlapOSControler : request-->SlapOSMaster')
import pdb; pdb.set_trace()
current_intance_config = {'software_type':software_type,
'software_configuration':software_configuration,
'computer_guid':computer_guid,
......@@ -180,6 +179,8 @@ class SlapOSControler(object):
filter_kw = filter_kw,
state = state)
self.instance_config[reference]['partition'] = partition
if state == 'destroyed':
del self.instance_config[reference]
except:
self.log("SlapOSControler.request, \
exception in registerOpenOrder", exc_info=sys.exc_info())
......@@ -200,7 +201,6 @@ class SlapOSControler(object):
self.log('SlapOSControler : delete instance')
try:
self._requestSpecificState(reference, 'destroyed')
del self.instance_config[reference]
except:
raise ValueError("Can't delete instance '%s' (instance may not been created?)" %reference)
......@@ -227,7 +227,7 @@ class SlapOSControler(object):
self.log('SlapOSControler : updateInstanceXML will request same'
'instance with new XML configuration...')
try:
try:
self.request(reference,
self.instance_config[reference]['software_url'],
self.instance_config[reference]['software_type'],
......
......@@ -101,7 +101,7 @@ class SlapOSMasterCommunicator(object):
hosting_subscription = self._curl(hosting_subscription_link)
self.hosting_subcriptions_dict.update({hosting_subscription['title']:hosting_subscription_link})
self.visited_hosting_subcriptions_link_list.append(hosting_subscription_link)
def _getRelatedInstanceLink(self, hosting_subscription_title):
"""
Return a list of all related instance_url from an hosting_subscription_title
......@@ -171,11 +171,34 @@ class SlapOSMasterCommunicator(object):
return True
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
\ No newline at end of file
def getHostingSubscriptionInformationDict(self, title):
"""
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