Skip to content

Commit

Permalink
Roll out new autoupdater to nightly channel only
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Oct 11, 2023
1 parent 9d74f80 commit 12a0a45
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 48 deletions.
11 changes: 10 additions & 1 deletion cmd/launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,16 @@ func runSubcommands() error {
func runNewerLauncherIfAvailable(ctx context.Context, logger log.Logger) {
newerBinary, err := latestLauncherPath(ctx, logger)
if err != nil {
level.Info(logger).Log("msg", "could not get updated version", "err", err)
level.Error(logger).Log(
"msg", "could not check out latest launcher, will fall back to old autoupdate library",
"err", err,
)

// Fall back to legacy autoupdate library
newerBinary, err = autoupdate.FindNewestSelf(ctx)
if err != nil {
return
}
}

if newerBinary == "" {
Expand Down
28 changes: 11 additions & 17 deletions pkg/autoupdate/tuf/autoupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,15 @@ func TestExecute_launcherUpdate(t *testing.T) {
// Assert expectation that we added the expected `testReleaseVersion` to the updates library
mockLibraryManager.AssertExpectations(t)

// In the future, we expect that we'd restart launcher. For now, we don't want unnecessary restarts.
/*
// Check log lines to confirm that we see the log `received interrupt to restart launcher after update, stopping`, indicating that
// the autoupdater shut down at the end
logLines := strings.Split(strings.TrimSpace(logBytes.String()), "\n")
// We expect at least 1 log for the shutdown line.
require.GreaterOrEqual(t, len(logLines), 1)
// Check that we shut down
require.Contains(t, logLines[len(logLines)-1], "received interrupt to restart launcher after update, stopping")
*/
// Check log lines to confirm that we see the log `received interrupt to restart launcher after update, stopping`, indicating that
// the autoupdater shut down at the end
logLines := strings.Split(strings.TrimSpace(logBytes.String()), "\n")

// We expect at least 1 log for the shutdown line.
require.GreaterOrEqual(t, len(logLines), 1)

// Check that we shut down
require.Contains(t, logLines[len(logLines)-1], "received interrupt to restart launcher after update, stopping")
}

func TestExecute_launcherUpdate_noRestartIfUsingLegacyAutoupdater(t *testing.T) {
Expand Down Expand Up @@ -280,11 +277,8 @@ func TestExecute_osquerydUpdate(t *testing.T) {
// We expect at least 1 log for the restart line.
require.GreaterOrEqual(t, len(logLines), 1)

// // In the future, we expect that we'd restart osquery. For now, we don't want unnecessary restarts.
/*
// Check that we restarted osqueryd
require.Contains(t, logLines[len(logLines)-1], "restarted binary after update")
*/
// Check that we restarted osqueryd
require.Contains(t, logLines[len(logLines)-1], "restarted binary after update")

// The autoupdater won't stop after an osqueryd download, so interrupt it and let it shut down
autoupdater.Interrupt(errors.New("test error"))
Expand Down
4 changes: 3 additions & 1 deletion pkg/autoupdate/tuf/library_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type autoupdateConfig struct {
localDevelopmentPath string
}

var channelsUsingNewAutoupdater = map[string]bool{}
var channelsUsingNewAutoupdater = map[string]bool{
"nightly": true,
}

// CheckOutLatestWithoutConfig returns information about the latest downloaded executable for our binary,
// searching for launcher configuration values in its config file.
Expand Down
40 changes: 11 additions & 29 deletions pkg/autoupdate/tuf/library_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"github.com/stretchr/testify/require"
)

func TestCheckOutLatest_withTufRepository(t *testing.T) { //nolint: paralleltest
channelsUsingNewAutoupdater["nightly"] = true
defer func() {
delete(channelsUsingNewAutoupdater, "nightly")
}()
func TestCheckOutLatest_withTufRepository(t *testing.T) {
t.Parallel()

for _, binary := range binaries { //nolint: paralleltest
for _, binary := range binaries {
binary := binary
t.Run(string(binary), func(t *testing.T) {
t.Parallel()

// Set up an update library
rootDir := t.TempDir()
updateDir := defaultLibraryDirectory(rootDir)
Expand Down Expand Up @@ -53,15 +52,13 @@ func TestCheckOutLatest_withTufRepository(t *testing.T) { //nolint: paralleltest
}
}

func TestCheckOutLatest_withoutTufRepository(t *testing.T) { // nolint:paralleltest
channelsUsingNewAutoupdater["nightly"] = true
defer func() {
delete(channelsUsingNewAutoupdater, "nightly")
}()

for _, binary := range binaries { //nolint: paralleltest
func TestCheckOutLatest_withoutTufRepository(t *testing.T) {
t.Parallel()
for _, binary := range binaries {
binary := binary
t.Run(string(binary), func(t *testing.T) {
t.Parallel()

// Set up an update library, but no TUF repo
rootDir := t.TempDir()
updateDir := defaultLibraryDirectory(rootDir)
Expand Down Expand Up @@ -101,21 +98,6 @@ func TestCheckOutLatest_NotAvailableOnNonNightlyChannels(t *testing.T) {
}
}

func TestUsingNewAutoupdater(t *testing.T) {
t.Parallel()

for _, binary := range binaries {
binary := binary
for _, channel := range []string{"beta", "stable", "nightly", "alpha"} {
channel := channel
t.Run(fmt.Sprintf("%s-%s", binary, channel), func(t *testing.T) {
t.Parallel()
require.False(t, UsingNewAutoupdater())
})
}
}
}

func Test_mostRecentVersion(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -207,7 +189,7 @@ func Test_usingNewAutoupdater(t *testing.T) {
}{
{
channelName: "nightly",
usesNewAutoupdater: false,
usesNewAutoupdater: true,
},
{
channelName: "alpha",
Expand Down

0 comments on commit 12a0a45

Please sign in to comment.