Skip to content

Commit

Permalink
Improved partition capacity. (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 authored Sep 13, 2024
1 parent 4b7b53c commit ff31f7d
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 99 deletions.
3 changes: 3 additions & 0 deletions cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log/slog"
"os"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -65,6 +66,8 @@ func (c *test[R]) testCmd(t *testing.T) {
require.NotEmpty(t, c.name, "test name must not be empty")
require.NotEmpty(t, c.cmd, "cmd must not be empty")

t.Setenv(strings.ToUpper(binaryName)+"_FORCE_COLOR", strconv.FormatBool(false))

if c.wantErr != nil {
_, _, config := c.newMockConfig(t)

Expand Down
9 changes: 5 additions & 4 deletions cmd/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/metal-stack/metal-go/api/client/health"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-go/test/client"
"github.com/metal-stack/metal-lib/pkg/healthstatus"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metal-lib/pkg/testcommon"
"github.com/metal-stack/metal-lib/rest"
Expand All @@ -23,14 +24,14 @@ func Test_HealthCmd(t *testing.T) {
Health: func(mock *mock.Mock) {
mock.On("Health", testcommon.MatchIgnoreContext(t, health.NewHealthParams()), nil).Return(&health.HealthOK{
Payload: &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusHealthy)),
Status: pointer.Pointer(string(healthstatus.HealthStatusHealthy)),
Message: pointer.Pointer("ok"),
},
}, nil)
},
},
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
Message: "ok",
Services: nil,
},
Expand All @@ -44,14 +45,14 @@ func Test_HealthCmd(t *testing.T) {
Health: func(mock *mock.Mock) {
mock.On("Health", testcommon.MatchIgnoreContext(t, health.NewHealthParams()), nil).Return(nil, &health.HealthInternalServerError{
Payload: &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusUnhealthy)),
Status: pointer.Pointer(string(healthstatus.HealthStatusUnhealthy)),
Message: pointer.Pointer("error"),
},
})
},
},
want: &rest.HealthResponse{
Status: rest.HealthStatusUnhealthy,
Status: healthstatus.HealthStatusUnhealthy,
Message: "error",
Services: nil,
},
Expand Down
96 changes: 48 additions & 48 deletions cmd/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,16 @@ func Test_PartitionCapacityCmd(t *testing.T) {
Name: "partition-1",
Servers: []*models.V1ServerCapacity{
{
Allocated: pointer.Pointer(int32(1)),
Faulty: pointer.Pointer(int32(2)),
Allocated: 1,
Faulty: 2,
Faultymachines: []string{"abc"},
Free: pointer.Pointer(int32(3)),
Other: pointer.Pointer(int32(4)),
Free: 3,
Other: 4,
Othermachines: []string{"def"},
Size: pointer.Pointer("size-1"),
Total: pointer.Pointer(int32(5)),
Reservations: pointer.Pointer(int32(3)),
Usedreservations: pointer.Pointer(int32(1)),
Total: 5,
Reservations: 3,
Usedreservations: 1,
},
},
},
Expand All @@ -294,39 +294,39 @@ func Test_PartitionCapacityCmd(t *testing.T) {
Name: "partition-1",
Servers: []*models.V1ServerCapacity{
{
Allocated: pointer.Pointer(int32(1)),
Faulty: pointer.Pointer(int32(2)),
Allocated: 1,
Faulty: 2,
Faultymachines: []string{"abc"},
Free: pointer.Pointer(int32(3)),
Other: pointer.Pointer(int32(4)),
Free: 3,
Other: 4,
Othermachines: []string{"def"},
Size: pointer.Pointer("size-1"),
Total: pointer.Pointer(int32(5)),
Reservations: pointer.Pointer(int32(3)),
Usedreservations: pointer.Pointer(int32(1)),
Total: 5,
Reservations: 3,
Usedreservations: 1,
},
},
},
},
wantTable: pointer.Pointer(`
PARTITION SIZE TOTAL FREE ALLOCATED RESERVED OTHER FAULTY
1 size-1 5 3 1 1/3 4 2
Total 5 3 1 1/3 4 2
PARTITION SIZE ALLOCATED FREE UNAVAILABLE RESERVATIONS | TOTAL | FAULTY
1 size-1 1 3 0 2 (1/3 used) | 5 | 2
Total 1 3 0 2 | 5 | 2
`),
wantWideTable: pointer.Pointer(`
PARTITION SIZE TOTAL FREE ALLOCATED RESERVED OTHER FAULTY
1 size-1 5 3 1 1/3 def abc
Total 5 3 1 1/3 4 2
PARTITION SIZE ALLOCATED FREE UNAVAILABLE RESERVATIONS | TOTAL | FAULTY PHONED HOME WAITING OTHER
1 size-1 1 3 0 2 (1/3 used) | 5 | 2 0 0 4
Total 1 3 0 2 | 5 | 2 0 0 4
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
1 partition-1
`),
wantMarkdown: pointer.Pointer(`
| PARTITION | SIZE | TOTAL | FREE | ALLOCATED | RESERVED | OTHER | FAULTY |
|-----------|--------|-------|------|-----------|----------|-------|--------|
| 1 | size-1 | 5 | 3 | 1 | 1/3 | 4 | 2 |
| Total | | 5 | 3 | 1 | 1/3 | 4 | 2 |
| PARTITION | SIZE | ALLOCATED | FREE | UNAVAILABLE | RESERVATIONS | TOTAL | FAULTY |
|-----------|--------|-----------|------|-------------|--------------|-------|--------|
| 1 | size-1 | 1 | 3 | 0 | 2 (1/3 used) | 5 | 2 |
| Total | | 1 | 3 | 0 | 2 | 5 | 2 |
`),
},
{
Expand All @@ -349,16 +349,16 @@ Total 5 3 1 1/3 4 2
Name: "partition-1",
Servers: []*models.V1ServerCapacity{
{
Allocated: pointer.Pointer(int32(1)),
Faulty: pointer.Pointer(int32(2)),
Allocated: 1,
Faulty: 2,
Faultymachines: []string{"abc"},
Free: pointer.Pointer(int32(3)),
Other: pointer.Pointer(int32(4)),
Free: 3,
Other: 4,
Othermachines: []string{"def"},
Size: pointer.Pointer("size-1"),
Total: pointer.Pointer(int32(5)),
Reservations: pointer.Pointer(int32(3)),
Usedreservations: pointer.Pointer(int32(1)),
Total: 5,
Reservations: 3,
Usedreservations: 1,
},
},
},
Expand All @@ -373,39 +373,39 @@ Total 5 3 1 1/3 4 2
Name: "partition-1",
Servers: []*models.V1ServerCapacity{
{
Allocated: pointer.Pointer(int32(1)),
Faulty: pointer.Pointer(int32(2)),
Allocated: 1,
Faulty: 2,
Faultymachines: []string{"abc"},
Free: pointer.Pointer(int32(3)),
Other: pointer.Pointer(int32(4)),
Free: 3,
Other: 4,
Othermachines: []string{"def"},
Size: pointer.Pointer("size-1"),
Total: pointer.Pointer(int32(5)),
Reservations: pointer.Pointer(int32(3)),
Usedreservations: pointer.Pointer(int32(1)),
Total: 5,
Reservations: 3,
Usedreservations: 1,
},
},
},
},
wantTable: pointer.Pointer(`
PARTITION SIZE TOTAL FREE ALLOCATED RESERVED OTHER FAULTY
1 size-1 5 3 1 1/3 4 2
Total 5 3 1 1/3 4 2
PARTITION SIZE ALLOCATED FREE UNAVAILABLE RESERVATIONS | TOTAL | FAULTY
1 size-1 1 3 0 2 (1/3 used) | 5 | 2
Total 1 3 0 2 | 5 | 2
`),
wantWideTable: pointer.Pointer(`
PARTITION SIZE TOTAL FREE ALLOCATED RESERVED OTHER FAULTY
1 size-1 5 3 1 1/3 def abc
Total 5 3 1 1/3 4 2
PARTITION SIZE ALLOCATED FREE UNAVAILABLE RESERVATIONS | TOTAL | FAULTY PHONED HOME WAITING OTHER
1 size-1 1 3 0 2 (1/3 used) | 5 | 2 0 0 4
Total 1 3 0 2 | 5 | 2 0 0 4
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
1 partition-1
`),
wantMarkdown: pointer.Pointer(`
| PARTITION | SIZE | TOTAL | FREE | ALLOCATED | RESERVED | OTHER | FAULTY |
|-----------|--------|-------|------|-----------|----------|-------|--------|
| 1 | size-1 | 5 | 3 | 1 | 1/3 | 4 | 2 |
| Total | | 5 | 3 | 1 | 1/3 | 4 | 2 |
| PARTITION | SIZE | ALLOCATED | FREE | UNAVAILABLE | RESERVATIONS | TOTAL | FAULTY |
|-----------|--------|-----------|------|-------------|--------------|-------|--------|
| 1 | size-1 | 1 | 3 | 0 | 2 (1/3 used) | 5 | 2 |
| Total | | 1 | 3 | 0 | 2 | 5 | 2 |
`),
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/printers.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func newPrinterFromCLI(out io.Writer) printers.Printer {
NoHeaders: viper.GetBool("no-headers"),
}).WithOut(out)

tp.SetMarkdown(format == "markdown")
tp.SetPrinter(tablePrinter)
tp.SetLastEventErrorThreshold(viper.GetDuration("last-event-error-threshold"))

Expand Down
13 changes: 7 additions & 6 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/healthstatus"
"github.com/metal-stack/metal-lib/pkg/pointer"
"github.com/metal-stack/metal-lib/rest"
"github.com/spf13/afero"
Expand Down Expand Up @@ -38,7 +39,7 @@ func Test_BasicRootCmdStuff(t *testing.T) {
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write(mustMarshal(t, &models.RestHealthResponse{
Status: pointer.Pointer(string(rest.HealthStatusHealthy)),
Status: pointer.Pointer(string(healthstatus.HealthStatusHealthy)),
}))
if err != nil {
t.Errorf("error writing response: %s", err)
Expand All @@ -60,7 +61,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -76,7 +77,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -86,7 +87,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -98,7 +99,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
{
Expand All @@ -109,7 +110,7 @@ api-token: "i-am-token"
},
disableMockClient: true,
want: &rest.HealthResponse{
Status: rest.HealthStatusHealthy,
Status: healthstatus.HealthStatusHealthy,
},
},
}
Expand Down
Loading

0 comments on commit ff31f7d

Please sign in to comment.