Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Oct 3, 2024
2 parents 7763267 + 45c24e5 commit c3450d2
Show file tree
Hide file tree
Showing 31 changed files with 1,452 additions and 478 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
12 changes: 12 additions & 0 deletions cmd/completion/size.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,15 @@ func (c *Completion) SizeListCompletion(cmd *cobra.Command, args []string, toCom
}
return names, cobra.ShellCompDirectiveNoFileComp
}

func (c *Completion) SizeReservationsListCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
resp, err := c.client.Size().ListSizeReservations(size.NewListSizeReservationsParams(), nil)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, s := range resp.Payload {
names = append(names, *s.ID)
}
return names, cobra.ShellCompDirectiveNoFileComp
}
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
112 changes: 96 additions & 16 deletions cmd/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,45 @@ var (
State: machine1.State,
Tags: machine1.Tags,
}
ipmiMachine2 = &models.V1MachineIPMIResponse{
Allocation: machine1.Allocation,
Bios: &models.V1MachineBIOS{
Version: pointer.Pointer("2.0"),
},
Changed: machine1.Changed,
Created: machine1.Created,
Description: machine1.Description,
Events: machine1.Events,
Hardware: machine1.Hardware,
ID: machine1.ID,
Ipmi: &models.V1MachineIPMI{
Address: pointer.Pointer("1.2.3.4"),
Bmcversion: pointer.Pointer("1.1"),
Fru: &models.V1MachineFru{
BoardPartNumber: "part123",
ChassisPartSerial: "chassis123",
ProductSerial: "product123",
},
LastUpdated: pointer.Pointer(strfmt.DateTime(testTime.Add(-5 * time.Second))),
Mac: pointer.Pointer("1.2.3.4"),
Powermetric: &models.V1PowerMetric{
Averageconsumedwatts: pointer.Pointer(float32(16.0)),
},
Powerstate: pointer.Pointer("ON"),
Powersupplies: []*models.V1PowerSupply{
{Status: &models.V1PowerSupplyStatus{Health: pointer.Pointer("OK")}},
{Status: &models.V1PowerSupplyStatus{Health: pointer.Pointer("NOT-OK")}},
},
},
Ledstate: &models.V1ChassisIdentifyLEDState{},
Liveliness: machine1.Liveliness,
Name: machine1.Name,
Partition: machine1.Partition,
Rackid: machine1.Rackid,
Size: machine1.Size,
State: machine1.State,
Tags: machine1.Tags,
}

machineIssue1 = &models.V1MachineIssue{
Description: pointer.Pointer("this is a test issue 1"),
Expand Down Expand Up @@ -458,21 +497,62 @@ func Test_MachineIPMICmd_MultiResult(t *testing.T) {
ipmiMachine1,
},
wantTable: pointer.Pointer(`
ID POWER IP MAC BOARD PART NUMBER BIOS BMC SIZE PARTITION RACK UPDATED
1 ●  (16.0W) 1.2.3.4 1.2.3.4 part123 2.0 1.1 1 1 rack-1 5s ago
ID POWER IP MAC BOARD PART NUMBER BIOS BMC SIZE PARTITION RACK UPDATED
1 ⏻ 16W 1.2.3.4 1.2.3.4 part123 2.0 1.1 1 1 rack-1 5s ago
`),
wantWideTable: pointer.Pointer(`
ID LAST EVENT STATUS POWER IP MAC BOARD PART NUMBER CHASSIS SERIAL PRODUCT SERIAL BIOS VERSION BMC VERSION SIZE PARTITION RACK UPDATED
1 Phoned Home ON 16W 1.2.3.4 1.2.3.4 part123 chassis123 product123 2.0 1.1 1 1 rack-1 5s ago
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
1 machine-1
`),
wantMarkdown: pointer.Pointer(`
| ID | | POWER | IP | MAC | BOARD PART NUMBER | BIOS | BMC | SIZE | PARTITION | RACK | UPDATED |
|----|--|-------|---------|---------|-------------------|------|-----|------|-----------|--------|---------|
| 1 | | ⏻ 16W | 1.2.3.4 | 1.2.3.4 | part123 | 2.0 | 1.1 | 1 | 1 | rack-1 | 5s ago |
`),
},
{
name: "machine ipmi with broken powersupply",
cmd: func(want []*models.V1MachineIPMIResponse) []string {
return []string{"machine", "ipmi"}
},
mocks: &client.MetalMockFns{
Machine: func(mock *mock.Mock) {
mock.On("FindIPMIMachines", testcommon.MatchIgnoreContext(t, machine.NewFindIPMIMachinesParams().WithBody(&models.V1MachineFindRequest{
NicsMacAddresses: nil,
NetworkDestinationPrefixes: []string{},
NetworkIps: []string{},
NetworkIds: []string{},
Tags: []string{},
})), nil).Return(&machine.FindIPMIMachinesOK{
Payload: []*models.V1MachineIPMIResponse{
ipmiMachine2,
},
}, nil)
},
},
want: []*models.V1MachineIPMIResponse{
ipmiMachine2,
},
wantTable: pointer.Pointer(`
ID POWER IP MAC BOARD PART NUMBER BIOS BMC SIZE PARTITION RACK UPDATED
1 ⏻ 16W 1.2.3.4 1.2.3.4 part123 2.0 1.1 1 1 rack-1 5s ago
`),
wantWideTable: pointer.Pointer(`
ID LAST EVENT STATUS POWER IP MAC BOARD PART NUMBER CHASSIS SERIAL PRODUCT SERIAL BIOS VERSION BMC VERSION SIZE PARTITION RACK UPDATED
1 Phoned Home ON 16.00W 1.2.3.4 1.2.3.4 part123 chassis123 product123 2.0 1.1 1 1 rack-1 5s ago
ID LAST EVENT STATUS POWER IP MAC BOARD PART NUMBER CHASSIS SERIAL PRODUCT SERIAL BIOS VERSION BMC VERSION SIZE PARTITION RACK UPDATED
1 Phoned Home ON Power Supply NOT-OK 16W 1.2.3.4 1.2.3.4 part123 chassis123 product123 2.0 1.1 1 1 rack-1 5s ago
`),
template: pointer.Pointer("{{ .id }} {{ .name }}"),
wantTemplate: pointer.Pointer(`
1 machine-1
`),
wantMarkdown: pointer.Pointer(`
| ID | | POWER | IP | MAC | BOARD PART NUMBER | BIOS | BMC | SIZE | PARTITION | RACK | UPDATED |
|----|--|------------|---------|---------|-------------------|------|-----|------|-----------|--------|---------|
| 1 | | ●  (16.0W) | 1.2.3.4 | 1.2.3.4 | part123 | 2.0 | 1.1 | 1 | 1 | rack-1 | 5s ago |
| ID | | POWER | IP | MAC | BOARD PART NUMBER | BIOS | BMC | SIZE | PARTITION | RACK | UPDATED |
|----|--|-------|---------|---------|-------------------|------|-----|------|-----------|--------|---------|
| 1 | | ⏻ 16W | 1.2.3.4 | 1.2.3.4 | part123 | 2.0 | 1.1 | 1 | 1 | rack-1 | 5s ago |
`),
},
}
Expand Down Expand Up @@ -586,21 +666,21 @@ func Test_MachineIssuesCmd(t *testing.T) {
},
want: machineWithIssues,
wantTable: pointer.Pointer(`
ID POWER ALLOCATED LOCK REASON LAST EVENT WHEN ISSUES
1 ●  (16.0W) yes state Phoned Home 7d this is a test issue 1 (issue-1-id)
this is a test issue 2 (issue-2-id)
ID POWER ALLOCATED LOCK REASON LAST EVENT WHEN ISSUES
1 ⏻ 16W yes state Phoned Home 7d this is a test issue 1 (issue-1-id)
this is a test issue 2 (issue-2-id)
`),
wantWideTable: pointer.Pointer(`
ID NAME PARTITION PROJECT POWER STATE LOCK REASON LAST EVENT WHEN ISSUES REF URL DETAILS
1 machine-1 1 project-1 ON 16.00W state Phoned Home 7d this is a test issue 1 (issue-1-id) https://url-1 more details 1
ID NAME PARTITION PROJECT POWER STATE LOCK REASON LAST EVENT WHEN ISSUES REF URL DETAILS
1 machine-1 1 project-1 ON 16W state Phoned Home 7d this is a test issue 1 (issue-1-id) https://url-1 more details 1
this is a test issue 2 (issue-2-id) https://url-2 more details 2
`),
wantMarkdown: pointer.Pointer(`
| ID | POWER | ALLOCATED | | LOCK REASON | LAST EVENT | WHEN | ISSUES |
|----|------------|-----------|--|-------------|-------------|------|-------------------------------------|
| 1 | ●  (16.0W) | yes | | state | Phoned Home | 7d | this is a test issue 1 (issue-1-id) |
| | | | | | | | this is a test issue 2 (issue-2-id) |
| ID | POWER | ALLOCATED | | LOCK REASON | LAST EVENT | WHEN | ISSUES |
|----|-------|-----------|--|-------------|-------------|------|-------------------------------------|
| 1 | ⏻ 16W | yes | | state | Phoned Home | 7d | this is a test issue 1 (issue-1-id) |
| | | | | | | | this is a test issue 2 (issue-2-id) |
`),
},
}
Expand Down
96 changes: 48 additions & 48 deletions cmd/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,16 +267,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 @@ -291,39 +291,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 @@ -346,16 +346,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 @@ -370,39 +370,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
Loading

0 comments on commit c3450d2

Please sign in to comment.