-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added StartTransientUnit API to BlueChi
Relates to: #1033 In order to provide a more complete set of systemd APIs through BlueChi the StartTransientUnit is being added. It also added a new integration test for the new API method. Signed-off-by: Michael Engel <[email protected]>
- Loading branch information
Showing
9 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/tests/tier0/bluechi-controller-start-transient-unit/main.fmf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
summary: Test starting a transient unit | ||
id: c683d707-9e11-49e2-8b87-d759ae676f52 |
73 changes: 73 additions & 0 deletions
73
tests/tests/tier0/bluechi-controller-start-transient-unit/python/start_transient.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import unittest | ||
|
||
from dasbus.typing import Variant | ||
from dasbus.loop import EventLoop | ||
|
||
from bluechi.api import Controller, Monitor, Node | ||
|
||
|
||
class TestStartTransientUnit(unittest.TestCase): | ||
|
||
def __init__(self, methodName="runTest"): | ||
super().__init__(methodName) | ||
|
||
self.transient_unit = "transient.service" | ||
self.received_new_signal = False | ||
self.received_removed_signal = False | ||
|
||
def test_start_transient_unit(self): | ||
loop = EventLoop() | ||
|
||
controller = Controller() | ||
monitor_path = controller.create_monitor() | ||
monitor = Monitor(monitor_path) | ||
monitor.subscribe("node-foo", self.transient_unit) | ||
|
||
def on_new_unit(node, unit, reason): | ||
if unit == self.transient_unit: | ||
self.received_new_signal = True | ||
|
||
def on_removed_unit(node, unit, reason): | ||
if unit == self.transient_unit: | ||
self.received_removed_signal = True | ||
loop.quit() | ||
|
||
monitor.on_unit_new(on_new_unit) | ||
monitor.on_unit_removed(on_removed_unit) | ||
|
||
node = Node("localhost") | ||
node.start_transient_unit( | ||
TestStartTransientUnit.transient_unit, | ||
"replace", | ||
[ | ||
("Description", Variant("s", "My Test Transient Service")), | ||
( | ||
"ExecStart", | ||
Variant( | ||
"a(sasb)", | ||
[ | ||
( | ||
"/usr/bin/sleep", | ||
["/usr/bin/sleep", "1"], | ||
False, | ||
) | ||
], | ||
), | ||
), | ||
], | ||
[], | ||
) | ||
|
||
loop.run() | ||
|
||
assert self.received_new_signal, "Did not receive new signal" | ||
assert self.received_removed_signal, "Did not receive remove signal" | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
33 changes: 33 additions & 0 deletions
33
...0/bluechi-controller-start-transient-unit/test_bluechi_controller_start_transient_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
import os | ||
from typing import Dict | ||
|
||
from bluechi_test.config import BluechiControllerConfig, BluechiAgentConfig | ||
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine | ||
from bluechi_test.test import BluechiTest | ||
|
||
|
||
def exec(ctrl: BluechiControllerMachine, _: Dict[str, BluechiAgentMachine]): | ||
result, output = ctrl.run_python(os.path.join("python", "start_transient.py")) | ||
if result != 0: | ||
raise Exception(output) | ||
|
||
|
||
def test_bluechi_controller_start_transient_unit( | ||
bluechi_test: BluechiTest, | ||
bluechi_ctrl_default_config: BluechiControllerConfig, | ||
bluechi_node_default_config: BluechiAgentConfig, | ||
): | ||
node_foo_cfg = bluechi_node_default_config.deep_copy() | ||
node_foo_cfg.node_name = "node-foo" | ||
|
||
bluechi_ctrl_default_config.allowed_node_names = ["node-foo"] | ||
|
||
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config) | ||
bluechi_test.add_bluechi_agent_config(node_foo_cfg) | ||
|
||
bluechi_test.run(exec) |