From 227c5161f27f82b85a0c847bc810e2ee69ebe59b Mon Sep 17 00:00:00 2001 From: Soufiane Echkem Date: Thu, 24 Oct 2024 16:13:08 +0100 Subject: [PATCH] feat(engine): Add inheritance test HostGroup --- tests/engine/contactgroup_inheritance.robot | 318 ++++++++++++++++++++ tests/resources/Engine.py | 29 ++ 2 files changed, 347 insertions(+) create mode 100644 tests/engine/contactgroup_inheritance.robot diff --git a/tests/engine/contactgroup_inheritance.robot b/tests/engine/contactgroup_inheritance.robot new file mode 100644 index 0000000000..9ce0e38ca9 --- /dev/null +++ b/tests/engine/contactgroup_inheritance.robot @@ -0,0 +1,318 @@ +*** Settings *** +Documentation Centreon Broker and Engine Verify contactgroup inheritance. + +Resource ../resources/import.resource + +Suite Setup Ctn Clean Before Suite +Suite Teardown Ctn Clean After Suite +Test Setup Ctn Stop Processes +Test Teardown Ctn Save Logs If Failed + + +*** Test Cases *** +EBSN5 + [Documentation] Verify contactgroup inheritance : contactgroup(empty) inherit from template (full) , on Start Engine + [Tags] engine contactgroup MON-151622 + Ctn Config Engine ${1} ${5} ${5} + Ctn Config Broker rrd + Ctn Config Broker central + Ctn Config Broker module + Ctn Config BBDO3 1 + Ctn Clear Retention + + # Create files : + Ctn Create Template File ${0} contactgroup alias ["contactgroup_template_1_alias"] + + # Delete unnecessary fields in templates: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 active_checks_enabled contactgroupTemplates.cfg + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 passive_checks_enabled contactgroupTemplates.cfg + + # Add Command : + Ctn Engine Config Add Command 0 command_notif /usr/bin/true + Ctn Engine Config Set Value In Contacts 0 John_Doe host_notification_commands command_notif + Ctn Engine Config Set Value In Contacts 0 John_Doe service_notification_commands command_notif + + # Add necessarily files : + Ctn Config Engine Add Cfg File ${0} contacts.cfg + Ctn Config Engine Add Cfg File ${0} contactgroups.cfg + Ctn Config Engine Add Cfg File ${0} contactgroupTemplates.cfg + + # Create contact groups + Ctn Add Contact Group ${0} ${1} ["John_Doe"] + Ctn Add Contact Group ${0} ${2} ["U1"] + Ctn Add Contact Group ${0} ${3} ["U2"] + Ctn Add Contact Group ${0} ${4} ["U3","U4"] + + # Delete unnecessary fields in contactgroup: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_1 alias contactgroups.cfg + Ctn Engine Config Delete Key In Cfg 0 contactgroup_1 members contactgroups.cfg + + # Set contactgroup_1 to use contactgroup_template_1 + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_1 use contactgroup_template_1 contactgroups.cfg + + # Operation in contactTemplates + ${config_values} Create Dictionary +... contactgroup_members contactgroup_3 +... members U1 + + FOR ${key} ${value} IN &{config_values} + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_template_1 ${key} ${value} contactgroupTemplates.cfg + END + + ${start} Get Current Date + Ctn Clear Retention + Ctn Start Broker + Ctn Start Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + ${output} Ctn Get Contactgroup Info Grpc contactgroup_1 + + Should Be Equal As Strings ${output}[name] contactgroup_1 + Should Be Equal As Strings ${output}[alias] contactgroup_template_1_alias + Should Not Contain ${output}[members] John_Doe + Should Contain ${output}[members] U1 + Should Contain ${output}[members] U2 + + Ctn Stop Engine + Ctn Kindly Stop Broker + +EBSN6 + [Documentation] Verify contactgroup inheritance : contactgroup(full) inherit from template (full) , on Start Engine + [Tags] engine contactgroup MON-151622 + Ctn Config Engine ${1} ${5} ${5} + Ctn Config Broker rrd + Ctn Config Broker central + Ctn Config Broker module + Ctn Config BBDO3 1 + Ctn Clear Retention + + # Create files : + Ctn Create Template File ${0} contactgroup alias ["contactgroup_template_1_alias"] + + # Delete unnecessary fields in templates: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 active_checks_enabled contactgroupTemplates.cfg + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 passive_checks_enabled contactgroupTemplates.cfg + + # Add Command : + Ctn Engine Config Add Command 0 command_notif /usr/bin/true + Ctn Engine Config Set Value In Contacts 0 John_Doe host_notification_commands command_notif + Ctn Engine Config Set Value In Contacts 0 John_Doe service_notification_commands command_notif + + # Add necessarily files : + Ctn Config Engine Add Cfg File ${0} contacts.cfg + Ctn Config Engine Add Cfg File ${0} contactgroups.cfg + Ctn Config Engine Add Cfg File ${0} contactgroupTemplates.cfg + + # Operation in contact group + Ctn Add Contact Group ${0} ${1} ["John_Doe"] + Ctn Add Contact Group ${0} ${2} ["U1"] + Ctn Add Contact Group ${0} ${3} ["U2"] + Ctn Add Contact Group ${0} ${4} ["U3","U4"] + + # Contactgroup_1 to use contactgroup_template_1 + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_1 use contactgroup_template_1 contactgroups.cfg + + # Operation in contactTemplates + ${config_values} Create Dictionary +... contactgroup_members contactgroup_2 + + FOR ${key} ${value} IN &{config_values} + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_1 ${key} ${value} contactgroups.cfg + END + + ${config_values_tmp} Create Dictionary +... contactgroup_members contactgroup_4 +... members U2 + + FOR ${key} ${value} IN &{config_values_tmp} + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_template_1 ${key} ${value} contactgroupTemplates.cfg + END + + ${start} Get Current Date + Ctn Clear Retention + Ctn Start Broker + Ctn Start Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + ${output} Ctn Get Contactgroup Info Grpc contactgroup_1 + + Should Be Equal As Strings ${output}[name] contactgroup_1 + Should Be Equal As Strings ${output}[alias] contactgroup_1 + Should Contain ${output}[members] John_Doe + Should Contain ${output}[members] U1 + Should Not Contain Any ${output}[members] U2 U3 U4 + + Ctn Stop Engine + Ctn Kindly Stop Broker + +EBSN7 + [Documentation] Verify contactgroup inheritance : contactgroup(empty) inherit from template (full) , on Reload Engine + [Tags] engine contactgroup MON-151622 + Ctn Config Engine ${1} ${5} ${5} + Ctn Config Broker rrd + Ctn Config Broker central + Ctn Config Broker module + Ctn Config BBDO3 1 + Ctn Clear Retention + + # Create files : + Ctn Create Template File ${0} contactgroup alias ["contactgroup_template_1_alias"] + + # Delete unnecessary fields in templates: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 active_checks_enabled contactgroupTemplates.cfg + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 passive_checks_enabled contactgroupTemplates.cfg + + # Add Command : + Ctn Engine Config Add Command 0 command_notif /usr/bin/true + Ctn Engine Config Set Value In Contacts 0 John_Doe host_notification_commands command_notif + Ctn Engine Config Set Value In Contacts 0 John_Doe service_notification_commands command_notif + + # Add necessarily files : + Ctn Config Engine Add Cfg File ${0} contacts.cfg + Ctn Config Engine Add Cfg File ${0} contactgroups.cfg + Ctn Config Engine Add Cfg File ${0} contactgroupTemplates.cfg + + # Operation in contact group + Ctn Add Contact Group ${0} ${1} ["John_Doe"] + + ${start} Get Current Date + Ctn Clear Retention + Ctn Start Broker + Ctn Start Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + # Operation in contact group + Ctn Add Contact Group ${0} ${2} ["U1"] + Ctn Add Contact Group ${0} ${3} ["U2"] + Ctn Add Contact Group ${0} ${4} ["U3","U4"] + + # Delete unnecessary fields in contactgroup: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_1 alias contactgroups.cfg + Ctn Engine Config Delete Key In Cfg 0 contactgroup_1 members contactgroups.cfg + + # Contactgroup_1 to use contactgroup_template_1 + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_1 use contactgroup_template_1 contactgroups.cfg + + # Operation in contactTemplates + ${config_values} Create Dictionary +... contactgroup_members contactgroup_3 +... members U1 + + FOR ${key} ${value} IN &{config_values} + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_template_1 ${key} ${value} contactgroupTemplates.cfg + END + + # Reload engine + ${start} Get Current Date + Ctn Reload Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + ${content} Create List Reload configuration finished + ${result} Ctn Find In Log With Timeout + ... ${ENGINE_LOG}/config0/centengine.log + ... ${start} + ... ${content} + ... 60 + ... verbose=False + Should Be True ${result} Engine is Not Ready after 60s!! + + ${output} Ctn Get Contactgroup Info Grpc contactgroup_1 + + Should Be Equal As Strings ${output}[name] contactgroup_1 + Should Be Equal As Strings ${output}[alias] contactgroup_template_1_alias + Should Not Contain ${output}[members] John_Doe + Should Contain ${output}[members] U1 + Should Contain ${output}[members] U2 + + Ctn Stop Engine + Ctn Kindly Stop Broker + +EBSN8 + [Documentation] Verify contactgroup inheritance : contactgroup(full) inherit from template (full) , on Reload Engine + [Tags] engine contactgroup MON-151622 + Ctn Config Engine ${1} ${5} ${5} + Ctn Config Broker rrd + Ctn Config Broker central + Ctn Config Broker module + Ctn Config BBDO3 1 + Ctn Clear Retention + + # Create files : + Ctn Create Template File ${0} contactgroup alias ["contactgroup_template_1_alias"] + + # Delete unnecessary fields in templates: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 active_checks_enabled contactgroupTemplates.cfg + Ctn Engine Config Delete Key In Cfg 0 contactgroup_template_1 passive_checks_enabled contactgroupTemplates.cfg + + # Add Command : + Ctn Engine Config Add Command 0 command_notif /usr/bin/true + Ctn Engine Config Set Value In Contacts 0 John_Doe host_notification_commands command_notif + Ctn Engine Config Set Value In Contacts 0 John_Doe service_notification_commands command_notif + + # Add necessarily files : + Ctn Config Engine Add Cfg File ${0} contacts.cfg + Ctn Config Engine Add Cfg File ${0} contactgroups.cfg + Ctn Config Engine Add Cfg File ${0} contactgroupTemplates.cfg + + # Operation in contact group + Ctn Add Contact Group ${0} ${1} ["John_Doe"] + + ${start} Get Current Date + Ctn Clear Retention + Ctn Start Broker + Ctn Start Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + + # Operation in contact group + Ctn Add Contact Group ${0} ${2} ["U1"] + Ctn Add Contact Group ${0} ${3} ["U2"] + Ctn Add Contact Group ${0} ${4} ["U3","U4"] + + # Delete unnecessary fields in contactgroup: + Ctn Engine Config Delete Key In Cfg 0 contactgroup_1 members contactgroups.cfg + + # Contactgroup_1 to use contactgroup_template_1 + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_1 use contactgroup_template_1 contactgroups.cfg + + # Operation in contactgroup + ${config_values} Create Dictionary +... contactgroup_members contactgroup_3 +... members U1 + + FOR ${key} ${value} IN &{config_values} + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_1 ${key} ${value} contactgroups.cfg + END + + # Operation in contactgroupTemplates + ${config_values_tmp} Create Dictionary +... contactgroup_members contactgroup_4 +... members John_Doe + + FOR ${key} ${value} IN &{config_values_tmp} + Ctn Engine Config Set Key Value In Cfg 0 contactgroup_template_1 ${key} ${value} contactgroupTemplates.cfg + END + + # Reload engine + ${start} Get Current Date + Ctn Reload Engine + Ctn Wait For Engine To Be Ready ${start} ${1} + ${content} Create List Reload configuration finished + ${result} Ctn Find In Log With Timeout + ... ${ENGINE_LOG}/config0/centengine.log + ... ${start} + ... ${content} + ... 60 + ... verbose=False + Should Be True ${result} Engine is Not Ready after 60s!! + + ${output} Ctn Get Contactgroup Info Grpc contactgroup_1 + + Log To Console ${output} + + Should Be Equal As Strings ${output}[name] contactgroup_1 + Should Be Equal As Strings ${output}[alias] contactgroup_1 + Should Not Contain Any ${output}[members] John_Doe U3 U4 + Should Contain ${output}[members] U1 + Should Contain ${output}[members] U2 + + Ctn Stop Engine + Ctn Kindly Stop Broker \ No newline at end of file diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index afdb68b762..1f6331ed63 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -1204,6 +1204,8 @@ def ctn_engine_config_set_key_value_in_cfg(idx: int, desc: str, key: str, value: found = False if file == "hostgroups.cfg": r = re.compile(r"^\s*hostgroup_name\s+" + desc + "\s*$") + elif file == "contactgroups.cfg": + r = re.compile(r"^\s*contactgroup_name\s+" + desc + "\s*$") elif len(file) > 13 and file[-13:] == "Templates.cfg": r = re.compile(r"^\s*name\s+" + desc + "\s*$") else: @@ -1238,6 +1240,8 @@ def ctn_engine_config_delete_key_in_cfg(idx: int, desc: str, key: str, file): if file == "hostgroups.cfg": r = re.compile(r"^\s*hostgroup_name\s+" + desc + "\s*$") + elif file == "contactgroups.cfg": + r = re.compile(r"^\s*contactgroup_name\s+" + desc + "\s*$") elif len(file) > 13 and file[-13:] == "Templates.cfg": if file[-13:] == "Templates.cfg": r = re.compile(r"^\s*name\s+" + desc + "\s*$") @@ -4005,6 +4009,31 @@ def ctn_get_hostgroup_info_grpc(name:str): logger.console(f"gRPC server not ready {e}") return {} + +def ctn_get_contactgroup_info_grpc(name:str): + """ + Retrieve contact group information via a gRPC call. + + Args: + name: The name of the contact group to retrieve. + + Returns: + A dictionary containing the contact group information, if successfully retrieved. + """ + limit = time.time() + 30 + while time.time() < limit: + time.sleep(1) + with grpc.insecure_channel("127.0.0.1:50001") as channel: + stub = engine_pb2_grpc.EngineStub(channel) + request = engine_pb2.ContactGroupIdentifier(name=name) + try: + cg = stub.GetContactGroup(request) + cg_dict = MessageToDict(cg, always_print_fields_with_no_presence=True) + return cg_dict + except Exception as e: + logger.console(f"gRPC server not ready {e}") + return {} + def ctn_check_key_value_existence(data_list, key, value): """ Check if a specific key-value pair exists in a list of data strings.