Commit 47d9bf42 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼 Committed by Rafael Monnerat

Fix the promise for backupserver

The promise should not fail if the backup was never launched because the instance just deployed.

/reviewed-on !47
parent 2848a965
...@@ -6,6 +6,7 @@ from slapos.grid.promise.generic import TestResult ...@@ -6,6 +6,7 @@ from slapos.grid.promise.generic import TestResult
import re import re
import sys import sys
import pytz import pytz
from os.path import isfile, getmtime
from datetime import datetime from datetime import datetime
from croniter import croniter from croniter import croniter
from dateutil.parser import parse from dateutil.parser import parse
...@@ -31,11 +32,20 @@ class RunPromise(GenericPromise): ...@@ -31,11 +32,20 @@ class RunPromise(GenericPromise):
* we can't grep "backup failed" in the text file * we can't grep "backup failed" in the text file
""" """
script = self.getConfig('script_fullpath')
status = self.getConfig('status_fullpath') status = self.getConfig('status_fullpath')
prev_cron = croniter(self.getConfig('cron_frequency'), datetime.now(pytz.utc)).get_prev(datetime) # date of the previous time cron launched prev_cron = croniter(self.getConfig('cron_frequency'), datetime.now(pytz.utc)).get_prev(datetime) # date of the previous time cron launched
status_url = "{}/private/{}/{}".format(self.getConfig("monitor_url"), self.getConfig("status_dirbasename"), self.getConfig("status_name")) status_url = "{}/private/{}/{}".format(self.getConfig("monitor_url"), self.getConfig("status_dirbasename"), self.getConfig("status_name"))
statistic_url = "{}/private/{}/{}".format(self.getConfig("monitor_url"), self.getConfig("statistic_dirbasename"), self.getConfig("statistic_name")) statistic_url = "{}/private/{}/{}".format(self.getConfig("monitor_url"), self.getConfig("statistic_dirbasename"), self.getConfig("statistic_name"))
# If log file is not present, it can be OK if we launched the instance after the last cron due date
if not isfile(status):
if pytz.utc.localize(datetime.utcfromtimestamp(getmtime(script))) < prev_cron:
self.logger.error("Backup status file is not present")
else:
self.logger.info("Backup was never launched")
return
# First, parse the log file # First, parse the log file
backup_started = False backup_started = False
backup_ended = False backup_ended = False
...@@ -73,10 +83,9 @@ class RunPromise(GenericPromise): ...@@ -73,10 +83,9 @@ class RunPromise(GenericPromise):
def test(self): def test(self):
""" """
Test is never failing because we don't want to check when buildout deploy This is the default test function. Could be commented.
the instance that the backup is working as it may not have started yet.
""" """
return TestResult(problem=False, message="") return self._test(result_count=1, failure_amount=1)
def anomaly(self): def anomaly(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