Commit e028637b authored by Benjamin Blanc's avatar Benjamin Blanc

testnode: add isHostingSubscriptionCorrectly method

parent 392574e7
......@@ -500,7 +500,7 @@ revision = %(revision2)s
"launchable": False, "randomized_path" : "azertyuiop"})
def patch_isMasterTestnode(self, *args, **kw):
return (grade == 'master')
def patch_isInstanceCorrectly(self, *args, **kw):
def patch_isHostingSubscriptionCorrectly(self, *args, **kw):
return True
test_self = self
test_result_path_root = os.path.join(test_self._temp_dir,'test/results')
......@@ -567,14 +567,14 @@ revision = %(revision2)s
original_generateConfiguration = TaskDistributor.generateConfiguration
original_isMasterTestnode = TaskDistributor.isMasterTestnode
original_updateInstanceXML = RunnerClass._updateInstanceXML
original_isInstanceCorrectly = SlapOSMasterCommunicator.isInstanceCorrectly
original_isHostingSubscriptionCorrectly = SlapOSMasterCommunicator.isHostingSubscriptionCorrectly
original_SlapOSMasterCommunicator__init__ = SlapOSMasterCommunicator.__init__
TaskDistributor.getSlaposAccountKey = patch_getSlaposAccountKey
TaskDistributor.getSlaposAccountCertificate = patch_getSlaposAccountCertificate
TaskDistributor.generateConfiguration = patch_generateConfiguration
TaskDistributor.isMasterTestnode = patch_isMasterTestnode
RunnerClass._updateInstanceXML = doNothing
SlapOSMasterCommunicator.isInstanceCorrectly = patch_isInstanceCorrectly
SlapOSMasterCommunicator.isHostingSubscriptionCorrectly = patch_isHostingSubscriptionCorrectly
SlapOSMasterCommunicator.__init__ = doNothing
original_startTestSuite = TaskDistributor.startTestSuite
original_subscribeNode = TaskDistributor.subscribeNode
......@@ -604,7 +604,7 @@ revision = %(revision2)s
TaskDistributor.generateConfiguration = original_generateConfiguration
TaskDistributor.isMasterTestnode = original_isMasterTestnode
RunnerClass._updateInstanceXML = original_updateInstanceXML
SlapOSMasterCommunicator.isInstanceCorrectly = original_isInstanceCorrectly
SlapOSMasterCommunicator.isHostingSubscriptionCorrectly = original_isHostingSubscriptionCorrectly
SlapOSMasterCommunicator.__init__ = original_SlapOSMasterCommunicator__init__
TaskDistributor.startTestSuite = original_startTestSuite
TaskDistributionTool.createTestResult = original_createTestResult
......@@ -666,7 +666,7 @@ revision = %(revision2)s
"launchable": False, "randomized_path" : "azertyuiop"})
def patch_isMasterTestnode(self, *args, **kw):
return grade == 'master'
def patch_isInstanceCorrectly(self, *args, **kw):
def patch_isHostingSubscriptionCorrectly(self, *args, **kw):
return True
test_self = self
test_result_path_root = os.path.join(test_self._temp_dir,'test/results')
......@@ -721,7 +721,7 @@ revision = %(revision2)s
original_supply = SlapOSControler.supply
original_request = SlapOSControler.request
original_updateInstanceXML = RunnerClass._updateInstanceXML
original_isInstanceCorrectly = SlapOSMasterCommunicator.isInstanceCorrectly
original_isHostingSubscriptionCorrectly = SlapOSMasterCommunicator.isHostingSubscriptionCorrectly
original_SlapOSMasterCommunicator__init__ = SlapOSMasterCommunicator.__init__
TaskDistributor.getSlaposAccountKey = patch_getSlaposAccountKey
TaskDistributor.getSlaposAccountCertificate = patch_getSlaposAccountCertificate
......@@ -730,7 +730,7 @@ revision = %(revision2)s
SlapOSControler.supply = doNothing
SlapOSControler.request = doNothing
RunnerClass._updateInstanceXML = doNothing
SlapOSMasterCommunicator.isInstanceCorrectly = patch_isInstanceCorrectly
SlapOSMasterCommunicator.isHostingSubscriptionCorrectly = patch_isHostingSubscriptionCorrectly
SlapOSMasterCommunicator.__init__ = doNothing
original_startTestSuite = TaskDistributor.startTestSuite
original_subscribeNode = TaskDistributor.subscribeNode
......@@ -760,7 +760,7 @@ revision = %(revision2)s
SlapOSControler.supply =original_supply
SlapOSControler.request = original_request
SlapOSControler.updateInstanceXML = original_updateInstanceXML
SlapOSMasterCommunicator.isInstanceCorrectly = original_isInstanceCorrectly
SlapOSMasterCommunicator.isHostingSubscriptionCorrectly = original_isHostingSubscriptionCorrectly
SlapOSMasterCommunicator.__init__ = original_SlapOSMasterCommunicator__init__
TaskDistributor.startTestSuite = original_startTestSuite
TaskDistributionTool.createTestResult = original_createTestResult
......@@ -936,7 +936,7 @@ revision = %(revision2)s
return "Certificate"
def patch_getTestType(self, *args, **kw):
return "ScalabilityTest"
def patch_isInstanceCorrectly(self, *args, **kw):
def patch_isHostingSubscriptionCorrectly(self, *args, **kw):
return True
test_self = self
test_result_path_root = os.path.join(test_self._temp_dir,'test/results')
......@@ -959,7 +959,7 @@ revision = %(revision2)s
original_supply = SlapOSControler.supply
original_request = SlapOSControler.request
original_updateInstanceXML = SlapOSControler.updateInstanceXML
original_isInstanceCorrectly = SlapOSMasterCommunicator.isInstanceCorrectly
original_isHostingSubscriptionCorrectly = SlapOSMasterCommunicator.isHostingSubscriptionCorrectly
original_SlapOSMasterCommunicator__init__ = SlapOSMasterCommunicator.__init__
#
......@@ -977,7 +977,7 @@ revision = %(revision2)s
SlapOSControler.supply = doNothing
SlapOSControler.request = doNothing
SlapOSControler.updateInstanceXML = doNothing
SlapOSMasterCommunicator.isInstanceCorrectly = patch_isInstanceCorrectly
SlapOSMasterCommunicator.isHostingSubscriptionCorrectly = patch_isHostingSubscriptionCorrectly
SlapOSMasterCommunicator.__init__ = doNothing
# Run
test_node = self.getTestNode()
......@@ -996,6 +996,6 @@ revision = %(revision2)s
SlapOSControler.supply = original_supply
SlapOSControler.request = original_request
SlapOSControler.updateInstanceXML = original_updateInstanceXML
SlapOSMasterCommunicator.isInstanceCorrectly = original_isInstanceCorrectly
SlapOSMasterCommunicator.isHostingSubscriptionCorrectly = original_isHostingSubscriptionCorrectly
SlapOSMasterCommunicator.__init__ = original_SlapOSMasterCommunicator__init__
time.sleep =original_sleep
......@@ -46,6 +46,7 @@ from erp5.util import taskdistribution
# for dummy slapos answer
import signal
MAX_INSTANCE_TIME = 60*60 # 1 hour
class ScalabilityTestRunner():
def __init__(self, testnode):
......@@ -181,7 +182,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
Return true if the specified instance is ready.
This method should communicates with SlapOS Master.
"""
return self.slapos_communicator.isInstanceCorrectly(instance_title, state)
return self.slapos_communicator.isHostingSubscriptionCorrectly(instance_title, state)
def remainSoftwareToInstall(self):
"""
......@@ -209,9 +210,13 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
# Used to simulate slapOS answer
def _waitInstance(self, instance_title, state):
self.log("Wait for instance state: %s" %state)
while (not self.isInstanceReady(instance_title, state)):
#TODO: add a time limit
max_time = MAX_INSTANCE_TIME
start_time = 0
while (not self.isInstanceReady(instance_title, state)
and (max_time > (time.time()-start_time))):
time.sleep(15)
pass
def prepareSlapOSForTestSuite(self, node_test_suite):
"""
......
......@@ -116,7 +116,8 @@ class SlapOSMasterCommunicator(object):
if excepted_news_text != news['news'][0]['text']:
return False
return len(related_instance_link_list) > 0
# check if requested state = status
def isInstanceCorrect(self, instance_link):
"""
Return True if instance status and instance news text ~looks corresponding.
......@@ -128,7 +129,20 @@ class SlapOSMasterCommunicator(object):
text = news['news'][0]['text']
requested_status = instance['status']
return ('Instance' in text) and ('correctly' in text) and (requested_status in text)
# check if requested state = status
def isHostingSubscriptionCorrect(self, hosting_subscription_title):
"""
Return True if all instance news related to hosting_subscription_title
correspond to the requested status.
"""
instance_link_list = self._getRelatedInstanceLink(hosting_subscription_title)
for instance_link in instance_link_list:
if not communicator.isInstanceCorrect(instance_link):
return False
return len(instance_link_list) > 0
# check if provided 'status' = status
def isInstanceCorrectly(self, instance_link, status):
"""
Return True if instance status and instance news text ~looks corresponding.
......@@ -137,14 +151,16 @@ class SlapOSMasterCommunicator(object):
text = self.getNewsFromInstanceLink(instance_link)['news'][0]['text']
return ('Instance' in text) and ('correctly' in text) and (status in text)
def isHostingSubscriptionCorrect(self, hosting_subscription_title):
# check if provided 'status' = status
def isHostingSubscriptionCorrectly(self, hosting_subscription_title, status):
"""
Return True if all instance news related to hosting_subscription_title
correspond to the requested status.
Return True if all instance status and instance news text ~looks corresponding.
( use the matching of 'correctly' and 'Instance' and status ).
"""
instance_link_list = self._getRelatedInstanceLink('TestScalability_21423104630420')
instance_link_list = self._getRelatedInstanceLink(hosting_subscription_title)
for instance_link in instance_link_list:
if not communicator.isInstanceCorrect(instance_link):
if not communicator.isInstanceCorrectly(instance_link, status):
return False
return len(instance_link_list) > 0
\ 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