Skip to content

Commit

Permalink
Test DaemonReload
Browse files Browse the repository at this point in the history
This integration test tests the Daemond Reload by adding
new service that won't start first. After changing the file and
by using daemon reload the service will start and will be 'active'

Signed-off-by: Artiom Divak <adivak@redhat.com>
  • Loading branch information
ArtiomDivak authored and engelmi committed Mar 12, 2024
1 parent 9abb3ca commit e604a21
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/bluechi_test/bluechictl.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def stop_unit(self, node_name: str, unit_name: str, check_result: bool = True, e
expected_result
)

def daemon_reload_node(self, node_name: str, check_result: bool = True, expected_result: int = 0) \
-> Tuple[Optional[int], Union[Iterator[bytes], Any, Tuple[bytes, bytes]]]:
return self._run(
f"Daemon Reload on node '{node_name}'",
f"daemon-reload {node_name}",
check_result,
expected_result
)

def enable_unit(self, node_name: str, unit_name: str, check_result: bool = True, expected_result: int = 0) \
-> Tuple[Optional[int], Union[Iterator[bytes], Any, Tuple[bytes, bytes]]]:
return self._run(
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/tier0/bluechi-daemon-reload/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
summary: Test bluechictl daemon-reload. This test will send an unrunble test will fail at start but then will be change and update with daemon-reload
id: bb9d4394-bd53-4d36-b8ba-ee91697c4850
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
ExecStart=/s
RemainAfterExit=yes
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: LGPL-2.1-or-later

import os
import logging

from typing import Dict
from bluechi_test.test import BluechiTest
from bluechi_test.machine import BluechiControllerMachine, BluechiAgentMachine
from bluechi_test.config import BluechiControllerConfig, BluechiAgentConfig

LOGGER = logging.getLogger(__name__)
NODE_FOO = "node-foo"


def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):

node_foo = nodes[NODE_FOO]
service_file = "simple.service"
service_path = os.path.join("/", "etc", "systemd", "system", service_file)

node_foo.copy_systemd_service(service_file, "systemd",
os.path.join("/", "etc", "systemd", "system"))
ctrl.bluechictl.start_unit(NODE_FOO, service_file)
assert node_foo.wait_for_unit_state_to_be(service_file, "failed")

node_foo.exec_run(f"sed -i '/ExecStart=/c\\ExecStart=/bin/true' {service_path}")
ctrl.bluechictl.daemon_reload_node(NODE_FOO)
ctrl.bluechictl.start_unit(NODE_FOO, service_file)
assert node_foo.wait_for_unit_state_to_be(service_file, "active")


def test_bluechi_deamon_reload(
bluechi_test: BluechiTest,
bluechi_node_default_config: BluechiAgentConfig, bluechi_ctrl_default_config: BluechiControllerConfig):
node_foo_cfg = bluechi_node_default_config.deep_copy()
node_foo_cfg.node_name = NODE_FOO

bluechi_test.add_bluechi_agent_config(node_foo_cfg)

bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO]
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)

bluechi_test.run(exec)

0 comments on commit e604a21

Please sign in to comment.