@@ -447,14 +447,26 @@ func getProcesses(t *gotesting.T, regex string) []runningProcess {
447447}
448448
449449func (f * Fixture ) SetClient () error {
450+ f .t .Logf ("[SetClient] Attempting to get control protocol address for OS: %s, workDir: %s" , f .operatingSystem , f .workDir )
450451 socketPath , err := control .AddressFromPath (f .operatingSystem , f .workDir )
451452 if err != nil {
453+ f .t .Logf ("[SetClient] Failed to get control protcol address: %v" , err )
452454 return fmt .Errorf ("failed to get control protcol address: %w" , err )
453455 }
456+ f .t .Logf ("[SetClient] Using socket path: %s" , socketPath )
454457
455458 c := client .New (client .WithAddress (socketPath ))
456459 f .setClient (c )
457-
460+ f .t .Logf ("[SetClient] Client set, attempting to ping agent via client..." )
461+ // Try a simple operation to verify the client is usable
462+ ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
463+ defer cancel ()
464+ _ , err = c .State (ctx )
465+ if err != nil {
466+ f .t .Logf ("[SetClient] WARNING: Unable to communicate with agent via client (State call failed): %v" , err )
467+ } else {
468+ f .t .Logf ("[SetClient] Successfully communicated with agent via client (State call succeeded)." )
469+ }
458470 return nil
459471}
460472
@@ -466,65 +478,68 @@ func (f *Fixture) SetClient() error {
466478// - the combined output of Install command stdout and stderr
467479// - an error if any.
468480func (f * Fixture ) installDeb (ctx context.Context , installOpts * InstallOpts , shouldEnroll bool , opts []process.CmdOption ) ([]byte , error ) {
469- f .t .Logf ("[test %s] Inside fixture installDeb function " , f .t . Name () )
481+ f .t .Logf ("[installDeb] Starting installDeb for package: %s " , f .srcPackage )
470482 // Prepare so that the f.srcPackage string is populated
471483 err := f .EnsurePrepared (ctx )
472484 if err != nil {
485+ f .t .Logf ("[installDeb] EnsurePrepared failed: %v" , err )
473486 return nil , fmt .Errorf ("failed to prepare: %w" , err )
474487 }
475488
476- // sudo apt-get install the deb
489+ f . t . Logf ( "[installDeb] Running apt-get install for: %s" , f . srcPackage )
477490 cmd := exec .CommandContext (ctx , "sudo" , "-E" , "apt-get" , "install" , "-y" , f .srcPackage ) // #nosec G204 -- Need to pass in name of package
478491 if installOpts .InstallServers {
479492 cmd .Env = append (cmd .Env , "ELASTIC_AGENT_FLAVOR=servers" )
480493 }
481494 out , err := cmd .CombinedOutput () // #nosec G204 -- Need to pass in name of package
495+ f .t .Logf ("[installDeb] apt-get install output: %s" , string (out ))
482496 if err != nil {
497+ f .t .Logf ("[installDeb] apt-get install failed: %v" , err )
483498 return out , fmt .Errorf ("apt install failed: %w output:%s" , err , string (out ))
484499 }
485500
486501 f .t .Cleanup (func () {
487- f .t .Logf ("[test %s] Inside fixture installDeb cleanup function" , f .t .Name ())
488-
502+ f .t .Logf ("[installDeb] Inside fixture installDeb cleanup function" )
489503 uninstallCtx , uninstallCancel := context .WithTimeout (context .Background (), 5 * time .Minute )
490504 defer uninstallCancel ()
491- // stop elastic-agent, non fatal if error, might have been stopped before this.
492- f .t .Logf ("running 'sudo systemctl stop elastic-agent'" )
505+ f .t .Logf ("[installDeb] running 'sudo systemctl stop elastic-agent'" )
493506 out , err := exec .CommandContext (uninstallCtx , "sudo" , "systemctl" , "stop" , "elastic-agent" ).CombinedOutput ()
494507 if err != nil {
495- f .t .Logf ("error systemctl stop elastic-agent: %s, output: %s" , err , string (out ))
508+ f .t .Logf ("[installDeb] error systemctl stop elastic-agent: %s, output: %s" , err , string (out ))
496509 }
497-
498510 if KeepInstalledFlag () {
499- f .t .Logf ("skipping uninstall; test failed and AGENT_KEEP_INSTALLED=true" )
511+ f .t .Logf ("[installDeb] skipping uninstall; test failed and AGENT_KEEP_INSTALLED=true" )
500512 return
501513 }
502-
503- // apt-get purge elastic-agent
504- f .t .Logf ("running 'sudo apt-get -y -q purge elastic-agent'" )
514+ f .t .Logf ("[installDeb] running 'sudo apt-get -y -q purge elastic-agent'" )
505515 out , err = exec .CommandContext (uninstallCtx , "sudo" , "apt-get" , "-y" , "-q" , "purge" , "elastic-agent" ).CombinedOutput ()
506516 if err != nil {
507- f .t .Logf ("failed to apt-get purge elastic-agent: %s, output: %s" , err , string (out ))
517+ f .t .Logf ("[installDeb] failed to apt-get purge elastic-agent: %s, output: %s" , err , string (out ))
508518 f .t .FailNow ()
509519 }
510520 })
511521
512- // start elastic-agent
522+ f . t . Logf ( "[installDeb] Starting elastic-agent service" )
513523 out , err = exec .CommandContext (ctx , "sudo" , "systemctl" , "start" , "elastic-agent" ).CombinedOutput ()
524+ f .t .Logf ("[installDeb] systemctl start output: %s" , string (out ))
514525 if err != nil {
526+ f .t .Logf ("[installDeb] systemctl start elastic-agent failed: %v" , err )
515527 return out , fmt .Errorf ("systemctl start elastic-agent failed: %w" , err )
516528 }
517529
530+ f .t .Logf ("[installDeb] Calling SetClient after starting agent" )
518531 err = f .SetClient ()
519532 if err != nil {
533+ f .t .Logf ("[installDeb] SetClient failed: %v" , err )
520534 return nil , err
521535 }
522536
523537 if ! shouldEnroll {
538+ f .t .Logf ("[installDeb] shouldEnroll is false, skipping enrollment step." )
524539 return nil , nil
525540 }
526541
527- // apt install doesn't enroll, so need to do that
542+ f . t . Logf ( "[installDeb] Running elastic-agent enroll" )
528543 enrollArgs := []string {"elastic-agent" , "enroll" }
529544 if installOpts .Force {
530545 enrollArgs = append (enrollArgs , "--force" )
@@ -544,11 +559,15 @@ func (f *Fixture) installDeb(ctx context.Context, installOpts *InstallOpts, shou
544559 if installOpts .EnrollmentToken != "" {
545560 enrollArgs = append (enrollArgs , "--enrollment-token" , installOpts .EnrollmentToken )
546561 }
562+ f .t .Logf ("[installDeb] enroll command: %v" , enrollArgs )
547563 out , err = exec .CommandContext (ctx , "sudo" , enrollArgs ... ).CombinedOutput ()
564+ f .t .Logf ("[installDeb] enroll output: %s" , string (out ))
548565 if err != nil {
566+ f .t .Logf ("[installDeb] elastic-agent enroll failed: %v" , err )
549567 return out , fmt .Errorf ("elastic-agent enroll failed: %w, output: %s args: %v" , err , string (out ), enrollArgs )
550568 }
551569
570+ f .t .Logf ("[installDeb] installDeb completed successfully." )
552571 return nil , nil
553572}
554573
0 commit comments