Commit 306a36e3 authored by Roque's avatar Roque

Refactoring in interaction between scalability runner and master communicator.

- Functionality in Slapos Master Communicator setters for instance name and request parameters moved to request method.
- Refactoring to avoid calling request method with hardcoded states.
- Refactoring in supply method: state parameter removed.
parent c388793a
...@@ -106,7 +106,7 @@ class ScalabilityTestRunner(): ...@@ -106,7 +106,7 @@ class ScalabilityTestRunner():
self.log("testnode, supply : %s %s", software_path, computer_guid) self.log("testnode, supply : %s %s", software_path, computer_guid)
if self.authorize_supply : if self.authorize_supply :
self.remaining_software_installation_dict[computer_guid] = software_path self.remaining_software_installation_dict[computer_guid] = software_path
self.slapos_communicator._supply("started") self.slapos_communicator._supply()
return {'status_code' : 0} return {'status_code' : 0}
else: else:
raise ValueError("Too late to supply now. ('self.authorize_supply' is False)") raise ValueError("Too late to supply now. ('self.authorize_supply' is False)")
...@@ -146,16 +146,12 @@ class ScalabilityTestRunner(): ...@@ -146,16 +146,12 @@ class ScalabilityTestRunner():
Create scalability instance Create scalability instance
""" """
if self.authorize_request: if self.authorize_request:
self.log("testnode, request : %s", instance_title)
config = self._generateInstanceXML(software_configuration, config = self._generateInstanceXML(software_configuration,
test_result, test_suite) test_result, test_suite)
self.log("testnode, request : %s", instance_title) request_kw = {"partition_parameter_kw": {"_" : json.dumps(config)} }
config = json.dumps(config)
request = {"_" : config}
request_kw = {"partition_parameter_kw": request }
#self.log("request_kw: " + str(request_kw)) # kept for DEBUG #self.log("request_kw: " + str(request_kw)) # kept for DEBUG
self.slapos_communicator.setName(instance_title) self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STARTED, instance_title, request_kw)
self.slapos_communicator.setRequestParameters(request_kw)
self.slapos_communicator._request("started")
self.authorize_request = False self.authorize_request = False
return {'status_code' : 0} return {'status_code' : 0}
else: else:
...@@ -211,18 +207,12 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -211,18 +207,12 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
return len(self.remaining_software_installation_dict) > 0 return len(self.remaining_software_installation_dict) > 0
def _updateInstanceXML(self, software_configuration, instance_title, def _updateInstanceXML(self, software_configuration, instance_title,
test_result, test_suite): test_result, test_suite):
"""
Just a proxy to SlapOSControler.updateInstanceXML.
"""
config = self._generateInstanceXML(software_configuration,
test_result, test_suite)
config = json.dumps(config)
self.log("testnode, updateInstanceXML : %s", instance_title) self.log("testnode, updateInstanceXML : %s", instance_title)
request = {"_" : config} config = self._generateInstanceXML(software_configuration,
request_kw = {"partition_parameter_kw": request } test_result, test_suite)
self.slapos_communicator.setRequestParameters(request_kw) request_kw = {"partition_parameter_kw": {"_" : json.dumps(config)} }
self.slapos_communicator._request("started") self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STARTED, instance_title, request_kw)
return {'status_code' : 0} return {'status_code' : 0}
def _waitInstance(self, instance_title, state, max_time=MAX_INSTANCE_TIME): def _waitInstance(self, instance_title, state, max_time=MAX_INSTANCE_TIME):
...@@ -240,7 +230,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -240,7 +230,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
self.log(error_message) self.log(error_message)
self.log("Do you use instance state propagation in your project?") self.log("Do you use instance state propagation in your project?")
self.log("Instance '%s' will be stopped and test aborted." %instance_title) self.log("Instance '%s' will be stopped and test aborted." %instance_title)
self.slapos_communicator._request('stopped') self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
time.sleep(60) time.sleep(60)
raise ValueError(error_message) raise ValueError(error_message)
self.log("Instance correctly '%s' after %s seconds." %(state, str(time.time()-start_time))) self.log("Instance correctly '%s' after %s seconds." %(state, str(time.time()-start_time)))
...@@ -435,20 +425,20 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -435,20 +425,20 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
# First configuration doesn't need XML configuration update. # First configuration doesn't need XML configuration update.
if count > 0: if count > 0:
self.log("[DEBUG] COUNT > 0 : updating XML configuration...") self.log("[DEBUG] COUNT > 0 : updating XML configuration...")
self.slapos_communicator._request('stopped') self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED) self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
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._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STARTED) self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STARTED)
self.slapos_communicator._request('started') self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STARTED)
''' '''
# ROQUE: for now, this old hack is not needed # ROQUE: for now, this old hack is not needed
# XXX: Dirty hack used to force haproxy to restart in time with all zope informations. # XXX: Dirty hack used to force haproxy to restart in time with all zope informations.
self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STARTED) self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STARTED)
self.slapos_communicator._request('stopped') self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED) self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
self.slapos_communicator._request('started') self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STARTED)
########################################################## ##########################################################
''' '''
...@@ -494,7 +484,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),)) ...@@ -494,7 +484,7 @@ late a SlapOS (positive) answer." %(str(os.getpid()),str(os.getpid()),))
break break
# Stop current instance # Stop current instance
self.slapos_communicator._request('stopped') self.slapos_communicator._request(SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED) self._waitInstance(self.instance_title, SlapOSMasterCommunicator.INSTANCE_STATE_STOPPED)
# Delete old instances # Delete old instances
......
...@@ -24,10 +24,10 @@ SOFTWARE_STATE_DESTROYING = "SOFTWARE_STATE_DESTROYING" ...@@ -24,10 +24,10 @@ SOFTWARE_STATE_DESTROYING = "SOFTWARE_STATE_DESTROYING"
INSTANCE_STATE_UNKNOWN = "INSTANCE_STATE_UNKNOWN" INSTANCE_STATE_UNKNOWN = "INSTANCE_STATE_UNKNOWN"
INSTANCE_STATE_STARTING = "INSTANCE_STATE_STARTING" INSTANCE_STATE_STARTING = "INSTANCE_STATE_STARTING"
INSTANCE_STATE_STARTED = "INSTANCE_STATE_STARTED" INSTANCE_STATE_STARTED = "started"
INSTANCE_STATE_STARTED_WITH_ERROR = "INSTANCE_STATE_STARTED_WITH_ERROR" INSTANCE_STATE_STARTED_WITH_ERROR = "INSTANCE_STATE_STARTED_WITH_ERROR"
INSTANCE_STATE_STOPPING = "INSTANCE_STATE_STOPPING" INSTANCE_STATE_STOPPING = "INSTANCE_STATE_STOPPING"
INSTANCE_STATE_STOPPED = "INSTANCE_STATE_STOPPED" INSTANCE_STATE_STOPPED = "stopped"
INSTANCE_STATE_DESTROYING = "INSTANCE_STATE_DESTROYING" INSTANCE_STATE_DESTROYING = "INSTANCE_STATE_DESTROYING"
TESTER_STATE_INITIAL = "TESTER_STATE_INITIAL" TESTER_STATE_INITIAL = "TESTER_STATE_INITIAL"
...@@ -88,34 +88,31 @@ class SlapOSMasterCommunicator(object): ...@@ -88,34 +88,31 @@ class SlapOSMasterCommunicator(object):
self.url = url self.url = url
def setName(self, name):
self.name = name
def setRequestParameters(self, request_kw):
if isinstance(request_kw, str) or \
isinstance(request_kw, unicode):
self.request_kw = json.loads(request_kw)
else:
self.request_kw = request_kw
@retryOnNetworkFailure @retryOnNetworkFailure
def _supply(self, state): def _supply(self):
if self.computer_guid is None: if self.computer_guid is None:
self._logger ('Nothing to supply for %s.' % (self.name)) self._logger ('Nothing to supply for %s.' % (self.name))
return None return None
self._logger('Supply %s@%s: %s', self.url, self.computer_guid, self._logger('Supply %s@%s', self.url, self.computer_guid)
state)
return self.slap_supply.supply(self.url, self.computer_guid) return self.slap_supply.supply(self.url, self.computer_guid)
@retryOnNetworkFailure @retryOnNetworkFailure
def _request(self, state): def _request(self, state, instance_title=None, request_kw=None):
if instance_title is not None:
self.name = instance_title
if request_kw is not None:
if isinstance(request_kw, str) or \
isinstance(request_kw, unicode):
self.request_kw = json.loads(request_kw)
else:
self.request_kw = request_kw
self._logger('Request %s@%s: %s', self.url, self.name, state) self._logger('Request %s@%s: %s', self.url, self.name, state)
self.latest_state = state self.latest_state = state
return self.slap_order.request( return self.slap_order.request(
software_release=self.url, software_release=self.url,
partition_reference=self.name, partition_reference=self.name,
state=state, state=state,
**self.request_kw) **self.request_kw)
@retryOnNetworkFailure @retryOnNetworkFailure
def _hateoas_getComputer(self, reference): def _hateoas_getComputer(self, reference):
......
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