-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for GetUnitFileState API
- Adds support for GetUnitFileState API on controller and node - Adds is-enabled command to bluechictl - Adds integration test Fixes: #934 Signed-off-by: Martin Perina <[email protected]>
- Loading branch information
Showing
13 changed files
with
193 additions
and
9 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
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,57 @@ | ||
/* | ||
* Copyright Contributors to the Eclipse BlueChi project | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
#include "method-is-enabled.h" | ||
#include "client.h" | ||
#include "usage.h" | ||
|
||
#include "libbluechi/common/opt.h" | ||
|
||
static int method_is_enabled_on(Client *client, char *node_name, char *unit_file) { | ||
int r = 0; | ||
_cleanup_sd_bus_error_ sd_bus_error error = SD_BUS_ERROR_NULL; | ||
_cleanup_sd_bus_message_ sd_bus_message *result = NULL; | ||
const char *state = NULL; | ||
|
||
r = assemble_object_path_string(NODE_OBJECT_PATH_PREFIX, node_name, &client->object_path); | ||
if (r < 0) { | ||
return r; | ||
} | ||
|
||
r = sd_bus_call_method( | ||
client->api_bus, | ||
BC_INTERFACE_BASE_NAME, | ||
client->object_path, | ||
NODE_INTERFACE, | ||
"GetUnitFileState", | ||
&error, | ||
&result, | ||
"s", | ||
unit_file); | ||
if (r < 0) { | ||
fprintf(stderr, "Failed to issue method call: %s\n", error.message); | ||
return r; | ||
} | ||
|
||
r = sd_bus_message_read(result, "s", &state); | ||
if (r < 0) { | ||
fprintf(stderr, "Failed to read result of method call: %s\n", error.message); | ||
return r; | ||
} | ||
|
||
printf("%s\n", state); | ||
|
||
return 0; | ||
} | ||
|
||
int method_is_enabled(Command *command, void *userdata) { | ||
return method_is_enabled_on(userdata, command->opargv[0], command->opargv[1]); | ||
} | ||
|
||
void usage_method_is_enabled() { | ||
usage_print_header(); | ||
usage_print_description("Check whether unit file is enabled"); | ||
usage_print_usage("bluechictl is-enabled [nodename] [unit]"); | ||
} |
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,13 @@ | ||
/* | ||
* Copyright Contributors to the Eclipse BlueChi project | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
#pragma once | ||
|
||
#include <stddef.h> | ||
|
||
#include "libbluechi/cli/command.h" | ||
|
||
int method_is_enabled(Command *command, void *userdata); | ||
void usage_method_is_enabled(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
summary: Test if bluechictl is-enabled returns the same enablement status of a specific | ||
node as running systemctl is-enabled on the node for all unit files | ||
id: 387cdca2-fa98-4c35-8bd0-352572a7e206 |
57 changes: 57 additions & 0 deletions
57
tests/tests/tier0/bluechictl-is-enabled/test_bluechictl_is_enabled.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,57 @@ | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
|
||
from typing import Dict | ||
|
||
from bluechi_test.config import BluechiAgentConfig, BluechiControllerConfig | ||
from bluechi_test.machine import BluechiAgentMachine, BluechiControllerMachine | ||
from bluechi_test.systemd_lists import ( | ||
RegexPattern, | ||
SystemdUnitFile, | ||
parse_bluechictl_list_output, | ||
) | ||
from bluechi_test.test import BluechiTest | ||
|
||
node_foo_name = "node-foo" | ||
|
||
|
||
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): | ||
node_foo = nodes[node_foo_name] | ||
|
||
all_res, all_out = ctrl.bluechictl.list_unit_files(node_name=node_foo_name) | ||
assert all_res == 0 | ||
all_unit_files = parse_bluechictl_list_output( | ||
content=all_out, | ||
line_pattern=RegexPattern.BLUECHICTL_LIST_UNIT_FILES, | ||
item_class=SystemdUnitFile, | ||
) | ||
|
||
for unit in all_unit_files[node_foo_name].values(): | ||
_, bc_status = ctrl.bluechictl.is_enabled( | ||
node_name=node_foo_name, unit_name=unit.key | ||
) | ||
sc_status = node_foo.systemctl.is_enabled(unit.key) | ||
if bc_status != sc_status: | ||
raise Exception( | ||
f"Bluechictl reported different status '{bc_status}' than systemctl '{sc_status}'" | ||
f" for unit '{unit.key}' on node '{node_foo_name}'" | ||
) | ||
|
||
|
||
def test_bluechi_list_unit_files_on_a_node( | ||
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_name | ||
|
||
bluechi_ctrl_default_config.allowed_node_names = [node_foo_name] | ||
|
||
bluechi_test.set_bluechi_controller_config(bluechi_ctrl_default_config) | ||
bluechi_test.add_bluechi_agent_config(node_foo_cfg) | ||
|
||
bluechi_test.run(exec) |