@@ -26,13 +26,12 @@ import (
2626 "github.com/elastic/elastic-agent-libs/mapstr"
2727 agentsystemprocess "github.com/elastic/elastic-agent-system-metrics/metric/system/process"
2828 "github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
29- "github.com/elastic/elastic-agent/pkg/control"
3029 "github.com/elastic/elastic-agent/pkg/control/v2/client"
3130 "github.com/elastic/elastic-agent/pkg/core/process"
3231)
3332
3433// ErrNotInstalled is returned in cases where Agent isn't installed
35- var ErrNotInstalled = errors .New ("Elastic Agent is not installed" ) //nolint:staticcheck // Elastic Agent is a proper noun
34+ var ErrNotInstalled = errors .New ("Elastic Agent is not installed" ) //nolint:stylecheck // Elastic Agent is a proper noun
3635
3736// CmdOpts creates vectors of command arguments for different agent commands
3837type CmdOpts interface {
@@ -331,12 +330,12 @@ func (f *Fixture) installNoPkgManager(ctx context.Context, installOpts *InstallO
331330
332331 // environment variable AGENT_KEEP_INSTALLED=true will skip the uninstallation
333332 // useful to debug the issue with the Elastic Agent
334- if f .t .Failed () && KeepInstalledFlag () {
333+ if f .t .Failed () && keepInstalledFlag () {
335334 f .t .Logf ("skipping uninstall; test failed and AGENT_KEEP_INSTALLED=true" )
336335 return
337336 }
338337
339- if KeepInstalledFlag () {
338+ if keepInstalledFlag () {
340339 f .t .Logf ("ignoring AGENT_KEEP_INSTALLED=true as test succeeded, " +
341340 "keeping the agent installed will jeopardise other tests" )
342341 }
@@ -446,19 +445,6 @@ func getProcesses(t *gotesting.T, regex string) []runningProcess {
446445 return processes
447446}
448447
449- func (f * Fixture ) SetDebRpmClient () error {
450- workDir := "/var/lib/elastic-agent"
451- socketPath , err := control .AddressFromPath (f .operatingSystem , workDir )
452- if err != nil {
453- return fmt .Errorf ("failed to get control protcol address: %w" , err )
454- }
455-
456- c := client .New (client .WithAddress (socketPath ))
457- f .setClient (c )
458-
459- return nil
460- }
461-
462448// installDeb installs the prepared Elastic Agent binary from the deb
463449// package and registers a t.Cleanup function to uninstall the agent if
464450// it hasn't been uninstalled. It also takes care of collecting a
@@ -496,7 +482,7 @@ func (f *Fixture) installDeb(ctx context.Context, installOpts *InstallOpts, shou
496482 f .t .Logf ("error systemctl stop elastic-agent: %s, output: %s" , err , string (out ))
497483 }
498484
499- if KeepInstalledFlag () {
485+ if keepInstalledFlag () {
500486 f .t .Logf ("skipping uninstall; test failed and AGENT_KEEP_INSTALLED=true" )
501487 return
502488 }
@@ -516,11 +502,6 @@ func (f *Fixture) installDeb(ctx context.Context, installOpts *InstallOpts, shou
516502 return out , fmt .Errorf ("systemctl start elastic-agent failed: %w" , err )
517503 }
518504
519- err = f .SetDebRpmClient ()
520- if err != nil {
521- return nil , err
522- }
523-
524505 if ! shouldEnroll {
525506 return nil , nil
526507 }
@@ -539,11 +520,11 @@ func (f *Fixture) installDeb(ctx context.Context, installOpts *InstallOpts, shou
539520 if installOpts .DelayEnroll {
540521 enrollArgs = append (enrollArgs , "--delay-enroll" )
541522 }
542- if installOpts .URL != "" {
543- enrollArgs = append (enrollArgs , "--url" , installOpts .URL )
523+ if installOpts .EnrollOpts . URL != "" {
524+ enrollArgs = append (enrollArgs , "--url" , installOpts .EnrollOpts . URL )
544525 }
545- if installOpts .EnrollmentToken != "" {
546- enrollArgs = append (enrollArgs , "--enrollment-token" , installOpts .EnrollmentToken )
526+ if installOpts .EnrollOpts . EnrollmentToken != "" {
527+ enrollArgs = append (enrollArgs , "--enrollment-token" , installOpts .EnrollOpts . EnrollmentToken )
547528 }
548529 out , err = exec .CommandContext (ctx , "sudo" , enrollArgs ... ).CombinedOutput ()
549530 if err != nil {
@@ -612,11 +593,6 @@ func (f *Fixture) installRpm(ctx context.Context, installOpts *InstallOpts, shou
612593 return out , fmt .Errorf ("systemctl start elastic-agent failed: %w" , err )
613594 }
614595
615- err = f .SetDebRpmClient ()
616- if err != nil {
617- return nil , err
618- }
619-
620596 if ! shouldEnroll {
621597 return nil , nil
622598 }
@@ -635,11 +611,11 @@ func (f *Fixture) installRpm(ctx context.Context, installOpts *InstallOpts, shou
635611 if installOpts .DelayEnroll {
636612 enrollArgs = append (enrollArgs , "--delay-enroll" )
637613 }
638- if installOpts .URL != "" {
639- enrollArgs = append (enrollArgs , "--url" , installOpts .URL )
614+ if installOpts .EnrollOpts . URL != "" {
615+ enrollArgs = append (enrollArgs , "--url" , installOpts .EnrollOpts . URL )
640616 }
641- if installOpts .EnrollmentToken != "" {
642- enrollArgs = append (enrollArgs , "--enrollment-token" , installOpts .EnrollmentToken )
617+ if installOpts .EnrollOpts . EnrollmentToken != "" {
618+ enrollArgs = append (enrollArgs , "--enrollment-token" , installOpts .EnrollOpts . EnrollmentToken )
643619 }
644620 // run sudo elastic-agent enroll
645621 out , err = exec .CommandContext (ctx , "sudo" , enrollArgs ... ).CombinedOutput ()
@@ -746,7 +722,7 @@ func (f *Fixture) uninstallNoPkgManager(ctx context.Context, uninstallOpts *Unin
746722 }
747723
748724 if err != nil && topPathStats != nil {
749- return out , fmt .Errorf ("Elastic Agent is still installed at [%s]" , topPath ) //nolint:staticcheck // Elastic Agent is a proper noun
725+ return out , fmt .Errorf ("Elastic Agent is still installed at [%s]" , topPath ) //nolint:stylecheck // Elastic Agent is a proper noun
750726 }
751727
752728 return out , nil
@@ -849,7 +825,7 @@ func collectDiagFlag() bool {
849825 return v
850826}
851827
852- func KeepInstalledFlag () bool {
828+ func keepInstalledFlag () bool {
853829 // failure reports false (ignore error)
854830 v , _ := strconv .ParseBool (os .Getenv ("AGENT_KEEP_INSTALLED" ))
855831 return v
0 commit comments