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():
config = self._generateInstanceXML(software_configuration,
test_result, test_suite)
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
return {'status_code' : 0}
else:
......@@ -210,7 +210,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
config = self._generateInstanceXML(software_configuration,
test_result, test_suite)
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}
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()),))
self.log("Software reachable profile path is : %s " %(self.reachable_profile))
# Initialize SlapOS Master Communicator
self.slapos_communicator = SlapOSMasterCommunicator.SoftwareReleaseTester(
self.slapos_communicator = SlapOSMasterCommunicator.SlapOSTester(
self.instance_title,
self.log,
slap,
......@@ -402,12 +402,12 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
for configuration in configuration_list:
# First configuration doesn't need XML configuration update.
if count > 0:
self.slapos_communicator.requestStop()
self.slapos_communicator.requestInstanceStop()
self.slapos_communicator.waitInstanceStopped(self.instance_title)
self._updateInstanceXML(configuration, self.instance_title,
node_test_suite.test_result, node_test_suite.test_suite)
self.slapos_communicator.waitInstanceStarted(self.instance_title)
self.slapos_communicator.requestStart()
self.slapos_communicator.requestInstanceStart()
self.slapos_communicator.waitInstanceStarted(self.instance_title)
self.log("[DEBUG] INSTANCE CORRECTLY STARTED")
......@@ -451,7 +451,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
break
# Stop current instance
self.slapos_communicator.requestStop()
self.slapos_communicator.requestInstanceStop()
self.slapos_communicator.waitInstanceStopped(self.instance_title)
# Delete old instances
......
......@@ -69,7 +69,7 @@ def retryOnNetworkFailure(func):
class SlapOSMasterCommunicator(object):
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.slap = slap
......@@ -250,6 +250,20 @@ class SlapOSMasterCommunicator(object):
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
def _getInstanceState(self):
latest_state = self.latest_state
......@@ -362,10 +376,7 @@ class SlapOSMasterCommunicator(object):
self._logger("Instance correctly '%s' after %s seconds." %(state, str(time.time()-start_time)))
return {'error_message' : None}
class SoftwareReleaseTester(SlapOSMasterCommunicator):
deadline = None
class SlapOSTester(SlapOSMasterCommunicator):
def __init__(self,
name,
logger,
......@@ -374,13 +385,10 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
slap_supply,
url, # software release url
computer_guid=None, # computer for supply if desired
request_kw=None, # instance parameters, if instantiation
# testing is desired
software_timeout=3600,
instance_timeout=3600,
request_kw=None
):
super(SoftwareReleaseTester, self).__init__(
super(SlapOSTester, self).__init__(
slap, slap_supply, slap_order, url, logger)
self.name = name
......@@ -393,6 +401,73 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
self.request_kw = request_kw
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.transition_dict = {
# step function
......@@ -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):
deadline = self.deadline
if deadline is not None:
......@@ -486,14 +521,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
return '<%s(state=%s, deadline=%s) at %x>' % (
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):
if len(self.message_history) == 0:
return "No message"
......@@ -520,21 +547,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
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
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