From 4bdde5e7e8bf262e4f7005e7f1f21aee113ffe43 Mon Sep 17 00:00:00 2001 From: David Boucher Date: Thu, 29 Feb 2024 21:57:52 +0100 Subject: [PATCH] enh(tests): new test to check host_parent --- tests/broker-engine/bbdo-protobuf.robot | 40 +++++++++++++++++++++++++ tests/resources/Engine.py | 22 ++++++++++++++ tests/resources/resources.resource | 3 +- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/tests/broker-engine/bbdo-protobuf.robot b/tests/broker-engine/bbdo-protobuf.robot index 17b51ed2152..2d763d41b2c 100644 --- a/tests/broker-engine/bbdo-protobuf.robot +++ b/tests/broker-engine/bbdo-protobuf.robot @@ -246,3 +246,43 @@ BEPB_SERVICE_DEPENDENCY Should Be Equal As Strings ${output} () host dependency not deleted from database [Teardown] Stop Engine Broker And Save Logs True + +BEPBHostParent + [Documentation] bbdo_version 3 communication of host parent relations + [Tags] broker engine protobuf bbdo + Config Engine ${1} + Add Parent To Host 0 host_1 host_2 + Config Broker central + Config BBDO3 ${1} + Broker Config Log central sql trace + Config Broker Sql Output central unified_sql + Clear Retention + ${start} Get Current Date + Start Broker True + Start Engine + Connect To Database pymysql ${DBName} ${DBUser} ${DBPass} ${DBHost} ${DBPort} + + FOR ${index} IN RANGE 30 + ${output} Query + ... SELECT child_id, parent_id FROM hosts_hosts_parents + Log To Console ${output} + Sleep 1s + IF "${output}" == "((1, 2),)" BREAK + END + Should Be Equal As Strings ${output} ((1, 2),) host parent not inserted + + # remove host + Config Engine ${1} + Reload Broker True + Reload Engine + + FOR ${index} IN RANGE 30 + ${output} Query + ... SELECT child_id, parent_id FROM hosts_hosts_parents + Log To Console ${output} + Sleep 1s + IF "${output}" == "()" BREAK + END + Should Be Equal As Strings ${output} () host parent not deleted + + [Teardown] Stop Engine Broker And Save Logs True diff --git a/tests/resources/Engine.py b/tests/resources/Engine.py index 238654f08f5..26852fb2747 100755 --- a/tests/resources/Engine.py +++ b/tests/resources/Engine.py @@ -2481,6 +2481,28 @@ def remove_tags_from_hosts(poller: int, type: str): ff.writelines(lines) +def add_parent_to_host(poller: int, host: str, parent_host: str): + """ + Add a parent host to an host. + + Args: + poller: index of the Engine configuration (from 0) + host: child host name. + parent_host: host name of the parent of the child host. + """ + with open(f"{CONF_DIR}/config{poller}/hosts.cfg", "r") as ff: + lines = ff.readlines() + r = re.compile(rf"^\s*host_name\s+{host}$") + for i in range(len(lines)): + if r.match(lines[i]): + lines.insert( + i + 1, f" parents {parent_host}\n") + break + + with open(f"{CONF_DIR}/config{poller}/hosts.cfg", "w") as ff: + ff.writelines(lines) + + def add_template_to_services(poller: int, tmpl: str, svc_lst): """ Add a service template to services. diff --git a/tests/resources/resources.resource b/tests/resources/resources.resource index f443be5952a..11099754523 100644 --- a/tests/resources/resources.resource +++ b/tests/resources/resources.resource @@ -84,8 +84,9 @@ Restart Broker Start Broker ${only_central} Reload Broker + [Arguments] ${only_central}=False Send Signal To Process SIGHUP b1 - Send Signal To Process SIGHUP b2 + IF not ${only_central} Send Signal To Process SIGHUP b2 Kindly Stop Broker [Arguments] ${only_central}=False