@@ -15,16 +15,19 @@ import (
15
15
"context"
16
16
"encoding/json"
17
17
"errors"
18
+ "fmt"
18
19
"net"
19
20
"net/http"
20
21
"net/http/httptest"
21
22
"os"
22
23
"path/filepath"
23
24
"strings"
25
+ "sync"
24
26
"testing"
25
27
"time"
26
28
27
29
"github.com/elastic/elastic-agent-client/v7/pkg/proto"
30
+ "github.com/elastic/elastic-agent/internal/pkg/fleetapi/acker"
28
31
"github.com/elastic/elastic-agent/internal/pkg/testutils"
29
32
30
33
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/status"
@@ -41,9 +44,11 @@ import (
41
44
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
42
45
"github.com/elastic/elastic-agent/internal/pkg/agent/application/monitoring/reload"
43
46
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
47
+ "github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
44
48
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
45
49
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
46
50
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
51
+ upgradeErrors "github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download/errors"
47
52
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/details"
48
53
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
49
54
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
@@ -1977,3 +1982,100 @@ func TestHasEndpoint(t *testing.T) {
1977
1982
})
1978
1983
}
1979
1984
}
1985
+
1986
+ type mockUpgradeManager struct {
1987
+ upgradeErr error
1988
+ }
1989
+
1990
+ func (m * mockUpgradeManager ) Upgradeable () bool {
1991
+ return true
1992
+ }
1993
+
1994
+ func (m * mockUpgradeManager ) Reload (cfg * config.Config ) error {
1995
+ return nil
1996
+ }
1997
+
1998
+ func (m * mockUpgradeManager ) Upgrade (ctx context.Context , version string , rollback bool , sourceURI string , action * fleetapi.ActionUpgrade , details * details.Details , skipVerifyOverride bool , skipDefaultPgp bool , pgpBytes ... string ) (_ reexec.ShutdownCallbackFn , err error ) {
1999
+ return nil , m .upgradeErr
2000
+ }
2001
+
2002
+ func (m * mockUpgradeManager ) Ack (ctx context.Context , acker acker.Acker ) error {
2003
+ return nil
2004
+ }
2005
+
2006
+ func (m * mockUpgradeManager ) AckAction (ctx context.Context , acker acker.Acker , action fleetapi.Action ) error {
2007
+ return nil
2008
+ }
2009
+
2010
+ func (m * mockUpgradeManager ) MarkerWatcher () upgrade.MarkerWatcher {
2011
+ return nil
2012
+ }
2013
+
2014
+ func TestCoordinator_Upgrade_InsufficientDiskSpaceError (t * testing.T ) {
2015
+ log , _ := loggertest .New ("coordinator-insufficient-disk-space-test" )
2016
+
2017
+ mockUpgradeManager := & mockUpgradeManager {
2018
+ upgradeErr : fmt .Errorf ("wrapped: %w" , upgradeErrors .ErrInsufficientDiskSpace ),
2019
+ }
2020
+
2021
+ initialState := State {
2022
+ CoordinatorState : agentclient .Healthy ,
2023
+ CoordinatorMessage : "Running" ,
2024
+ }
2025
+
2026
+ coord := & Coordinator {
2027
+ state : initialState ,
2028
+ logger : log ,
2029
+ upgradeMgr : mockUpgradeManager ,
2030
+ stateBroadcaster : broadcaster .New (initialState , 64 , 32 ),
2031
+ overrideStateChan : make (chan * coordinatorOverrideState ),
2032
+ upgradeDetailsChan : make (chan * details.Details ),
2033
+ }
2034
+
2035
+ wg := sync.WaitGroup {}
2036
+ wg .Add (2 )
2037
+
2038
+ overrideStates := []agentclient.State {}
2039
+ go func () {
2040
+ state1 := <- coord .overrideStateChan
2041
+ overrideStates = append (overrideStates , state1 .state )
2042
+
2043
+ state2 := <- coord .overrideStateChan
2044
+ if state2 != nil {
2045
+ overrideStates = append (overrideStates , state2 .state )
2046
+ }
2047
+
2048
+ wg .Done ()
2049
+ }()
2050
+
2051
+ upgradeDetails := []* details.Details {}
2052
+ go func () {
2053
+ upgradeDetails = append (upgradeDetails , <- coord .upgradeDetailsChan )
2054
+ upgradeDetails = append (upgradeDetails , <- coord .upgradeDetailsChan )
2055
+ wg .Done ()
2056
+ }()
2057
+
2058
+ err := coord .Upgrade (t .Context (), "" , "" , nil )
2059
+ require .Error (t , err )
2060
+ require .Equal (t , err , upgradeErrors .ErrInsufficientDiskSpace )
2061
+
2062
+ wg .Wait ()
2063
+
2064
+ require .Equal (t , []agentclient.State {agentclient .Upgrading }, overrideStates )
2065
+
2066
+ require .Equal (t , []* details.Details {
2067
+ {
2068
+ TargetVersion : "" ,
2069
+ State : details .StateRequested ,
2070
+ ActionID : "" ,
2071
+ },
2072
+ {
2073
+ TargetVersion : "" ,
2074
+ State : details .StateFailed ,
2075
+ Metadata : details.Metadata {
2076
+ FailedState : details .StateRequested ,
2077
+ ErrorMsg : upgradeErrors .ErrInsufficientDiskSpace .Error (),
2078
+ },
2079
+ },
2080
+ }, upgradeDetails )
2081
+ }
0 commit comments