• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipse-bluechi / bluechi / 19941333032

04 Dec 2025 07:27PM UTC coverage: 82.516% (-0.1%) from 82.632%
19941333032

push

github

engelmi
Remove test data with too long log configs

The test cases for too long log configs (level, target and isquiet) causes
the bluechi-agent service to fail (as expected). However, this happens in
the test setup phase where we expect a running agent. Due to timing issues
this check might even pass, depending how fast the status is being checked.
This causes the test to be flacky.
Since such a long input for log configs is unrealistic and the proper level
for testing is on the unit level (test without the long data is already in
place), these cases have een removed.
In addition, the unused BluechiConfig variable for max line length has been
removed.

Signed-off-by: Michael Engel <mengel@redhat.com>

5687 of 6892 relevant lines covered (82.52%)

1865.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.56
/src/controller/proxy_monitor.c
1
/*
2
 * Copyright Contributors to the Eclipse BlueChi project
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
#include "libbluechi/log/log.h"
7

8
#include "controller.h"
9
#include "job.h"
10
#include "monitor.h"
11
#include "node.h"
12
#include "proxy_monitor.h"
13

14
Subscription *create_proxy_monitor_subscription(ProxyMonitor *monitor, const char *node) {
14✔
15
        Subscription *subscription = subscription_new(node);
14✔
16
        if (subscription == NULL) {
14✔
17
                return NULL;
18
        }
19

20
        subscription->monitor = monitor; /* Weak ref to avoid circular dep */
14✔
21
        subscription->free_monitor = NULL;
14✔
22

23
        subscription->handle_unit_new = proxy_monitor_on_unit_new;
14✔
24
        subscription->handle_unit_removed = proxy_monitor_on_unit_removed;
14✔
25
        subscription->handle_unit_state_changed = proxy_monitor_on_unit_state_changed;
14✔
26
        subscription->handle_unit_property_changed = proxy_monitor_on_unit_property_changed;
14✔
27

28
        return subscription;
14✔
29
}
30

31
ProxyMonitor *proxy_monitor_new(
14✔
32
                Node *node, const char *target_node_name, const char *unit_name, const char *proxy_object_path) {
33
        _cleanup_proxy_monitor_ ProxyMonitor *monitor = malloc0(sizeof(ProxyMonitor));
14✔
34
        if (monitor == NULL) {
14✔
35
                return NULL;
36
        }
37

38
        monitor->ref_count = 1;
14✔
39
        monitor->node = node;
14✔
40

41
        monitor->unit_name = strdup(unit_name);
14✔
42
        if (monitor->unit_name == NULL) {
14✔
43
                return NULL;
44
        }
45

46
        monitor->proxy_object_path = strdup(proxy_object_path);
14✔
47
        if (monitor->proxy_object_path == NULL) {
14✔
48
                return NULL;
49
        }
50

51
        monitor->subscription = create_proxy_monitor_subscription(monitor, target_node_name);
14✔
52
        if (monitor->subscription == NULL) {
14✔
53
                return NULL;
54
        }
55

56
        if (!subscription_add_unit(monitor->subscription, unit_name)) {
14✔
57
                return NULL;
58
        }
59

60
        return steal_pointer(&monitor);
61
}
62

63
ProxyMonitor *proxy_monitor_ref(ProxyMonitor *monitor) {
48✔
64
        monitor->ref_count++;
48✔
65
        return monitor;
48✔
66
}
67

68
static void proxy_monitor_drop_dep(ProxyMonitor *monitor);
69

70
void proxy_monitor_unref(ProxyMonitor *monitor) {
62✔
71
        monitor->ref_count--;
62✔
72
        if (monitor->ref_count != 0) {
62✔
73
                return;
74
        }
75

76
        if (monitor->target_node) {
14✔
77
                proxy_monitor_drop_dep(monitor);
10✔
78
                node_unref(monitor->target_node);
10✔
79
        }
80

81
        if (monitor->subscription) {
14✔
82
                subscription_unref(monitor->subscription);
14✔
83
        }
84

85
        free_and_null(monitor->unit_name);
14✔
86
        free_and_null(monitor->proxy_object_path);
14✔
87
        free(monitor);
14✔
88
}
89

90
int proxy_monitor_set_target_node(ProxyMonitor *monitor, Node *target_node) {
10✔
91
        monitor->target_node = node_ref(target_node);
10✔
92

93
        int res = node_add_proxy_dependency(target_node, monitor->unit_name);
10✔
94
        if (res < 0) {
10✔
95
                return res;
96
        }
97
        monitor->added_dep = true;
10✔
98
        return 0;
10✔
99
}
100

101
static void proxy_monitor_drop_dep(ProxyMonitor *monitor) {
20✔
102
        if (monitor->added_dep) {
20✔
103
                int res = node_remove_proxy_dependency(monitor->target_node, monitor->unit_name);
10✔
104
                if (res < 0) {
10✔
105
                        bc_log_error("Failed to remove proxy dependency");
×
106
                }
107
                monitor->added_dep = false;
10✔
108
        }
109
}
20✔
110

111
void proxy_monitor_close(ProxyMonitor *monitor) {
10✔
112
        proxy_monitor_drop_dep(monitor);
10✔
113
}
10✔
114

115
int proxy_monitor_on_unit_new(
10✔
116
                UNUSED void *userdata, UNUSED const char *node, UNUSED const char *unit, const char *reason) {
117
        ProxyMonitor *monitor = (ProxyMonitor *) userdata;
10✔
118
        bc_log_debugf("ProxyMonitor processing unit new %s %s %s", node, unit, reason);
10✔
119
        proxy_monitor_send_new(monitor, reason);
10✔
120
        return 0;
10✔
121
}
122

123
int proxy_monitor_on_unit_state_changed(
22✔
124
                UNUSED void *userdata,
125
                UNUSED const char *node,
126
                UNUSED const char *unit,
127
                const char *active_state,
128
                const char *substate,
129
                const char *reason) {
130
        ProxyMonitor *monitor = (ProxyMonitor *) userdata;
22✔
131

132
        bc_log_debugf("ProxyMonitor processing unit state changed %s %s %s %s %s",
22✔
133
                      node,
134
                      unit,
135
                      active_state,
136
                      substate,
137
                      reason);
138
        proxy_monitor_send_state_changed(monitor, active_state, substate, reason);
22✔
139

140
        return 0;
22✔
141
}
142

143
int proxy_monitor_on_unit_removed(
2✔
144
                UNUSED void *userdata, UNUSED const char *node, UNUSED const char *unit, const char *reason) {
145
        ProxyMonitor *monitor = (ProxyMonitor *) userdata;
2✔
146
        bc_log_debugf("ProxyMonitor processing unit removed %s %s %s", node, unit, reason);
2✔
147
        proxy_monitor_send_removed(monitor, reason);
2✔
148
        return 0;
2✔
149
}
150

151
int proxy_monitor_on_unit_property_changed(
102✔
152
                UNUSED void *userdata,
153
                UNUSED const char *node,
154
                UNUSED const char *unit,
155
                UNUSED const char *interface,
156
                UNUSED sd_bus_message *m) {
157
        return 0;
102✔
158
}
159

160
static int proxy_monitor_send_error_callback(sd_bus_message *m, void *userdata, UNUSED sd_bus_error *ret_error) {
4✔
161
        _cleanup_proxy_monitor_ ProxyMonitor *monitor = userdata;
8✔
162

163
        if (sd_bus_message_is_method_error(m, NULL)) {
4✔
164
                bc_log_errorf("Failed to send proxy error on node %s with object path %s: %s",
×
165
                              monitor->node->name,
166
                              monitor->proxy_object_path,
167
                              sd_bus_message_get_error(m)->message);
168
        }
169
        return 0;
4✔
170
}
171

172
void proxy_monitor_send_error(ProxyMonitor *monitor, const char *message) {
4✔
173
        int r = sd_bus_call_method_async(
12✔
174
                        monitor->node->agent_bus,
4✔
175
                        NULL,
176
                        BC_INTERFACE_BASE_NAME,
177
                        monitor->proxy_object_path,
4✔
178
                        INTERNAL_PROXY_INTERFACE,
179
                        "Error",
180
                        proxy_monitor_send_error_callback,
181
                        proxy_monitor_ref(monitor),
4✔
182
                        "s",
183
                        message);
184
        if (r < 0) {
4✔
185
                bc_log_errorf("Failed to call Error on node %s object %s with message '%s': %s",
×
186
                              monitor->node->name,
187
                              monitor->proxy_object_path,
188
                              message,
189
                              strerror(-r));
190
        }
191
}
4✔
192

193
static int proxy_monitor_send_state_changed_callback(
22✔
194
                sd_bus_message *m, void *userdata, UNUSED sd_bus_error *ret_error) {
195
        _cleanup_proxy_monitor_ ProxyMonitor *monitor = userdata;
44✔
196

197
        if (sd_bus_message_is_method_error(m, NULL)) {
22✔
198
                bc_log_errorf("Failed to send proxy state change node %s with object path %s: %s",
×
199
                              monitor->node->name,
200
                              monitor->proxy_object_path,
201
                              sd_bus_message_get_error(m)->message);
202
        }
203
        return 0;
22✔
204
}
205

206
int proxy_monitor_send_state_changed(
22✔
207
                ProxyMonitor *monitor, const char *active_state, const char *substate, const char *reason) {
208
        int r = sd_bus_call_method_async(
66✔
209
                        monitor->node->agent_bus,
22✔
210
                        NULL,
211
                        BC_INTERFACE_BASE_NAME,
212
                        monitor->proxy_object_path,
22✔
213
                        INTERNAL_PROXY_INTERFACE,
214
                        "TargetStateChanged",
215
                        proxy_monitor_send_state_changed_callback,
216
                        proxy_monitor_ref(monitor),
22✔
217
                        "sss",
218
                        active_state,
219
                        substate,
220
                        reason);
221
        if (r < 0) {
22✔
222
                bc_log_errorf("Failed to send proxy state changed on node %s object %s: %s",
×
223
                              monitor->node->name,
224
                              monitor->proxy_object_path,
225
                              strerror(-r));
226
        }
227
        return r;
22✔
228
}
229

230
static int proxy_monitor_send_new_callback(sd_bus_message *m, void *userdata, UNUSED sd_bus_error *ret_error) {
10✔
231
        _cleanup_proxy_monitor_ ProxyMonitor *monitor = userdata;
20✔
232

233
        if (sd_bus_message_is_method_error(m, NULL)) {
10✔
234
                bc_log_errorf("Failed to send proxy new %s with object path %s: %s",
×
235
                              monitor->node->name,
236
                              monitor->proxy_object_path,
237
                              sd_bus_message_get_error(m)->message);
238
        }
239
        return 0;
10✔
240
}
241

242
int proxy_monitor_send_new(ProxyMonitor *monitor, const char *reason) {
10✔
243
        int r = sd_bus_call_method_async(
30✔
244
                        monitor->node->agent_bus,
10✔
245
                        NULL,
246
                        BC_INTERFACE_BASE_NAME,
247
                        monitor->proxy_object_path,
10✔
248
                        INTERNAL_PROXY_INTERFACE,
249
                        "TargetNew",
250
                        proxy_monitor_send_new_callback,
251
                        proxy_monitor_ref(monitor),
10✔
252
                        "s",
253
                        reason);
254
        if (r < 0) {
10✔
255
                bc_log_errorf("Failed to send proxy new on node %s object %s: %s",
×
256
                              monitor->node->name,
257
                              monitor->proxy_object_path,
258
                              strerror(-r));
259
        }
260
        return r;
10✔
261
}
262

263
static int proxy_monitor_send_removed_callback(sd_bus_message *m, void *userdata, UNUSED sd_bus_error *ret_error) {
2✔
264
        _cleanup_proxy_monitor_ ProxyMonitor *monitor = userdata;
4✔
265

266
        if (sd_bus_message_is_method_error(m, NULL)) {
2✔
267
                bc_log_errorf("Failed to send proxy removed %s with object path %s: %s",
×
268
                              monitor->node->name,
269
                              monitor->proxy_object_path,
270
                              sd_bus_message_get_error(m)->message);
271
        }
272
        return 0;
2✔
273
}
274

275
int proxy_monitor_send_removed(ProxyMonitor *monitor, const char *reason) {
2✔
276
        int r = sd_bus_call_method_async(
6✔
277
                        monitor->node->agent_bus,
2✔
278
                        NULL,
279
                        BC_INTERFACE_BASE_NAME,
280
                        monitor->proxy_object_path,
2✔
281
                        INTERNAL_PROXY_INTERFACE,
282
                        "TargetRemoved",
283
                        proxy_monitor_send_removed_callback,
284
                        proxy_monitor_ref(monitor),
2✔
285
                        "s",
286
                        reason);
287
        if (r < 0) {
2✔
288
                bc_log_errorf("Failed to send proxy removed on node %s object %s: %s",
×
289
                              monitor->node->name,
290
                              monitor->proxy_object_path,
291
                              strerror(-r));
292
        }
293
        return r;
2✔
294
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc