Commit cba1f4e0 authored by Roque's avatar Roque

Code cleanup and summary of changes.

Cleanup:
- Old code comments removed
- Debug comments removed
- Old log entries for debug removed

Overall summary of changes:
- The base of this code comes from some work done by Rafael in here:
    https://lab.nexedi.com/nexedi/slapos.toolbox/blob/master/slapos/agent/tester.py
- Minor refactoring in communication with slap objects for supply and request.
- New setters (they will be refactored soon)
parent 0815d716
...@@ -77,9 +77,6 @@ class SlapOSMasterCommunicator(object): ...@@ -77,9 +77,6 @@ class SlapOSMasterCommunicator(object):
self.hateoas_navigator = self.slap._hateoas_navigator self.hateoas_navigator = self.slap._hateoas_navigator
self.hosting_subscription_url = None self.hosting_subscription_url = None
#self.computer_guid = computer_guid
#self.name = name
if url is not None and \ if url is not None and \
url.startswith(SOFTWARE_PRODUCT_NAMESPACE): url.startswith(SOFTWARE_PRODUCT_NAMESPACE):
...@@ -100,18 +97,15 @@ class SlapOSMasterCommunicator(object): ...@@ -100,18 +97,15 @@ class SlapOSMasterCommunicator(object):
self.request_kw = json.loads(request_kw) self.request_kw = json.loads(request_kw)
else: else:
self.request_kw = request_kw self.request_kw = request_kw
#self._logger("request parameters set: " + str(self.request_kw))
@retryOnNetworkFailure @retryOnNetworkFailure
def _supply(self, state): def _supply(self, state):
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("From SlapOSMasterCommunicator")
self._logger('Supply %s@%s: %s', self.url, self.computer_guid, self._logger('Supply %s@%s: %s', self.url, self.computer_guid,
state) state)
return self.slap_supply.supply(self.url, self.computer_guid) return self.slap_supply.supply(self.url, self.computer_guid)
#return self.slap_supply.supply(self.url, self.computer_guid, state)
@retryOnNetworkFailure @retryOnNetworkFailure
def _request(self, state): def _request(self, state):
...@@ -323,10 +317,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -323,10 +317,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))
# ROQUE: this method is a hack. This set must occur during request.
def forceSetState(self, state):
self.latest_state = state
def getInfo(self): def getInfo(self):
info = "" info = ""
info += "Software Release URL: %s\n" % (self.url) info += "Software Release URL: %s\n" % (self.url)
...@@ -439,23 +429,11 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -439,23 +429,11 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
monitor_v6_url = information["connection_dict"].get("monitor_v6_url") monitor_v6_url = information["connection_dict"].get("monitor_v6_url")
try: try:
monitor_information_dict = self.getRSSEntryFromMonitoring(monitor_v6_url) monitor_information_dict = self.getRSSEntryFromMonitoring(monitor_v6_url)
#self._logger("[DEBUG] monitor information dictionary: ")
#self._logger(str(monitor_information_dict))
except Exception: except Exception:
self._logger.exception('Unable to download promises for: %s' % (instance["title"])) self._logger ('Unable to download promises for: %s' % (instance["title"]))
self._logger (traceback.format_exc()) self._logger (traceback.format_exc())
monitor_information_dict = {"message": "Unable to download"} monitor_information_dict = {"message": "Unable to download"}
#self._logger('Information of instance ' + instance["title"])
#self._logger("{")
#self._logger ('Instance state: %s -> %s' % (instance['title'], state))
#self._logger ('Instance Created at: %s -> %s' % (instance['title'], info_created_at))
#self._logger(str(information))
#self._logger("Instance news: ")
#self._logger(str(news))
#self._logger("News: " + str(news[0]["text"]))
#self._logger("}")
message_list.append({ message_list.append({
'title': instance["title"], 'title': instance["title"],
'slave': is_slave, 'slave': is_slave,
...@@ -466,12 +444,12 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -466,12 +444,12 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
}) })
except slapos.slap.ServerError: except slapos.slap.ServerError:
self._logger.exception('Got an error requesting partition for ' self._logger ('Got an error requesting partition for '
'its state') 'its state')
return INSTANCE_STATE_UNKNOWN return INSTANCE_STATE_UNKNOWN
except:
#self._logger("COMPLETE MESSAGE LIST: ") self._logger("ERROR getting instance state")
#self._logger(str(message_list)) return INSTANCE_STATE_UNKNOWN
started = 0 started = 0
stopped = 0 stopped = 0
...@@ -479,7 +457,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -479,7 +457,6 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
for instance in message_list: for instance in message_list:
if not instance['slave'] and \ if not instance['slave'] and \
instance['state'] in (INSTANCE_STATE_UNKNOWN, INSTANCE_STATE_STARTED_WITH_ERROR): instance['state'] in (INSTANCE_STATE_UNKNOWN, INSTANCE_STATE_STARTED_WITH_ERROR):
self._logger("RETURNING INSTANCE STATE: " + instance['state'] + " (not slave)")
return instance['state'] return instance['state']
elif not instance['slave'] and instance['state'] == INSTANCE_STATE_STARTED: elif not instance['slave'] and instance['state'] == INSTANCE_STATE_STARTED:
started = 1 started = 1
...@@ -487,21 +464,16 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator): ...@@ -487,21 +464,16 @@ class SoftwareReleaseTester(SlapOSMasterCommunicator):
stopped = 1 stopped = 1
if instance['slave'] and instance['state'] == INSTANCE_STATE_UNKNOWN: if instance['slave'] and instance['state'] == INSTANCE_STATE_UNKNOWN:
self._logger("RETURNING INSTANCE STATE: UNKNOWN (slave+unknown)")
return instance['state'] return instance['state']
if started and stopped: if started and stopped:
self._logger("RETURNING INSTANCE STATE: UNKNOWN (started+stopped)")
self._logger("HACK - RETURNING STOPPED")
return INSTANCE_STATE_STOPPED return INSTANCE_STATE_STOPPED
return INSTANCE_STATE_UNKNOWN return INSTANCE_STATE_UNKNOWN
if started: if started:
self._logger("RETURNING INSTANCE STATE: STARTED")
return INSTANCE_STATE_STARTED return INSTANCE_STATE_STARTED
if stopped: if stopped:
self._logger("RETURNING INSTANCE STATE: STOPPED")
return INSTANCE_STATE_STOPPED return INSTANCE_STATE_STOPPED
@retryOnNetworkFailure @retryOnNetworkFailure
......
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