Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve integration tests stability #579

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions tests/bluechi_test/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,26 @@ def get_unit_state(self, unit_name: str) -> str:
_, output = self.exec_run(f"systemctl is-active {unit_name}")
return output

def wait_for_unit_state_to_be(self, unit_name: str, expected_state: str, timeout: float = 4.0) -> bool:
def _is_unit_in_state(self, unit_name: str, expected_state: str) -> bool:
latest_state = self.get_unit_state(unit_name)
logger.debug(f"Got state '{latest_state}' for unit {unit_name}")
return latest_state == expected_state

def wait_for_unit_state_to_be(
self,
unit_name: str,
expected_state: str,
timeout: float = 5.0,
delay: float = 0.5) -> bool:
latest_state = ""

if self._is_unit_in_state(unit_name, expected_state):
return True

start = time.time()
while (time.time() - start) < timeout:
latest_state = self.get_unit_state(unit_name)
if latest_state == expected_state:
time.sleep(delay)
mkemel marked this conversation as resolved.
Show resolved Hide resolved
if self._is_unit_in_state(unit_name, expected_state):
return True

logger.debug(f"Timeout while waiting for '{unit_name}' to reach state '{expected_state}'. \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@ def create_local_node_config() -> BluechiNodeConfig:


def verify_resolving_fqdn(ctrl: BluechiControllerContainer, _: Dict[str, BluechiNodeContainer]):
result, output = ctrl.exec_run('systemctl is-active bluechi-controller')
assert result == 0
assert output == 'active'

# create config for local bluechi-agent and adding config to controller container
local_node_cfg = create_local_node_config()
local_node_cfg.node_name = local_node_name
local_node_cfg.manager_host = "localhost"
ctrl.create_file(local_node_cfg.get_confd_dir(), local_node_cfg.file_name, local_node_cfg.serialize())

ctrl.systemctl_start_and_wait("bluechi-agent", 1)
result, output = ctrl.exec_run('systemctl is-active bluechi-agent')
assert result == 0
assert output == 'active'
ctrl.wait_for_unit_state_to_be('bluechi-agent', 'active')

result, output = ctrl.exec_run(f'bluechictl list-units {local_node_name}')
assert result == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@


def foo_startup_verify(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer]):
result, output = ctrl.exec_run('systemctl is-active bluechi-controller')

assert result == 0
assert output == 'active'

result, output = ctrl.exec_run('bluechictl status node-foo bluechi-agent.service')

assert result == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
target_dir = os.path.join("/", "etc", "systemd", "system")

foo.copy_systemd_service(simple_service, source_dir, target_dir)
assert foo.wait_for_unit_state_to_be(simple_service, "inactive")

_, output = foo.exec_run(f"systemctl is-enabled {simple_service}")
if output != "disabled":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
target_dir = os.path.join("/", "etc", "systemd", "system")

foo.copy_systemd_service(simple_service, source_dir, target_dir)
assert foo.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, simple_service)
verify_service_start(foo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@


def startup_verify(ctrl: BluechiControllerContainer, _: Dict[str, BluechiNodeContainer]):
result, output = ctrl.exec_run('systemctl is-active bluechi-controller')

assert result == 0
assert output == 'active'
ctrl.wait_for_unit_state_to_be('bluechi-controller', 'active')


def test_long_multiline_config_setting(bluechi_test: BluechiTest, bluechi_ctrl_default_config: BluechiControllerConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@


def startup_verify(ctrl: BluechiControllerContainer, _: Dict[str, BluechiNodeContainer]):
result, output = ctrl.exec_run('systemctl is-active bluechi-controller')

assert result == 0
assert output == 'active'
ctrl.wait_for_unit_state_to_be('bluechi-controller', 'active')


def test_controller_startup(bluechi_test: BluechiTest, bluechi_ctrl_default_config: BluechiControllerConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
raise Exception(output)

ctrl.exec_run("systemctl stop bluechi-controller")
_, output = ctrl.exec_run('systemctl is-active bluechi-controller')
assert output == 'inactive'
ctrl.wait_for_unit_state_to_be('bluechi-controller', 'inactive')

ctrl.exec_run("systemctl start bluechi-controller")
ctrl.wait_for_bluechi()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
target_dir = os.path.join("/", "etc", "systemd", "system")

foo.copy_systemd_service(requesting_service, source_dir, target_dir)
assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start_failed(foo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start_failed(foo, bar)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo2.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo1.wait_for_unit_state_to_be(requesting_service, "inactive")
assert foo2.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

bluechi_dep_service = assemble_bluechi_dep_service_name(simple_service)
bluechi_proxy_service = assemble_bluechi_proxy_service_name(node_bar_name, simple_service)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_the_second_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_the_first_service, "inactive")
assert foo.wait_for_unit_state_to_be(requesting_the_second_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

bluechi_dep_service = assemble_bluechi_dep_service_name(simple_service)
bluechi_proxy_service = assemble_bluechi_proxy_service_name(node_bar_name, simple_service)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start(foo, bar)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start(foo, bar)
ctrl.stop_unit(node_bar_name, assemble_bluechi_dep_service_name(simple_service))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start(foo, bar)
ctrl.stop_unit(node_foo_name, requesting_service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start(foo, bar)
ctrl.stop_unit(node_foo_name, requesting_service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def exec(ctrl: BluechiControllerContainer, nodes: Dict[str, BluechiNodeContainer
foo.copy_systemd_service(requesting_service, source_dir, target_dir)
bar.copy_systemd_service(simple_service, source_dir, target_dir)

assert foo.wait_for_unit_state_to_be(requesting_service, "inactive")
assert bar.wait_for_unit_state_to_be(simple_service, "inactive")

ctrl.start_unit(node_foo_name, requesting_service)
verify_proxy_start(foo, bar)
ctrl.stop_unit(node_bar_name, simple_service)
Expand Down