Skip to content

Commit

Permalink
enh(tests): new test to check host_parent
Browse files Browse the repository at this point in the history
  • Loading branch information
bouda1 committed Feb 29, 2024
1 parent 42437dd commit 4bdde5e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
40 changes: 40 additions & 0 deletions tests/broker-engine/bbdo-protobuf.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions tests/resources/Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion tests/resources/resources.resource
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4bdde5e

Please sign in to comment.