Beispiel #1
0
	def rendezvous(self, wait_for_all=not ONLY_WAIT_FOR_CRITICAL): # Rendezvous for processes
		"""
		wait for all process in the list to complette
		New version, replaces the 08/09/2015 one, better use of OOP

		:type wait_for_all: bool
		"""
		offset = len(PRE_BOOT_CHECK_LIST)
		for each in self[:]:
			assert isinstance(each, SysCheckUnit) and each.has_proc
			# Only wait for mandatory checks
			if wait_for_all or each.mandatory:
				each.block()
				self._results[each.url] = each.exitcode == 0
				if self.FAIL_ON_CRITICAL_MISSING and each.exitcode != 0 and each.mandatory:
					print TermColoring.fail('BREEZE INIT FAILED ( %s )' % repr(each.ex()))
					from sys import exit
					exit(2)
				each.terminate()
				self.remove(each)

		for each in self:
			self._results[each.url] = each.exitcode == 0

		success_text = 'successful : %s/%s' % (len(self.succeeded) + offset, len(self.boot_tests) + offset)

		if not self.any_running:
			print TermColoring.ok_green('System is up and running, All checks done ! (%s)' % success_text)
		else:
			print TermColoring.ok_green('System is up and running, %s, ') % success_text + \
				TermColoring.warning('but %s (non critical) check%s %s still running %s') % \
				(self.running_count, 's' if self.running_count > 1 else '', self.article, self.still_running)
Beispiel #2
0
	def rendezvous(self, wait_for_all=not ONLY_WAIT_FOR_CRITICAL): # Rendezvous for processes
		"""
		wait for all process in the list to complette
		New version, replaces the 08/09/2015 one, better use of OOP

		:type wait_for_all: bool
		"""
		offset = len(PRE_BOOT_CHECK_LIST)
		for each in self[:]:
			assert isinstance(each, SysCheckUnit) and each.has_proc
			# Only wait for mandatory checks
			if wait_for_all or each.mandatory:
				each.block()
				self._results[each.url] = each.exitcode == 0
				if self.FAIL_ON_CRITICAL_MISSING and each.exitcode != 0 and each.mandatory:
					print TermColoring.fail('BREEZE INIT FAILED ( %s )' % repr(each.ex()))
					from sys import exit
					exit(2)
				each.terminate()
				self.remove(each)

		for each in self:
			self._results[each.url] = each.exitcode == 0

		success_text = 'successful : %s/%s' % (len(self.succeeded) + offset, len(self.boot_tests) + offset)

		if not self.any_running:
			print TermColoring.ok_green('System is up and running, All checks done ! (%s)' % success_text)
		else:
			print TermColoring.ok_green('System is up and running, %s, ') % success_text + \
				TermColoring.warning('but %s (non critical) check%s %s still running %s') % \
				(self.running_count, 's' if self.running_count > 1 else '', self.article, self.still_running)
Beispiel #3
0
	def split_runner(self, from_ui=False):
		""" Checker function runner, Call the function, display console message and exception if appropriate

		:type from_ui: bool
		"""
		has_raised, res = False, False
		if callable(self.checker_function):
			try:
				res = self.checker_function(self.arg) if self.arg is not None else self.checker_function()
			except SystemCheckFailed as e:
				has_raised = True
				self.ex = e
			except Exception as e:
				has_raised = True
				self.ex = e
				logger.warning('sys_check2 %s failed to return: %s' % (self.url, e))
		else:
			raise InvalidArgument(TermColoring.fail('Argument function must be a callable object'))

		sup2 = TermColoring.warning('required and critical !' if self.mandatory else 'NOT critical') if not res else ''
		if not from_ui:
			print self.msg,
			sup = self.run_after() if self.run_after is not None and callable(self.run_after) else ''
			print OK if res else BAD if self.mandatory else WARN, sup, sup2

		if not res:
			import sys
			if self.RAISE_EXCEPTION and not from_ui:
				raise self.ex
			if from_ui or self.mandatory:
				sys.exit(self.EXIT_CHECK_RAISED) if has_raised else sys.exit(self.EXIT_CHECK_FAILED)
			sys.exit(self.EXIT_NON_CRITICAL_FAILED)
Beispiel #4
0
	def __init__(self, function, url, legend, msg, a_type, t_out=0, arg=None, run_after=None, ex=SystemCheckFailed,
				mandatory=False, long_poll=False, ui_text=('Online', 'Offline')):
		"""
		init Arguments :
		function: the function to run to asses test result
		url: id of test, and url part to access it
		legend: title to display on WebUI
		msg: title to display on Console
		type: type of this test
		t_out: timeout to set test as failed
		arg: arguments to function
		run_after: a function to run after this test
		ex: an exception to eventually raise on check failure
		mandatory: is this test success is required to system consistent boot

		:param function: the function to run to asses test result
		:type function: callable
		:param url: id of test, and url part to access it
		:type url: str
		:param legend: title to display on WebUI
		:type legend: str
		:param msg: title to display on Console
		:type msg: str
		:param a_type: type of this test
		:type a_type: RunType.property
		:param t_out: timeout to set test as failed
		:type t_out: int
		:param arg: arguments to funct
		:type arg:
		:param run_after: a function to run after this test
		:type run_after: callable
		:param ex: an exception to eventually raise on check failure
		:type ex: Exception
		:param mandatory: is this test success is required to system consistent boot
		:type mandatory: bool
		:param ui_text: optional text to be shown in UI, default is ('Online', 'Offline')
		:type ui_text: (str, str)
		"""
		if a_type is RunType.runtime or callable(function):
			self.checker_function = function
			self.url = url
			self.legend = legend
			self._msg = msg
			self.t_out = int(t_out)
			self.arg = arg
			self.type = a_type
			self.run_after = run_after
			self.mandatory = mandatory
			self.ex = ex
			self.lp = long_poll
			self.ui_text = ui_text
			super(SysCheckUnit, self).__init__()
		else:
			raise InvalidArgument(TermColoring.fail('Argument function must be a callable object'))
Beispiel #5
0
	def __init__(self, function, url, legend, msg, a_type, t_out=0, arg=None, run_after=None, ex=SystemCheckFailed,
				mandatory=False, long_poll=False, ui_text=('Online', 'Offline')):
		"""
		init Arguments :
		function: the function to run to asses test result
		url: id of test, and url part to access it
		legend: title to display on WebUI
		msg: title to display on Console
		type: type of this test
		t_out: timeout to set test as failed
		arg: arguments to function
		run_after: a function to run after this test
		ex: an exception to eventually raise on check failure
		mandatory: is this test success is required to system consistent boot

		:param function: the function to run to asses test result
		:type function: callable
		:param url: id of test, and url part to access it
		:type url: str
		:param legend: title to display on WebUI
		:type legend: str
		:param msg: title to display on Console
		:type msg: str
		:param a_type: type of this test
		:type a_type: RunType.property
		:param t_out: timeout to set test as failed
		:type t_out: int
		:param arg: arguments to funct
		:type arg:
		:param run_after: a function to run after this test
		:type run_after: callable
		:param ex: an exception to eventually raise on check failure
		:type ex: Exception
		:param mandatory: is this test success is required to system consistent boot
		:type mandatory: bool
		:param ui_text: optional text to be shown in UI, default is ('Online', 'Offline')
		:type ui_text: (str, str)
		"""
		if a_type is RunType.runtime or callable(function):
			self.checker_function = function
			self.url = url
			self.legend = legend
			self._msg = msg
			self.t_out = int(t_out)
			self.arg = arg
			self.type = a_type
			self.run_after = run_after
			self.mandatory = mandatory
			self.ex = ex
			self.lp = long_poll
			self.ui_text = ui_text
			super(SysCheckUnit, self).__init__()
		else:
			raise InvalidArgument(TermColoring.fail('Argument function must be a callable object'))
Beispiel #6
0
	def split_runner(self, from_ui=False):
		""" Checker function runner.
		Call the function, display console message and exception if appropriate

		:type from_ui: bool
		"""
		res = False
		if callable(self.checker_function):
			try:
				if self.arg is not None:
					res = self.checker_function(self.arg)
				else:
					res = self.checker_function()
			except Exception as e:
				self.ex = e
				pass
		else:
			raise InvalidArgument(TermColoring.fail('Argument function must be a callable object'))

		sup = ''
		sup2 = ''

		if not res:
			if self.mandatory:
				sup2 = TermColoring.warning('required and critical !')
			else:
				sup2 = TermColoring.warning('NOT critical')

		if not from_ui:
			print self.msg,
			if self.run_after is not None and callable(self.run_after):
				sup = self.run_after()
			print OK if res else BAD if self.mandatory else WARN, sup, sup2

		if not res:
			import sys
			if self.RAISE_EXCEPTION and not from_ui:
				raise self.ex
			if from_ui or self.mandatory:
				sys.exit(1)
			sys.exit(2)
Beispiel #7
0
from django.conf import settings
from breeze.b_exceptions import *
from django.http import HttpRequest
from collections import OrderedDict

DEBUG = True
SKIP_SYSTEM_CHECK = False

if DEBUG:
	# quick fix to solve PyCharm Django console environment issue
	from breeze.process import MyProcess as Process
else:
	from multiprocessing import Process

OK = '[' + TermColoring.ok_green('OK') + ']'
BAD = '[' + TermColoring.fail('NO') + ']'
WARN = '[' + TermColoring.warning('NO') + ']'


# clem 25/09/2015
class CheckerList(list):
	""" list of SysCheckUnit with filtering properties """
	FAIL_ON_CRITICAL_MISSING = True
	ONLY_WAIT_FOR_CRITICAL = True # if checker should also wait for non-critical

	def __init__(self, check_list):
		self._list_to_check = check_list
		self._results = dict()
		super(CheckerList, self).__init__()

	@property
Beispiel #8
0
from breeze.b_exceptions import *
from django.http import HttpRequest
from collections import OrderedDict

DEBUG = True
SKIP_SYSTEM_CHECK = False

# if DEBUG:
# # quick fix to solve PyCharm Django console environment issue
# 	#from breeze.process import Process
# else:
# 	from multiprocessing import Process
from breeze.process import Process

OK = '[' + TermColoring.ok_green('OK') + ']'
BAD = '[' + TermColoring.fail('NO') + ']'
WARN = '[' + TermColoring.warning('NO') + ']'


# clem 25/09/2015
class CheckerList(list):
	""" list of SysCheckUnit with filtering properties """
	FAIL_ON_CRITICAL_MISSING = True
	ONLY_WAIT_FOR_CRITICAL = True # if checker should also wait for non-critical

	def __init__(self, check_list):
		self._list_to_check = check_list
		self._results = dict()
		super(CheckerList, self).__init__()

	@property