Skip to content

Commit

Permalink
Optimize checks for service status
Browse files Browse the repository at this point in the history
1. We don't need to check bluechi-controller or bluechi-agent service
   status at the beginning of each test, because we already check this
   status at the end of each container startup
2. We should be calling `wait_for_unit_state_to_be` instead of directly
   calling `systemctl is-active` to make sure that service will get to
   the required status (even though it may not be yet in the required
   status).

Signed-off-by: Martin Perina <[email protected]>
  • Loading branch information
mwperina committed Oct 2, 2023
1 parent 27093b1 commit bc4b439
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 22 deletions.
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 @@ -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

0 comments on commit bc4b439

Please sign in to comment.