Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package commands
const clientDialTimeoutInSeconds = 5
const sourceTimeoutInSeconds = 15
const emtSoftwareUpdateTimerInSeconds = 1200
const defaultSoftwareUpdateTimerInSeconds = 660
const defaultSoftwareUpdateTimerInSeconds = 72000
const configTimeoutInSeconds = 15
const firmwareUpdateTimerInSeconds = 90
const queryTimeoutInSeconds = 15
26 changes: 14 additions & 12 deletions in-band-manageability/internal/os_updater/ubuntu/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"google.golang.org/protobuf/encoding/protojson"
)

const aptLockTimeoutOption = "Dpkg::Lock::Timeout=300"

// Updater is the concrete implementation of the Updater interface
// for the Ubuntu OS.
type Updater struct {
Expand Down Expand Up @@ -214,11 +216,11 @@ func GetEstimatedSize(cmdExec common.Executor, packageList []string) (bool, uint
// If specific packages are requested, check those; otherwise check system-wide upgrade
if len(packageList) > 0 {
// For specific packages: apt-get install --dry-run <packages>
cmd = append([]string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o",
cmd = append([]string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold", "-u", "install", "--assume-no"}, packageList...)
} else {
// For system-wide upgrade
cmd = []string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o",
cmd = []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}
}

Expand Down Expand Up @@ -315,17 +317,17 @@ func noDownload(packages []string) [][]string {
log.Println("No download mode")
cmds := [][]string{
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold", "-yq", "-f", "install"},
}

if len(packages) == 0 {
cmds = append(cmds, []string{common.AptGetCmd, "-o",
cmds = append(cmds, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o",
"Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold",
"--with-new-pkgs", "--fix-missing", "-yq", "upgrade"})
} else {
cmds = append(cmds, [][]string{append([]string{common.AptGetCmd, "-o",
cmds = append(cmds, [][]string{append([]string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o",
"Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold",
"--fix-missing", "-yq",
Expand Down Expand Up @@ -429,17 +431,17 @@ func downloadOnly(packages []string) [][]string {

cmds := [][]string{
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
{common.AptGetCmd, "update"},
{common.AptGetCmd, "-o", aptLockTimeoutOption, "update"},
}

if len(packages) == 0 {
cmds = append(cmds, []string{common.AptGetCmd, "-o",
cmds = append(cmds, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o",
"Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold",
"--with-new-pkgs", "--download-only",
"--fix-missing", "-yq", "upgrade"})
} else {
cmds = append(cmds, [][]string{append([]string{common.AptGetCmd, "-o",
cmds = append(cmds, [][]string{append([]string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o",
"Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold", "--download-only",
"--fix-missing", "-yq", "install"}, packages...)}...)
Expand All @@ -452,15 +454,15 @@ func fullInstall(packages []string) [][]string {
log.Println("Download and install mode")

cmds := [][]string{
{common.AptGetCmd, "update"},
{common.AptGetCmd, "-yq", "-f", "install"}, // Fix broken dependencies
{common.AptGetCmd, "-o", aptLockTimeoutOption, "update"},
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-yq", "-f", "install"}, // Fix broken dependencies
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
}

if len(packages) == 0 {
cmds = append(cmds, []string{common.AptGetCmd, "-yq", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "upgrade"})
cmds = append(cmds, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-yq", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "upgrade"})
} else {
cmds = append(cmds, []string{common.AptGetCmd, "-yq", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install"})
cmds = append(cmds, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-yq", "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "install"})
cmds = append(cmds, packages)
}

Expand Down
26 changes: 13 additions & 13 deletions in-band-manageability/internal/os_updater/ubuntu/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func TestNoDownload(t *testing.T) {
t.Run("no packages", func(t *testing.T) {
expectedCmds := [][]string{
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold", "-yq", "-f", "install"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef",
"-o", "Dpkg::Options::=--force-confold",
"--with-new-pkgs",
"--fix-missing", "-yq", "upgrade"},
Expand All @@ -67,9 +67,9 @@ func TestNoDownload(t *testing.T) {
packages := []string{"package1", "package2"}
expectedCmds := [][]string{
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o",
"Dpkg::Options::=--force-confold", "-yq", "-f", "install"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef",
"-o", "Dpkg::Options::=--force-confold",
"--fix-missing", "-yq",
"install", "package1", "package2"},
Expand All @@ -85,8 +85,8 @@ func TestDownloadOnly(t *testing.T) {
t.Run("no packages", func(t *testing.T) {
expectedCmds := [][]string{
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
{common.AptGetCmd, "update"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "update"},
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef",
"-o", "Dpkg::Options::=--force-confold",
"--with-new-pkgs", "--download-only", "--fix-missing",
"-yq", "upgrade"},
Expand All @@ -101,8 +101,8 @@ func TestDownloadOnly(t *testing.T) {
packages := []string{"package1", "package2"}
expectedCmds := [][]string{
{common.DpkgCmd, "--configure", "-a", "--force-confdef", "--force-confold"},
{common.AptGetCmd, "update"},
{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef",
{common.AptGetCmd, "-o", aptLockTimeoutOption, "update"},
{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef",
"-o", "Dpkg::Options::=--force-confold",
"--download-only", "--fix-missing",
"-yq", "install", "package1", "package2"},
Expand All @@ -125,7 +125,7 @@ func TestGetEstimatedSize(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, uint64(0), size)
assert.Equal(t, 1, len(mockExec.commands))
assert.Equal(t, []string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
assert.Equal(t, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
})

t.Run("successful size estimation", func(t *testing.T) {
Expand All @@ -140,7 +140,7 @@ func TestGetEstimatedSize(t *testing.T) {
assert.True(t, isUpdateAvail)
assert.Equal(t, uint64(524288000), size)
assert.Equal(t, 1, len(mockExec.commands))
assert.Equal(t, []string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
assert.Equal(t, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
})

t.Run("failed to get size estimation", func(t *testing.T) {
Expand All @@ -155,7 +155,7 @@ func TestGetEstimatedSize(t *testing.T) {
assert.False(t, isUpdateAvail)
assert.Equal(t, uint64(0), size)
assert.Equal(t, 1, len(mockExec.commands))
assert.Equal(t, []string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
assert.Equal(t, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
})

t.Run("no size information in output", func(t *testing.T) {
Expand All @@ -169,7 +169,7 @@ func TestGetEstimatedSize(t *testing.T) {
assert.False(t, isUpdateAvail)
assert.Equal(t, uint64(0), size)
assert.Equal(t, 1, len(mockExec.commands))
assert.Equal(t, []string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
assert.Equal(t, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
})

t.Run("command execution error but valid output", func(t *testing.T) {
Expand All @@ -184,7 +184,7 @@ func TestGetEstimatedSize(t *testing.T) {
assert.True(t, isUpdateAvail)
assert.Equal(t, uint64(524288000), size)
assert.Equal(t, 1, len(mockExec.commands))
assert.Equal(t, []string{common.AptGetCmd, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
assert.Equal(t, []string{common.AptGetCmd, "-o", aptLockTimeoutOption, "-o", "Dpkg::Options::=--force-confdef", "-o", "Dpkg::Options::=--force-confold", "--with-new-pkgs", "-u", "upgrade", "--assume-no"}, mockExec.commands[0])
})
}

Expand Down
Loading