-
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.
Added Api to set the default target Signed-off-by: Artiom Divak <[email protected]>
- Loading branch information
1 parent
ee6a46c
commit d7b39b3
Showing
15 changed files
with
208 additions
and
44 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
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,85 @@ | ||
/* | ||
* Copyright Contributors to the Eclipse BlueChi project | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
#include "method-set-default-target.h" | ||
#include "client.h" | ||
#include "usage.h" | ||
|
||
#include "libbluechi/common/opt.h" | ||
|
||
static int method_set_default_target_on(Client *client, char *node_name, char *target, char *force) { | ||
_cleanup_sd_bus_error_ sd_bus_error error = SD_BUS_ERROR_NULL; | ||
_cleanup_sd_bus_message_ sd_bus_message *message = NULL; | ||
int r = 0; | ||
bool force_b = 0; | ||
if (!strcmp(force, "true")) { | ||
force_b = 1; | ||
} else if (!strcmp(force, "false")) { | ||
force_b = 0; | ||
} else { | ||
fprintf(stderr, "Please provide a true/false value for force parameter\n"); | ||
return -1; | ||
} | ||
|
||
|
||
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, | ||
"SetDefaultTarget", | ||
&error, | ||
&message, | ||
"sb", | ||
target, | ||
force_b); | ||
if (r < 0) { | ||
fprintf(stderr, "Failed to issue method call: %s\n", error.message); | ||
return r; | ||
} | ||
|
||
r = sd_bus_message_enter_container(message, SD_BUS_TYPE_ARRAY, "(sss)"); | ||
if (r < 0) { | ||
fprintf(stderr, "Failed to open the strings array container: %s\n", strerror(-r)); | ||
return r; | ||
} | ||
printf("["); | ||
for (;;) { | ||
const char *result1 = NULL; | ||
const char *result2 = NULL; | ||
const char *result3 = NULL; | ||
|
||
r = sd_bus_message_read(message, "(sss)", &result1, &result2, &result3); | ||
if (r < 0) { | ||
fprintf(stderr, "Failed to read the SetDefaultTarget response: %s\n", strerror(-r)); | ||
return r; | ||
} | ||
if (r == 0) { | ||
break; | ||
} | ||
printf("(%s %s %s),", result1, result2, result3); | ||
} | ||
printf("]\n"); | ||
|
||
printf("The default target of node %s is now: %s\n", node_name, target); | ||
|
||
return r; | ||
} | ||
|
||
void usage_method_set_default_target() { | ||
usage_print_header(); | ||
usage_print_usage("bluechictl set-default [nodename]"); | ||
} | ||
|
||
|
||
int method_set_default_target(Command *command, void *userdata) { | ||
return method_set_default_target_on( | ||
userdata, command->opargv[0], command->opargv[1], command->opargv[2]); | ||
} |
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,11 @@ | ||
/* | ||
* Copyright Contributors to the Eclipse BlueChi project | ||
* | ||
* SPDX-License-Identifier: LGPL-2.1-or-later | ||
*/ | ||
#pragma once | ||
|
||
#include "libbluechi/cli/command.h" | ||
|
||
int method_set_default_target(Command *command, void *userdata); | ||
void usage_method_set_default_target(); |
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
File renamed without changes.
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 the set default target function | ||
id: 6cfa53b6-7429-43fd-a9b5-ff59e98b7408 |
46 changes: 46 additions & 0 deletions
46
tests/tests/tier0/bluechi-set-default-target/test_bluechi_agent_set_deault_target.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,46 @@ | ||
# | ||
# 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.test import BluechiTest | ||
|
||
NODE_FOO = "node-foo" | ||
|
||
|
||
def exec(ctrl: BluechiControllerMachine, nodes: Dict[str, BluechiAgentMachine]): | ||
node_foo = nodes[NODE_FOO] | ||
multi_user_string = "multi-user.target" | ||
graphical_string = "graphical.target" | ||
|
||
_, systemd_result = node_foo.exec_run("systemctl get-default") | ||
|
||
if systemd_result == multi_user_string: | ||
ctrl.bluechictl.set_default_target(NODE_FOO, graphical_string, "false") | ||
_, systemd_result = node_foo.exec_run("systemctl get-default") | ||
assert systemd_result == graphical_string | ||
else: | ||
ctrl.bluechictl.set_default_target(NODE_FOO, multi_user_string, "false") | ||
_, systemd_result = node_foo.exec_run("systemctl get-default") | ||
assert systemd_result == multi_user_string | ||
|
||
|
||
def test_bluechi_set_default_target( | ||
bluechi_test: BluechiTest, | ||
bluechi_node_default_config: BluechiAgentConfig, | ||
bluechi_ctrl_default_config: BluechiControllerConfig, | ||
): | ||
|
||
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) |