@@ -249,15 +249,27 @@ func (imts *IngestManagerTestSuite) processStateOnTheHost(process string, state
249249 return nil
250250}
251251
252- func startAgent (profile string , serviceName string ) error {
253- cmd := []string {"elastic-agent" , "run" }
254- err := execCommandInService (profile , serviceName , cmd , true )
252+ func execCommandInService (profile string , serviceName string , cmds []string , detach bool ) error {
253+ serviceManager := services .NewServiceManager ()
254+
255+ composes := []string {
256+ profile , // profile name
257+ serviceName , // service
258+ }
259+ composeArgs := []string {"exec" , "-T" }
260+ if detach {
261+ composeArgs = append (composeArgs , "-d" )
262+ }
263+ composeArgs = append (composeArgs , serviceName )
264+ composeArgs = append (composeArgs , cmds ... )
265+
266+ err := serviceManager .RunCommand (profile , composes , composeArgs , profileEnv )
255267 if err != nil {
256268 log .WithFields (log.Fields {
257- "command" : cmd ,
269+ "command" : cmds ,
258270 "error" : err ,
259271 "service" : serviceName ,
260- }).Error ("Could not run the agent " )
272+ }).Error ("Could not execute command in container " )
261273
262274 return err
263275 }
@@ -295,27 +307,15 @@ func getContainerHostname(containerName string) (string, error) {
295307 return hostname , nil
296308}
297309
298- func execCommandInService (profile string , serviceName string , cmds []string , detach bool ) error {
299- serviceManager := services .NewServiceManager ()
300-
301- composes := []string {
302- profile , // profile name
303- serviceName , // service
304- }
305- composeArgs := []string {"exec" , "-T" }
306- if detach {
307- composeArgs = append (composeArgs , "-d" )
308- }
309- composeArgs = append (composeArgs , serviceName )
310- composeArgs = append (composeArgs , cmds ... )
311-
312- err := serviceManager .RunCommand (profile , composes , composeArgs , profileEnv )
310+ func startAgent (profile string , serviceName string ) error {
311+ cmd := []string {"elastic-agent" , "run" }
312+ err := execCommandInService (profile , serviceName , cmd , true )
313313 if err != nil {
314314 log .WithFields (log.Fields {
315- "command" : cmds ,
315+ "command" : cmd ,
316316 "error" : err ,
317317 "service" : serviceName ,
318- }).Error ("Could not execute command in container " )
318+ }).Error ("Could not run the agent " )
319319
320320 return err
321321 }
0 commit comments