@@ -217,48 +217,68 @@ def test_configurator_ignores_opamp_without_endpoint(self, client_mock, agent_mo
217217
218218class TestOpAMPHandler (TestCase ):
219219 @mock .patch .object (logging , "getLogger" )
220- def test_does_not_nothing_without_remote_config (self , get_logger_mock ):
220+ def test_does_nothing_without_remote_config (self , get_logger_mock ):
221221 message = opamp_pb2 .ServerToAgent ()
222+ agent = mock .Mock ()
222223 client = mock .Mock ()
223- opamp_handler (client , message )
224+ opamp_handler (agent , client , message )
224225
225226 get_logger_mock .assert_not_called ()
226227
227228 @mock .patch .object (logging , "getLogger" )
228229 def test_ignores_non_elastic_filename (self , get_logger_mock ):
230+ agent = mock .Mock ()
229231 client = mock .Mock ()
230232 config = opamp_pb2 .AgentConfigMap ()
231233 config .config_map ["non-elastic" ].body = json .dumps ({"logging_level" : "trace" }).encode ()
232234 config .config_map ["non-elastic" ].content_type = "application/json"
233- remote_config = opamp_pb2 .AgentRemoteConfig (config = config )
235+ remote_config = opamp_pb2 .AgentRemoteConfig (config = config , config_hash = b"1234" )
234236 message = opamp_pb2 .ServerToAgent (remote_config = remote_config )
235- opamp_handler (client , message )
237+ opamp_handler (agent , client , message )
236238
237239 get_logger_mock .assert_not_called ()
238240
241+ client ._update_remote_config_status .assert_called_once_with (
242+ remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
243+ )
244+ client ._build_remote_config_status_response_message .assert_called_once_with (
245+ client ._update_remote_config_status ()
246+ )
247+ agent .send .assert_called_once_with (payload = mock .ANY )
248+
239249 @mock .patch .object (logging , "getLogger" )
240250 def test_sets_matching_logging_level (self , get_logger_mock ):
251+ agent = mock .Mock ()
241252 client = mock .Mock ()
242253 config = opamp_pb2 .AgentConfigMap ()
243254 config .config_map ["elastic" ].body = json .dumps ({"logging_level" : "trace" }).encode ()
244255 config .config_map ["elastic" ].content_type = "application/json"
245- remote_config = opamp_pb2 .AgentRemoteConfig (config = config )
256+ remote_config = opamp_pb2 .AgentRemoteConfig (config = config , config_hash = b"1234" )
246257 message = opamp_pb2 .ServerToAgent (remote_config = remote_config )
247- opamp_handler (client , message )
258+ opamp_handler (agent , client , message )
248259
249260 get_logger_mock .assert_has_calls (
250261 [mock .call ("opentelemetry" ), mock .call ().setLevel (5 ), mock .call ("elasticotel" ), mock .call ().setLevel (5 )]
251262 )
252263
264+ client ._update_remote_config_status .assert_called_once_with (
265+ remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
266+ )
267+ client ._build_remote_config_status_response_message .assert_called_once_with (
268+ client ._update_remote_config_status ()
269+ )
270+ agent .send .assert_called_once_with (payload = mock .ANY )
271+
253272 @mock .patch .object (logging , "getLogger" )
254273 def test_sets_logging_to_default_info_without_logging_level_entry_in_config (self , get_logger_mock ):
274+ agent = mock .Mock ()
255275 client = mock .Mock ()
256276 config = opamp_pb2 .AgentConfigMap ()
257277 config .config_map ["elastic" ].body = json .dumps ({}).encode ()
258278 config .config_map ["elastic" ].content_type = "application/json"
259- remote_config = opamp_pb2 .AgentRemoteConfig (config = config )
279+ remote_config = opamp_pb2 .AgentRemoteConfig (config = config , config_hash = b"1234" )
260280 message = opamp_pb2 .ServerToAgent (remote_config = remote_config )
261- opamp_handler (client , message )
281+ opamp_handler (agent , client , message )
262282
263283 get_logger_mock .assert_has_calls (
264284 [
@@ -269,14 +289,28 @@ def test_sets_logging_to_default_info_without_logging_level_entry_in_config(self
269289 ]
270290 )
271291
292+ client ._update_remote_config_status .assert_called_once_with (
293+ remote_config_hash = b"1234" , status = opamp_pb2 .RemoteConfigStatuses_APPLIED , error_message = ""
294+ )
295+ client ._build_remote_config_status_response_message .assert_called_once_with (
296+ client ._update_remote_config_status ()
297+ )
298+ agent .send .assert_called_once_with (payload = mock .ANY )
299+
272300 @mock .patch .object (logging , "getLogger" )
273301 def test_warns_if_logging_level_does_not_match_our_map (self , get_logger_mock ):
302+ agent = mock .Mock ()
274303 client = mock .Mock ()
275304 config = opamp_pb2 .AgentConfigMap ()
276305 config .config_map ["elastic" ].body = json .dumps ({"logging_level" : "unexpected" }).encode ()
277306 config .config_map ["elastic" ].content_type = "application/json"
278- remote_config = opamp_pb2 .AgentRemoteConfig (config = config )
307+ remote_config = opamp_pb2 .AgentRemoteConfig (config = config , config_hash = b"1234" )
279308 message = opamp_pb2 .ServerToAgent (remote_config = remote_config )
280309
281310 with self .assertLogs (config_logger , logging .WARNING ):
282- opamp_handler (client , message )
311+ opamp_handler (agent , client , message )
312+
313+ client ._build_remote_config_status_response_message .assert_called_once_with (
314+ client ._update_remote_config_status ()
315+ )
316+ agent .send .assert_called_once_with (payload = mock .ANY )
0 commit comments