forked from eclipse-bluechi/bluechi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR will add watch option for 'bluechi status'. I added monitor for the units that are requested to be watch. And every time the status of the service changed the screen is cleared and every the new status is printed . Related: eclipse-bluechi#706 Signed-off-by: Artiom Divak <adivak@redhat.com>
- Loading branch information
1 parent
5e0331f
commit 23cd243
Showing
4 changed files
with
224 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
summary: Test client watch option by running in the controller container "bluechictl status" of a spasific node in the agent container and watching the status change when the service is down and up | ||
id: bb9d4394-bd53-4d36-b8ba-ee91697c4810 |
50 changes: 50 additions & 0 deletions
50
tests/tests/tier0/bluechictl-status-watch-service/python/bluechictl_status_watch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import logging | ||
import re | ||
import unittest | ||
|
||
from bluechi_machine_lib.bluechictl import BackgroundRunner, SimpleEventEvaluator | ||
from dasbus.error import DBusError | ||
|
||
from bluechi.api import Node | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
node_foo_name = "node-foo" | ||
simple_service = "simple.service" | ||
|
||
|
||
class TestBluechictlStatusWatch(unittest.TestCase): | ||
|
||
def setUp(self) -> None: | ||
service_status_active = re.compile(r"^" + simple_service + ".* active") | ||
service_status_inactive = re.compile(r"^" + simple_service + ".* inactive") | ||
expected_patterns = {service_status_active, service_status_inactive} | ||
args = ["status", node_foo_name, simple_service, "-w"] | ||
self.evaluator = SimpleEventEvaluator(expected_patterns) | ||
self.bgrunner = BackgroundRunner(args, self.evaluator) | ||
|
||
def test_bluechictl_status_watch(self): | ||
self.bgrunner.start() | ||
|
||
# stop the bluechi controller service to trigger a disconnected message in the agent | ||
# hacky solution to cause a disconnect: | ||
# stop the controller service | ||
# problem: | ||
# dasbus will raise a DBusError for connection timeout on v1.4, v1.7 doesn't | ||
# the command will be executed anyway, resulting in the desired shutdown of the node | ||
# therefore, the DBusError is silenced for now, but all other errors are still raised | ||
node = Node(node_foo_name) | ||
node.stop_unit(simple_service, "replace") | ||
node.start_unit(simple_service, "replace") | ||
node.stop_unit(simple_service, "replace") | ||
|
||
self.bgrunner.stop() | ||
assert self.evaluator.processing_finished() | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
44 changes: 44 additions & 0 deletions
44
tests/tests/tier0/bluechictl-status-watch-service/test_bluechictl_status_watch_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import os | ||
from typing import Dict | ||
|
||
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig | ||
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine | ||
from bluechi_test.service import Option, Section, SimpleRemainingService | ||
from bluechi_test.test import BluechiTest | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
NODE_FOO = "node-foo" | ||
|
||
|
||
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): | ||
node_foo = nodes[NODE_FOO] | ||
service = SimpleRemainingService() | ||
service.set_option(Section.Service, Option.ExecStart, "/bin/true") | ||
|
||
node_foo.install_systemd_service(service) | ||
ctrl.bluechictl.daemon_reload_node(NODE_FOO) | ||
ctrl.bluechictl.start_unit(NODE_FOO, service.name) | ||
|
||
result, _ = ctrl.run_python(os.path.join("python", "bluechictl_status_watch.py")) | ||
assert result == 0 | ||
|
||
|
||
def test_bluechictl_status_watch_service( | ||
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) |