Skip to content

Commit 1baff88

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 - use global constant for node-ctrl name Fixes: #1042
1 parent 30cf42a commit 1baff88

File tree

38 files changed

+226
-286
lines changed

38 files changed

+226
-286
lines changed

tests/bluechi_test/constants.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#
2+
# Copyright Contributors to the Eclipse BlueChi project
3+
#
4+
# SPDX-License-Identifier: LGPL-2.1-or-later
5+
6+
NODE_CTRL_NAME = "node-ctrl"

tests/bluechi_test/test.py

+15
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from bluechi_test.client import ContainerClient, SSHClient
1515
from bluechi_test.command import Command
1616
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
17+
from bluechi_test.constants import NODE_CTRL_NAME
1718
from bluechi_test.machine import (
1819
BluechiAgentMachine,
1920
BluechiControllerMachine,
@@ -51,6 +52,14 @@ def __init__(
5152

5253
self._test_init_time = datetime.datetime.now()
5354

55+
self.set_bluechi_local_agent_config(
56+
BluechiAgentConfig(
57+
file_name="agent.conf",
58+
node_name=NODE_CTRL_NAME,
59+
controller_address="unix:path=/run/bluechi/bluechi.sock",
60+
).deep_copy()
61+
)
62+
5463
def set_bluechi_controller_config(self, cfg: BluechiControllerConfig):
5564
self.bluechi_controller_config = cfg
5665

@@ -253,6 +262,9 @@ def setup(
253262
if self.bluechi_controller_config is None:
254263
raise Exception("Bluechi Controller configuration not set")
255264

265+
if self.bluechi_local_agent_config is not None:
266+
self.bluechi_controller_config.allowed_node_names.append(NODE_CTRL_NAME)
267+
256268
success = True
257269
ctrl_container: BluechiControllerMachine = None
258270
node_container: Dict[str, BluechiAgentMachine] = dict()
@@ -386,6 +398,9 @@ def setup(
386398
if len(self.available_hosts) < 1:
387399
raise Exception("No available hosts!")
388400

401+
if self.bluechi_local_agent_config is not None:
402+
self.bluechi_controller_config.allowed_node_names.append(NODE_CTRL_NAME)
403+
389404
success = True
390405
ctrl_machine: BluechiControllerMachine = None
391406
agent_machines: Dict[str, BluechiAgentMachine] = dict()

tests/tests/tier0/bluechi-agent-connect-via-controller-address/test_bluechi_agent_connect_via_controller_address.py

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ def test_agent_invalid_configuration(
6363
bluechi_node_default_config: BluechiAgentConfig,
6464
bluechi_ctrl_default_config: BluechiControllerConfig,
6565
):
66+
# Disable default local agent on controller node using UDS,
67+
# because we test local agent with TCP connection
68+
bluechi_test.set_bluechi_local_agent_config(None)
6669

6770
node_foo_cfg = bluechi_node_default_config.deep_copy()
6871
node_foo_cfg.node_name = NODE_FOO

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

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

4747
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
4848

49+
# Disable default local agent on controller node using UDS,
50+
# because we test local agent with TCP connection
51+
bluechi_test.set_bluechi_local_agent_config(None)
52+
4953
bluechi_test.run(verify_resolving_fqdn)

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
#
44
# SPDX-License-Identifier: LGPL-2.1-or-later
55

6+
import os
67
import unittest
78

89
from bluechi.api import Node
910

11+
NODE_CTRL_NAME = os.getenv("NODE_CTRL_NAME", "node-ctrl")
12+
1013

1114
class TestNodeIsConnected(unittest.TestCase):
1215
def test_node_is_connected(self):
13-
n = Node("node-foo")
16+
n = Node(NODE_CTRL_NAME)
1417
assert n.status == "online"
15-
assert n.name == "node-foo"
18+
assert n.name == NODE_CTRL_NAME
1619

1720

1821
if __name__ == "__main__":

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

+3-15
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
import os
77
from typing import Dict
88

9-
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
9+
from bluechi_test.config import BluechiControllerConfig
10+
from bluechi_test.constants import NODE_CTRL_NAME
1011
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1112
from bluechi_test.test import BluechiTest
1213

13-
node_foo_name = "node-foo"
14-
1514

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

1817
assert ctrl.wait_for_unit_state_to_be("bluechi-controller", "active")
1918
# local bluechi-agent is running, check if it is connected
19+
os.environ["NODE_CTRL_NAME"] = NODE_CTRL_NAME
2020
result, output = ctrl.run_python(os.path.join("python", "is_node_connected.py"))
2121
if result != 0:
2222
raise Exception(output)
@@ -25,17 +25,5 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
2525
def test_bluechi_and_agent_on_same_machine(
2626
bluechi_test: BluechiTest, bluechi_ctrl_default_config: BluechiControllerConfig
2727
):
28-
29-
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name]
30-
3128
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-
)
4129
bluechi_test.run(exec)

tests/tests/tier0/bluechi-anonymous-node/test_anonymous_node.py

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def test_anonymous_node(
3333
bluechi_ctrl_default_config: BluechiControllerConfig,
3434
bluechi_node_default_config: BluechiAgentConfig,
3535
):
36+
bluechi_test.set_bluechi_local_agent_config(None)
3637

3738
node_foo_config = bluechi_node_default_config.deep_copy()
3839
node_foo_config.node_name = node_foo_name

tests/tests/tier0/bluechi-controller-disable-tcp-enable-uds/test_bluechi_controller_disable_tcp_enable_uds.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from typing import Dict
88

99
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
10+
from bluechi_test.constants import NODE_CTRL_NAME
1011
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1112
from bluechi_test.test import BluechiTest
1213
from bluechi_test.util import Timeout
1314

1415
LOGGER = logging.getLogger(__name__)
15-
NODE_LOCAL = "node-local"
16+
NODE_LOCAL = NODE_CTRL_NAME
1617

1718

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

tests/tests/tier0/bluechi-controller-runs-tcp-and-socket-activation-parallel/test_bluechi_controller_runs_tcp_and_socket_activation_parallel.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from typing import Dict
88

99
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
10+
from bluechi_test.constants import NODE_CTRL_NAME
1011
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1112
from bluechi_test.test import BluechiTest
1213
from bluechi_test.util import Timeout
1314

1415
LOGGER = logging.getLogger(__name__)
15-
NODE_LOCAL = "node-local"
16+
NODE_LOCAL = NODE_CTRL_NAME
1617
NODE_REMOTE = "node-remote"
1718

1819

tests/tests/tier0/bluechi-controller-runs-uds-and-socket-activation-parallel/test_bluechi_controller_runs_uds_and_socket_activation_parallel.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from typing import Dict
88

99
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
10+
from bluechi_test.constants import NODE_CTRL_NAME
1011
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1112
from bluechi_test.test import BluechiTest
1213
from bluechi_test.util import Timeout
1314

1415
LOGGER = logging.getLogger(__name__)
15-
NODE_LOCAL = "node-local"
16+
NODE_LOCAL = NODE_CTRL_NAME
1617

1718

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

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,27 @@
33
#
44
# SPDX-License-Identifier: LGPL-2.1-or-later
55

6+
import os
67
import time
78
import unittest
89

910
from bluechi_machine_lib.util import Timeout
1011

1112
from bluechi.api import Node
1213

13-
NODE_NAME = "node-foo"
14+
NODE_CTRL_NAME = os.getenv("NODE_CTRL_NAME", "node-ctrl")
1415

1516

1617
class TestNodeIsConnected(unittest.TestCase):
1718
def test_node_is_connected(self):
1819

19-
with Timeout(5, f"Timeout while waiting for agent '{NODE_NAME}' to be online"):
20+
with Timeout(
21+
5, f"Timeout while waiting for agent '{NODE_CTRL_NAME}' to be online"
22+
):
2023
status = "offline"
2124
while status != "online":
2225
try:
23-
status = Node(NODE_NAME).status
26+
status = Node(NODE_CTRL_NAME).status
2427
time.sleep(0.5)
2528
except Exception:
2629
pass

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

+3-16
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
11+
from bluechi_test.constants import NODE_CTRL_NAME
1112
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1213
from bluechi_test.test import BluechiTest
1314

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

1717

1818
def exec(ctrl: BluechiControllerMachine, _: Dict[str, BluechiAgentMachine]):
@@ -22,21 +22,9 @@ 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

27+
os.environ["NODE_CTRL_NAME"] = NODE_CTRL_NAME
4028
result, output = ctrl.run_python(os.path.join("python", "is_node_connected.py"))
4129
if result != 0:
4230
raise Exception(output)
@@ -46,7 +34,6 @@ def test_bluechi_controller_socket_activation(
4634
bluechi_test: BluechiTest,
4735
bluechi_ctrl_default_config: BluechiControllerConfig,
4836
):
49-
bluechi_ctrl_default_config.allowed_node_names = [NODE_FOO]
5037
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config)
5138

5239
bluechi_test.run(exec)

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

+10-14
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
from typing import Dict
88

99
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig
10+
from bluechi_test.constants import NODE_CTRL_NAME
1011
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine
1112
from bluechi_test.test import BluechiTest
1213
from bluechi_test.util import Timeout, get_test_env_value_int
1314

1415
LOGGER = logging.getLogger(__name__)
1516

1617
AGENT_ONE = "agent-one"
17-
AGENT_TWO = "agent-two"
1818
SLEEP_DURATION = get_test_env_value_int("SLEEP_DURATION", 2)
1919

2020

@@ -76,10 +76,10 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
7676
assert nodes[AGENT_ONE].wait_for_unit_state_to_be("bluechi-agent", "active")
7777

7878
# Test 3: Agent-two offline
79-
LOGGER.debug("Stopping agent-two.")
80-
nodes[AGENT_TWO].systemctl.stop_unit("bluechi-agent")
79+
LOGGER.debug(f"Stopping {NODE_CTRL_NAME}.")
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(
@@ -94,16 +94,16 @@ def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]):
9494
), "Monitor command should produce output when agent-two is offline."
9595

9696
# Bring agent-two back online
97-
LOGGER.debug("Starting agent-two.")
98-
nodes[AGENT_TWO].systemctl.start_unit("bluechi-agent")
97+
LOGGER.debug(f"Starting {NODE_CTRL_NAME}.")
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-
153-
bluechi_ctrl_default_config.allowed_node_names = [AGENT_ONE, AGENT_TWO]
150+
bluechi_ctrl_default_config.allowed_node_names = [AGENT_ONE]
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)

0 commit comments

Comments
 (0)