diff --git a/AUTHORS b/AUTHORS index 912e5766b..38e0db88e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,10 +1,227 @@ -Main developpers: - +5c077yP +Alexander Springer +Alexander Springer +Alexandre Boisvert +Alexandre Viau +Andreas Karfusehr +Andreas Karfusehr +Andreas Paul +Andrew McGilvray +Andrus Viik +Arthur Gautier +Arthur Gautier +Bruno Clermont +Charlie Andrews +Charlie Root +Christian Posch +Christophe SIMON +Christophe Simon +Claneys Skyne +DUVAL +DUVAL Kévin +Daniel Hokka Zakrisson +Daniel Widerin +Danijel Tasov David Durieux - - - -Contributors: - - - +David GUENAUL +David GUENAULT +David GUENAULT +David GUENAULT +David Gil +David Gil +David Laval +David Moreau Simard +David- +Davide Franco +Davide Franco +Demelziraptor +Denetariko +Denis Sacchet +Dessai.Imrane +DessaiImrane +Driskell +Durieux David +Eric Herot +FORLOT Romain +Florentin Raud +Forlot Romain +Forlot Romain +François Lafont +Fred MOHIER +Frescha +Frescha +FrogX +FrogX +Frédéric MOHIER +Frédéric MOHIER +Frédéric Pégé +Frédéric Pégé +Frédéric Pégé +Frédéric Vachon +GAULUPEAU Jonathan +GAULUPEAU Jonathan +Gabes Jean +Gabès Jean +Gabès Jean +Gerhard Lausser +Gerhard Lausser +Grégory Starck +Grégory Starck +Grégory Starck +Guillaume Bour +Guillaume Bour +H4wkmoon +H4wkmoon +Hannes Körber +Hartmut Goebel +Hartmut Goebel +Henry Bakker +Hermann.Lauer@iwr.uni-heidelberg.de +Httqm +Hubert +Jan Ulferts +Jean +Jean Gabes +Jean Remond +Jean-Charles +Jean-Claude Computing +Jean-Maxime LEBLANC +Joaquim Roy +Johan Svensson +John Hurliman +Jonathan GAULUPEAU +Konstantin Shalygin +Laurent Ollagnier +Laurent Ollagnier +Litrin Jiang +Luke L +Magnus Appelquist +Marc MAURICE +Mathias Fussenegger +Mathieu MD +Mathieu Parent +Matthieu Caneill +Michael Leinartas +Mickael FALCK +Morkxy +Naparuba +Naparuba +Nicolas Brisac +Nicolas DUPEUX +Nicolas DUPEUX +Nicolas Dupeux +Nicolas Limage +Nicolas Pichon +Olivier H +Olivier Hanesse +Olivier LI-KIANG-CHEONG +Pavel Volkovitskiy +Peter Woodman +Philippe Pepos Petitclerc +Philippe Pépos Petitclerc +Pradeep Jindal +Raphaël Doursenaud +Rich Trott +Robin Gloster +Romain Forlot +Romain LE DISEZ +Romain LE DISEZ +Romain THERRAT +Ryan Davis +Rémi SAUVAT +Samuel Milette-Lacombe +Sebastien Coavoux +Sebastien Coavoux +Sebastien Coavoux +Sebastien Coavoux +Sismic +Sispheor +Socketubs +Squiz +Steve Schnepp +Stéphane Duchesneau +Sylvain Boureau +Sébastein Coavoux +Sébastien +Sébastien +Sébastien Coavoux +Sébastien Coavoux +S�bastien Coavoux +The Gitter Badger +Thibault Cohen +Thibault Cohen +Thibautg16 +Thomas Cellerier +Thomas Meson +ThomasWaldmann +Tim Adam +Timo Veith +Valentin Brajon +Victor Igumnov +Zoran Zaric +andrewmcgilvray +anonimoose +aurelien +aviau +baoboa +brightdroid +cedef +chris81 +claneys +colourmeamused +cyrilleJ +david hannequin +david-guenault +dhannequin +fgth +fhoubart +flaf +foomip +frescha +fsoyer +gmat +h4wkmoon +hvad +itxx00 +jean-francois BUTKIEWICZ +jfbutkiewicz +jmartignago +jmcollongette +jogaulupeau +k0ste +lafont +nagios +nagios +nap +nap +naparuba +naparuba +nerocide +ning.xie +odyssey4me +olivierHa +openglx +pydubreucq +raphaeltr +rasoso +root +root +root +root +root +root +root +shinken +shinken +smilingsubnode +spil-brensen +system +system +system +t0xicCode +t0xicCode +thomascellerier +xkilian +yam +yol +yol diff --git a/alignak/daemons/arbiterdaemon.py b/alignak/daemons/arbiterdaemon.py index c96b4fa97..417cbb1da 100644 --- a/alignak/daemons/arbiterdaemon.py +++ b/alignak/daemons/arbiterdaemon.py @@ -370,9 +370,9 @@ def load_config_file(self): # pylint: disable=R0915 # The conf can be incorrect here if the cut into parts see errors like # a realm with hosts and not schedulers for it if not self.conf.conf_is_correct: - self.conf.show_errors() err = "Configuration is incorrect, sorry, I bail out" logger.error(err) + self.conf.show_errors() sys.exit(err) logger.info('Things look okay - No serious problems were detected ' diff --git a/alignak/objects/checkmodulation.py b/alignak/objects/checkmodulation.py index 328a0597b..d7a0f4791 100644 --- a/alignak/objects/checkmodulation.py +++ b/alignak/objects/checkmodulation.py @@ -54,7 +54,6 @@ from alignak.objects.commandcallitem import CommandCallItems from alignak.property import StringProp from alignak.util import to_name_if_possible -from alignak.log import logger class CheckModulation(Item): @@ -76,7 +75,7 @@ class CheckModulation(Item): running_properties = Item.running_properties.copy() - _special_properties = ('check_period',) + special_properties = ('check_period',) macros = {} @@ -120,49 +119,38 @@ def get_check_command(self, timeperiods, t_to_go): return None def is_correct(self): - """Check if the CheckModulation definition is correct:: + """Check if this object configuration is correct :: - * Check for required attribute - * Raise previous configuration errors + * Check our own specific properties + * Call our parent class is_correct checker - :return: True if the definition is correct, False otherwise + :return: True if the configuration is correct, otherwise False :rtype: bool """ state = True - cls = self.__class__ - # Raised all previously saw errors like unknown commands or timeperiods - if self.configuration_errors != []: - state = False - for err in self.configuration_errors: - logger.error("[item::%s] %s", self.get_name(), err) - - for prop, entry in cls.properties.items(): - if prop not in cls._special_properties: - if not hasattr(self, prop) and entry.required: - logger.error("[checkmodulation::%s] %s property not set", self.get_name(), - prop) - state = False # Bad boy... - - # Ok now we manage special cases... - # Service part + # Internal checks before executing inherited function... if not hasattr(self, 'check_command'): - logger.error("[checkmodulation::%s] do not have any check_command defined", - self.get_name()) + msg = "[checkmodulation::%s] do not have any check_command defined" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False else: if self.check_command is None: - logger.error("[checkmodulation::%s] a check_command is missing", self.get_name()) + msg = "[checkmodulation::%s] a check_command is missing" % (self.get_name()) + self.configuration_errors.append(msg) state = False if not self.check_command.is_valid(): - logger.error("[checkmodulation::%s] a check_command is invalid", self.get_name()) + msg = "[checkmodulation::%s] a check_command is invalid" % (self.get_name()) + self.configuration_errors.append(msg) state = False # Ok just put None as check_period, means 24x7 if not hasattr(self, 'check_period'): self.check_period = None - return state + return super(CheckModulation, self).is_correct() and state class CheckModulations(CommandCallItems): diff --git a/alignak/objects/config.py b/alignak/objects/config.py index 3b06273dc..e428f5113 100644 --- a/alignak/objects/config.py +++ b/alignak/objects/config.py @@ -888,8 +888,11 @@ def load_params(self, params): # it's a macro or a useless now param, we don't touch this val = value else: - logger.warning("Guessing the property %s type because it is not in " - "%s object properties", key, self.__class__.__name__) + msg = "Guessing the property %s type because it is not in %s object properties" % ( + key, self.__class__.__name__ + ) + self.configuration_warnings.append(msg) + logger.warning(msg) val = ToGuessProp.pythonize(clean_params[key]) setattr(self, key, val) @@ -2080,7 +2083,7 @@ def check_error_on_hard_unmanaged_parameters(self): # r &= False return valid - def is_correct(self): # pylint: disable=R0912 + def is_correct(self): # pylint: disable=R0912,R0915 """Check if all elements got a good configuration :return: True if the configuration is correct else False @@ -2105,8 +2108,17 @@ def is_correct(self): # pylint: disable=R0912 cur = getattr(self, obj) if not cur.is_correct(): + if self.read_config_silent == 0: + logger.info('Checked %s, not correct!', obj) + valid = False - logger.error("\t%s conf incorrect!!", obj) + self.configuration_errors += cur.configuration_errors + logger.error("\t%s configuration is incorrect!", obj) + if cur.configuration_warnings: + self.configuration_warnings += cur.configuration_warnings + logger.warning("\t%s configuration warnings: %d, total: %d", obj, + len(cur.configuration_warnings), len(self.configuration_warnings)) + if self.read_config_silent == 0: logger.info('\tChecked %d %s', len(cur), obj) @@ -2119,9 +2131,19 @@ def is_correct(self): # pylint: disable=R0912 continue if self.read_config_silent == 0: logger.info('Checking %s...', obj) + if not cur.is_correct(): + if self.read_config_silent == 0: + logger.info('Checked %s, not correct!', obj) + valid = False - logger.error("\t%s conf incorrect!!", obj) + self.configuration_errors += cur.configuration_errors + logger.error("\t%s configuration is incorrect!", obj) + if cur.configuration_warnings: + self.configuration_warnings += cur.configuration_warnings + logger.error("\t%s configuration warnings: %d, total: %d", obj, + len(cur.configuration_warnings), len(self.configuration_warnings)) + if self.read_config_silent == 0: logger.info('\tChecked %d %s', len(cur), obj) @@ -2234,12 +2256,24 @@ def add_error(self, txt): self.conf_is_correct = False def show_errors(self): - """Loop over configuration_errors and log them + """ + Loop over configuration warnings and log them as INFO log + Loop over configuration errors and log them as INFO log + + Note that the warnings and errors are logged on the fly during the configuration parsing. + It is not necessary to log as WARNING and ERROR in this function which is used as a sum-up + on the end of configuration parsing when an error has been detected. :return: None """ - for err in self.configuration_errors: - logger.error(err) + if self.configuration_warnings: + logger.info("Configuration warnings:") + for msg in self.configuration_warnings: + logger.info(msg) + if self.configuration_errors: + logger.info("Configuration errors:") + for msg in self.configuration_errors: + logger.info(msg) def create_packs(self, nb_packs): # pylint: disable=R0915,R0914,R0912,W0613 """Create packs of hosts and services (all dependencies are resolved) @@ -2336,14 +2370,19 @@ def create_packs(self, nb_packs): # pylint: disable=R0915,R0914,R0912,W0613 if elt.realm: tmp_realms.add(elt.realm) if len(tmp_realms) > 1: - self.add_error("Error: the realm configuration of yours hosts is not good " - "because there a more than one realm in one pack (host relations):") - for host in pack: + self.add_error("Error: the realm configuration of yours hosts is not good because " + "there is more than one realm in one pack (host relations):") + for host_id in pack: + host = self.hosts[host_id] if host.realm is None: - self.add_error(' the host %s do not have a realm' % host.get_name()) + self.add_error(' -> the host %s do not have a realm' % host.get_name()) else: - self.add_error(' the host %s is in the realm %s' % - (host.get_name(), host.realm.get_name())) + # Do not use get_name for the realm because it is not an object but a + # string containing the not found realm name if the realm is not existing! + # As of it, it may raise an exception + # TODO: improve this log to have the realm name + self.add_error(' -> the host %s is in the realm %s' % + (host.get_name(), host.realm)) if len(tmp_realms) == 1: # Ok, good realm = self.realms[tmp_realms.pop()] # There is just one element realm.packs.append(pack) diff --git a/alignak/objects/contact.py b/alignak/objects/contact.py index 72fc864cb..0862d946b 100644 --- a/alignak/objects/contact.py +++ b/alignak/objects/contact.py @@ -56,7 +56,7 @@ from alignak.util import strip_and_uniq from alignak.property import BoolProp, IntegerProp, StringProp, ListProp -from alignak.log import logger, naglog_result +from alignak.log import naglog_result from alignak.commandcall import CommandCall @@ -271,10 +271,10 @@ def get_notification_commands(self, notifways, n_type): return res def is_correct(self): - """Check if this host configuration is correct :: + """Check if this object configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * Check our own specific properties + * Call our parent class is_correct checker :return: True if the configuration is correct, otherwise False :rtype: bool @@ -282,32 +282,30 @@ def is_correct(self): state = True cls = self.__class__ - # All of the above are checks in the notificationways part - for prop, entry in cls.properties.items(): - if prop not in self.special_properties: - if not hasattr(self, prop) and entry.required: - logger.error("[contact::%s] %s property not set", self.get_name(), prop) - state = False # Bad boy... + # Internal checks before executing inherited function... # There is a case where there is no nw: when there is not special_prop defined # at all!! if self.notificationways == []: for prop in self.special_properties: if not hasattr(self, prop): - logger.error("[contact::%s] %s property is missing", self.get_name(), prop) + msg = "[contact::%s] %s property is missing" % (self.get_name(), prop) + self.configuration_errors.append(msg) state = False if hasattr(self, 'contact_name'): for char in cls.illegal_object_name_chars: if char in self.contact_name: - logger.error("[contact::%s] %s character not allowed in contact_name", - self.get_name(), char) + msg = "[contact::%s] %s character not allowed in contact_name" % ( + self.get_name(), char + ) + self.configuration_errors.append(msg) state = False else: if hasattr(self, 'alias'): # take the alias if we miss the contact_name self.contact_name = self.alias - return state + return super(Contact, self).is_correct() and state def raise_enter_downtime_log_entry(self): """Raise CONTACT DOWNTIME ALERT entry (info level) diff --git a/alignak/objects/contactgroup.py b/alignak/objects/contactgroup.py index 02639dd11..734e052dc 100644 --- a/alignak/objects/contactgroup.py +++ b/alignak/objects/contactgroup.py @@ -56,7 +56,7 @@ """ from alignak.objects.itemgroup import Itemgroup, Itemgroups -from alignak.property import StringProp +from alignak.property import StringProp, ListProp from alignak.log import logger @@ -71,6 +71,8 @@ class Contactgroup(Itemgroup): 'uuid': StringProp(default='', fill_brok=['full_status']), 'contactgroup_name': StringProp(fill_brok=['full_status']), 'alias': StringProp(fill_brok=['full_status']), + 'contactgroup_members': ListProp(default=[], fill_brok=['full_status'], + merging='join', split_on_coma=True) }) macros = { @@ -101,18 +103,13 @@ def get_name(self): def get_contactgroup_members(self): """ - Get contactgroup members + Get list of groups members of this contactgroup - :return: list of hosts + :return: list of contacts :rtype: list """ - # TODO: imho a Contactgroup instance should always have defined - # its contactgroup_members attribute, even if it's empty / the empty list. if hasattr(self, 'contactgroup_members'): - # more over: it should already be in the list form, - # not anymore in the "bare" string from as read - # from configuration (files or db or whatever) - return [m.strip() for m in self.contactgroup_members.split(',')] + return self.contactgroup_members else: return [] diff --git a/alignak/objects/escalation.py b/alignak/objects/escalation.py index 63540ae6d..977aab858 100644 --- a/alignak/objects/escalation.py +++ b/alignak/objects/escalation.py @@ -57,7 +57,6 @@ from alignak.util import strip_and_uniq from alignak.property import BoolProp, IntegerProp, StringProp, ListProp -from alignak.log import logger class Escalation(Item): @@ -204,55 +203,59 @@ def get_next_notif_time(self, t_wished, status, creation_time, interval, escal_p return start def is_correct(self): - """Check if all elements got a good configuration + """Check if this object configuration is correct :: + + * Check our own specific properties + * Call our parent class is_correct checker :return: True if the configuration is correct, otherwise False :rtype: bool """ state = True - cls = self.__class__ + + # Internal checks before executing inherited function... # If we got the _time parameters, we are time based. Unless, we are not :) if hasattr(self, 'first_notification_time') or hasattr(self, 'last_notification_time'): self.time_based = True - special_properties = self.special_properties_time_based - else: # classic ones - special_properties = self.special_properties - - for prop, entry in cls.properties.items(): - if prop not in special_properties: - if not hasattr(self, prop) and entry.required: - logger.error('%s: I do not have %s', self.get_name(), prop) - state = False # Bad boy... - - # Raised all previously saw errors like unknown contacts and co - if self.configuration_errors != []: - state = False - for err in self.configuration_errors: - logger.error(err) # Ok now we manage special cases... if not hasattr(self, 'contacts') and not hasattr(self, 'contact_groups'): - logger.error('%s: I do not have contacts nor contact_groups', self.get_name()) + msg = '%s: I do not have contacts nor contact_groups' % (self.get_name()) + self.configuration_errors.append(msg) state = False # If time_based or not, we do not check all properties if self.time_based: if not hasattr(self, 'first_notification_time'): - logger.error('%s: I do not have first_notification_time', self.get_name()) + msg = '%s: I do not have first_notification_time' % (self.get_name()) + self.configuration_errors.append(msg) state = False if not hasattr(self, 'last_notification_time'): - logger.error('%s: I do not have last_notification_time', self.get_name()) + msg = '%s: I do not have last_notification_time' % (self.get_name()) + self.configuration_errors.append(msg) state = False else: # we check classical properties if not hasattr(self, 'first_notification'): - logger.error('%s: I do not have first_notification', self.get_name()) + msg = '%s: I do not have first_notification' % (self.get_name()) + self.configuration_errors.append(msg) state = False if not hasattr(self, 'last_notification'): - logger.error('%s: I do not have last_notification', self.get_name()) + msg = '%s: I do not have last_notification' % (self.get_name()) + self.configuration_errors.append(msg) state = False - return state + # Change the special_properties definition according to time_based ... + save_special_properties = self.special_properties + if self.time_based: + self.special_properties = self.special_properties_time_based + + state_parent = super(Escalation, self).is_correct() + + if self.time_based: + self.special_properties = save_special_properties + + return state_parent and state class Escalations(Items): diff --git a/alignak/objects/host.py b/alignak/objects/host.py index 48c0ca775..3088d1051 100644 --- a/alignak/objects/host.py +++ b/alignak/objects/host.py @@ -273,25 +273,28 @@ def fill_predictive_missing_parameters(self): self.state = 'UNREACHABLE' def is_correct(self): - """Check if this host configuration is correct :: + """Check if this object configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * Check our own specific properties + * Call our parent class is_correct checker :return: True if the configuration is correct, otherwise False :rtype: bool """ - state = super(Host, self).is_correct() - cls = self.__class__ + state = True + # Internal checks before executing inherited function... + cls = self.__class__ if hasattr(self, 'host_name'): for char in cls.illegal_object_name_chars: if char in self.host_name: - logger.error("[%s::%s] host_name got an illegal character: %s", - self.my_type, self.get_name(), char) + msg = "[%s::%s] host_name got an illegal character: %s" % ( + self.my_type, self.get_name(), char + ) + self.configuration_errors.append(msg) state = False - return state + return super(Host, self).is_correct() and state def get_services(self): """Get all services for this host @@ -1289,26 +1292,34 @@ def find_hosts_that_use_template(self, tpl_name): return [h.host_name for h in self if tpl_name in h.tags if hasattr(h, "host_name")] def is_correct(self): - """Check if this host configuration is correct :: + """Check if the hosts list configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * check if any loop exists in each host dependencies + * Call our parent class is_correct checker - :return: True if the configuration is correct, False otherwise + :return: True if the configuration is correct, otherwise False :rtype: bool """ - valid = super(Hosts, self).is_correct() + state = True + + # Internal checks before executing inherited function... loop = self.no_loop_in_parents("self", "parents") if len(loop) > 0: - logger.error("Loop detected while checking hosts ") + msg = "Loop detected while checking hosts " + self.configuration_errors.append(msg) + state = False for uuid, item in self.items.iteritems(): for elem in loop: if elem == uuid: - logger.error("Host %s is parent in dependency defined in %s", - item.get_name(), item.imported_from) + msg = "Host %s is parent in dependency defined in %s" % ( + item.get_name(), item.imported_from + ) + self.configuration_errors.append(msg) elif elem in item.parents: - logger.error("Host %s is child in dependency defined in %s", - self[elem].get_name(), self[elem].imported_from) - return False + msg = "Host %s is child in dependency defined in %s" % ( + self[elem].get_name(), self[elem].imported_from + ) + self.configuration_errors.append(msg) + state = False - return valid + return super(Hosts, self).is_correct() and state diff --git a/alignak/objects/hostdependency.py b/alignak/objects/hostdependency.py index 641271617..71dce2faa 100644 --- a/alignak/objects/hostdependency.py +++ b/alignak/objects/hostdependency.py @@ -260,10 +260,11 @@ def linkify_h_by_hd(self, hosts): getattr(hostdep, 'dependent_host_name', None) is None: continue - hosts.add_act_dependency(hostdep.dependent_host_name, hostdep.host_name, - hostdep.notification_failure_criteria, - getattr(hostdep, 'dependency_period', ''), - hostdep.inherits_parent) + if not hosts.add_act_dependency(hostdep.dependent_host_name, hostdep.host_name, + hostdep.notification_failure_criteria, + getattr(hostdep, 'dependency_period', ''), + hostdep.inherits_parent): + return hosts.add_chk_dependency(hostdep.dependent_host_name, hostdep.host_name, hostdep.execution_failure_criteria, @@ -276,26 +277,33 @@ def linkify_h_by_hd(self, hosts): hosts[hostdep.dependent_host_name].get_name()) def is_correct(self): - """Check if this host configuration is correct :: + """Check if this object configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * Check our own specific properties + * Call our parent class is_correct checker - :return: True if the configuration is correct, False otherwise + :return: True if the configuration is correct, otherwise False :rtype: bool """ - valid = super(Hostdependencies, self).is_correct() + state = True + + # Internal checks before executing inherited function... loop = self.no_loop_in_parents("host_name", "dependent_host_name") if len(loop) > 0: - logger.error("Loop detected while checking host dependencies") + msg = "Loop detected while checking host dependencies" + self.configuration_errors.append(msg) + state = False for item in self: for elem in loop: if elem == item.host_name: - logger.error("Host %s is parent host_name in dependency defined in %s", - item.host_name_string, item.imported_from) + msg = "Host %s is parent host_name in dependency defined in %s" % ( + item.host_name_string, item.imported_from + ) + self.configuration_errors.append(msg) elif elem == item.dependent_host_name: - logger.error("Host %s is child host_name in dependency defined in %s", - item.dependent_host_name_string, item.imported_from) - return False + msg = "Host %s is child host_name in dependency defined in %s" % ( + item.dependent_host_name_string, item.imported_from + ) + self.configuration_errors.append(msg) - return valid + return super(Hostdependencies, self).is_correct() and state diff --git a/alignak/objects/hostgroup.py b/alignak/objects/hostgroup.py index 9dd0b5923..a80deb310 100644 --- a/alignak/objects/hostgroup.py +++ b/alignak/objects/hostgroup.py @@ -57,7 +57,7 @@ from alignak.objects.itemgroup import Itemgroup, Itemgroups from alignak.util import get_obj_name -from alignak.property import StringProp +from alignak.property import StringProp, ListProp from alignak.log import logger @@ -70,14 +70,16 @@ class Hostgroup(Itemgroup): properties = Itemgroup.properties.copy() properties.update({ - 'uuid': StringProp(default='', fill_brok=['full_status']), - 'hostgroup_name': StringProp(fill_brok=['full_status']), - 'alias': StringProp(fill_brok=['full_status']), - 'notes': StringProp(default='', fill_brok=['full_status']), - 'notes_url': StringProp(default='', fill_brok=['full_status']), - 'action_url': StringProp(default='', fill_brok=['full_status']), - 'realm': StringProp(default='', fill_brok=['full_status'], - conf_send_preparation=get_obj_name), + 'uuid': StringProp(default='', fill_brok=['full_status']), + 'hostgroup_name': StringProp(fill_brok=['full_status']), + 'alias': StringProp(fill_brok=['full_status']), + 'hostgroup_members': ListProp(default=[], fill_brok=['full_status'], + merging='join', split_on_coma=True), + 'notes': StringProp(default='', fill_brok=['full_status']), + 'notes_url': StringProp(default='', fill_brok=['full_status']), + 'action_url': StringProp(default='', fill_brok=['full_status']), + 'realm': StringProp(default='', fill_brok=['full_status'], + conf_send_preparation=get_obj_name), }) macros = { @@ -111,18 +113,13 @@ def get_hosts(self): def get_hostgroup_members(self): """ - Get hostgroup members + Get list of groups members of this hostgroup :return: list of hosts :rtype: list """ - # TODO: consistency : a Hostgroup instance should always - # have its hostgroup_members attribute defined, even if the empty list if hasattr(self, 'hostgroup_members'): - # consistency: any Hostgroup instance's hostgroup_members attribute - # should already be decoded/parsed: - # this should already be in its list form. - return [m.strip() for m in self.hostgroup_members.split(',')] + return self.hostgroup_members else: return [] @@ -303,10 +300,11 @@ def explode(self): :return: None """ - # We do not want a same hg to be explode again and again + # We do not want a same hostgroup to be exploded again and again # so we tag it for tmp_hg in self.items.values(): tmp_hg.already_explode = False + for hostgroup in self.items.values(): if hasattr(hostgroup, 'hostgroup_members') and not \ hostgroup.already_explode: diff --git a/alignak/objects/item.py b/alignak/objects/item.py index 8e9fb3dde..f2c6e3959 100644 --- a/alignak/objects/item.py +++ b/alignak/objects/item.py @@ -412,23 +412,37 @@ def is_correct(self): """ Check if this object is correct + This function: + - checks if the required properties are defined, ignoring special_properties if some exist + - logs the previously found warnings and errors + :return: True if it's correct, otherwise False :rtype: bool """ state = True properties = self.__class__.properties - # Raised all previously saw errors like unknown contacts and co - if self.configuration_errors != []: - state = False - for err in self.configuration_errors: - logger.error("[item::%s] %s", self.get_name(), err) - for prop, entry in properties.items(): + if hasattr(self, 'special_properties') and prop in getattr(self, 'special_properties'): + continue if not hasattr(self, prop) and entry.required: - logger.error("[item::%s] %s property is missing", self.get_name(), prop) + msg = "[%s::%s] %s property is missing" % ( + self.my_type, self.get_name(), prop + ) + self.configuration_errors.append(msg) state = False + # Log all previously sawn warnings + if self.configuration_warnings: + for msg in self.configuration_warnings: + logger.warning("*** CFG *** [%s::%s] %s", self.my_type, self.get_name(), msg) + + # Raise all previously sawn errors + if self.configuration_errors: + state = False + for msg in self.configuration_errors: + logger.error("*** CFG *** [%s::%s] %s", self.my_type, self.get_name(), msg) + return state def old_properties_names_to_new(self): @@ -1100,14 +1114,20 @@ def linkify_templates(self): i.tags = self.get_all_tags(i) def is_correct(self): - """ - Check if all items are correct (no error) + """Check if the items list configuration is correct :: + + * check if duplicate items exist in the list and warn about this + * set alias and display_name property for each item in the list if they do not exist + * check each item in the list + * log all previous warnings + * log all previous errors - :return: True if correct, otherwise False + :return: True if the configuration is correct, otherwise False :rtype: bool """ - # we are ok at the beginning. Hope we still ok at the end... + # we are ok at the beginning. Hope we are still ok at the end... valid = True + # Some class do not have twins, because they do not have names # like servicedependencies twins = getattr(self, 'twins', None) @@ -1115,21 +1135,13 @@ def is_correct(self): # Ok, look at no twins (it's bad!) for t_id in twins: i = self.items[t_id] - logger.warning("[items] %s.%s is duplicated from %s", - i.__class__.my_type, - i.get_name(), - getattr(i, 'imported_from', "unknown source")) - - # Then look if we have some errors in the conf - # Juts print warnings, but raise errors - for err in self.configuration_warnings: - logger.warning("[items] %s", err) - - for err in self.configuration_errors: - logger.error("[items] %s", err) - valid = False + msg = "[items] %s.%s is duplicated from %s" % ( + i.__class__.my_type, i.get_name(), + getattr(i, 'imported_from', "unknown source") + ) + self.configuration_warnings.append(msg) - # Then look for individual ok + # Better check individual items before displaying the global items list errors and warnings for i in self: # Alias and display_name hook hook prop_name = getattr(self.__class__, 'name_property', None) @@ -1140,9 +1152,28 @@ def is_correct(self): # Now other checks if not i.is_correct(): - source = getattr(i, 'imported_from', "unknown source") - logger.error("[items] In %s is incorrect ; from %s", i.get_name(), source) valid = False + source = getattr(i, 'imported_from', "unknown source") + msg = "Configuration in %s::%s is incorrect; from: %s" % ( + i.my_type, i.get_name(), source + ) + self.configuration_errors.append(msg) + + if i.configuration_errors: + self.configuration_errors += i.configuration_errors + if i.configuration_warnings: + self.configuration_warnings += i.configuration_warnings + + # Log all previously sawn warnings + if self.configuration_warnings: + for msg in self.configuration_warnings: + logger.warning("[items] %s", msg) + + # Raise all previously sawn errors + if self.configuration_errors: + valid = False + for msg in self.configuration_errors: + logger.error("[items] %s", msg) return valid diff --git a/alignak/objects/itemgroup.py b/alignak/objects/itemgroup.py index ccf8aaba5..1d53c158a 100644 --- a/alignak/objects/itemgroup.py +++ b/alignak/objects/itemgroup.py @@ -60,7 +60,6 @@ from alignak.brok import Brok from alignak.property import ListProp -from alignak.log import logger class Itemgroup(Item): @@ -129,6 +128,9 @@ def add_string_member(self, member): :type member: str :return: None """ + # Avoid empty elements in lists ... + if not member: + return add_fun = list.extend if isinstance(member, list) else list.append if not hasattr(self, "members"): self.members = [] @@ -164,20 +166,17 @@ def is_correct(self): :return: True if group is correct, otherwise False :rtype: bool """ - res = True + state = True if self.unknown_members: for member in self.unknown_members: - logger.error("[itemgroup::%s] as %s, got unknown member %s", - self.get_name(), self.__class__.my_type, member) - res = False + msg = "[%s::%s] as %s, got unknown member '%s'" % ( + self.my_type, self.get_name(), self.__class__.my_type, member + ) + self.configuration_errors.append(msg) + state = False - if self.configuration_errors != []: - for err in self.configuration_errors: - logger.error("[itemgroup] %s", err) - res = False - - return res + return super(Itemgroup, self).is_correct() and state def has(self, prop): """ diff --git a/alignak/objects/macromodulation.py b/alignak/objects/macromodulation.py index 1aec52ef9..d138cdda1 100644 --- a/alignak/objects/macromodulation.py +++ b/alignak/objects/macromodulation.py @@ -52,7 +52,6 @@ from alignak.objects.item import Item, Items from alignak.property import StringProp from alignak.util import to_name_if_possible -from alignak.log import logger class MacroModulation(Item): @@ -72,7 +71,7 @@ class MacroModulation(Item): running_properties = Item.running_properties.copy() - _special_properties = ('modulation_period',) + special_properties = ('modulation_period',) macros = {} @@ -99,34 +98,18 @@ def is_active(self, timperiods): return False def is_correct(self): - """ - Check if the macromodulation is valid and have all properties defined + """Check if this object configuration is correct :: + + * Call our parent class is_correct checker - :return: True if valid, otherwise False + :return: True if the configuration is correct, otherwise False :rtype: bool """ - state = True - cls = self.__class__ - - # Raised all previously saw errors like unknown commands or timeperiods - if self.configuration_errors != []: - state = False - for err in self.configuration_errors: - logger.error("[item::%s] %s", self.get_name(), err) - - for prop, entry in cls.properties.items(): - if prop not in cls._special_properties: - if not hasattr(self, prop) and entry.required: - logger.error( - "[macromodulation::%s] %s property not set", self.get_name(), prop - ) - state = False # Bad boy... - # Ok just put None as modulation_period, means 24x7 if not hasattr(self, 'modulation_period'): self.modulation_period = None - return state + return super(MacroModulation, self).is_correct() class MacroModulations(Items): diff --git a/alignak/objects/notificationway.py b/alignak/objects/notificationway.py index c68464b4e..ce217ba5c 100644 --- a/alignak/objects/notificationway.py +++ b/alignak/objects/notificationway.py @@ -57,7 +57,6 @@ from alignak.objects.commandcallitem import CommandCallItems from alignak.property import BoolProp, IntegerProp, StringProp, ListProp -from alignak.log import logger from alignak.commandcall import CommandCall @@ -274,80 +273,84 @@ def get_notification_commands(self, o_type): return notif_commands def is_correct(self): - """Check if this host configuration is correct :: + """Check if this object configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * Check our own specific properties + * Call our parent class is_correct checker :return: True if the configuration is correct, otherwise False :rtype: bool """ state = True - cls = self.__class__ - - # Raised all previously saw errors like unknown commands or timeperiods - if self.configuration_errors != []: - state = False - for err in self.configuration_errors: - logger.error("[item::%s] %s", self.get_name(), err) + # Do not execute checks if notifications are disabled if (hasattr(self, 'service_notification_options') and self.service_notification_options == ['n']): if (hasattr(self, 'host_notification_options') and self.host_notification_options == ['n']): return True - for prop, entry in cls.properties.items(): - if prop not in self.special_properties: - if not hasattr(self, prop) and entry.required: - logger.error("[notificationway::%s] %s property not set", - self.get_name(), prop) - state = False # Bad boy... + # Internal checks before executing inherited function... - # Ok now we manage special cases... # Service part if not hasattr(self, 'service_notification_commands'): - logger.error("[notificationway::%s] do not have any " - "service_notification_commands defined", self.get_name()) + msg = "[notificationway::%s] do not have any service_notification_commands defined" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False else: for cmd in self.service_notification_commands: if cmd is None: - logger.error("[notificationway::%s] a " - "service_notification_command is missing", self.get_name()) + msg = "[notificationway::%s] a service_notification_command is missing" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False if not cmd.is_valid(): - logger.error("[notificationway::%s] a " - "service_notification_command is invalid", self.get_name()) + msg = "[notificationway::%s] a service_notification_command is invalid" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False if getattr(self, 'service_notification_period', None) is None: - logger.error("[notificationway::%s] the " - "service_notification_period is invalid", self.get_name()) + msg = "[notificationway::%s] the service_notification_period is invalid" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False # Now host part if not hasattr(self, 'host_notification_commands'): - logger.error("[notificationway::%s] do not have any " - "host_notification_commands defined", self.get_name()) + msg = "[notificationway::%s] do not have any host_notification_commands defined" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False else: for cmd in self.host_notification_commands: if cmd is None: - logger.error("[notificationway::%s] a " - "host_notification_command is missing", self.get_name()) + msg = "[notificationway::%s] a host_notification_command is missing" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False if not cmd.is_valid(): - logger.error("[notificationway::%s] a host_notification_command " - "is invalid (%s)", cmd.get_name(), str(cmd.__dict__)) + msg = "[notificationway::%s] a host_notification_command is invalid (%s)" % ( + cmd.get_name(), str(cmd.__dict__) + ) + self.configuration_errors.append(msg) state = False if getattr(self, 'host_notification_period', None) is None: - logger.error("[notificationway::%s] the host_notification_period " - "is invalid", self.get_name()) + msg = "[notificationway::%s] the host_notification_period is invalid" % ( + self.get_name() + ) + self.configuration_errors.append(msg) state = False - return state + return super(NotificationWay, self).is_correct() and state class NotificationWays(CommandCallItems): diff --git a/alignak/objects/schedulingitem.py b/alignak/objects/schedulingitem.py index 3c84e9892..b2be095e9 100644 --- a/alignak/objects/schedulingitem.py +++ b/alignak/objects/schedulingitem.py @@ -66,7 +66,6 @@ import random import time import traceback -import sys from alignak.objects.item import Item from alignak.objects.commandcallitem import CommandCallItems @@ -2987,25 +2986,32 @@ def notification_is_blocked_by_contact(self, notifways, timeperiods, cdowntimes, pass def is_correct(self): + """Check if this object configuration is correct :: - state = True - - for prop, entry in self.__class__.properties.items(): - if not entry.special and not hasattr(self, prop) and entry.required: - logger.error("[%s::%s] %s property not set", - self.my_type, self.get_name(), prop) - state = False + * Check our own specific properties + * Call our parent class is_correct checker - # Then look if we have some errors in the conf - # Juts print warnings, but raise errors - for err in self.configuration_warnings: - logger.warning("[%s::%s] %s", self.my_type, self.get_name(), err) + :return: True if the configuration is correct, otherwise False + :rtype: bool + """ + state = True - # Raised all previously saw errors like unknown contacts and co - if self.configuration_errors != []: - state = False - for err in self.configuration_errors: - logger.error("[%s::%s] %s", self.my_type, self.get_name(), err) + # for prop, entry in self.__class__.properties.items(): + # if not entry.special and not hasattr(self, prop) and entry.required: + # logger.error("[%s::%s] %s property not set", + # self.my_type, self.get_name(), prop) + # state = False + # + # # Then look if we have some errors in the conf + # # Juts print warnings, but raise errors + # for err in self.configuration_warnings: + # logger.warning("[%s::%s] %s", self.my_type, self.get_name(), err) + # + # # Raised all previously saw errors like unknown contacts and co + # if self.configuration_errors != []: + # state = False + # for err in self.configuration_errors: + # logger.error("[%s::%s] %s", self.my_type, self.get_name(), err) # If no notif period, set it to None, mean 24x7 if not hasattr(self, 'notification_period'): @@ -3013,42 +3019,58 @@ def is_correct(self): # Ok now we manage special cases... if self.notifications_enabled and self.contacts == []: - logger.warning("[%s::%s] no contacts nor contact_groups property", - self.my_type, self.get_name()) + msg = "[%s::%s] no contacts nor contact_groups property" % ( + self.my_type, self.get_name() + ) + self.configuration_warnings.append(msg) # If we got an event handler, it should be valid if getattr(self, 'event_handler', None) and not self.event_handler.is_valid(): - logger.error("[%s::%s] event_handler '%s' is invalid", - self.my_type, self.get_name(), self.event_handler.command) + msg = "[%s::%s] event_handler '%s' is invalid" % ( + self.my_type, self.get_name(), self.event_handler.command + ) + self.configuration_errors.append(msg) state = False if not hasattr(self, 'check_command'): - logger.error("[%s::%s] no check_command", self.my_type, self.get_name()) + msg = "[%s::%s] no check_command" % ( + self.my_type, self.get_name() + ) + self.configuration_errors.append(msg) state = False # Ok got a command, but maybe it's invalid else: if not self.check_command.is_valid(): - logger.error("[%s::%s] check_command '%s' invalid", - self.my_type, self.get_name(), self.check_command.command) + msg = "[%s::%s] check_command '%s' invalid" % ( + self.my_type, self.get_name(), self.check_command.command + ) + self.configuration_errors.append(msg) state = False if self.got_business_rule: if not self.business_rule.is_valid(): - logger.error("[%s::%s] business_rule invalid", - self.my_type, self.get_name()) + msg = "[%s::%s] business_rule invalid" % ( + self.my_type, self.get_name() + ) + self.configuration_errors.append(msg) for bperror in self.business_rule.configuration_errors: - logger.error("[%s::%s]: %s", self.my_type, self.get_name(), bperror) + msg = "[%s::%s]: %s" % (self.my_type, self.get_name(), bperror) + self.configuration_errors.append(msg) state = False if not hasattr(self, 'notification_interval') \ and self.notifications_enabled is True: - logger.error("[%s::%s] no notification_interval but notifications enabled", - self.my_type, self.get_name()) + msg = "[%s::%s] no notification_interval but notifications enabled" % ( + self.my_type, self.get_name() + ) + self.configuration_errors.append(msg) state = False # if no check_period, means 24x7, like for services if not hasattr(self, 'check_period'): self.check_period = None + state = super(SchedulingItem, self).is_correct() + return state @@ -3105,7 +3127,10 @@ def add_act_dependency(self, son_id, parent_id, notif_failure_criteria, dep_peri son = self[son_id] else: logger.error("Dependency son (%s) unknown, configuration error", son_id) - sys.exit(2) + msg = "Dependency son (%s) unknown, configuration error" % (son_id) + self.configuration_errors.append(msg) + # sys.exit(2) + return False parent = self[parent_id] son.act_depend_of.append((parent_id, notif_failure_criteria, 'logic_dep', dep_period, inherits_parents)) @@ -3116,6 +3141,8 @@ def add_act_dependency(self, son_id, parent_id, notif_failure_criteria, dep_peri son.parent_dependencies.add(parent_id) parent.child_dependencies.add(son_id) + return True + def del_act_dependency(self, son_id, parent_id): """Remove act_dependency between two hosts or services. diff --git a/alignak/objects/service.py b/alignak/objects/service.py index b9054cfff..c6c176984 100644 --- a/alignak/objects/service.py +++ b/alignak/objects/service.py @@ -301,6 +301,14 @@ def get_name(self): return self.name return 'SERVICE-DESCRIPTION-MISSING' + def get_servicegroups(self): + """Accessor to servicegroups attribute + + :return: servicegroup list object of host + :rtype: list + """ + return self.servicegroups + def get_groupnames(self, sgs): """Get servicegroups list @@ -344,15 +352,15 @@ def get_service_tags(self): return self.tags def is_correct(self): - """Check if this host configuration is correct :: + """Check if this object configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * Check our own specific properties + * Call our parent class is_correct checker - :return: True if the configuration is correct, False otherwise + :return: True if the configuration is correct, otherwise False :rtype: bool """ - state = super(Service, self).is_correct() + state = True cls = self.__class__ # Set display_name if need @@ -360,20 +368,25 @@ def is_correct(self): self.display_name = getattr(self, 'service_description', '') if not self.host_name: - logger.error("[%s::%s] not bound do any host.", self.my_type, self.get_name()) + msg = "[%s::%s] not bound to any host." % (self.my_type, self.get_name()) + self.configuration_errors.append(msg) state = False elif self.host is None: - logger.error("[%s::%s] unknown host_name '%s'", - self.my_type, self.get_name(), self.host_name) + msg = "[%s::%s] unknown host_name '%s'" % ( + self.my_type, self.get_name(), self.host_name + ) + self.configuration_errors.append(msg) state = False if hasattr(self, 'service_description'): for char in cls.illegal_object_name_chars: if char in self.service_description: - logger.error("[%s::%s] service_description got an illegal character: %s", - self.my_type, self.get_name(), char) + msg = "[%s::%s] service_description got an illegal character: %s" % ( + self.my_type, self.get_name(), char + ) state = False - return state + + return super(Service, self).is_correct() and state def duplicate(self, host): """For a given host, look for all copy we must create for for_each property diff --git a/alignak/objects/servicedependency.py b/alignak/objects/servicedependency.py index d5de3790e..8683209c7 100644 --- a/alignak/objects/servicedependency.py +++ b/alignak/objects/servicedependency.py @@ -406,28 +406,35 @@ def linkify_s_by_sd(self, services): services[servicedep.dependent_service_description].get_name()) def is_correct(self): - """Check if this host configuration is correct :: + """Check if this object configuration is correct :: - * All required parameter are specified - * Go through all configuration warnings and errors that could have been raised earlier + * Check our own specific properties + * Call our parent class is_correct checker :return: True if the configuration is correct, otherwise False :rtype: bool """ - valid = super(Servicedependencies, self).is_correct() + state = True + + # Internal checks before executing inherited function... loop = self.no_loop_in_parents("service_description", "dependent_service_description") if len(loop) > 0: - logger.error("Loop detected while checking service dependencies") + msg = "Loop detected while checking service dependencies" + self.configuration_errors.append(msg) + state = False for item in self: for elem in loop: if elem == item.service_description: - logger.error("Service %s is parent service_description in dependency " - "defined in %s", item.service_description_string, - item.imported_from) + msg = "Service %s is parent service_description in dependency "\ + "defined in %s" % ( + item.service_description_string, item.imported_from + ) + self.configuration_errors.append(msg) elif elem == item.dependent_service_description: - logger.error("Service %s is child service_description in dependency" - " defined in %s", item.dependent_service_description_string, - item.imported_from) - return False + msg = "Service %s is child service_description in dependency"\ + " defined in %s" % ( + item.dependent_service_description_string, item.imported_from + ) + self.configuration_errors.append(msg) - return valid + return super(Servicedependencies, self).is_correct() and state diff --git a/alignak/objects/servicegroup.py b/alignak/objects/servicegroup.py index ae7fe42cb..bf681b2d2 100644 --- a/alignak/objects/servicegroup.py +++ b/alignak/objects/servicegroup.py @@ -51,7 +51,7 @@ This module provide Servicegroup and Servicegroups classes used to group services """ -from alignak.property import StringProp +from alignak.property import StringProp, ListProp from alignak.log import logger from .itemgroup import Itemgroup, Itemgroups @@ -66,13 +66,14 @@ class Servicegroup(Itemgroup): properties = Itemgroup.properties.copy() properties.update({ - 'uuid': StringProp(default='', fill_brok=['full_status']), - 'servicegroup_name': StringProp(fill_brok=['full_status']), - 'alias': StringProp(fill_brok=['full_status']), - 'notes': StringProp(default='', fill_brok=['full_status']), - 'notes_url': StringProp(default='', fill_brok=['full_status']), - 'action_url': StringProp(default='', fill_brok=['full_status']), - 'servicegroup_members': StringProp(default='', fill_brok=['full_status']), + 'uuid': StringProp(default='', fill_brok=['full_status']), + 'servicegroup_name': StringProp(fill_brok=['full_status']), + 'alias': StringProp(fill_brok=['full_status']), + 'servicegroup_members': ListProp(default=[], fill_brok=['full_status'], + merging='join', split_on_coma=True), + 'notes': StringProp(default='', fill_brok=['full_status']), + 'notes_url': StringProp(default='', fill_brok=['full_status']), + 'action_url': StringProp(default='', fill_brok=['full_status']), }) macros = { @@ -106,14 +107,13 @@ def get_name(self): def get_servicegroup_members(self): """ - Get list of members of this servicegroup + Get list of groups members of this servicegroup - :return: list of services (members) + :return: list of services :rtype: list | str """ - # TODO: a Servicegroup instance should always have its servicegroup_members defined. if hasattr(self, 'servicegroup_members'): - return [m.strip() for m in self.servicegroup_members.split(',')] + return self.servicegroup_members else: return [] @@ -254,22 +254,22 @@ def explode(self): :return: None """ - # We do not want a same hg to be explode again and again + # We do not want a same service group to be exploded again and again # so we tag it - for servicegroup in self: + for servicegroup in self.items.values(): servicegroup.already_explode = False - for servicegroup in self: + for servicegroup in self.items.values(): if hasattr(servicegroup, 'servicegroup_members') and not \ servicegroup.already_explode: # get_services_by_explosion is a recursive # function, so we must tag hg so we do not loop - for sg2 in self: + for sg2 in self.items.values(): sg2.rec_tag = False servicegroup.get_services_by_explosion(self) # We clean the tags - for servicegroup in self: + for servicegroup in self.items.values(): try: del servicegroup.rec_tag except AttributeError: diff --git a/alignak/objects/timeperiod.py b/alignak/objects/timeperiod.py index 33ba2a679..19679f738 100644 --- a/alignak/objects/timeperiod.py +++ b/alignak/objects/timeperiod.py @@ -592,23 +592,29 @@ def has(self, prop): return hasattr(self, prop) def is_correct(self): - """ - Check if dateranges of timeperiod are valid + """Check if this object configuration is correct :: + + * Check if dateranges of timeperiod are valid + * Call our parent class is_correct checker - :return: false if at least one datarange is invalid + :return: True if the configuration is correct, otherwise False if at least one daterange + is not correct :rtype: bool """ - valid = True + state = True for daterange in self.dateranges: good = daterange.is_correct() if not good: - logger.error("[timeperiod::%s] invalid daterange ", self.get_name()) - valid &= good + msg = "[timeperiod::%s] invalid daterange " % (self.get_name()) + self.configuration_errors.append(msg) + state &= good # Warn about non correct entries for entry in self.invalid_entries: - logger.warning("[timeperiod::%s] invalid entry '%s'", self.get_name(), entry) - return valid + msg = "[timeperiod::%s] invalid entry '%s'" % (self.get_name(), entry) + self.configuration_errors.append(msg) + + return super(Timeperiod, self).is_correct() and state def __str__(self): """ diff --git a/install_hooks.py b/install_hooks.py index ee4656ad9..cdf95c88e 100644 --- a/install_hooks.py +++ b/install_hooks.py @@ -163,4 +163,3 @@ def fix_alignak_cfg(config): "== ==\n" "=======================================================================================================\n" ) - diff --git a/test/_old/etc/alignak_bad_hg_conf.cfg b/test/_old/etc/alignak_bad_hg_conf.cfg deleted file mode 100644 index 36d349715..000000000 --- a/test/_old/etc/alignak_bad_hg_conf.cfg +++ /dev/null @@ -1,6 +0,0 @@ - -define hostgroup { - hostgroup_name allhosts_bad - alias All Hosts - members test_router_0,test_host_0,BADMEMBERHG -} diff --git a/test/_old/etc/alignak_bad_service_interval.cfg b/test/_old/etc/alignak_bad_service_interval.cfg deleted file mode 100644 index fc9d15cd6..000000000 --- a/test/_old/etc/alignak_bad_service_interval.cfg +++ /dev/null @@ -1,15 +0,0 @@ -define host { - host_name fake host - alias fake host - address 192.168.0.1 - use generic-host -} - - -define service{ - host_name fake host - service_description fake svc1 - use generic-service - check_command _echo - check_interval 1,555 -} \ No newline at end of file diff --git a/test/_old/etc/alignak_business_rules_bad_realm_conf.cfg b/test/_old/etc/alignak_business_rules_bad_realm_conf.cfg deleted file mode 100644 index 8bfd5cf47..000000000 --- a/test/_old/etc/alignak_business_rules_bad_realm_conf.cfg +++ /dev/null @@ -1,127 +0,0 @@ -define scheduler{ - scheduler_name scheduler-1 ; just the name - address localhost ; ip or dns address of the daemon - port 7768 ; tcp port of the daemon - spare 0 ; (0 = not a spare, 1 = is spare) - weight 1 ; (some schedulers can manage more hosts than others) - timeout 3 ; 'ping' timeout - data_timeout 120 ; 'data send' timeout - max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD - check_interval 60 ; ping it every minute - realm Realm1 ; optional (realm are multi-datacenters features) -} - -define poller{ - poller_name poller-1 - address localhost - port 7771 - manage_sub_realms 0 ; optional and advanced: does it take jobs from schedulers of sub realms? - min_workers 0 ; optional: starts with N worker processes. 0 means: "number of cpus" - max_workers 0 ; optional: no more than N worker processes. 0 means: "number of cpus" - processes_by_worker 256 ; optional: each worker manages 256 checks - polling_interval 1 ; optional: get jobs from schedulers each 1 second - timeout 3 ; 'ping' timeout - data_timeout 120 ; 'data send' timeout - check_interval 60 ; ping it every minute - max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD - realm Realm1 -} - -define broker{ - broker_name broker-1 - address localhost - port 7772 - spare 0 - modules Livestatus - manage_sub_realms 1 ; optional, like for poller - manage_arbiters 1 ; optional: take data from Arbiter. There should be - check_interval 60 ; ping it every minute - timeout 3 ; 'ping' timeout - data_timeout 120 ; 'data send' timeout - max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD - realm Realm1 -} - -# Reactionner launches notifications -define reactionner{ - reactionner_name reactionner-1 - address localhost - port 7769 - spare 0 - manage_sub_realms 0 ;optionnal: like for poller - min_workers 1 ;optionnal: like for poller - max_workers 15 ;optionnal: like for poller - polling_interval 1 ;optionnal: like for poller - timeout 3 ; 'ping' timeout - data_timeout 120 ; 'data send' timeout - check_interval 60 ; ping it every minute - max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD - realm Realm1 -} - -define realm{ - realm_name NoDefault -} - -define realm{ - realm_name Realm1 -} - -define realm{ - realm_name Realm2 -} - - -define host{ - address 127.0.0.1 - alias up_0 - host_name test_host_realm1 - hostgroups hostgroup_01,up - use generic-host - realm Realm1 -} - -define host{ - address 127.0.0.1 - alias up_0 - host_name test_host_realm2 - hostgroups hostgroup_01,up - use generic-host - realm Realm2 -} - -define service{ - check_command check_service!ok - host_name test_host_realm1 - service_description test_ok_realm1_0 - use generic-service -} - -define service{ - check_command check_service!ok - host_name test_host_realm2 - service_description test_ok_realm2_0 - use generic-service -} - -define service{ - check_command bp_rule!(test_host_realm1,test_ok_realm1_0 & test_host_realm2,test_ok_realm2_0) - host_name test_host_realm1 - service_description Test bad services BP rules - use generic-service -} - -define service{ - check_command bp_rule!(test_host_realm1 & test_host_realm2) - host_name test_host_realm1 - service_description Test bad host BP rules - use generic-service -} - -define service{ - check_command bp_rule!((test_host_realm1,test_ok_realm1_0 & test_host_realm2,test_ok_realm2_0) | (test_host_realm1 & test_host_realm2)) - host_name test_host_realm1 - service_description Test bad services BP rules complex - use generic-service -} - diff --git a/test/_old/etc/alignak_conf_in_symlinks.cfg b/test/_old/etc/alignak_conf_in_symlinks.cfg deleted file mode 100644 index fdf8162b3..000000000 --- a/test/_old/etc/alignak_conf_in_symlinks.cfg +++ /dev/null @@ -1 +0,0 @@ -cfg_dir=conf_in_symlinks/links/ diff --git a/test/_old/etc/alignak_contactgroup_nomembers.cfg b/test/_old/etc/alignak_contactgroup_nomembers.cfg deleted file mode 100644 index 13309f180..000000000 --- a/test/_old/etc/alignak_contactgroup_nomembers.cfg +++ /dev/null @@ -1,11 +0,0 @@ -define contactgroup{ - contactgroup_name test_contact_nomember - alias test_contacts_alias_nomember -} - -define host{ - contact_groups test_contact,test_contact_nomember - name generic-host_nomember - register 0 - -} diff --git a/test/_old/etc/alignak_groups_pickle.cfg b/test/_old/etc/alignak_groups_pickle.cfg deleted file mode 100644 index f2942618d..000000000 --- a/test/_old/etc/alignak_groups_pickle.cfg +++ /dev/null @@ -1,56 +0,0 @@ - -define realm{ - realm_name World - default 1 - realm_members R1, R2 -} - - -define realm{ - realm_name R1 -} - -define realm{ - realm_name R2 -} - -define scheduler { - scheduler_name R1 - address localhost - realm R1 -} - - -define scheduler { - scheduler_name world - address localhsot - realm World -} - -define scheduler { - scheduler_name R2 - address localhsot - realm R2 -} - - -define hostgroup{ - hostgroup_name everyone - members * -} - - -define host{ - use generic-host - host_name HR1 - realm R1 - hostgroups everyone -} - - -define host{ - use generic-host - host_name HR2 - realm R2 - hostgroups everyone -} diff --git a/test/_old/etc/alignak_hostdep_withno_depname.cfg b/test/_old/etc/alignak_hostdep_withno_depname.cfg deleted file mode 100644 index 86203e385..000000000 --- a/test/_old/etc/alignak_hostdep_withno_depname.cfg +++ /dev/null @@ -1,22 +0,0 @@ - -define hostdependency { - host_name test_host_0 - dependent_hostgroup_name flap -} - - - -define host{ - address 127.0.0.1 - alias up_0 - check_command check-host-alive-parent!up!$HOSTSTATE:test_router_0$ - event_handler eventhandler - check_period 24x7 - host_name test_host_1 - hostgroups flap - parents test_router_0 - use generic-host - criticity 5 - _ostype gnulinux - _oslicense gpl -} \ No newline at end of file diff --git a/test/_old/etc/alignak_hostgroup_no_host.cfg b/test/_old/etc/alignak_hostgroup_no_host.cfg deleted file mode 100644 index 3dce7c336..000000000 --- a/test/_old/etc/alignak_hostgroup_no_host.cfg +++ /dev/null @@ -1,23 +0,0 @@ -define hostgroup { - hostgroup_name void - alias Void group -} - -define service{ - active_checks_enabled 1 - check_command check_service!ok - check_interval 1 - hostgroup_name void - icon_image ../../docs/images/tip.gif - icon_image_alt icon alt string - notes just a notes string - retry_interval 1 - service_description test_void_no_host - servicegroups servicegroup_01,ok - use generic-service - event_handler eventhandler - notes_url /alignak/wiki/doku.php/$HOSTNAME$/$SERVICEDESC$ - action_url /alignak/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ - _custname custvalue -} - diff --git a/test/_old/etc/alignak_hostgroup_with_space.cfg b/test/_old/etc/alignak_hostgroup_with_space.cfg deleted file mode 100644 index 32f7a99b0..000000000 --- a/test/_old/etc/alignak_hostgroup_with_space.cfg +++ /dev/null @@ -1,74 +0,0 @@ -define service{ - active_checks_enabled 1 - check_command check_service!ok - check_interval 1 - hostgroups I love have long name,And Another One - icon_image ../../docs/images/tip.gif?host=$HOSTNAME$&srv=$SERVICEDESC$ - icon_image_alt icon alt string - notes just a notes string - retry_interval 1 - service_description test_With Spaces - servicegroups servicegroup_01,ok - use generic-service - event_handler eventhandler - notes_url /alignak/wiki/doku.php/$HOSTNAME$/$SERVICEDESC$ - action_url /alignak/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ - _custname custvalue -} - - - -define service{ - active_checks_enabled 1 - check_command check_service!ok - check_interval 1 - hostgroups I love have long name & And Another One - icon_image ../../docs/images/tip.gif?host=$HOSTNAME$&srv=$SERVICEDESC$ - icon_image_alt icon alt string - notes just a notes string - retry_interval 1 - service_description test_With anoter Spaces - servicegroups servicegroup_01,ok - use generic-service - event_handler eventhandler - notes_url /alignak/wiki/doku.php/$HOSTNAME$/$SERVICEDESC$ - action_url /alignak/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ - _custname custvalue -} - - -define service{ - active_checks_enabled 1 - check_command check_service!ok - check_interval 1 - hostgroups With a dot . here&And Another One - icon_image ../../docs/images/tip.gif?host=$HOSTNAME$&srv=$SERVICEDESC$ - icon_image_alt icon alt string - notes just a notes string - retry_interval 1 - service_description test_With dot - servicegroups servicegroup_01,ok - use generic-service - event_handler eventhandler - notes_url /alignak/wiki/doku.php/$HOSTNAME$/$SERVICEDESC$ - action_url /alignak/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ - _custname custvalue -} - - -define hostgroup { - hostgroup_name I love have long name - members test_router_0,test_host_0 -} - - -define hostgroup { - hostgroup_name And Another One - members test_router_0,test_host_0 -} - - -define hostgroup { - hostgroup_name With a dot . here - members test_router_0,test_host_0 -} diff --git a/test/_old/etc/alignak_servicegroups_generated.cfg b/test/_old/etc/alignak_servicegroups_generated.cfg deleted file mode 100644 index 0dceef483..000000000 --- a/test/_old/etc/alignak_servicegroups_generated.cfg +++ /dev/null @@ -1,55 +0,0 @@ -define host { - host_name fake host - alias fake host - address 192.168.50.43 - business_impact 4 - icon_image_alt Linux - icon_image base/linux40.gif - statusmap_image base/linux40.gd2 - check_command _echo - check_period 24x7 - notification_period 24x7 - #use Template_Host_Generic - use generic-host - contact_groups - check_interval 1555 - retry_interval 1555 -} - -define service{ - host_name fake host - service_description fake svc1 - use generic-service - check_command _echo - check_interval 5 - retry_interval 5 -} - -define service{ - host_name fake host - service_description fake svc2 - use generic-service - check_command _echo - check_interval 5 - retry_interval 5 -} - -define service{ - host_name fake host - service_description fake svc3 - use generic-service - check_command _echo - servicegroups MYSVCGP, MYSVCGP2 - check_interval 5 - retry_interval 5 -} - -define service{ - host_name fake host - service_description fake svc4 - use generic-service - check_command _echo - servicegroups MYSVCGP3,MYSVCGP4 - check_interval 5 - retry_interval 5 -} diff --git a/test/_old/test_antivirg.py b/test/_old/test_antivirg.py deleted file mode 100644 index b5eeba7f2..000000000 --- a/test/_old/test_antivirg.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -*- coding: utf-8 -* -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . - -from alignak_test import * - -class TestConfig(AlignakTest): - - def setUp(self): - # load the configuration from file - self.setup_with_file(['etc/alignak_antivirg.cfg']) - - def test_hostname_antivirg(self): - """Check that it is allowed to have a host with the "__ANTI-VIRG__" substring in its hostname""" - - # the global configuration must be valid - self.assertTrue(self.conf.conf_is_correct) - - # try to get the host - # if it is not possible to get the host, it is probably because - # "__ANTI-VIRG__" has been replaced by ";" - hst = self.conf.hosts.find_by_name('test__ANTI-VIRG___0') - self.assertIsNotNone(hst, "host 'test__ANTI-VIRG___0' not found") - - # Check that the host has a valid configuration - self.assertTrue(hst.is_correct(), "config of host '%s' is not true" % hst.get_name()) - - def test_parsing_comment(self): - """Check that the semicolon is a comment delimiter""" - - # the global configuration must be valid - self.assertTrue(self.conf.conf_is_correct, "config is not correct") - - # try to get the host - hst = self.conf.hosts.find_by_name('test_host_1') - self.assertIsNotNone(hst, "host 'test_host_1' not found") - - # Check that the host has a valid configuration - self.assertTrue(hst.is_correct(), "config of host '%s' is not true" % (hst.get_name())) - - def test_escaped_semicolon(self): - """Check that it is possible to have a host with a semicolon in its hostname - - The consequences of this aren't tested. We try just to send a command but - I think that others programs which send commands don't think to escape - the semicolon. - - """ - - # the global configuration must be valid - self.assertTrue(self.conf.conf_is_correct) - - # try to get the host - hst = self.conf.hosts.find_by_name('test_host_2;with_semicolon') - self.assertIsNotNone(hst, "host 'test_host_2;with_semicolon' not found") - - # Check that the host has a valid configuration - self.assertTrue(hst.is_correct(), "config of host '%s' is not true" % hst.get_name()) - - # We can send a command by escaping the semicolon. - - - command = '[%lu] PROCESS_HOST_CHECK_RESULT;test_host_2\;with_semicolon;2;down' % (time.time()) - self.sched.run_external_command(command) - - # can need 2 run for get the consum (I don't know why) - self.scheduler_loop(1, []) - self.scheduler_loop(1, []) - -if '__main__' == __name__: - unittest.main() - diff --git a/test/_old/test_bad_contact_call.py b/test/_old/test_bad_contact_call.py deleted file mode 100644 index 38486c0a3..000000000 --- a/test/_old/test_bad_contact_call.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Zoran Zaric, zz@zoranzaric.de -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestConfig(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_bad_contact_call.cfg']) - - def test_bad_contact_call(self): - # The service got a unknow contact. It should raise an error - svc = self.conf.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0_badcon") - print "Contacts:", svc.contacts - self.assertEqual(False, svc.is_correct()) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_bad_hostgroup.py b/test/_old/test_bad_hostgroup.py deleted file mode 100644 index fe5d38b21..000000000 --- a/test/_old/test_bad_hostgroup.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestBadHostGroupConf(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_bad_hg_conf.cfg']) - - def test_bad_conf(self): - self.assertFalse(self.conf.conf_is_correct) - self.assert_any_log_match("itemgroup::.* as hostgroup, got unknown member BADMEMBERHG") - self.assert_no_log_match("itemgroup::.* as servicegroup, got unknown member BADMEMBERHG") - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_bad_notification_period.py b/test/_old/test_bad_notification_period.py deleted file mode 100644 index 70f79e121..000000000 --- a/test/_old/test_bad_notification_period.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestBadNotificationPeriod(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_bad_notification_period.cfg']) - - # if a notif period is bad, should be catched! - def test_bad_notification_period(self): - self.assertEqual(False, self.conf.conf_is_correct) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_bad_realm_conf.py b/test/_old/test_bad_realm_conf.py deleted file mode 100644 index 122ebcdd9..000000000 --- a/test/_old/test_bad_realm_conf.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestBadRealmConf(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_bad_realm_conf.cfg']) - - def test_bad_conf(self): - self.assertFalse(self.conf.conf_is_correct) - self.assert_any_log_match(" Error : More than one realm are set to the default realm") - self.assert_any_log_match("\[host::.*\] the host .* got an invalid realm") - self.assert_any_log_match("\[itemgroup::.*\] as realm, got unknown member UNKNOWNREALM") - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_bad_sat_realm_conf.py b/test/_old/test_bad_sat_realm_conf.py deleted file mode 100644 index 0f0cd740a..000000000 --- a/test/_old/test_bad_sat_realm_conf.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestBadSatRealmConf(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_bad_sat_realm_conf.cfg']) - - def test_badconf(self): - self.assertFalse(self.conf.conf_is_correct) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_bad_service_interval.py b/test/_old/test_bad_service_interval.py deleted file mode 100644 index 269e62850..000000000 --- a/test/_old/test_bad_service_interval.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestBadServiceInterval(AlignakTest): - def setUp(self): - self.setup_with_file(['etc/alignak_bad_service_interval.cfg']) - - def test_bad_conf(self): - self.assertFalse(self.conf.conf_is_correct) - self.assert_any_log_match("services conf incorrect!!") - self.assert_any_log_match("Error while pythonizing parameter 'check_interval': invalid literal for float\(\): (u')?1,555'?") - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_business_rules_with_bad_realm_conf.py b/test/_old/test_business_rules_with_bad_realm_conf.py deleted file mode 100644 index 514be9850..000000000 --- a/test/_old/test_business_rules_with_bad_realm_conf.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Olivier Hanesse, olivier.hanesse@gmail.com -# aviau, alexandre.viau@savoirfairelinux.com -# Grégory Starck, g.starck@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestBusinessRulesBadRealmConf(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_business_rules_bad_realm_conf.cfg']) - - def test_bad_conf(self): - self.assertFalse(self.conf.conf_is_correct) - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_config.py b/test/_old/test_config.py deleted file mode 100644 index c96a9fae4..000000000 --- a/test/_old/test_config.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr -# Jean Gabes, naparuba@gmail.com -# Zoran Zaric, zz@zoranzaric.de -# Gerhard Lausser, gerhard.lausser@consol.de - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestConfig(AlignakTest): - def setUp(self): - self.setup_with_file(['etc/alignak_broken_1.cfg']) - - def test_conf_is_correct(self): - # - # Config is not correct because of a wrong relative path - # in the main config file - # - self.assertFalse(self.conf.conf_is_correct) - #self.show_logs() - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_config_host.py b/test/_old/test_config_host.py deleted file mode 100644 index cac26fad2..000000000 --- a/test/_old/test_config_host.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . - -""" This file is used to test variables of host config """ - -from alignak_test import * - - -class TestConfigHost(AlignakTest): - def setUp(self): - self.setup_with_file(['etc/host_config_all.cfg']) - - def test_initial_state_down(self): - cg = self.sched.hosts.find_by_name('test_host_0') - self.assertEqual('DOWN', cg.state) - - def test_initial_state_unreachable(self): - cg = self.sched.hosts.find_by_name('test_host_1') - self.assertEqual('UNREACHABLE', cg.state) - - def test_initial_state_ok(self): - cg = self.sched.hosts.find_by_name('test_host_2') - self.assertEqual('UP', cg.state) - - def test_initial_state_nodefined(self): - cg = self.sched.hosts.find_by_name('test_host_3') - self.assertEqual('UP', cg.state) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_config_service.py b/test/_old/test_config_service.py deleted file mode 100644 index f241c0d82..000000000 --- a/test/_old/test_config_service.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . - -""" This file is used to test variables of service config """ - -from alignak_test import * - - -class TestConfigService(AlignakTest): - def setUp(self): - self.setup_with_file(['etc/service_config_all.cfg']) - - def test_initial_state_warning(self): - cg = self.sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_0') - self.assertEqual('WARNING', cg.state) - - def test_initial_state_unknown(self): - cg = self.sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_1') - self.assertEqual('UNKNOWN', cg.state) - - def test_initial_state_critical(self): - cg = self.sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_2') - self.assertEqual('CRITICAL', cg.state) - - def test_initial_state_ok(self): - cg = self.sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_3') - self.assertEqual('OK', cg.state) - - def test_initial_state_notdefined(self): - cg = self.sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_4') - self.assertEqual('OK', cg.state) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_contactgroup_nomembers.py b/test/_old/test_contactgroup_nomembers.py deleted file mode 100644 index b0b55666e..000000000 --- a/test/_old/test_contactgroup_nomembers.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestContactgroupWitoutMembers(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_contactgroup_nomembers.cfg']) - - # It seems that a contact group with no member cause some crash for the arbiter. - # should fix it :) - def test_contactgroup_nomember(self): - # Look for the members of the test_contact_nomember - cg = self.sched.conf.contactgroups.find_by_name('test_contact_nomember') - self.assertIsNot(cg, None) - print cg.members - self.assertEqual([], cg.members) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_contactgroups_plus_inheritance.py b/test/_old/test_contactgroups_plus_inheritance.py deleted file mode 100644 index 984fef0af..000000000 --- a/test/_old/test_contactgroups_plus_inheritance.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Olivier Hanesse, olivier.hanesse@gmail.com -# Grégory Starck, g.starck@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test attribute inheritance and the right order -# - -from alignak_test import * - - -class TestPlusInInheritance(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_contactgroups_plus_inheritance.cfg']) - - def _dump(self, h): - print "Dumping host", h.get_name() - print h.contact_groups - for c in h.contacts: - print "->", self.sched.contacts[c].get_name() - - def _dump_svc(self,s): - print "Dumping Service", s.get_name() - print " contact_groups : %s " % s.contact_groups - for c in s.contacts: - print "->", self.sched.contacts[c].get_name() - - def test_contactgroups_plus_inheritance(self): - host0 = self.sched.hosts.find_by_name("test_host_0") - # HOST 1 should have 2 group of contacts - # WARNING, it's a string, not the real objects! - self._dump(host0) - - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in host0.contacts]) - self.assertIn("test_contact_2", [self.sched.contacts[c].get_name() for c in host0.contacts]) - - host2 = self.sched.hosts.find_by_name("test_host_2") - self._dump(host2) - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in host2.contacts]) - - host3 = self.sched.hosts.find_by_name("test_host_3") - self._dump(host3) - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in host3.contacts]) - self.assertIn("test_contact_2", [self.sched.contacts[c].get_name() for c in host3.contacts]) - - host4 = self.sched.hosts.find_by_name("test_host_4") - self._dump(host4) - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in host4.contacts]) - - host5 = self.sched.hosts.find_by_name("test_host_5") - self._dump(host5) - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in host5.contacts]) - self.assertIn("test_contact_2", [self.sched.contacts[c].get_name() for c in host5.contacts]) - - - host6 = self.sched.hosts.find_by_name("test_host_6") - self._dump(host6) - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in host6.contacts]) - self.assertIn("test_contact_2", [self.sched.contacts[c].get_name() for c in host6.contacts]) - - # Now Let's check service inheritance - - svc1 = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "svc_tmplA") - self._dump_svc(svc1) - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in svc1.contacts]) - - svc2 = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "svc_tmplB") - self._dump_svc(svc2) - self.assertIn("test_contact_2", [self.sched.contacts[c].get_name() for c in svc2.contacts]) - - svc3 = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "svc_tmplA_tmplB") - self.assertIn("test_contact_1", [self.sched.contacts[c].get_name() for c in svc3.contacts]) - self.assertIn("test_contact_2", [self.sched.contacts[c].get_name() for c in svc3.contacts]) - self._dump_svc(svc3) - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_groups_pickle.py b/test/_old/test_groups_pickle.py deleted file mode 100644 index fc5165828..000000000 --- a/test/_old/test_groups_pickle.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2010: -# Jean Gabes, naparuba@gmail.com - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestConfig(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_groups_pickle.cfg']) - - def test_dispatch(self): - - - sub_confs = self.conf.confs - print "NB SUB CONFS", len(sub_confs) - - vcfg = None - # Find where hr1 is - for cfg in sub_confs.values(): - if 'HR1' in [h.get_name() for h in cfg.hosts]: - print 'FOUNCED', len(cfg.hosts) - vcfg = cfg - - - # Look ifthe hg in the conf is valid - vhg = vcfg.hostgroups.find_by_name('everyone') - self.assert_(len(vhg.members) == 1) - - hr1 = [h for h in vcfg.hosts if h.get_name() == "HR1"][0] - print hr1.hostgroups - hg1 = None - for hg in hr1.hostgroups: - if vcfg.hostgroups[hg].get_name() == 'everyone': - hg1 = vcfg.hostgroups[hg] - - - - print "Founded hostgroup", hg1 - print 'There should be only one host there' - self.assert_(len(hg1.members) == 1) - print 'and should be the same than the vcfg one!' - self.assert_(hg1 == vhg) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_groups_with_no_alias.py b/test/_old/test_groups_with_no_alias.py deleted file mode 100644 index 6c8defb51..000000000 --- a/test/_old/test_groups_with_no_alias.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestGroupwithNoAlias(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_groups_with_no_alias.cfg']) - - def test_look_for_alias(self): - # - # Config is not correct because of a wrong relative path - # in the main config file - # - print "Get the hosts and services" - now = time.time() - hg = self.sched.hostgroups.find_by_name("NOALIAS") - self.assertIsNot(hg, None) - print hg.__dict__ - self.assertEqual("NOALIAS", hg.alias) - - sg = self.sched.servicegroups.find_by_name("NOALIAS") - self.assertIsNot(sg, None) - print sg.__dict__ - self.assertEqual("NOALIAS", sg.alias) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_hostdep_with_multiple_names.py b/test/_old/test_hostdep_with_multiple_names.py deleted file mode 100644 index 641c30bd9..000000000 --- a/test/_old/test_hostdep_with_multiple_names.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestHostDepWithMultipleNames(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_hostdep_with_multiple_names.cfg']) - - def test_DepWithMultipleNames(self): - for n in ['svn1', 'svn2', 'svn3', 'svn4', 'nas1', 'nas2', 'nas3']: - val = globals()[n] = self.sched.hosts.find_by_name(n) - self.assertIsNot(val, None) - # We check that nas3 is a father of svn4, the simple case - self.assertIn(nas3.uuid, [e[0] for e in svn4.act_depend_of]) - - # Now the more complex one - for son in [svn1, svn2, svn3]: - for father in [nas1, nas2]: - print 'Checking if', father.get_name(), 'is the father of', son.get_name() - print son.act_depend_of - for e in son.act_depend_of: - print self.sched.find_item_by_id(e[0]).get_name() - self.assertIn(father.uuid, [e[0] for e in son.act_depend_of]) - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_hostdep_withno_depname.py b/test/_old/test_hostdep_withno_depname.py deleted file mode 100644 index b1a700ff3..000000000 --- a/test/_old/test_hostdep_withno_depname.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestHostDepWithNodepname(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_hostdep_withno_depname.cfg']) - - def test_hostdep_withno_depname(self): - # - # Config is not correct because of a wrong relative path - # in the main config file - # - print "Get the hosts and services" - now = time.time() - host = self.sched.hosts.find_by_name("test_host_0") - h2 = self.sched.hosts.find_by_name("test_host_1") - self.assertIsNot(h2, None) - # Should got a link between host and h2 - print h2.act_depend_of - self.assertGreater(len(h2.act_depend_of), 0) - l = h2.act_depend_of[0] - h = l[0] # the host that h2 depend on - self.assertIs(host.uuid, h) - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_hostgroup_no_host.py b/test/_old/test_hostgroup_no_host.py deleted file mode 100644 index d924cd75d..000000000 --- a/test/_old/test_hostgroup_no_host.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Hartmut Goebel, h.goebel@goebel-consult.de -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestHostGroupNoHost(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_hostgroup_no_host.cfg']) - - def test_hostgroup_wit_no_host(self): - self.assertTrue(self.sched.conf.conf_is_correct) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_hostgroup_with_space.py b/test/_old/test_hostgroup_with_space.py deleted file mode 100644 index b2ca6ffa7..000000000 --- a/test/_old/test_hostgroup_with_space.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com -# Grégory Starck, g.starck@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -class TestHostGroupWithSpace(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_hostgroup_with_space.cfg']) - - - def test_hostgroup_with_space(self): - svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_With Spaces") - self.assertIsNot(svc, None) - - svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", 'test_With anoter Spaces') - self.assertIsNot(svc, None) - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_hostgroup_with_void_member.py b/test/_old/test_hostgroup_with_void_member.py deleted file mode 100644 index 5d97928a8..000000000 --- a/test/_old/test_hostgroup_with_void_member.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Jean Gabes, naparuba@gmail.com - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -from alignak_test import * - - -# test members property with , at the end -class TestHostgroupAndContactGroupWithVoidMember(AlignakTest): - - def setUp(self): - self.setup_with_file(['etc/alignak_hostgroup_with_void_member.cfg']) - - def test_me(self): - self.assertTrue(self.sched.conf.is_correct) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/_old/test_servicegroups.py b/test/_old/test_servicegroups.py deleted file mode 100644 index c0cacd4d0..000000000 --- a/test/_old/test_servicegroups.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors -# -# This file is part of Alignak. -# -# Alignak is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Alignak is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Alignak. If not, see . -# -# -# This file incorporates work covered by the following copyright and -# permission notice: -# -# Copyright (C) 2009-2014: -# Grégory Starck, g.starck@gmail.com -# Jean Gabes, naparuba@gmail.com -# Sebastien Coavoux, s.coavoux@free.fr - -# This file is part of Shinken. -# -# Shinken is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Shinken is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Shinken. If not, see . - -# -# This file is used to test reading and processing of config files -# - -import copy -from alignak_test import * - - -class TestServicegroup(AlignakTest): - def setUp(self): - self.setup_with_file(["etc/alignak_servicegroups_generated.cfg"]) - - - def test_servicegroup(self): - self.assertEqual(True, self.conf.conf_is_correct) - sgs = [] - for name in ["MYSVCGP", "MYSVCGP2", "MYSVCGP3", "MYSVCGP4"]: - sg = self.sched.servicegroups.find_by_name(name) - sgs.append(sg) - self.assertIsNot(sg, None) - - svc3 = self.sched.services.find_srv_by_name_and_hostname("fake host", "fake svc3") - svc4 = self.sched.services.find_srv_by_name_and_hostname("fake host", "fake svc4") - self.assertIn(svc3.uuid, sgs[0].members) - self.assertIn(svc3.uuid, sgs[1].members) - self.assertIn(svc4.uuid, sgs[2].members) - self.assertIn(svc4.uuid, sgs[3].members) - - self.assertIn(sgs[0].uuid, svc3.servicegroups) - self.assertIn(sgs[1].uuid, svc3.servicegroups) - self.assertIn(sgs[2].uuid, svc4.servicegroups) - self.assertIn(sgs[3].uuid, svc4.servicegroups) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/alignak_test.py b/test/alignak_test.py index f86ac1ee6..363453729 100755 --- a/test/alignak_test.py +++ b/test/alignak_test.py @@ -141,25 +141,51 @@ def setup_with_file(self, configuration_file): """ Load alignak with defined configuration file + If the configuration loading fails, a SystemExit exception is raised to the caller. + + The conf_is_correct property indicates if the configuration loading succeeded or failed. + + The configuration errors property contains a list of the error message that are normally + logged as ERROR by the arbiter. + @verified :param configuration_file: path + file name of the main configuration file :type configuration_file: str :return: None """ + self.broks = {} + self.schedulers = [] self.arbiter = None + self.conf_is_correct = False + self.configuration_warnings = [] + self.configuration_errors = [] self.arbiter = Arbiter([configuration_file], False, False, False, False, '/tmp/arbiter.log', 'arbiter-master') - self.arbiter.load_config_file() + try: + self.arbiter.load_config_file() + # If this assertion does not match, then there is a bug in the arbiter :) + self.assertTrue(self.arbiter.conf.conf_is_correct) + self.conf_is_correct = True + except SystemExit: + self.configuration_warnings = self.arbiter.conf.configuration_warnings + print("Configuration warnings:") + for msg in self.configuration_warnings: + print(" - %s" % msg) + self.configuration_errors = self.arbiter.conf.configuration_errors + print("Configuration errors:") + for msg in self.configuration_errors: + print(" - %s" % msg) + raise + for arb in self.arbiter.conf.arbiters: if arb.get_name() == self.arbiter.config_name: self.arbiter.myself = arb self.arbiter.dispatcher = Dispatcher(self.arbiter.conf, self.arbiter.myself) self.arbiter.dispatcher.prepare_dispatch() - self.schedulers = [] for scheduler in self.arbiter.dispatcher.schedulers: sched = Alignak([], False, False, True, '/tmp/scheduler.log') # logger.setLevel('DEBUG') @@ -174,7 +200,7 @@ def add(self, b): self.broks[b.uuid] = b return if isinstance(b, ExternalCommand): - self.sched.run_external_command(b.cmd_line) + self.schedulers[0].run_external_command(b.cmd_line) def fake_check(self, ref, exit_status, output="OK"): # print "fake", ref @@ -267,10 +293,10 @@ def worker_loop(self, verbose=True): def show_logs(self): print "--- logs <<<----------------------------------" - if hasattr(self.scheduler, "sched"): - broks = self.scheduler.sched.broks - else: - broks = self.broks + broks = self.broks + if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"): + broks = self.schedulers[0].sched.broks + for brok in sorted(broks.values(), lambda x, y: cmp(x.uuid, y.uuid)): if brok.type == 'log': brok.prepare() @@ -308,8 +334,8 @@ def show_and_clear_actions(self): self.clear_actions() def count_logs(self): - if hasattr(self.scheduler, "sched"): - broks = self.scheduler.sched.broks + if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"): + broks = self.schedulers[0].sched.broks else: broks = self.broks return len([b for b in broks.values() if b.type == 'log']) @@ -322,10 +348,10 @@ def count_actions(self): return len(actions.values()) def clear_logs(self): - if hasattr(self.scheduler, "sched"): - broks = self.scheduler.sched.broks - else: - broks = self.broks + broks = self.broks + if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"): + broks = self.schedulers[0].sched.broks + id_to_del = [] for b in broks.values(): if b.type == 'log': @@ -394,7 +420,10 @@ def assert_log_match(self, index, pattern): """ regex = re.compile(pattern) log_num = 1 - broks = sorted(self.schedulers[0].sched.broks.values(), key=lambda x: x.creation_time) + broks = self.broks + if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"): + broks = self.schedulers[0].sched.broks + found = False for brok in broks: if brok.type == 'log': @@ -457,8 +486,10 @@ def assert_checks_match(self, index, pattern, field): def _any_log_match(self, pattern, assert_not): regex = re.compile(pattern) - broks = getattr(self, 'sched', self).broks - broks = sorted(broks.values(), lambda x, y: cmp(x.uuid, y.uuid)) + broks = self.broks + if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"): + broks = self.schedulers[0].sched.broks + for brok in broks: if brok.type == 'log': brok.prepare() @@ -480,7 +511,11 @@ def assert_no_log_match(self, pattern): def get_log_match(self, pattern): regex = re.compile(pattern) res = [] - for brok in sorted(self.sched.broks.values(), lambda x, y: cmp(x.uuid, y.uuid)): + broks = self.broks + if hasattr(self, "schedulers") and self.schedulers and hasattr(self.schedulers[0], "sched"): + broks = self.schedulers[0].sched.broks + + for brok in broks: if brok.type == 'log': if re.search(regex, brok.data['log']): res.append(brok.data['log']) @@ -495,6 +530,62 @@ def xtest_conf_is_correct(self): self.print_header() self.assertTrue(self.conf.conf_is_correct) + def show_configuration_logs(self): + """ + Prints the configuration logs + + @verified + :return: + """ + print("Configuration warnings:") + for msg in self.configuration_warnings: + print(" - %s" % msg) + print("Configuration errors:") + for msg in self.configuration_errors: + print(" - %s" % msg) + + def _any_cfg_log_match(self, pattern, assert_not): + """ + Search a pattern in configuration log (warning and error) + + @verified + :param pattern: + :return: + """ + regex = re.compile(pattern) + + cfg_logs = self.configuration_warnings + self.configuration_errors + + for log in cfg_logs: + if re.search(regex, log): + self.assertTrue(not assert_not, + "Found matching log line:\n" + "pattern = %r\nlog = %r" % (pattern, log)) + return + + self.assertTrue(assert_not, "No matching log line found:\n" + "pattern = %r\n" "logs = %r" % (pattern, cfg_logs)) + + def assert_any_cfg_log_match(self, pattern): + """ + Assert if any configuration log matches the pattern + + @verified + :param pattern: + :return: + """ + self._any_cfg_log_match(pattern, assert_not=False) + + def assert_no_cfg_log_match(self, pattern): + """ + Assert if no configuration log matches the pattern + + @verified + :param pattern: + :return: + """ + self._any_cfg_log_match(pattern, assert_not=True) + ShinkenTest = AlignakTest diff --git a/test/cfg/conf_in_symlinks/alignak_conf_in_symlinks.cfg b/test/cfg/conf_in_symlinks/alignak_conf_in_symlinks.cfg new file mode 100644 index 000000000..83d339d1c --- /dev/null +++ b/test/cfg/conf_in_symlinks/alignak_conf_in_symlinks.cfg @@ -0,0 +1,3 @@ +cfg_dir=../default + +cfg_dir=./links/ diff --git a/test/_old/etc/conf_in_symlinks/dest/service_hide.cfg b/test/cfg/conf_in_symlinks/dest/service_hide.cfg similarity index 100% rename from test/_old/etc/conf_in_symlinks/dest/service_hide.cfg rename to test/cfg/conf_in_symlinks/dest/service_hide.cfg diff --git a/test/_old/etc/conf_in_symlinks/links/link b/test/cfg/conf_in_symlinks/links/link similarity index 100% rename from test/_old/etc/conf_in_symlinks/links/link rename to test/cfg/conf_in_symlinks/links/link diff --git a/test/_old/etc/alignak_antivirg.cfg b/test/cfg/config/alignak_antivirg.cfg similarity index 98% rename from test/_old/etc/alignak_antivirg.cfg rename to test/cfg/config/alignak_antivirg.cfg index a98a55a2d..5616a367f 100644 --- a/test/_old/etc/alignak_antivirg.cfg +++ b/test/cfg/config/alignak_antivirg.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define host{ check_interval 1 check_period 24x7 diff --git a/test/_old/etc/alignak_bad_contact_call.cfg b/test/cfg/config/alignak_bad_contact_call.cfg similarity index 97% rename from test/_old/etc/alignak_bad_contact_call.cfg rename to test/cfg/config/alignak_bad_contact_call.cfg index f18fd0ca6..2dfc1416b 100644 --- a/test/_old/etc/alignak_bad_contact_call.cfg +++ b/test/cfg/config/alignak_bad_contact_call.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define service{ action_url http://search.cpan.org/dist/Monitoring-Generator-TestConfig/ active_checks_enabled 1 diff --git a/test/_old/etc/alignak_bad_escalation_on_groups.cfg b/test/cfg/config/alignak_bad_escalation_on_groups.cfg similarity index 98% rename from test/_old/etc/alignak_bad_escalation_on_groups.cfg rename to test/cfg/config/alignak_bad_escalation_on_groups.cfg index f86e012a2..64941f6fc 100644 --- a/test/_old/etc/alignak_bad_escalation_on_groups.cfg +++ b/test/cfg/config/alignak_bad_escalation_on_groups.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define host{ address 127.0.0.1 alias up_0 diff --git a/test/_old/etc/alignak_bad_notification_character.cfg b/test/cfg/config/alignak_bad_notification_character.cfg similarity index 98% rename from test/_old/etc/alignak_bad_notification_character.cfg rename to test/cfg/config/alignak_bad_notification_character.cfg index f3f17f022..a4d9b2ab2 100644 --- a/test/_old/etc/alignak_bad_notification_character.cfg +++ b/test/cfg/config/alignak_bad_notification_character.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define command{ command_name check_service_bad command_line $USER1$/test_servicecheck.pl --type=$ARG1$ --failchance=5% --previous-state=$SERVICESTATE$ --state-duration=$SERVICEDURATIONSEC$ --total-critical-on-host=$TOTALHOSTSERVICESCRITICAL$ --total-warning-on-host=$TOTALHOSTSERVICESWARNING$ --hostname $HOSTNAME$ --servicedesc $SERVICEDESC$ &é"'( diff --git a/test/_old/etc/alignak_bad_notification_period.cfg b/test/cfg/config/alignak_bad_notification_period.cfg similarity index 90% rename from test/_old/etc/alignak_bad_notification_period.cfg rename to test/cfg/config/alignak_bad_notification_period.cfg index 8b35d9f62..b25fb0854 100644 --- a/test/_old/etc/alignak_bad_notification_period.cfg +++ b/test/cfg/config/alignak_bad_notification_period.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define service{ host_name test_host_0 service_description test_ok_0_badperiod diff --git a/test/_old/etc/alignak_bad_realm_conf.cfg b/test/cfg/config/alignak_bad_realm_conf.cfg similarity index 98% rename from test/_old/etc/alignak_bad_realm_conf.cfg rename to test/cfg/config/alignak_bad_realm_conf.cfg index 938aad552..de8929b63 100644 --- a/test/_old/etc/alignak_bad_realm_conf.cfg +++ b/test/cfg/config/alignak_bad_realm_conf.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define realm{ realm_name NoDefault } diff --git a/test/_old/etc/alignak_bad_sat_realm_conf.cfg b/test/cfg/config/alignak_bad_sat_realm_conf.cfg similarity index 76% rename from test/_old/etc/alignak_bad_sat_realm_conf.cfg rename to test/cfg/config/alignak_bad_sat_realm_conf.cfg index 27ea07d39..8c02f5008 100644 --- a/test/_old/etc/alignak_bad_sat_realm_conf.cfg +++ b/test/cfg/config/alignak_bad_sat_realm_conf.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define broker { broker_name Broker-test realm NoGood diff --git a/test/cfg/config/alignak_bad_service_interval.cfg b/test/cfg/config/alignak_bad_service_interval.cfg new file mode 100644 index 000000000..f862b4bf8 --- /dev/null +++ b/test/cfg/config/alignak_bad_service_interval.cfg @@ -0,0 +1,17 @@ +cfg_dir=../default + +define host { + host_name fake host + alias fake host + address 192.168.0.1 + use generic-host +} + + +define service{ + host_name fake host + service_description fake svc1 + use generic-service + check_command _echo + check_interval 1,555 +} \ No newline at end of file diff --git a/test/_old/etc/alignak_bad_servicedependencies.cfg b/test/cfg/config/alignak_bad_servicedependencies.cfg similarity index 99% rename from test/_old/etc/alignak_bad_servicedependencies.cfg rename to test/cfg/config/alignak_bad_servicedependencies.cfg index 24cffd5bd..a8bdda19c 100644 --- a/test/_old/etc/alignak_bad_servicedependencies.cfg +++ b/test/cfg/config/alignak_bad_servicedependencies.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define host { host_name fake host alias fake host diff --git a/test/_old/etc/alignak_bad_timeperiods.cfg b/test/cfg/config/alignak_bad_timeperiods.cfg similarity index 89% rename from test/_old/etc/alignak_bad_timeperiods.cfg rename to test/cfg/config/alignak_bad_timeperiods.cfg index 8b3fde69b..267153f06 100644 --- a/test/_old/etc/alignak_bad_timeperiods.cfg +++ b/test/cfg/config/alignak_bad_timeperiods.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define timeperiod{ timeperiod_name 24x7_bad2 alias 24 Hours A Day, 7 Days A Week @@ -7,7 +9,7 @@ define timeperiod{ wednesday 00:00-24:00 thursday 00:00-24:00 friday 00:00-24:00 -#We make an error here in the satuerday name +#We make an error here in the saturday name satourday 00:00-24:00 } diff --git a/test/_old/etc/alignak_broken_1.cfg b/test/cfg/config/alignak_broken_1.cfg similarity index 100% rename from test/_old/etc/alignak_broken_1.cfg rename to test/cfg/config/alignak_broken_1.cfg diff --git a/test/cfg/config/alignak_business_rules_bad_realm_conf.cfg b/test/cfg/config/alignak_business_rules_bad_realm_conf.cfg new file mode 100644 index 000000000..c4c833442 --- /dev/null +++ b/test/cfg/config/alignak_business_rules_bad_realm_conf.cfg @@ -0,0 +1,128 @@ +cfg_dir=../default + +define scheduler{ + scheduler_name scheduler-1 ; just the name + address localhost ; ip or dns address of the daemon + port 7768 ; tcp port of the daemon + spare 0 ; (0 = not a spare, 1 = is spare) + weight 1 ; (some schedulers can manage more hosts than others) + timeout 3 ; 'ping' timeout + data_timeout 120 ; 'data send' timeout + max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD + check_interval 60 ; ping it every minute + realm Realm1 ; optional (realm are multi-datacenters features) +} + +define poller{ + poller_name poller-1 + address localhost + port 7771 + manage_sub_realms 0 ; optional and advanced: does it take jobs from schedulers of sub realms? + min_workers 0 ; optional: starts with N worker processes. 0 means: "number of cpus" + max_workers 0 ; optional: no more than N worker processes. 0 means: "number of cpus" + processes_by_worker 256 ; optional: each worker manages 256 checks + polling_interval 1 ; optional: get jobs from schedulers each 1 second + timeout 3 ; 'ping' timeout + data_timeout 120 ; 'data send' timeout + check_interval 60 ; ping it every minute + max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD + realm Realm1 +} + +define broker{ + broker_name broker-1 + address localhost + port 7772 + spare 0 + ; modules Livestatus + manage_sub_realms 1 ; optional, like for poller + manage_arbiters 1 ; optional: take data from Arbiter. There should be + check_interval 60 ; ping it every minute + timeout 3 ; 'ping' timeout + data_timeout 120 ; 'data send' timeout + max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD + realm Realm1 +} + +# Reactionner launches notifications +define reactionner{ + reactionner_name reactionner-1 + address localhost + port 7769 + spare 0 + manage_sub_realms 0 ;optionnal: like for poller + min_workers 1 ;optionnal: like for poller + max_workers 15 ;optionnal: like for poller + polling_interval 1 ;optionnal: like for poller + timeout 3 ; 'ping' timeout + data_timeout 120 ; 'data send' timeout + check_interval 60 ; ping it every minute + max_check_attempts 3 ; if at least max_check_attempts ping failed, the node is DEAD + realm Realm1 +} + +define realm{ + realm_name NoDefault +} + +define realm{ + realm_name Realm1 +} + +define realm{ + realm_name Realm2 +} + + +define host{ + address 127.0.0.1 + alias up_0 + host_name test_host_realm1 + hostgroups hostgroup_01,up + use generic-host + realm Realm1 +} + +define host{ + address 127.0.0.1 + alias up_0 + host_name test_host_realm2 + hostgroups hostgroup_01,up + use generic-host + realm Realm2 +} + +define service{ + check_command check_service!ok + host_name test_host_realm1 + service_description test_ok_realm1_0 + use generic-service +} + +define service{ + check_command check_service!ok + host_name test_host_realm2 + service_description test_ok_realm2_0 + use generic-service +} + +define service{ + check_command bp_rule!(test_host_realm1,test_ok_realm1_0 & test_host_realm2,test_ok_realm2_0) + host_name test_host_realm1 + service_description Test bad services BP rules + use generic-service +} + +define service{ + check_command bp_rule!(test_host_realm1 & test_host_realm2) + host_name test_host_realm1 + service_description Test bad host BP rules + use generic-service +} + +define service{ + check_command bp_rule!((test_host_realm1,test_ok_realm1_0 & test_host_realm2,test_ok_realm2_0) | (test_host_realm1 & test_host_realm2)) + host_name test_host_realm1 + service_description Test bad services BP rules complex + use generic-service +} diff --git a/test/_old/etc/host_config_all.cfg b/test/cfg/config/host_config_all.cfg similarity index 99% rename from test/_old/etc/host_config_all.cfg rename to test/cfg/config/host_config_all.cfg index bafe53e17..6173c9590 100644 --- a/test/_old/etc/host_config_all.cfg +++ b/test/cfg/config/host_config_all.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define host{ check_interval 1 check_period 24x7 diff --git a/test/_old/etc/service_config_all.cfg b/test/cfg/config/service_config_all.cfg similarity index 99% rename from test/_old/etc/service_config_all.cfg rename to test/cfg/config/service_config_all.cfg index 1ae7d1ab2..fa58133a3 100644 --- a/test/_old/etc/service_config_all.cfg +++ b/test/cfg/config/service_config_all.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define host{ check_interval 1 check_period 24x7 diff --git a/test/cfg/contactgroup/alignak_contactgroup_members.cfg b/test/cfg/contactgroup/alignak_contactgroup_members.cfg new file mode 100755 index 000000000..9044ab6d3 --- /dev/null +++ b/test/cfg/contactgroup/alignak_contactgroup_members.cfg @@ -0,0 +1,22 @@ +cfg_dir=../default + +define contact{ + contact_name test_contact_2 + alias Second contact alias + service_notification_period 24x7 + host_notification_period 24x7 + service_notification_options w,u,c,r,f + host_notification_options d,u,r,f,s + service_notification_commands notify-service + host_notification_commands notify-host + email nobody@localhost + can_submit_commands 0 + ; contactgroups another_contact_test +} + +define contactgroup { + contactgroup_name allcontacts_and_groups + alias All: Contacts and groups + members test_contact, test_contact_2 + contactgroup_members test_contact +} diff --git a/test/cfg/contactgroup/alignak_contactgroup_no_contact.cfg b/test/cfg/contactgroup/alignak_contactgroup_no_contact.cfg new file mode 100755 index 000000000..7c9bb30a6 --- /dev/null +++ b/test/cfg/contactgroup/alignak_contactgroup_no_contact.cfg @@ -0,0 +1,6 @@ +cfg_dir=../default + +define contactgroup { + contactgroup_name void + alias Void group +} diff --git a/test/cfg/contactgroup/alignak_contactgroup_with_space.cfg b/test/cfg/contactgroup/alignak_contactgroup_with_space.cfg new file mode 100755 index 000000000..2e9b09442 --- /dev/null +++ b/test/cfg/contactgroup/alignak_contactgroup_with_space.cfg @@ -0,0 +1,6 @@ +cfg_dir=../default + +define contactgroup { + contactgroup_name test_With Spaces + members test_contact +} diff --git a/test/cfg/contactgroup/alignak_contactgroup_with_void_member.cfg b/test/cfg/contactgroup/alignak_contactgroup_with_void_member.cfg new file mode 100755 index 000000000..24a594d9f --- /dev/null +++ b/test/cfg/contactgroup/alignak_contactgroup_with_void_member.cfg @@ -0,0 +1,35 @@ +cfg_dir=../default + +define hostgroup{ + hostgroup_name MYGROUP + members h1,h2, +} + + +define host{ + host_name h1 + use generic-host +} + +define host{ + host_name h2 + use generic-host +} + + + +define contactgroup{ + contactgroup_name SPACEMARINES + members m1 , m2 , +} + + +define contact{ + contact_name m1 + use generic-contact +} + +define contact{ + contact_name m2 + use generic-contact +} \ No newline at end of file diff --git a/test/_old/etc/alignak_contactgroups_plus_inheritance.cfg b/test/cfg/contactgroup/alignak_contactgroups_plus_inheritance.cfg similarity index 99% rename from test/_old/etc/alignak_contactgroups_plus_inheritance.cfg rename to test/cfg/contactgroup/alignak_contactgroups_plus_inheritance.cfg index c70a221e7..83b7be3c5 100644 --- a/test/_old/etc/alignak_contactgroups_plus_inheritance.cfg +++ b/test/cfg/contactgroup/alignak_contactgroups_plus_inheritance.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define contactgroup{ contactgroup_name test_contact_1 alias test_contacts_alias_1 diff --git a/test/cfg/contactgroup/alignak_groups_with_no_alias.cfg b/test/cfg/contactgroup/alignak_groups_with_no_alias.cfg new file mode 100755 index 000000000..a7acb3ee2 --- /dev/null +++ b/test/cfg/contactgroup/alignak_groups_with_no_alias.cfg @@ -0,0 +1,4 @@ + +define contactgroup { + contactgroup_name NOALIAS +} diff --git a/test/_old/etc/alignak_hostdep_with_multiple_names.cfg b/test/cfg/hostdependency/alignak_hostdep_with_multiple_names.cfg similarity index 99% rename from test/_old/etc/alignak_hostdep_with_multiple_names.cfg rename to test/cfg/hostdependency/alignak_hostdep_with_multiple_names.cfg index 1addbf87d..c6cd9e451 100644 --- a/test/_old/etc/alignak_hostdep_with_multiple_names.cfg +++ b/test/cfg/hostdependency/alignak_hostdep_with_multiple_names.cfg @@ -1,4 +1,4 @@ - +cfg_dir=../default define host{ diff --git a/test/cfg/hostdependency/alignak_hostdep_with_no_depname.cfg b/test/cfg/hostdependency/alignak_hostdep_with_no_depname.cfg new file mode 100644 index 000000000..9647cebca --- /dev/null +++ b/test/cfg/hostdependency/alignak_hostdep_with_no_depname.cfg @@ -0,0 +1,29 @@ +cfg_dir=../default + +# 0 depends upon 1 +define hostdependency { + host_name test_host_1 + dependent_hostname test_host_0 +} + +# All host from flap group depends upon 0 +define hostdependency { + host_name test_host_0 + dependent_hostgroup_name flap +} + +# test_router_0 is a parent of test_host_1 +define host{ + address 127.0.0.1 + alias up_0 + check_command check-host-alive-parent!up!$HOSTSTATE:test_router_0$ + event_handler eventhandler + check_period 24x7 + host_name test_host_1 + hostgroups flap + parents test_router_0 + use generic-host + criticity 5 + _ostype gnulinux + _oslicense gpl +} \ No newline at end of file diff --git a/test/cfg/hostgroup/alignak_bad_hg_conf.cfg b/test/cfg/hostgroup/alignak_bad_hg_conf.cfg new file mode 100644 index 000000000..af20ec844 --- /dev/null +++ b/test/cfg/hostgroup/alignak_bad_hg_conf.cfg @@ -0,0 +1,15 @@ +cfg_dir=../default + + +define hostgroup { + hostgroup_name allhosts_bad + alias All Hosts bad + members test_router_0,test_host_0,BAD_HOST +} + +define hostgroup { + hostgroup_name allhosts_groups_bad + alias All Hosts bad + members test_router_0,test_host_0 + hostgroup_members BAD_HOSTGROUP +} diff --git a/test/_old/etc/alignak_groups_with_no_alias.cfg b/test/cfg/hostgroup/alignak_groups_with_no_alias.cfg similarity index 100% rename from test/_old/etc/alignak_groups_with_no_alias.cfg rename to test/cfg/hostgroup/alignak_groups_with_no_alias.cfg diff --git a/test/cfg/hostgroup/alignak_hostgroup_members.cfg b/test/cfg/hostgroup/alignak_hostgroup_members.cfg new file mode 100755 index 000000000..ec5a906fc --- /dev/null +++ b/test/cfg/hostgroup/alignak_hostgroup_members.cfg @@ -0,0 +1,8 @@ +cfg_dir=../default + +define hostgroup { + hostgroup_name allhosts_and_groups + alias All Hosts and groups + members test_router_0,test_host_0 + hostgroup_members hostgroup_01, hostgroup_02, hostgroup_03, hostgroup_04 +} diff --git a/test/cfg/hostgroup/alignak_hostgroup_no_host.cfg b/test/cfg/hostgroup/alignak_hostgroup_no_host.cfg new file mode 100755 index 000000000..be675c65a --- /dev/null +++ b/test/cfg/hostgroup/alignak_hostgroup_no_host.cfg @@ -0,0 +1,6 @@ +cfg_dir=../default + +define hostgroup { + hostgroup_name void + alias Void group +} diff --git a/test/cfg/hostgroup/alignak_hostgroup_with_space.cfg b/test/cfg/hostgroup/alignak_hostgroup_with_space.cfg new file mode 100755 index 000000000..15beb8ee4 --- /dev/null +++ b/test/cfg/hostgroup/alignak_hostgroup_with_space.cfg @@ -0,0 +1,13 @@ +cfg_dir=../default + +define hostgroup { + hostgroup_name test_With Spaces + members test_router_0,test_host_0 +} + + +define hostgroup { + hostgroup_name test_With another Spaces + members test_router_0,test_host_0 +} + diff --git a/test/_old/etc/alignak_hostgroup_with_void_member.cfg b/test/cfg/hostgroup/alignak_hostgroup_with_void_member.cfg old mode 100644 new mode 100755 similarity index 95% rename from test/_old/etc/alignak_hostgroup_with_void_member.cfg rename to test/cfg/hostgroup/alignak_hostgroup_with_void_member.cfg index a4a54131c..24a594d9f --- a/test/_old/etc/alignak_hostgroup_with_void_member.cfg +++ b/test/cfg/hostgroup/alignak_hostgroup_with_void_member.cfg @@ -1,3 +1,5 @@ +cfg_dir=../default + define hostgroup{ hostgroup_name MYGROUP members h1,h2, diff --git a/test/cfg/servicegroup/alignak_groups_with_no_alias.cfg b/test/cfg/servicegroup/alignak_groups_with_no_alias.cfg new file mode 100644 index 000000000..e6e4967d8 --- /dev/null +++ b/test/cfg/servicegroup/alignak_groups_with_no_alias.cfg @@ -0,0 +1,8 @@ + +define servicegroup { + servicegroup_name NOALIAS +} + +define hostgroup { + hostgroup_name NOALIAS +} diff --git a/test/cfg/servicegroup/alignak_servicegroup_members.cfg b/test/cfg/servicegroup/alignak_servicegroup_members.cfg new file mode 100755 index 000000000..cdde2a4e6 --- /dev/null +++ b/test/cfg/servicegroup/alignak_servicegroup_members.cfg @@ -0,0 +1,7 @@ +cfg_dir=../default + +define servicegroup { + servicegroup_name allservices_and_groups + members test_host_0,test_ok_0 + servicegroup_members servicegroup_01, servicegroup_02, servicegroup_03, servicegroup_04 +} diff --git a/test/cfg/servicegroup/alignak_servicegroup_no_service.cfg b/test/cfg/servicegroup/alignak_servicegroup_no_service.cfg new file mode 100755 index 000000000..c6f74111e --- /dev/null +++ b/test/cfg/servicegroup/alignak_servicegroup_no_service.cfg @@ -0,0 +1,6 @@ +cfg_dir=../default + +define servicegroup { + servicegroup_name void + alias Void group +} diff --git a/test/cfg/servicegroup/alignak_servicegroup_with_space.cfg b/test/cfg/servicegroup/alignak_servicegroup_with_space.cfg new file mode 100755 index 000000000..3108b200d --- /dev/null +++ b/test/cfg/servicegroup/alignak_servicegroup_with_space.cfg @@ -0,0 +1,13 @@ +cfg_dir=../default + +define servicegroup { + servicegroup_name test_With Spaces + members test_host_0,test_ok_0 +} + + +define servicegroup { + servicegroup_name test_With another Spaces + members test_host_0,test_ok_0 +} + diff --git a/test/cfg/servicegroup/alignak_servicegroup_with_void_member.cfg b/test/cfg/servicegroup/alignak_servicegroup_with_void_member.cfg new file mode 100755 index 000000000..24a594d9f --- /dev/null +++ b/test/cfg/servicegroup/alignak_servicegroup_with_void_member.cfg @@ -0,0 +1,35 @@ +cfg_dir=../default + +define hostgroup{ + hostgroup_name MYGROUP + members h1,h2, +} + + +define host{ + host_name h1 + use generic-host +} + +define host{ + host_name h2 + use generic-host +} + + + +define contactgroup{ + contactgroup_name SPACEMARINES + members m1 , m2 , +} + + +define contact{ + contact_name m1 + use generic-contact +} + +define contact{ + contact_name m2 + use generic-contact +} \ No newline at end of file diff --git a/test/cfg/servicegroup/alignak_servicegroups_generated.cfg b/test/cfg/servicegroup/alignak_servicegroups_generated.cfg new file mode 100644 index 000000000..f85e754b5 --- /dev/null +++ b/test/cfg/servicegroup/alignak_servicegroups_generated.cfg @@ -0,0 +1,57 @@ +cfg_dir=../default + +define host { + host_name fake host + alias fake host + address 192.168.50.43 + business_impact 4 + icon_image_alt Linux + icon_image base/linux40.gif + statusmap_image base/linux40.gd2 + check_command _echo + check_period 24x7 + notification_period 24x7 + #use Template_Host_Generic + use generic-host + contact_groups + check_interval 1555 + retry_interval 1555 +} + +define service{ + host_name fake host + service_description fake svc1 + use generic-service + check_command _echo + check_interval 5 + retry_interval 5 +} + +define service{ + host_name fake host + service_description fake svc2 + use generic-service + check_command _echo + check_interval 5 + retry_interval 5 +} + +define service{ + host_name fake host + service_description fake svc3 + use generic-service + check_command _echo + servicegroups MYSVCGP, MYSVCGP2 + check_interval 5 + retry_interval 5 +} + +define service{ + host_name fake host + service_description fake svc4 + use generic-service + check_command _echo + servicegroups MYSVCGP3,MYSVCGP4 + check_interval 5 + retry_interval 5 +} diff --git a/test/test_config.py b/test/test_config.py new file mode 100755 index 000000000..fe76db899 --- /dev/null +++ b/test/test_config.py @@ -0,0 +1,326 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors +# +# This file is part of Alignak. +# +# Alignak is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Alignak is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Alignak. If not, see . +# +# + +""" +This file contains the test for the Alignak configuration checks +""" +import os +import time +from alignak_test import AlignakTest + + +class TestConfig(AlignakTest): + """ + This class tests the configuration + """ + + def test_config_ok(self): + """ + Default configuration has no loading problems ... + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + self.assertTrue(self.conf_is_correct) + # No error messages + self.assertEqual(len(self.configuration_errors), 0) + # No warning messages + self.assertEqual(len(self.configuration_warnings), 0) + + + def test_symlinks(self): + if os.name == 'nt': + return + + self.print_header() + self.setup_with_file('cfg/conf_in_symlinks/alignak_conf_in_symlinks.cfg') + + svc = self.arbiter.conf.services.find_srv_by_name_and_hostname("test_host_0", "test_HIDDEN") + self.assertIsNotNone(svc) + + def test_broken_configuration(self): + """ + Configuration is not correct because of a wrong relative path in the main config file + :return: None + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_broken_1.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + def test_bad_contact(self): + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_bad_contact_call.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + # The service got a unknow contact. It should raise an error + svc = self.arbiter.conf.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0_badcon") + print "Contacts:", svc.contacts + self.assertFalse(svc.is_correct()) + self.assert_any_cfg_log_match( + "Configuration in service::test_ok_0_badcon is incorrect; from: "\ + "cfg/config/../default/daemons/reactionner-master.cfg:42" + ) + self.assert_any_cfg_log_match( + "the contact 'IDONOTEXIST' defined for 'test_ok_0_badcon' is unknown" + ) + + def test_bad_notification_period(self): + """ + Config is not correct because of an unknown notification_period + :return: + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_bad_notification_period.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + self.assert_any_cfg_log_match( + "Configuration in service::test_ok_0_badperiod is incorrect; from: "\ + "cfg/config/../default/daemons/reactionner-master.cfg:42" + ) + self.assert_any_cfg_log_match( + "The notification_period of the service 'test_ok_0_badperiod' "\ + "named 'IDONOTEXIST' is unknown!" + ) + + def test_bad_realm_conf(self): + """ + Config is not correct because of an unknown notification_period + :return: + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_bad_realm_conf.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + self.assert_any_cfg_log_match( + "Configuration in host::test_host_realm3 is incorrect; from: " + "cfg/config/../default/daemons/reactionner-master.cfg:90" + ) + self.assert_any_cfg_log_match( + "the host test_host_realm3 got an invalid realm \(Realm3\)!" + ) + self.assert_any_cfg_log_match( + "Configuration in realm::Realm1 is incorrect; from: cfg/config/../default/daemons/reactionner-master.cfg:47" + ) + self.assert_any_cfg_log_match( + "\[realm::Realm1\] as realm, got unknown member 'UNKNOWNREALM'" + ) + self.assert_any_cfg_log_match( + "Error : More than one realm are set to the default realm" + ) + self.assert_any_cfg_log_match( + "Error: the realm configuration of yours hosts is not good because there is more " + "than one realm in one pack \(host relations\):" + ) + self.assert_any_cfg_log_match( + "the host test_host_realm2 is in the realm " + ) + self.assert_any_cfg_log_match( + "the host test_host_realm1 is in the realm " + ) + self.assert_any_cfg_log_match( + "the host test_host_realm3 is in the realm Realm3" + ) + # self.assert_any_cfg_log_match( + # "The realm Realm2 has hosts but no scheduler!" + # ) + self.assert_any_cfg_log_match( + "There are 6 hosts defined, and 3 hosts dispatched in the realms. " + "Some hosts have been ignored" + ) + + def test_business_rules_bad_realm_conf(self): + """ + Config is not correct because of bad configuration in BR realms + :return: + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_business_rules_bad_realm_conf.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + self.assert_any_cfg_log_match( + "Error: Business_rule \'test_host_realm1/Test bad services BP rules\' " + "got hosts from another realm: Realm2" + ) + self.assert_any_cfg_log_match( + "Business_rule \'test_host_realm1/Test bad services BP rules complex'\ " + "got hosts from another realm: Realm2" + ) + self.assert_any_cfg_log_match( + "Business_rule \'test_host_realm1/Test bad services BP rules complex\' " + "got hosts from another realm: Realm2" + ) + self.assert_any_cfg_log_match( + "Business_rule \'test_host_realm1/Test bad host BP rules\' " + "got hosts from another realm: Realm2" + ) + self.assert_any_cfg_log_match( + "Error: the realm configuration of yours hosts is not good because there is more " + "than one realm in one pack \(host relations\):" + ) + self.assert_any_cfg_log_match( + "the host test_host_realm2 is in the realm " + ) + self.assert_any_cfg_log_match( + "the host test_host_realm1 is in the realm " + ) + self.assert_any_cfg_log_match( + "There are 4 hosts defined, and 2 hosts dispatched in the realms. " + "Some hosts have been ignored" + ) + + def test_bad_satellite_realm_conf(self): + """ + Config is not correct because of an unknown notification_period + :return: + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_bad_sat_realm_conf.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + self.assert_any_cfg_log_match( + "Configuration in broker::Broker-test is incorrect; from: " + "cfg/config/../default/daemons/reactionner-master.cfg:42" + ) + self.assert_any_cfg_log_match( + "The broker Broker-test got a unknown realm 'NoGood'" + ) + + def test_bad_service_interval(self): + """ + Config is not correct because of a bad service interval configuration + :return: + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/config/alignak_bad_service_interval.cfg') + self.assertFalse(self.conf_is_correct) + self.show_configuration_logs() + + self.assert_any_cfg_log_match( + "Configuration in service::fake svc1 is incorrect; from: " + "cfg/config/../default/daemons/reactionner-master.cfg:50" + ) + self.assert_any_cfg_log_match( + "Error while pythonizing parameter \'check_interval\': " + "invalid literal for float\(\): 1,555" + ) + + def test_config_hosts(self): + """ + Test hosts initial states + :return: None + """ + self.print_header() + self.setup_with_file('cfg/config/host_config_all.cfg') + self.assertTrue(self.conf_is_correct) + + cg = self.schedulers[0].sched.hosts.find_by_name('test_host_0') + self.assertEqual('DOWN', cg.state) + + cg = self.schedulers[0].sched.hosts.find_by_name('test_host_1') + self.assertEqual('UNREACHABLE', cg.state) + + cg = self.schedulers[0].sched.hosts.find_by_name('test_host_2') + self.assertEqual('UP', cg.state) + + cg = self.schedulers[0].sched.hosts.find_by_name('test_host_3') + self.assertEqual('UP', cg.state) + + def test_config_hosts_names(self): + """ + Test hosts allowed hosts names: + - Check that it is allowed to have a host with the "__ANTI-VIRG__" + substring in its hostname + - Check that the semicolon is a comment delimiter + - Check that it is possible to have a host with a semicolon in its hostname: + The consequences of this aren't tested. We try just to send a command but + other programs which send commands probably don't escape the semicolon. + + :return: None + """ + self.print_header() + self.setup_with_file('cfg/config/alignak_antivirg.cfg') + self.assertTrue(self.conf_is_correct, "Configuration is not valid") + + # try to get the host + # if it is not possible to get the host, it is probably because + # "__ANTI-VIRG__" has been replaced by ";" + hst = self.arbiter.conf.hosts.find_by_name('test__ANTI-VIRG___0') + self.assertIsNotNone(hst, "host 'test__ANTI-VIRG___0' not found") + self.assertTrue(hst.is_correct(), "config of host '%s' is not correct" % hst.get_name()) + + # try to get the host + hst = self.arbiter.conf.hosts.find_by_name('test_host_1') + self.assertIsNotNone(hst, "host 'test_host_1' not found") + self.assertTrue(hst.is_correct(), "config of host '%s' is not true" % (hst.get_name())) + + # try to get the host + hst = self.arbiter.conf.hosts.find_by_name('test_host_2;with_semicolon') + self.assertIsNotNone(hst, "host 'test_host_2;with_semicolon' not found") + self.assertTrue(hst.is_correct(), "config of host '%s' is not true" % hst.get_name()) + + # We can send a command by escaping the semicolon. + command = '[%lu] PROCESS_HOST_CHECK_RESULT;test_host_2\;with_semicolon;2;down' % ( + time.time()) + self.schedulers[0].sched.run_external_command(command) + + # can need 2 run for get the consum (I don't know why) + self.scheduler_loop(1, []) + self.scheduler_loop(1, []) + + def test_config_services(self): + """ + Test services initial states + :return: None + """ + + self.print_header() + self.setup_with_file('cfg/config/service_config_all.cfg') + + cg = self.schedulers[0].sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_0') + self.assertEqual('WARNING', cg.state) + + cg = self.schedulers[0].sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_1') + self.assertEqual('UNKNOWN', cg.state) + + cg = self.schedulers[0].sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_2') + self.assertEqual('CRITICAL', cg.state) + + cg = self.schedulers[0].sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_3') + self.assertEqual('OK', cg.state) + + cg = self.schedulers[0].sched.services.find_srv_by_name_and_hostname('test_host_0', 'test_service_4') + self.assertEqual('OK', cg.state) + diff --git a/test/test_contactgroup.py b/test/test_contactgroup.py new file mode 100755 index 000000000..312765aad --- /dev/null +++ b/test/test_contactgroup.py @@ -0,0 +1,312 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors +# +# This file is part of Alignak. +# +# Alignak is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Alignak is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Alignak. If not, see . +# +# + +""" +This file test all cases of eventhandler +""" + +import time + +from alignak.objects import Contact +from alignak.objects import Contactgroup +from alignak_test import AlignakTest + + +class TestContactGroup(AlignakTest): + """ + This class tests the contactgroups + """ + + def test_contactgroup(self): + """ + Default configuration has no loading problems ... as of it contactgroups are parsed + correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + def test_look_for_alias(self): + """ + Default configuration has no loading problems ... as of it contactgroups are parsed correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/contactgroup/alignak_groups_with_no_alias.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a contactgroup named NOALIAS + cg = self.schedulers[0].sched.contactgroups.find_by_name("NOALIAS") + self.assertIsInstance(cg, Contactgroup) + self.assertEqual(cg.get_name(), "NOALIAS") + self.assertEqual(cg.alias, "NOALIAS") + + def test_contactgroup_members(self): + """ + Test if members are linked from group + + :return: None + """ + self.print_header() + self.setup_with_file('cfg/contactgroup/alignak_contactgroup_members.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a contactgroup named allhosts_and_groups + cg = self.schedulers[0].sched.contactgroups.find_by_name("allcontacts_and_groups") + self.assertIsInstance(cg, Contactgroup) + self.assertEqual(cg.get_name(), "allcontacts_and_groups") + + self.assertEqual( + len(self.schedulers[0].sched.contactgroups.get_members_by_name("allcontacts_and_groups")), + 2 + ) + + self.assertEqual(len(cg.get_contacts()), 2) + + self.assertEqual(len(cg.get_contactgroup_members()), 1) + + def test_members_contactgroup(self): + """ + Test if group is linked from the member + :return: None + """ + self.print_header() + self.setup_with_file('cfg/contactgroup/alignak_contactgroup_members.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a contactgroup named allhosts_and_groups + cg = self.schedulers[0].sched.contactgroups.find_by_name("allcontacts_and_groups") + self.assertIsInstance(cg, Contactgroup) + self.assertEqual(cg.get_name(), "allcontacts_and_groups") + + self.assertEqual( + len(self.schedulers[0].sched.contactgroups.get_members_by_name( + "allcontacts_and_groups" + )), + 2 + ) + + self.assertEqual(len(cg.get_contacts()), 2) + print("List contactgroup contacts:") + for contact_id in cg.members: + contact = self.schedulers[0].sched.contacts[contact_id] + print("Contact: %s" % contact) + self.assertIsInstance(contact, Contact) + + if contact.get_name() == 'test_ok_0': + self.assertEqual(len(contact.get_contactgroups()), 4) + for group_id in contact.contactgroups: + group = self.schedulers[0].sched.contactgroups[group_id] + print("Group: %s" % group) + self.assertIn(group.get_name(), [ + 'ok', 'contactgroup_01', 'contactgroup_02', 'allcontacts_and_groups' + ]) + + self.assertEqual(len(cg.get_contactgroup_members()), 1) + print("List contactgroup groups:") + for group in cg.get_contactgroup_members(): + print("Group: %s" % group) + self.assertIn(group, [ + 'test_contact' + ]) + + def test_contactgroup_with_no_contact(self): + """ + Allow contactgroups with no hosts + :return: None + """ + self.print_header() + self.setup_with_file('cfg/contactgroup/alignak_contactgroup_no_contact.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + self.assertEqual( + len(self.schedulers[0].sched.contactgroups), + 3 + ) + + for group in self.schedulers[0].sched.contactgroups: + # contactgroups property returns an object list ... unlike the hostgroups property + # of an host group ... + # group = self.schedulers[0].sched.contactgroups[group_id] + print("Group: %s" % group) + + # Found a contactgroup named void + cg = self.schedulers[0].sched.contactgroups.find_by_name("void") + print("cg: %s" % cg) + self.assertIsInstance(cg, Contactgroup) + self.assertEqual(cg.get_name(), "void") + + self.assertEqual( + len(self.schedulers[0].sched.contactgroups.get_members_by_name("void")), + 0 + ) + + print("Contacts: %s" % cg.get_contactgroup_members()) + self.assertEqual(len(cg.get_contactgroup_members()), 0) + + print("Contacts: %s" % cg.get_contacts()) + self.assertEqual(len(cg.get_contacts()), 0) + + def test_contactgroup_with_space(self): + """ + Test that contactgroups can have a name with spaces + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + self.nb_contactgroups = len(self.schedulers[0].sched.contactgroups) + + self.setup_with_file('cfg/contactgroup/alignak_contactgroup_with_space.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + # Two more groups than the default configuration + self.assertEqual( + len(self.schedulers[0].sched.contactgroups), self.nb_contactgroups + 1 + ) + + self.assertEqual( + self.schedulers[0].sched.contactgroups.find_by_name("test_With Spaces").get_name(), + "test_With Spaces" + ) + self.assertIsNot( + self.schedulers[0].sched.contactgroups.get_members_by_name( + "test_With Spaces" + ), + [] + ) + + def _dump_host(self, h): + print "Dumping host", h.get_name() + print h.contact_groups + for c in h.contacts: + print "->", self.schedulers[0].sched.contacts[c].get_name() + + def _dump_svc(self, s): + print "Dumping Service", s.get_name() + print " contact_groups : %s " % s.contact_groups + for c in s.contacts: + print "->", self.schedulers[0].sched.contacts[c].get_name() + + def test_contactgroups_plus_inheritance(self): + """ + Test that contactgroups correclty manage inheritance + :return: None + """ + self.print_header() + self.setup_with_file('cfg/contactgroup/alignak_contactgroups_plus_inheritance.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + host0 = self.schedulers[0].sched.hosts.find_by_name("test_host_0") + # HOST 1 should have 2 group of contacts + # WARNING, it's a string, not the real objects! + self._dump_host(host0) + + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in host0.contacts] + ) + self.assertIn( + "test_contact_2", + [self.schedulers[0].sched.contacts[c].get_name() for c in host0.contacts] + ) + + host2 = self.schedulers[0].sched.hosts.find_by_name("test_host_2") + self._dump_host(host2) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in host2.contacts] + ) + + host3 = self.schedulers[0].sched.hosts.find_by_name("test_host_3") + self._dump_host(host3) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in host3.contacts] + ) + self.assertIn( + "test_contact_2", + [self.schedulers[0].sched.contacts[c].get_name() for c in host3.contacts] + ) + + host4 = self.schedulers[0].sched.hosts.find_by_name("test_host_4") + self._dump_host(host4) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in host4.contacts] + ) + + host5 = self.schedulers[0].sched.hosts.find_by_name("test_host_5") + self._dump_host(host5) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in host5.contacts] + ) + self.assertIn( + "test_contact_2", + [self.schedulers[0].sched.contacts[c].get_name() for c in host5.contacts] + ) + + host6 = self.schedulers[0].sched.hosts.find_by_name("test_host_6") + self._dump_host(host6) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in host6.contacts] + ) + self.assertIn( + "test_contact_2", + [self.schedulers[0].sched.contacts[c].get_name() for c in host6.contacts] + ) + + # Now Let's check service inheritance + + svc1 = self.schedulers[0].sched.services.find_srv_by_name_and_hostname( + "test_host_0", "svc_tmplA" + ) + self._dump_svc(svc1) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in svc1.contacts] + ) + + svc2 = self.schedulers[0].sched.services.find_srv_by_name_and_hostname( + "test_host_0", "svc_tmplB" + ) + self._dump_svc(svc2) + self.assertIn( + "test_contact_2", + [self.schedulers[0].sched.contacts[c].get_name() for c in svc2.contacts] + ) + + svc3 = self.schedulers[0].sched.services.find_srv_by_name_and_hostname( + "test_host_0", "svc_tmplA_tmplB" + ) + self.assertIn( + "test_contact_1", + [self.schedulers[0].sched.contacts[c].get_name() for c in svc3.contacts] + ) + self.assertIn( + "test_contact_2", + [self.schedulers[0].sched.contacts[c].get_name() for c in svc3.contacts] + ) + self._dump_svc(svc3) diff --git a/test/test_dependencies.py b/test/test_dependencies.py index 35f85c87a..f9871d557 100644 --- a/test/test_dependencies.py +++ b/test/test_dependencies.py @@ -38,6 +38,8 @@ def test_conf_dependencies(self): :return: None """ self.setup_with_file('cfg/cfg_dependencies.cfg') + self.assertEqual(len(self.configuration_errors), 0) + self.assertEqual(len(self.configuration_warnings), 0) # test_host_00 -> test_router_00 test_host_00 = self.schedulers[0].sched.hosts.find_by_name("test_host_00") @@ -102,6 +104,8 @@ def test_conf_notright1(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad1.cfg') + self.assertEqual(len(self.configuration_errors), 4) + self.assertEqual(len(self.configuration_warnings), 0) def test_conf_notright2(self): """ @@ -112,6 +116,8 @@ def test_conf_notright2(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad2.cfg') + self.assertEqual(len(self.configuration_errors), 4) + self.assertEqual(len(self.configuration_warnings), 0) def test_conf_notright3(self): """ @@ -122,6 +128,8 @@ def test_conf_notright3(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad3.cfg') + self.assertEqual(len(self.configuration_errors), 1) + self.assertEqual(len(self.configuration_warnings), 8) def test_conf_notright4(self): """ @@ -132,6 +140,8 @@ def test_conf_notright4(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad4.cfg') + self.assertEqual(len(self.configuration_errors), 1) + self.assertEqual(len(self.configuration_warnings), 0) def test_conf_notright5(self): """ @@ -142,6 +152,8 @@ def test_conf_notright5(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad5.cfg') + self.assertEqual(len(self.configuration_errors), 1) + self.assertEqual(len(self.configuration_warnings), 0) def test_conf_notright6(self): """ @@ -152,6 +164,8 @@ def test_conf_notright6(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad6.cfg') + self.assertEqual(len(self.configuration_errors), 1) + self.assertEqual(len(self.configuration_warnings), 0) def test_conf_notright7(self): """ @@ -162,6 +176,9 @@ def test_conf_notright7(self): """ with self.assertRaises(SystemExit): self.setup_with_file('cfg/cfg_dependencies_bad7.cfg') + # Service test_ok_0_notknown not found for 2 hosts. + self.assertEqual(len(self.configuration_errors), 2) + self.assertEqual(len(self.configuration_warnings), 0) def test_service_host_case_1(self): """ diff --git a/test/test_hostdependency.py b/test/test_hostdependency.py new file mode 100755 index 000000000..13cd13459 --- /dev/null +++ b/test/test_hostdependency.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors +# +# This file is part of Alignak. +# +# Alignak is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Alignak is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Alignak. If not, see . +# +# + +""" +This file test all cases of eventhandler +""" + +import time + +from alignak.objects import Host +from alignak.objects import Hostgroup +from alignak_test import AlignakTest + + +class TestHostDependency(AlignakTest): + """ + This class tests the hostdependency + """ + + def test_hostdependencies(self): + """ + Default configuration has no loading problems ... as of it hosts + dependencies are parsed correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + def test_hostdep_simple(self): + """ + test_host_1 dependes upon test_host_0 + test_router_0 is parent of test_host_1 + all the hosts in flap group dependes upon test_host_0 + :return: + """ + self.print_header() + self.setup_with_file('cfg/hostdependency/alignak_hostdep_with_no_depname.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + print("Get the hosts and services") + test_router_0 = self.schedulers[0].sched.hosts.find_by_name("test_router_0") + self.assertIsNotNone(test_router_0) + print("test_router_0 is: %s" % test_router_0.uuid) + print("test_router_0 'parents': %s" % test_router_0.act_depend_of) + print("test_router_0 'children': %s" % test_router_0.act_depend_of_me) + + test_host_0 = self.schedulers[0].sched.hosts.find_by_name("test_host_0") + self.assertIsNotNone(test_host_0) + print("test_host_0 is: %s" % test_host_0.uuid) + print("test_host_0 'parents': %s" % test_host_0.act_depend_of) + print("test_host_0 'children': %s" % test_host_0.act_depend_of_me) + + svc_0 = self.schedulers[0].sched.services.find_srv_by_name_and_hostname( + "test_host_0", "test_ok_0" + ) + + test_host_1 = self.schedulers[0].sched.hosts.find_by_name("test_host_1") + self.assertIsNotNone(test_host_1) + print("test_host_1 is: %s" % test_host_1.uuid) + print("test_host_1 'parents': %s" % test_host_1.act_depend_of) + print("test_host_1 'children': %s" % test_host_1.act_depend_of_me) + + # test_router_0 is a dependency of test_host_0 and test_host_1 + self.assertEqual(len(test_router_0.act_depend_of_me), 2) + for link in test_router_0.act_depend_of_me: + item_id = link[0] + self.assertIn(item_id, [test_host_0.uuid, test_host_1.uuid]) + + # test_host_0 depends upon test_router_0 + self.assertEqual(len(test_host_0.act_depend_of), 1) + for link in test_host_0.act_depend_of: + item_id = link[0] + self.assertIn(item_id, [test_router_0.uuid]) + + # test_host_0 is a dependency of test_host_1 and of a service + self.assertEqual(len(test_host_0.act_depend_of_me), 2) + for link in test_host_0.act_depend_of_me: + item_id = link[0] + self.assertIn(item_id, [test_host_1.uuid, svc_0.uuid]) + + # test_host_1 depends upon test_host_0 and test_router_0 + self.assertEqual(len(test_host_1.act_depend_of), 2) + for link in test_host_1.act_depend_of: + item_id = link[0] + self.assertIn(item_id, [test_host_0.uuid, test_router_0.uuid]) + + def test_hostdep_complex(self): + """ + test_host_1 dependes upon test_host_0 + test_router_0 is parent of test_host_1 + all the hosts in flap group dependes upon test_host_0 + :return: + """ + self.print_header() + self.setup_with_file('cfg/hostdependency/alignak_hostdep_with_multiple_names.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + for n in ['svn1', 'svn2', 'svn3', 'svn4', 'nas1', 'nas2', 'nas3']: + host = globals()[n] = self.schedulers[0].sched.hosts.find_by_name(n) + self.assertIsNotNone(host) + + # We check that nas3 is a father of svn4, the simple case + self.assertIn(nas3.uuid, [e[0] for e in svn4.act_depend_of]) + + # Now the more complex one + for son in [svn1, svn2, svn3]: + for father in [nas1, nas2]: + print 'Checking if', father.get_name(), 'is the father of', son.get_name() + print son.act_depend_of + for e in son.act_depend_of: + print self.schedulers[0].sched.find_item_by_id(e[0]).get_name() + self.assertIn(father.uuid, [e[0] for e in son.act_depend_of]) + diff --git a/test/test_hostgroup.py b/test/test_hostgroup.py new file mode 100755 index 000000000..19c91a743 --- /dev/null +++ b/test/test_hostgroup.py @@ -0,0 +1,226 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors +# +# This file is part of Alignak. +# +# Alignak is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Alignak is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Alignak. If not, see . +# +# + +""" +This file contains the test for the hostgroups objects +""" + +import time + +from alignak.objects import Host +from alignak.objects import Hostgroup +from alignak_test import AlignakTest + + +class TestHostGroup(AlignakTest): + """ + This class tests the hostgroups + """ + + def test_hostgroup(self): + """ + Default configuration has no loading problems ... as of it hostgroups are parsed correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + def test_bad_hostgroup(self): + """ + Default configuration has no loading problems ... as of it hostgroups are parsed correctly + :return: None + """ + self.print_header() + with self.assertRaises(SystemExit): + self.setup_with_file('cfg/hostgroup/alignak_bad_hg_conf.cfg') + + # Configuration is not ok + self.assertEqual(self.conf_is_correct, False) + # Two error messages, bad hostgroup member + self.assertEqual(len(self.configuration_errors), 2) + # Two warning messages + self.assertEqual(len(self.configuration_warnings), 2) + # Error is an unknown member in a group (\ escape the [ and ' ...) + self.assert_any_cfg_log_match( + "\[hostgroup::allhosts_bad\] as hostgroup, got unknown member \'BAD_HOST\'" + ) + self.assert_any_cfg_log_match( + "Configuration in hostgroup::allhosts_bad is incorrect; from: "\ + "cfg/hostgroup/../default/daemons/reactionner-master.cfg:43" + ) + self.show_configuration_logs() + + def test_look_for_alias(self): + """ + Default configuration has no loading problems ... as of it hostgroups are parsed correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/hostgroup/alignak_groups_with_no_alias.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a hostgroup named NOALIAS + hg = self.schedulers[0].sched.hostgroups.find_by_name("NOALIAS") + self.assertIsInstance(hg, Hostgroup) + self.assertEqual(hg.get_name(), "NOALIAS") + self.assertEqual(hg.alias, "NOALIAS") + + def test_hostgroup_members(self): + """ + Test if members are linked from group + + :return: None + """ + self.print_header() + self.setup_with_file('cfg/hostgroup/alignak_hostgroup_members.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a hostgroup named allhosts_and_groups + hg = self.schedulers[0].sched.hostgroups.find_by_name("allhosts_and_groups") + self.assertIsInstance(hg, Hostgroup) + self.assertEqual(hg.get_name(), "allhosts_and_groups") + + self.assertEqual( + len(self.schedulers[0].sched.hostgroups.get_members_by_name("allhosts_and_groups")), + 2 + ) + + self.assertEqual(len(hg.hostgroup_members), 4) + self.assertEqual(len(hg.get_hostgroup_members()), 4) + + self.assertEqual(len(hg.get_hosts()), 2) + + def test_members_hostgroup(self): + """ + Test if group is linked from the member + :return: None + """ + self.print_header() + self.setup_with_file('cfg/hostgroup/alignak_hostgroup_members.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a hostgroup named allhosts_and_groups + hg = self.schedulers[0].sched.hostgroups.find_by_name("allhosts_and_groups") + self.assertIsInstance(hg, Hostgroup) + self.assertEqual(hg.get_name(), "allhosts_and_groups") + + self.assertEqual( + len(self.schedulers[0].sched.hostgroups.get_members_by_name("allhosts_and_groups")), + 2 + ) + + self.assertEqual(len(hg.get_hosts()), 2) + print("List hostgroup hosts:") + for host_id in hg.members: + host = self.schedulers[0].sched.hosts[host_id] + print("Host: %s" % host) + self.assertIsInstance(host, Host) + + if host.get_name() == 'test_router_0': + self.assertEqual(len(host.get_hostgroups()), 3) + for group_id in host.hostgroups: + group = self.schedulers[0].sched.hostgroups[group_id] + print("Group: %s" % group) + self.assertIn(group.get_name(), [ + 'router', 'allhosts', 'allhosts_and_groups' + ]) + + if host.get_name() == 'test_host_0': + self.assertEqual(len(host.get_hostgroups()), 4) + for group_id in host.hostgroups: + group = self.schedulers[0].sched.hostgroups[group_id] + print("Group: %s" % group) + self.assertIn(group.get_name(), [ + 'allhosts', 'allhosts_and_groups', 'up', 'hostgroup_01' + ]) + + self.assertEqual(len(hg.get_hostgroup_members()), 4) + print("List hostgroup groups:") + for group in hg.get_hostgroup_members(): + print("Group: %s" % group) + self.assertIn(group, [ + 'hostgroup_01', 'hostgroup_02', 'hostgroup_03', 'hostgroup_04' + ]) + + def test_hostgroup_with_no_host(self): + """ + Allow hostgroups with no hosts + :return: None + """ + self.print_header() + self.setup_with_file('cfg/hostgroup/alignak_hostgroup_no_host.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + # Found a hostgroup named void + hg = self.schedulers[0].sched.hostgroups.find_by_name("void") + self.assertIsInstance(hg, Hostgroup) + self.assertEqual(hg.get_name(), "void") + + self.assertEqual( + len(self.schedulers[0].sched.hostgroups.get_members_by_name("void")), + 0 + ) + + self.assertEqual(len(hg.get_hostgroup_members()), 0) + + self.assertEqual(len(hg.get_hosts()), 0) + + def test_hostgroup_with_space(self): + """ + Test that hostgroups can have a name with spaces + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + self.nb_hostgroups = len(self.schedulers[0].sched.hostgroups) + + self.setup_with_file('cfg/hostgroup/alignak_hostgroup_with_space.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + # Two more groups than the default configuration + self.assertEqual( + len(self.schedulers[0].sched.hostgroups), self.nb_hostgroups + 2 + ) + + self.assertEqual( + self.schedulers[0].sched.hostgroups.find_by_name("test_With Spaces").get_name(), + "test_With Spaces" + ) + self.assertIsNot( + self.schedulers[0].sched.hostgroups.get_members_by_name( + "test_With Spaces" + ), + [] + ) + + self.assertEqual( + self.schedulers[0].sched.hostgroups.find_by_name("test_With another Spaces").get_name(), + "test_With another Spaces" + ) + self.assertIsNot( + self.schedulers[0].sched.hostgroups.get_members_by_name( + "test_With another Spaces" + ), + [] + ) diff --git a/test/test_servicegroup.py b/test/test_servicegroup.py new file mode 100755 index 000000000..46ba484ae --- /dev/null +++ b/test/test_servicegroup.py @@ -0,0 +1,224 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors +# +# This file is part of Alignak. +# +# Alignak is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Alignak is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Alignak. If not, see . +# +# + +""" +This file test all cases of eventhandler +""" + +import time + +from alignak.objects import Service +from alignak.objects import Servicegroup +from alignak_test import AlignakTest + + +class TestServiceGroup(AlignakTest): + """ + This class tests the servicegroups + """ + + def test_servicegroup(self): + """ + Default configuration has no loading problems ... as of it servicegroups are parsed + correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + def test_look_for_alias(self): + """ + Default configuration has no loading problems ... as of it servicegroups are parsed correctly + :return: None + """ + self.print_header() + self.setup_with_file('cfg/servicegroup/alignak_groups_with_no_alias.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a servicegroup named NOALIAS + sg = self.schedulers[0].sched.servicegroups.find_by_name("NOALIAS") + self.assertIsInstance(sg, Servicegroup) + self.assertEqual(sg.get_name(), "NOALIAS") + self.assertEqual(sg.alias, "NOALIAS") + + def test_servicegroup_members(self): + """ + Test if members are linked from group + + :return: None + """ + self.print_header() + self.setup_with_file('cfg/servicegroup/alignak_servicegroup_members.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a servicegroup named allhosts_and_groups + sg = self.schedulers[0].sched.servicegroups.find_by_name("allservices_and_groups") + self.assertIsInstance(sg, Servicegroup) + self.assertEqual(sg.get_name(), "allservices_and_groups") + + self.assertEqual( + len(self.schedulers[0].sched.servicegroups.get_members_by_name("allservices_and_groups")), + 1 + ) + + self.assertEqual(len(sg.get_services()), 1) + + self.assertEqual(len(sg.get_servicegroup_members()), 4) + + def test_members_servicegroup(self): + """ + Test if group is linked from the member + :return: None + """ + self.print_header() + self.setup_with_file('cfg/servicegroup/alignak_servicegroup_members.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + #  Found a servicegroup named allhosts_and_groups + sg = self.schedulers[0].sched.servicegroups.find_by_name("allservices_and_groups") + self.assertIsInstance(sg, Servicegroup) + self.assertEqual(sg.get_name(), "allservices_and_groups") + + self.assertEqual( + len(self.schedulers[0].sched.servicegroups.get_members_by_name( + "allservices_and_groups" + )), + 1 + ) + + self.assertEqual(len(sg.get_services()), 1) + print("List servicegroup services:") + for service_id in sg.members: + service = self.schedulers[0].sched.services[service_id] + print("Service: %s" % service) + self.assertIsInstance(service, Service) + + if service.get_name() == 'test_ok_0': + self.assertEqual(len(service.get_servicegroups()), 4) + for group_id in service.servicegroups: + group = self.schedulers[0].sched.servicegroups[group_id] + print("Group: %s" % group) + self.assertIn(group.get_name(), [ + 'ok', 'servicegroup_01', 'servicegroup_02', 'allservices_and_groups' + ]) + + self.assertEqual(len(sg.get_servicegroup_members()), 4) + print("List servicegroup groups:") + for group in sg.get_servicegroup_members(): + print("Group: %s" % group) + self.assertIn(group, [ + 'servicegroup_01', 'servicegroup_02', 'servicegroup_03', 'servicegroup_04' + ]) + + def test_servicegroup_with_no_service(self): + """ + Allow servicegroups with no hosts + :return: None + """ + self.print_header() + self.setup_with_file('cfg/servicegroup/alignak_servicegroup_no_service.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + # Found a servicegroup named void + sg = self.schedulers[0].sched.servicegroups.find_by_name("void") + self.assertIsInstance(sg, Servicegroup) + self.assertEqual(sg.get_name(), "void") + + self.assertEqual( + len(self.schedulers[0].sched.servicegroups.get_members_by_name("void")), + 0 + ) + + print("Services: %s" % sg.get_servicegroup_members()) + self.assertEqual(len(sg.get_servicegroup_members()), 0) + + print("Services: %s" % sg.get_services()) + self.assertEqual(len(sg.get_services()), 0) + + def test_servicegroup_with_space(self): + """ + Test that servicegroups can have a name with spaces + :return: None + """ + self.print_header() + self.setup_with_file('cfg/cfg_default.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + self.nb_servicegroups = len(self.schedulers[0].sched.servicegroups) + + self.setup_with_file('cfg/servicegroup/alignak_servicegroup_with_space.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + + # Two more groups than the default configuration + self.assertEqual( + len(self.schedulers[0].sched.servicegroups), self.nb_servicegroups + 2 + ) + + self.assertEqual( + self.schedulers[0].sched.servicegroups.find_by_name("test_With Spaces").get_name(), + "test_With Spaces" + ) + self.assertIsNot( + self.schedulers[0].sched.servicegroups.get_members_by_name( + "test_With Spaces" + ), + [] + ) + + self.assertEqual( + self.schedulers[0].sched.servicegroups.find_by_name("test_With another Spaces").get_name(), + "test_With another Spaces" + ) + self.assertIsNot( + self.schedulers[0].sched.servicegroups.get_members_by_name( + "test_With another Spaces" + ), + [] + ) + + def test_servicegroups_generated(self): + """ + Test that servicegroups can have a name with spaces + :return: None + """ + self.print_header() + self.setup_with_file('cfg/servicegroup/alignak_servicegroups_generated.cfg') + self.assertTrue(self.schedulers[0].conf.conf_is_correct) + self.nb_servicegroups = len(self.schedulers[0].sched.servicegroups) + + sgs = [] + for name in ["MYSVCGP", "MYSVCGP2", "MYSVCGP3", "MYSVCGP4"]: + sg = self.schedulers[0].sched.servicegroups.find_by_name(name) + self.assertIsNot(sg, None) + sgs.append(sg) + + svc3 = self.schedulers[0].sched.services.find_srv_by_name_and_hostname("fake host", "fake svc3") + svc4 = self.schedulers[0].sched.services.find_srv_by_name_and_hostname("fake host", "fake svc4") + self.assertIn(svc3.uuid, sgs[0].members) + self.assertIn(svc3.uuid, sgs[1].members) + self.assertIn(svc4.uuid, sgs[2].members) + self.assertIn(svc4.uuid, sgs[3].members) + + self.assertIn(sgs[0].uuid, svc3.servicegroups) + self.assertIn(sgs[1].uuid, svc3.servicegroups) + self.assertIn(sgs[2].uuid, svc4.servicegroups) + self.assertIn(sgs[3].uuid, svc4.servicegroups)