Commit f5c4a33f authored by Roque's avatar Roque Committed by Klaus Wölfel

testnode: refactoring in SlapOS communicator

- some method names were changed to make them clearer
- new intermediate class 'SlapOSTester'
parent 716d1e0b
...@@ -149,7 +149,7 @@ class ScalabilityTestRunner(): ...@@ -149,7 +149,7 @@ class ScalabilityTestRunner():
config = self._generateInstanceXML(software_configuration, config = self._generateInstanceXML(software_configuration,
test_result, test_suite) test_result, test_suite)
request_kw = {"partition_parameter_kw": {"_" : json.dumps(config)} } request_kw = {"partition_parameter_kw": {"_" : json.dumps(config)} }
self.slapos_communicator.requestStart(instance_title, request_kw) self.slapos_communicator.requestInstanceStart(instance_title, request_kw)
self.authorize_request = False self.authorize_request = False
return {'status_code' : 0} return {'status_code' : 0}
else: else:
...@@ -210,7 +210,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -210,7 +210,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
config = self._generateInstanceXML(software_configuration, config = self._generateInstanceXML(software_configuration,
test_result, test_suite) test_result, test_suite)
request_kw = {"partition_parameter_kw": {"_" : json.dumps(config)} } request_kw = {"partition_parameter_kw": {"_" : json.dumps(config)} }
self.slapos_communicator.requestStart(instance_title, request_kw) self.slapos_communicator.requestInstanceStart(instance_title, request_kw)
return {'status_code' : 0} return {'status_code' : 0}
def _waitInstanceCreation(self, instance_title, max_time=MAX_CREATION_INSTANCE_TIME): def _waitInstanceCreation(self, instance_title, max_time=MAX_CREATION_INSTANCE_TIME):
...@@ -334,7 +334,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -334,7 +334,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
self.log("Software reachable profile path is : %s " %(self.reachable_profile)) self.log("Software reachable profile path is : %s " %(self.reachable_profile))
# Initialize SlapOS Master Communicator # Initialize SlapOS Master Communicator
self.slapos_communicator = SlapOSMasterCommunicator.SoftwareReleaseTester( self.slapos_communicator = SlapOSMasterCommunicator.SlapOSTester(
self.instance_title, self.instance_title,
self.log, self.log,
slap, slap,
...@@ -402,16 +402,16 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -402,16 +402,16 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
for configuration in configuration_list: for configuration in configuration_list:
# First configuration doesn't need XML configuration update. # First configuration doesn't need XML configuration update.
if count > 0: if count > 0:
self.slapos_communicator.requestStop() self.slapos_communicator.requestInstanceStop()
self.slapos_communicator.waitInstanceStopped(self.instance_title) self.slapos_communicator.waitInstanceStopped(self.instance_title)
self._updateInstanceXML(configuration, self.instance_title, self._updateInstanceXML(configuration, self.instance_title,
node_test_suite.test_result, node_test_suite.test_suite) node_test_suite.test_result, node_test_suite.test_suite)
self.slapos_communicator.waitInstanceStarted(self.instance_title) self.slapos_communicator.waitInstanceStarted(self.instance_title)
self.slapos_communicator.requestStart() self.slapos_communicator.requestInstanceStart()
self.slapos_communicator.waitInstanceStarted(self.instance_title) self.slapos_communicator.waitInstanceStarted(self.instance_title)
self.log("[DEBUG] INSTANCE CORRECTLY STARTED") self.log("[DEBUG] INSTANCE CORRECTLY STARTED")
# ROQUE XXX : for debug # ROQUE XXX : for debug
if True: if True:
self.log("RETURN FOR DEBUG") self.log("RETURN FOR DEBUG")
...@@ -451,7 +451,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -451,7 +451,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
break break
# Stop current instance # Stop current instance
self.slapos_communicator.requestStop() self.slapos_communicator.requestInstanceStop()
self.slapos_communicator.waitInstanceStopped(self.instance_title) self.slapos_communicator.waitInstanceStopped(self.instance_title)
# Delete old instances # Delete old instances
...@@ -516,4 +516,4 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -516,4 +516,4 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
Used by the method testnode.constructProfile() to know Used by the method testnode.constructProfile() to know
if the software.cfg have to use relative path or not. if the software.cfg have to use relative path or not.
""" """
return True return True
\ No newline at end of file
...@@ -69,7 +69,7 @@ def retryOnNetworkFailure(func): ...@@ -69,7 +69,7 @@ def retryOnNetworkFailure(func):
class SlapOSMasterCommunicator(object): class SlapOSMasterCommunicator(object):
latest_state = None latest_state = None
def __init__(self, slap, slap_supply, slap_order, url, logger ): def __init__(self, slap, slap_supply, slap_order, url, logger):
self._logger = logger self._logger = logger
self.slap = slap self.slap = slap
...@@ -250,6 +250,20 @@ class SlapOSMasterCommunicator(object): ...@@ -250,6 +250,20 @@ class SlapOSMasterCommunicator(object):
return SOFTWARE_STATE_UNKNOWN return SOFTWARE_STATE_UNKNOWN
@retryOnNetworkFailure
def getRSSEntryFromMonitoring(self, base_url):
if base_url is None:
return {}
feed_url = base_url + '/monitor-public/rssfeed.html'
d = feedparser.parse(feed_url)
if len(d.entries) > 0:
return {"date": d.entries[0].published,
"message": d.entries[0].description,
"title" : d.entries[0].title}
return {}
@retryOnNetworkFailure @retryOnNetworkFailure
def _getInstanceState(self): def _getInstanceState(self):
latest_state = self.latest_state latest_state = self.latest_state
...@@ -362,10 +376,7 @@ class SlapOSMasterCommunicator(object): ...@@ -362,10 +376,7 @@ class SlapOSMasterCommunicator(object):
self._logger("Instance correctly '%s' after %s seconds." %(state, str(time.time()-start_time))) self._logger("Instance correctly '%s' after %s seconds." %(state, str(time.time()-start_time)))
return {'error_message' : None} return {'error_message' : None}
class SlapOSTester(SlapOSMasterCommunicator):
class SoftwareReleaseTester(SlapOSMasterCommunicator):
deadline = None
def __init__(self, def __init__(self,
name, name,
logger, logger,
...@@ -374,14 +385,11 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -374,14 +385,11 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
slap_supply, slap_supply,
url, # software release url url, # software release url
computer_guid=None, # computer for supply if desired computer_guid=None, # computer for supply if desired
request_kw=None, # instance parameters, if instantiation request_kw=None
# testing is desired
software_timeout=3600,
instance_timeout=3600,
): ):
super(SoftwareReleaseTester, self).__init__( super(SlapOSTester, self).__init__(
slap, slap_supply, slap_order, url, logger) slap, slap_supply, slap_order, url, logger)
self.name = name self.name = name
self.computer_guid = computer_guid self.computer_guid = computer_guid
...@@ -392,7 +400,74 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -392,7 +400,74 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
else: else:
self.request_kw = request_kw self.request_kw = request_kw
self.message_history = [] self.message_history = []
def getInfo(self):
info = ""
info += "Software Release URL: %s\n" % (self.url)
if self.computer_guid is not None:
info += "Supply requested on: %s\n" % (self.computer_guid)
info += "Instance Requested (Parameters): %s\n" % self.request_kw
return info
def supply(self, software_path=None, computer_guid=None):
if software_path is not None:
self.url = software_path
if computer_guid is not None:
self.computer_guid = computer_guid
self._supply()
def requestInstanceStart(self, instance_title=None, request_kw=None):
self._request(INSTANCE_STATE_STARTED, instance_title, request_kw)
def requestInstanceStop(self, instance_title=None, request_kw=None):
self._request(INSTANCE_STATE_STOPPED, instance_title, request_kw)
def requestInstanceDestroy(self, instance_title=None, request_kw=None):
self._request(INSTANCE_STATE_DESTROYED, instance_title, request_kw)
def waitInstanceStarted(self, instance_title):
error_message = self._waitInstance(instance_title, INSTANCE_STATE_STARTED)["error_message"]
if error_message is not None:
self._logger(error_message)
self._logger("Do you use instance state propagation in your project?")
self._logger("Instance '%s' will be stopped and test aborted." %instance_title)
self.requestInstanceStop()
time.sleep(60)
raise ValueError(error_message)
def waitInstanceStopped(self, instance_title):
error_message = self._waitInstance(instance_title, INSTANCE_STATE_STOPPED)["error_message"]
if error_message is not None:
self._logger(error_message)
self._logger("Do you use instance state propagation in your project?")
raise ValueError(error_message)
def waitInstanceDestroyed(self, instance_title):
error_message = self._waitInstance(instance_title, INSTANCE_STATE_DESTROYED)["error_message"]
if error_message is not None:
self._logger(error_message)
self._logger("Do you use instance state propagation in your project?")
raise ValueError(error_message)
class SoftwareReleaseTester(SlapOSTester):
deadline = None
def __init__(self,
name,
logger,
slap,
slap_order,
slap_supply,
url, # software release url
computer_guid=None, # computer for supply if desired
request_kw=None,
software_timeout=3600,
instance_timeout=3600,
):
super(SoftwareReleaseTester, self).__init__(
name, logger, slap, slap_order, slap_supply, url, computer_guid, request_kw)
self.state = TESTER_STATE_INITIAL self.state = TESTER_STATE_INITIAL
self.transition_dict = { self.transition_dict = {
# step function # step function
...@@ -438,46 +513,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -438,46 +513,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
), ),
} }
def supply(self, software_path=None, computer_guid=None):
if software_path is not None:
self.url = software_path
if computer_guid is not None:
self.computer_guid = computer_guid
self._supply()
def requestStart(self, instance_title=None, request_kw=None):
self._request(INSTANCE_STATE_STARTED, instance_title, request_kw)
def requestStop(self, instance_title=None, request_kw=None):
self._request(INSTANCE_STATE_STOPPED, instance_title, request_kw)
def requestDestroy(self, instance_title=None, request_kw=None):
self._request(INSTANCE_STATE_DESTROYED, instance_title, request_kw)
def waitInstanceStarted(self, instance_title):
error_message = self._waitInstance(instance_title, INSTANCE_STATE_STARTED)["error_message"]
if error_message is not None:
self._logger(error_message)
self._logger("Do you use instance state propagation in your project?")
self._logger("Instance '%s' will be stopped and test aborted." %instance_title)
self.requestStop()
time.sleep(60)
raise ValueError(error_message)
def waitInstanceStopped(self, instance_title):
error_message = self._waitInstance(instance_title, INSTANCE_STATE_STOPPED)["error_message"]
if error_message is not None:
self._logger(error_message)
self._logger("Do you use instance state propagation in your project?")
raise ValueError(error_message)
def waitInstanceDestroyed(self, instance_title):
error_message = self._waitInstance(instance_title, INSTANCE_STATE_DESTROYED)["error_message"]
if error_message is not None:
self._logger(error_message)
self._logger("Do you use instance state propagation in your project?")
raise ValueError(error_message)
def __repr__(self): def __repr__(self):
deadline = self.deadline deadline = self.deadline
if deadline is not None: if deadline is not None:
...@@ -486,14 +521,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -486,14 +521,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
return '<%s(state=%s, deadline=%s) at %x>' % ( return '<%s(state=%s, deadline=%s) at %x>' % (
self.__class__.__name__, self.state, deadline, id(self)) self.__class__.__name__, self.state, deadline, id(self))
def getInfo(self):
info = ""
info += "Software Release URL: %s\n" % (self.url)
if self.computer_guid is not None:
info += "Supply requested on: %s\n" % (self.computer_guid)
info += "Instance Requested (Parameters): %s\n" % self.request_kw
return info
def getFormatedLastMessage(self): def getFormatedLastMessage(self):
if len(self.message_history) == 0: if len(self.message_history) == 0:
return "No message" return "No message"
...@@ -520,21 +547,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -520,21 +547,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
return summary + message return summary + message
@retryOnNetworkFailure
def getRSSEntryFromMonitoring(self, base_url):
if base_url is None:
return {}
feed_url = base_url + '/monitor-public/rssfeed.html'
d = feedparser.parse(feed_url)
if len(d.entries) > 0:
return {"date": d.entries[0].published,
"message": d.entries[0].description,
"title" : d.entries[0].title}
return {}
@retryOnNetworkFailure @retryOnNetworkFailure
def teardown(self): def teardown(self):
""" """
......
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