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

added integration test for enabling a unit #332

Merged
merged 1 commit into from
Jun 1, 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
7 changes: 7 additions & 0 deletions tests/hirte_test/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,10 @@ def stop_unit(self, node_name: str, unit_name: str) -> None:
result, output = self.exec_run(f"hirtectl stop {node_name} {unit_name}")
if result != 0:
raise Exception(f"Failed to start service {unit_name} on node {node_name}: {output}")

def enable_unit(self, node_name: str, unit_name: str) -> None:
print(f"Enabling unit {unit_name} on node {node_name}")

result, output = self.exec_run(f"hirtectl enable {node_name} {unit_name}")
if result != 0:
raise Exception(f"Failed to enable service {unit_name} on node {node_name}: {output}")
6 changes: 6 additions & 0 deletions tests/tests/tier0/hirte-enable-service/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
summary: Test if a disabled systemd service can be enabled using hirtectl

tier: 0

test: |
pytest -svv
10 changes: 10 additions & 0 deletions tests/tests/tier0/hirte-enable-service/systemd/simple.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=I am truth

[Service]
Type=simple
ExecStart=/bin/true
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import os
import pytest
from typing import Dict

from hirte_test.config import HirteControllerConfig, HirteNodeConfig
from hirte_test.container import HirteControllerContainer, HirteNodeContainer
from hirte_test.test import HirteTest


node_foo_name = "node-foo"
simple_service = "simple.service"


def exec(ctrl: HirteControllerContainer, nodes: Dict[str, HirteNodeContainer]):
foo = nodes[node_foo_name]

source_dir = "systemd"
target_dir = os.path.join("/", "etc", "systemd", "system")

foo.copy_systemd_service(simple_service, source_dir, target_dir)

_, output = foo.exec_run(f"systemctl is-enabled {simple_service}")
if output != "disabled":
raise Exception(f"Failed pre-check if unit {simple_service} is enabled: {output}")

ctrl.enable_unit(node_foo_name, simple_service)

_, output = foo.exec_run(f"systemctl is-enabled {simple_service}")
if output != "enabled":
raise Exception(f"Unit {simple_service} expected to be enabled, but got: {output}")


@pytest.mark.timeout(10)
def test_proxy_service_start(
hirte_test: HirteTest,
hirte_ctrl_default_config: HirteControllerConfig,
hirte_node_default_config: HirteNodeConfig):

node_foo_cfg = hirte_node_default_config.deep_copy()
node_foo_cfg.node_name = node_foo_name

hirte_ctrl_default_config.allowed_node_names = [node_foo_name]

hirte_test.set_hirte_controller_config(hirte_ctrl_default_config)
hirte_test.add_hirte_node_config(node_foo_cfg)

hirte_test.run(exec)