Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
fix: enableUnattendedUpgrades not honored (#4987)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadarsie authored Oct 25, 2022
1 parent b218d4f commit 2ad1466
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/api/converterfromapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func convertLinuxProfileToVLabs(obj *LinuxProfile, vlabsProfile *vlabs.LinuxProf
vlabsProfile.CustomNodesDNS.DNSServer = obj.CustomNodesDNS.DNSServer
}
vlabsProfile.RunUnattendedUpgradesOnBootstrap = obj.RunUnattendedUpgradesOnBootstrap
vlabsProfile.EnableUnattendedUpgrades = obj.EnableUnattendedUpgrades
vlabsProfile.Eth0MTU = obj.Eth0MTU
}

Expand Down
82 changes: 82 additions & 0 deletions pkg/api/converterfromapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,3 +924,85 @@ func TestConvertComponentsToVlabs(t *testing.T) {
}
}
}

func TestConvertLinuxProfileToVlabs(t *testing.T) {
ssh := struct {
PublicKeys []vlabs.PublicKey `json:"publicKeys" validate:"required,min=1"`
}{
PublicKeys: []vlabs.PublicKey{},
}

cases := []struct {
name string
w LinuxProfile
expected vlabs.LinuxProfile
}{
{
name: "unattended upgrades on bootstrap",
w: LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
expected: vlabs.LinuxProfile{
Secrets: []vlabs.KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
},
{
name: "unattended upgrades on bootstrap",
w: LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
expected: vlabs.LinuxProfile{
Secrets: []vlabs.KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
},
{
name: "unattended upgrades on bootstrap",
w: LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
expected: vlabs.LinuxProfile{
Secrets: []vlabs.KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
},
{
name: "unattended upgrades on bootstrap",
w: LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
expected: vlabs.LinuxProfile{
Secrets: []vlabs.KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
actual := vlabs.LinuxProfile{}
convertLinuxProfileToVLabs(&c.w, &actual)

diff := cmp.Diff(actual, c.expected)

if diff != "" {
t.Errorf("unexpected diff testing convertLinuxProfileToVLabs: %s", diff)
}
})
}
}
1 change: 1 addition & 0 deletions pkg/api/convertertoapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func convertVLabsLinuxProfile(vlabs *vlabs.LinuxProfile, api *LinuxProfile) {
api.CustomNodesDNS.DNSServer = vlabs.CustomNodesDNS.DNSServer
}
api.RunUnattendedUpgradesOnBootstrap = vlabs.RunUnattendedUpgradesOnBootstrap
api.EnableUnattendedUpgrades = vlabs.EnableUnattendedUpgrades
api.Eth0MTU = vlabs.Eth0MTU
}

Expand Down
81 changes: 81 additions & 0 deletions pkg/api/convertertoapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,3 +1167,84 @@ func TestConvertComponentsToAPI(t *testing.T) {
}
}
}

func TestConvertVLabsLinuxProfile(t *testing.T) {
ssh := struct {
PublicKeys []PublicKey `json:"publicKeys"`
}{
PublicKeys: []PublicKey{},
}

cases := []struct {
name string
w vlabs.LinuxProfile
expected LinuxProfile
}{
{
name: "unattended upgrades on bootstrap",
w: vlabs.LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
expected: LinuxProfile{
Secrets: []KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
},
{
name: "unattended upgrades on bootstrap",
w: vlabs.LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
expected: LinuxProfile{
Secrets: []KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
},
{
name: "unattended upgrades on bootstrap",
w: vlabs.LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
expected: LinuxProfile{
Secrets: []KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(true),
EnableUnattendedUpgrades: to.BoolPtr(false),
},
},
{
name: "unattended upgrades on bootstrap",
w: vlabs.LinuxProfile{
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
expected: LinuxProfile{
Secrets: []KeyVaultSecrets{},
SSH: ssh,
RunUnattendedUpgradesOnBootstrap: to.BoolPtr(false),
EnableUnattendedUpgrades: to.BoolPtr(true),
},
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
t.Parallel()
actual := LinuxProfile{}
convertVLabsLinuxProfile(&c.w, &actual)

diff := cmp.Diff(actual, c.expected)
if diff != "" {
t.Errorf("unexpected diff testing convertVLabsLinuxProfile: %s", diff)
}
})
}
}

0 comments on commit 2ad1466

Please sign in to comment.