Skip to content

Commit

Permalink
feat(instance): use sbs images from marketplace on server create (#4466)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax authored Feb 4, 2025
1 parent 7c6d626 commit 4bcc0e3
Show file tree
Hide file tree
Showing 165 changed files with 45,739 additions and 62,495 deletions.
4 changes: 2 additions & 2 deletions internal/namespaces/instance/v1/custom_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func Test_ImageCreate(t *testing.T) {
t.Run("Create simple image", core.Test(&core.TestConfig{
BeforeFunc: core.BeforeFuncCombine(
createServer("Server"),
core.ExecStoreBeforeCmd("Server", testServerCommand("stopped=true image=ubuntu-jammy root-volume=l:20G")),
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
),
Commands: instance.GetCommands(),
Expand Down Expand Up @@ -77,7 +77,7 @@ func Test_ImageDelete(t *testing.T) {

func createImage(metaKey string) core.BeforeFunc {
return core.BeforeFuncCombine(
createServer("Server"),
core.ExecStoreBeforeCmd("Server", testServerCommand("stopped=true image=ubuntu-jammy root-volume=l:20G")),
core.ExecStoreBeforeCmd("Snapshot", `scw instance snapshot create volume-id={{ (index .Server.Volumes "0").ID }}`),
core.ExecStoreBeforeCmd(metaKey, `scw instance image create snapshot-id={{ .Snapshot.Snapshot.ID }} arch=x86_64`),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (sb *ServerBuilder) isWindows() bool {

func (sb *ServerBuilder) rootVolumeIsSBS() bool {
if sb.rootVolume == nil {
return false
return true // Default to SBS if no volume type is requested. Local SSD is now only on explicit request.
}

return sb.rootVolume.VolumeType == instance.VolumeVolumeTypeSbsVolume
Expand Down
34 changes: 17 additions & 17 deletions internal/namespaces/instance/v1/custom_server_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,42 +43,42 @@ func Test_CreateServer(t *testing.T) {

t.Run("GP1-XS", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: "scw instance server create type=GP1-XS image=ubuntu_bionic stopped=true",
Cmd: "scw instance server create type=GP1-XS image=ubuntu_jammy stopped=true",
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
assert.Equal(t, "GP1-XS", ctx.Result.(*instanceSDK.Server).CommercialType)
},
core.TestCheckExitCode(0),
),
AfterFunc: deleteServerAfterFunc(),
}))

t.Run("With name", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic name=yo stopped=true"),
Cmd: testServerCommand("image=ubuntu_jammy name=yo stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
assert.Equal(t, "yo", ctx.Result.(*instanceSDK.Server).Name)
},
core.TestCheckExitCode(0),
),
AfterFunc: deleteServerAfterFunc(),
}))

t.Run("With start", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic -w"),
Cmd: testServerCommand("image=ubuntu_jammy -w"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
assert.Equal(t, instanceSDK.ServerStateRunning, ctx.Result.(*instanceSDK.Server).State)
},
core.TestCheckExitCode(0),
),
AfterFunc: deleteServerAfterFunc(),
}))
Expand All @@ -99,15 +99,15 @@ func Test_CreateServer(t *testing.T) {

t.Run("Tags", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic tags.0=prod tags.1=blue stopped=true"),
Cmd: testServerCommand("image=ubuntu_jammy tags.0=prod tags.1=blue stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
assert.NotNil(t, ctx.Result)
assert.Equal(t, "prod", ctx.Result.(*instanceSDK.Server).Tags[0])
assert.Equal(t, "blue", ctx.Result.(*instanceSDK.Server).Tags[1])
},
core.TestCheckExitCode(0),
),
AfterFunc: deleteServerAfterFunc(),
}))
Expand Down Expand Up @@ -226,7 +226,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("valid additional block volumes", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic additional-volumes.0=b:1G additional-volumes.1=b:5G additional-volumes.2=b:10G stopped=true"),
Cmd: testServerCommand("image=ubuntu_jammy additional-volumes.0=b:1G additional-volumes.1=b:5G additional-volumes.2=b:10G stopped=true"),
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
testServerSBSVolumeSize("1", 1),
Expand Down Expand Up @@ -365,7 +365,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("IPs", func(t *testing.T) {
t.Run("explicit new IP", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic ip=new stopped=true"),
Cmd: testServerCommand("ip=new stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
Expand All @@ -382,7 +382,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("run with dynamic IP", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic ip=dynamic -w"), // dynamic IP is created at runtime
Cmd: testServerCommand("ip=dynamic -w"), // dynamic IP is created at runtime
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
Expand All @@ -401,7 +401,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("existing IP", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: createIP("IP"),
Cmd: testServerCommand("image=ubuntu_bionic ip={{ .IP.Address }} stopped=true"),
Cmd: testServerCommand("ip={{ .IP.Address }} stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
Expand All @@ -419,7 +419,7 @@ func Test_CreateServer(t *testing.T) {
t.Run("existing IP ID", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: createIP("IP"),
Cmd: testServerCommand("image=ubuntu_bionic ip={{ .IP.ID }} stopped=true"),
Cmd: testServerCommand("ip={{ .IP.ID }} stopped=true"),
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
Expand All @@ -436,7 +436,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic ip=ipv6 dynamic-ip-required=false -w"), // IPv6 is created at runtime
Cmd: testServerCommand("ip=ipv6 dynamic-ip-required=false -w"), // IPv6 is created at runtime
Check: core.TestCheckCombine(
func(t *testing.T, ctx *core.CheckFuncCtx) {
t.Helper()
Expand All @@ -452,7 +452,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6 and dynamic ip", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic dynamic-ip-required=true ip=ipv6 -w"), // IPv6 is created at runtime
Cmd: testServerCommand("dynamic-ip-required=true ip=ipv6 -w"), // IPv6 is created at runtime
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand All @@ -470,7 +470,7 @@ func Test_CreateServer(t *testing.T) {

t.Run("with ipv6 and ipv4", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_bionic ip=both -w"), // IPv6 is created at runtime
Cmd: testServerCommand("ip=both -w"), // IPv6 is created at runtime
Check: core.TestCheckCombine(
core.TestCheckExitCode(0),
func(t *testing.T, ctx *core.CheckFuncCtx) {
Expand Down Expand Up @@ -573,7 +573,7 @@ func Test_CreateServerErrors(t *testing.T) {

t.Run("Error: invalid total local volumes size: too high 2", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
Cmd: testServerCommand("image=ubuntu_jammy additional-volumes.0=local:20GB"),
Cmd: testServerCommand("image=ubuntu_jammy additional-volumes.0=local:30GB"),
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(1),
Expand Down
2 changes: 1 addition & 1 deletion internal/namespaces/instance/v1/custom_server_ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Test_ServerSSH(t *testing.T) {

t.Run("Stopped server", core.Test(&core.TestConfig{
Commands: instance.GetCommands(),
BeforeFunc: createServerBionic("Server"),
BeforeFunc: createServer("Server"),
Cmd: "scw instance server ssh {{ .Server.ID }}",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
Expand Down
Loading

0 comments on commit 4bcc0e3

Please sign in to comment.