Skip to content

Commit 4b1ab93

Browse files
committed
fix(tests): start local agent be default
update all test cases(which requires 2 agents) to use node-local as second agent remove redundant agent configs and use the controller machine for local agent operations simplify test setups by removing unnecessary agent configuration current progress: - [x] monitor-wildcard-unit-changes - [x] proxy-service-start - [x] bluechi-reset-failed - [x] monitor-multiple-nodes-and-units - [x] monitor-system-status 3 agents - [x] bluechi-nodes-statuses - [x] bluechi-is-oneline-system - [x] bluechi-reset-failed - [x] bluechi-reset-failed-node - [x] proxy-service-stop-target - [x] proxy-service-stop-requesting - [x] proxy-service-stop-bluechi-dep - [x] bluechi-list-units-on-all-nodes - [x] monitor-wildcard-node-reconnect - [x] bluechi-is-online-system-monitor - [x] monitor-multiple-nodes-and-units - [x] proxy-service-fails-on-execstart - [x] proxy-service-fails-on-typo-in-file - [x] proxy-service-multiple-services-one-node - [x] service-fails-on-non-existent-service - [x] service-stop-requesting-with-unneeded - [x] multiple-services-multiple-nodes - [x] propagate-target-service-failure - [x] socket-activation-parallel Fixes: #1042
1 parent aa0bf8b commit 4b1ab93

File tree

31 files changed

+141
-234
lines changed

31 files changed

+141
-234
lines changed

tests/bluechi_test/test.py

+8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def __init__(
5151

5252
self._test_init_time = datetime.datetime.now()
5353

54+
self.set_bluechi_local_agent_config(
55+
BluechiAgentConfig(
56+
file_name="agent.conf",
57+
node_name="node-local",
58+
controller_address="unix:path=/run/bluechi/bluechi.sock",
59+
).deep_copy()
60+
)
61+
5462
def set_bluechi_controller_config(self, cfg: BluechiControllerConfig):
5563
self.bluechi_controller_config = cfg
5664

tests/tests/tier0/bluechi-agent-resolve-fqdn/test_bluechi_agent_resolve_fqdn.py

+2
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ def test_agent_resolve_fqdn(
4646

4747
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
4848

49+
bluechi_test.set_bluechi_local_agent_config(None)
50+
4951
bluechi_test.run(verify_resolving_fqdn)

tests/tests/tier0/bluechi-and-agent-on-same-machine/python/is_node_connected.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
class TestNodeIsConnected(unittest.TestCase):
1212
def test_node_is_connected(self):
13-
n = Node("node-foo")
13+
n = Node("node-local")
1414
assert n.status == "online"
15-
assert n.name == "node-foo"
15+
assert n.name == "node-local"
1616

1717

1818
if __name__ == "__main__":

tests/tests/tier0/bluechi-and-agent-on-same-machine/test_bluechi_and_agent_on_same_machine.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import os
77
from typing import Dict
88

9-
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
9+
from bluechi_test.config import BluechiControllerConfig
1010
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1111
from bluechi_test.test import BluechiTest
1212

13-
node_foo_name = "node-foo"
13+
node_foo_name = "node-local"
1414

1515

1616
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
@@ -29,13 +29,4 @@ def test_bluechi_and_agent_on_same_machine(
2929
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name]
3030

3131
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
32-
# don't add node_foo_config to bluechi_test to prevent it being started
33-
# as separate container
34-
bluechi_test.set_bluechi_local_agent_config(
35-
BluechiAgentConfig(
36-
controller_address="unix:path=/run/bluechi/bluechi.sock",
37-
node_name=node_foo_name,
38-
file_name="agent.conf",
39-
).deep_copy()
40-
)
4132
bluechi_test.run(exec)

tests/tests/tier0/bluechi-controller-socket-activation/python/is_node_connected.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from bluechi.api import Node
1212

13-
NODE_NAME = "node-foo"
13+
NODE_NAME = "node-local"
1414

1515

1616
class TestNodeIsConnected(unittest.TestCase):

tests/tests/tier0/bluechi-controller-socket-activation/test_bluechi_controller_socket_activation.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import os
88
from typing import Dict
99

10-
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
10+
from bluechi_test.config import BluechiControllerConfig
1111
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1212
from bluechi_test.test import BluechiTest
1313

1414
LOGGER = logging.getLogger(__name__)
15-
NODE_FOO = "node-foo"
15+
NODE_FOO = "node-local"
1616

1717

1818
def exec(ctrl: BluechiControllerMachine, _: Dict[str, BluechiAgentMachine]):
@@ -22,19 +22,6 @@ def exec(ctrl: BluechiControllerMachine, _: Dict[str, BluechiAgentMachine]):
2222
ctrl.systemctl.start_unit("bluechi-controller.socket")
2323
assert ctrl.wait_for_unit_state_to_be("bluechi-controller.socket", "active")
2424

25-
agent_config = BluechiAgentConfig(
26-
file_name="agent.conf",
27-
controller_address="unix:path=/run/bluechi/bluechi.sock",
28-
node_name=NODE_FOO,
29-
)
30-
ctrl.create_file(
31-
agent_config.get_confd_dir(),
32-
agent_config.file_name,
33-
agent_config.serialize(),
34-
)
35-
36-
ctrl.systemctl.start_unit("bluechi-agent.service")
37-
ctrl.wait_for_unit_state_to_be("bluechi-agent.service", "active")
3825
ctrl.wait_for_unit_state_to_be("bluechi-controller.service", "active")
3926

4027
result, output = ctrl.run_python(os.path.join("python", "is_node_connected.py"))

tests/tests/tier0/bluechi-is-online-system-monitor/test_bluechi_is_online_system_monitor.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
LOGGER = logging.getLogger(__name__)
1515

1616
AGENT_ONE = "agent-one"
17-
AGENT_TWO = "agent-two"
17+
AGENT_TWO = "node-local"
1818
SLEEP_DURATION = get_test_env_value_int("SLEEP_DURATION", 2)
1919

2020

@@ -77,9 +77,9 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
7777

7878
# Test 3: Agent-two offline
7979
LOGGER.debug("Stopping agent-two.")
80-
nodes[AGENT_TWO].systemctl.stop_unit("bluechi-agent")
80+
ctrl.systemctl.stop_unit("bluechi-agent")
8181

82-
assert nodes[AGENT_TWO].wait_for_unit_state_to_be("bluechi-agent", "inactive")
82+
assert ctrl.wait_for_unit_state_to_be("bluechi-agent", "inactive")
8383

8484
monitor_result_test_three = MonitorResult()
8585
monitor_thread = threading.Thread(
@@ -95,15 +95,15 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
9595

9696
# Bring agent-two back online
9797
LOGGER.debug("Starting agent-two.")
98-
nodes[AGENT_TWO].systemctl.start_unit("bluechi-agent")
98+
ctrl.systemctl.start_unit("bluechi-agent")
9999

100100
# Test 4: Both agents offline
101101
LOGGER.debug("Stopping both agents.")
102102
nodes[AGENT_ONE].systemctl.stop_unit("bluechi-agent")
103-
nodes[AGENT_TWO].systemctl.stop_unit("bluechi-agent")
103+
ctrl.systemctl.stop_unit("bluechi-agent")
104104

105105
assert nodes[AGENT_ONE].wait_for_unit_state_to_be("bluechi-agent", "inactive")
106-
assert nodes[AGENT_TWO].wait_for_unit_state_to_be("bluechi-agent", "inactive")
106+
assert ctrl.wait_for_unit_state_to_be("bluechi-agent", "inactive")
107107

108108
monitor_result_test_four = MonitorResult()
109109
monitor_thread = threading.Thread(
@@ -120,7 +120,7 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
120120
# Bring both agents back online
121121
LOGGER.debug("Starting both agents.")
122122
nodes[AGENT_ONE].systemctl.start_unit("bluechi-agent")
123-
nodes[AGENT_TWO].systemctl.start_unit("bluechi-agent")
123+
ctrl.systemctl.start_unit("bluechi-agent")
124124

125125
# Test 5: Controller offline
126126
LOGGER.debug("Stopping the controller.")
@@ -147,13 +147,9 @@ def test_bluechi_is_online_system_monitor(
147147
agent_one_cfg = bluechi_node_default_config.deep_copy()
148148
agent_one_cfg.node_name = AGENT_ONE
149149

150-
agent_two_cfg = bluechi_node_default_config.deep_copy()
151-
agent_two_cfg.node_name = AGENT_TWO
152-
153150
bluechi_ctrl_default_config.allowed_node_names = [AGENT_ONE, AGENT_TWO]
154151

155152
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
156153
bluechi_test.add_bluechi_agent_config(agent_one_cfg)
157-
bluechi_test.add_bluechi_agent_config(agent_two_cfg)
158154

159155
bluechi_test.run(exec)

tests/tests/tier0/bluechi-is-online-system/test_bluechi_is_online_system.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
LOGGER = logging.getLogger(__name__)
1313

1414
AGENT_ONE = "agent-one"
15-
AGENT_TWO = "agent-two"
15+
AGENT_TWO = "node-local"
1616

1717

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

2020
agent_one = nodes[AGENT_ONE]
21-
agent_two = nodes[AGENT_TWO]
2221

2322
# Test 1: Both agents and controller are online
2423
LOGGER.debug("Testing with both agents and controller online.")
@@ -38,20 +37,20 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
3837

3938
# Test 3: Agent-two offline
4039
LOGGER.debug("Stopping agent-two.")
41-
agent_two.systemctl.stop_unit("bluechi-agent")
40+
ctrl.systemctl.stop_unit("bluechi-agent")
4241

4342
assert (
4443
not ctrl.bluechi_is_online.system_is_online()
4544
), "Expected system to report offline when agent-two is inactive"
4645

4746
# Bring agent-two back online
4847
LOGGER.debug("Starting agent-two.")
49-
agent_two.systemctl.start_unit("bluechi-agent")
48+
ctrl.systemctl.start_unit("bluechi-agent")
5049

5150
# Test 4: Both agents are offline
5251
LOGGER.debug("Stopping both agents.")
5352
agent_one.systemctl.stop_unit("bluechi-agent")
54-
agent_two.systemctl.stop_unit("bluechi-agent")
53+
ctrl.systemctl.stop_unit("bluechi-agent")
5554

5655
assert (
5756
not ctrl.bluechi_is_online.system_is_online()
@@ -60,7 +59,7 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
6059
# Bring both agents back online
6160
LOGGER.debug("Starting both agents.")
6261
agent_one.systemctl.start_unit("bluechi-agent")
63-
agent_two.systemctl.start_unit("bluechi-agent")
62+
ctrl.systemctl.start_unit("bluechi-agent")
6463

6564
# Test 5: Controller offline
6665
LOGGER.debug("Stopping the controller.")
@@ -80,13 +79,9 @@ def test_bluechi_is_online_system(
8079
agent_one_cfg = bluechi_node_default_config.deep_copy()
8180
agent_one_cfg.node_name = AGENT_ONE
8281

83-
agent_two_cfg = bluechi_node_default_config.deep_copy()
84-
agent_two_cfg.node_name = AGENT_TWO
85-
8682
bluechi_ctrl_default_config.allowed_node_names = [AGENT_ONE, AGENT_TWO]
8783

8884
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
8985
bluechi_test.add_bluechi_agent_config(agent_one_cfg)
90-
bluechi_test.add_bluechi_agent_config(agent_two_cfg)
9186

9287
bluechi_test.run(exec)

tests/tests/tier0/bluechi-list-units-on-all-nodes/test_bluechi_list_units_on_all_nodes.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from bluechi_test.test import BluechiTest
1818

1919
node_foo_name = "node-foo"
20-
node_bar_name = "node-bar"
20+
node_bar_name = "node-local"
2121

2222

2323
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
@@ -51,13 +51,9 @@ def test_bluechi_nodes_statuses(
5151
node_foo_cfg = bluechi_node_default_config.deep_copy()
5252
node_foo_cfg.node_name = node_foo_name
5353

54-
node_bar_cfg = bluechi_node_default_config.deep_copy()
55-
node_bar_cfg.node_name = node_bar_name
56-
5754
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name, node_bar_name]
5855

5956
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
6057
bluechi_test.add_bluechi_agent_config(node_foo_cfg)
61-
bluechi_test.add_bluechi_agent_config(node_bar_cfg)
6258

6359
bluechi_test.run(exec)

tests/tests/tier0/bluechi-nodes-statuses/test_bluechi_nodes_statuses.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from bluechi_test.test import BluechiTest
1111

1212
node_foo_name = "node-foo"
13-
node_bar_name = "node-bar"
13+
node_bar_name = "node-local"
1414

1515

1616
def verify_status_output(output: str, expected: Dict[str, str]):
@@ -51,13 +51,9 @@ def test_bluechi_nodes_statuses(
5151
node_foo_cfg = bluechi_node_default_config.deep_copy()
5252
node_foo_cfg.node_name = node_foo_name
5353

54-
node_bar_cfg = bluechi_node_default_config.deep_copy()
55-
node_bar_cfg.node_name = node_bar_name
56-
5754
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name, node_bar_name]
5855

5956
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
6057
bluechi_test.add_bluechi_agent_config(node_foo_cfg)
61-
bluechi_test.add_bluechi_agent_config(node_bar_cfg)
6258

6359
bluechi_test.run(exec)

tests/tests/tier0/bluechi-reset-failed-node/test_bluechi_reset_failed_node.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@
1313

1414
LOGGER = logging.getLogger(__name__)
1515
NODE_FOO = "node-foo"
16-
NODE_BAR = "node-bar"
16+
NODE_BAR = "node-local"
1717

1818

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

2121
node_foo = nodes[NODE_FOO]
22-
node_bar = nodes[NODE_BAR]
2322

2423
failed_service_node_bar = SimpleRemainingService(name="simple.service")
2524
failed_service_node_bar.set_option(Section.Service, Option.ExecStart, "/s")
2625
failed_service_node_foo = SimpleRemainingService(name="simple.service")
2726
failed_service_node_foo.set_option(Section.Service, Option.ExecStart, "/s")
2827

2928
node_foo.install_systemd_service(failed_service_node_bar)
30-
node_bar.install_systemd_service(failed_service_node_foo)
29+
ctrl.install_systemd_service(failed_service_node_foo)
3130

3231
ctrl.bluechictl.start_unit(NODE_FOO, failed_service_node_foo.name)
3332
ctrl.bluechictl.start_unit(NODE_BAR, failed_service_node_bar.name)
3433

3534
assert node_foo.wait_for_unit_state_to_be(failed_service_node_foo.name, "failed")
36-
assert node_bar.wait_for_unit_state_to_be(failed_service_node_bar.name, "failed")
35+
assert ctrl.wait_for_unit_state_to_be(failed_service_node_bar.name, "failed")
3736

3837
ctrl.bluechictl.reset_failed(node_name=NODE_FOO)
3938

4039
assert node_foo.wait_for_unit_state_to_be(failed_service_node_foo.name, "inactive")
41-
assert node_bar.wait_for_unit_state_to_be(failed_service_node_bar.name, "failed")
40+
assert ctrl.wait_for_unit_state_to_be(failed_service_node_bar.name, "failed")
4241

4342

4443
def test_bluechi_reset_failed_node(
@@ -49,11 +48,7 @@ def test_bluechi_reset_failed_node(
4948
node_foo_cfg = bluechi_node_default_config.deep_copy()
5049
node_foo_cfg.node_name = NODE_FOO
5150

52-
node_bar_cfg = bluechi_node_default_config.deep_copy()
53-
node_bar_cfg.node_name = NODE_BAR
54-
5551
bluechi_test.add_bluechi_agent_config(node_foo_cfg)
56-
bluechi_test.add_bluechi_agent_config(node_bar_cfg)
5752

5853
bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO, NODE_BAR]
5954
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)

tests/tests/tier0/bluechi-reset-failed/test_bluechi_reset_failed.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,31 @@
1313

1414
LOGGER = logging.getLogger(__name__)
1515
NODE_FOO = "node-foo"
16-
NODE_BAR = "node-bar"
16+
NODE_BAR = "node-local"
1717

1818

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

2121
node_foo = nodes[NODE_FOO]
22-
node_bar = nodes[NODE_BAR]
2322

2423
failed_service_node_bar = SimpleRemainingService(name="simple.service")
2524
failed_service_node_bar.set_option(Section.Service, Option.ExecStart, "/s")
2625
failed_service_node_foo = SimpleRemainingService(name="simple.service")
2726
failed_service_node_foo.set_option(Section.Service, Option.ExecStart, "/s")
2827

2928
node_foo.install_systemd_service(failed_service_node_bar)
30-
node_bar.install_systemd_service(failed_service_node_foo)
29+
ctrl.install_systemd_service(failed_service_node_foo)
3130

3231
ctrl.bluechictl.start_unit(NODE_FOO, failed_service_node_foo.name)
33-
ctrl.bluechictl.start_unit(NODE_BAR, failed_service_node_bar.name)
32+
ctrl.systemctl_start_and_wait(failed_service_node_bar.name)
3433

3534
assert node_foo.wait_for_unit_state_to_be(failed_service_node_foo.name, "failed")
36-
assert node_bar.wait_for_unit_state_to_be(failed_service_node_bar.name, "failed")
35+
assert ctrl.wait_for_unit_state_to_be(failed_service_node_bar.name, "failed")
3736

3837
ctrl.bluechictl.reset_failed()
3938

4039
assert node_foo.wait_for_unit_state_to_be(failed_service_node_foo.name, "inactive")
41-
assert node_bar.wait_for_unit_state_to_be(failed_service_node_bar.name, "inactive")
40+
assert ctrl.wait_for_unit_state_to_be(failed_service_node_bar.name, "inactive")
4241

4342

4443
def test_bluechi_reset_failed(
@@ -49,11 +48,7 @@ def test_bluechi_reset_failed(
4948
node_foo_cfg = bluechi_node_default_config.deep_copy()
5049
node_foo_cfg.node_name = NODE_FOO
5150

52-
node_bar_cfg = bluechi_node_default_config.deep_copy()
53-
node_bar_cfg.node_name = NODE_BAR
54-
5551
bluechi_test.add_bluechi_agent_config(node_foo_cfg)
56-
bluechi_test.add_bluechi_agent_config(node_bar_cfg)
5752

5853
bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO, NODE_BAR]
5954
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)

tests/tests/tier0/monitor-agent-loses-connection/test_monitor_agent_loses_connection.py

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
4949
def test_monitor_agent_loses_connection(
5050
bluechi_test: BluechiTest, bluechi_ctrl_default_config: BluechiControllerConfig
5151
):
52+
bluechi_test.set_bluechi_local_agent_config(None)
5253

5354
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name]
5455

tests/tests/tier0/monitor-multiple-nodes-and-units/python/monitor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from bluechi.api import Controller, Monitor, Node, Structure
1111

1212
node_name_foo = "node-foo"
13-
node_name_bar = "node-bar"
13+
node_name_bar = "node-local"
1414

1515
service_simple = "simple.service"
1616
service_also_simple = "also-simple.service"

0 commit comments

Comments
 (0)