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
2 changes: 1 addition & 1 deletion cmd/completion/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func (c *Completion) AuditPhase(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{apiv2.AuditPhase_AUDIT_PHASE_REQUEST.String(), apiv2.AuditPhase_AUDIT_PHASE_RESPONSE.String()}, cobra.ShellCompDirectiveNoFileComp
return c.genericEnums(apiv2.AuditPhase_name)
}

func (c *Completion) AuditStatusCodes(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down
14 changes: 14 additions & 0 deletions cmd/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@ type Completion struct {
func OutputFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"table", "wide", "markdown", "json", "yaml", "template"}, cobra.ShellCompDirectiveNoFileComp
}

func (c *Completion) genericEnums(enums map[int32]string) ([]string, cobra.ShellCompDirective) {
var names []string

for id, name := range enums {
if id == 0 {
// skip UNSPECIFIED
continue
}
names = append(names, name)
}

return names, cobra.ShellCompDirectiveNoFileComp
}
8 changes: 1 addition & 7 deletions cmd/completion/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,5 @@ import (
)

func (c *Completion) ComponentTypes(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var names []string

for _, name := range apiv2.ComponentType_name {
names = append(names, name)
}

return names, cobra.ShellCompDirectiveNoFileComp
return c.genericEnums(apiv2.ComponentType_name)
}
8 changes: 1 addition & 7 deletions cmd/completion/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,5 @@ func (c *Completion) Firewall(cmd *cobra.Command, args []string, toComplete stri
}

func (c *Completion) BMCCommands(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
var names []string

for _, name := range apiv2.MachineBMCCommand_name {
names = append(names, name)
}

return names, cobra.ShellCompDirectiveNoFileComp
return c.genericEnums(apiv2.MachineBMCCommand_name)
}
4 changes: 2 additions & 2 deletions cmd/tableprinters/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (t *TablePrinter) SwitchTable(switches []*apiv2.Switch, wide bool) ([]strin
rows [][]string
)

header := []string{"ID", "Partition", "Rack", "OS", "Status", "Last Sync"}
header := []string{"ID", "Partition", "Rack", "OS", "Metalcore", "Status", "Last Sync"}
if wide {
header = []string{"ID", "Partition", "Rack", "OS", "Metalcore", "IP", "Mode", "Last Sync", "Sync Duration", "Last Error"}
t.t.DisableAutoWrap(true)
Expand Down Expand Up @@ -171,7 +171,7 @@ func (t *TablePrinter) SwitchTable(switches []*apiv2.Switch, wide bool) ([]strin
if wide {
rows = append(rows, []string{id, partition, rack, os, metalCore, s.ManagementIp, mode, syncLast, syncDurStr, lastError})
} else {
rows = append(rows, []string{id, partition, rack, osIcon, shortStatus, syncLast})
rows = append(rows, []string{id, partition, rack, osIcon, metalCore, shortStatus, syncLast})
}
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/tableprinters/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestTablePrinter_SwitchTable(t *testing.T) {
name: "switches empty",
switches: []*apiv2.Switch{},
wide: false,
wantHeader: []string{"ID", "Partition", "Rack", "OS", "Status", "Last Sync"},
wantHeader: []string{"ID", "Partition", "Rack", "OS", "Metalcore", "Status", "Last Sync"},
wantRows: nil,
},
{
Expand Down Expand Up @@ -266,15 +266,15 @@ func TestTablePrinter_SwitchTable(t *testing.T) {
},
},
wide: false,
wantHeader: []string{"ID", "Partition", "Rack", "OS", "Status", "Last Sync"},
wantHeader: []string{"ID", "Partition", "Rack", "OS", "Metalcore", "Status", "Last Sync"},
wantRows: [][]string{
// FIXME: color of the dots is ignored; how to test for correct colors?
{"r01leaf01", "partition-a", "rack01", "🦔", color.GreenString(dot), "0s ago"}, // status green but error because one port is not in its desired state
{"r01leaf02", "partition-a", "rack01", "🐢", nbr + color.RedString(dot), "0s ago"}, // status red because in replace mode
{"r02leaf01", "partition-a", "rack02", apiv2.SwitchOSVendor_SWITCH_OS_VENDOR_UNSPECIFIED.String(), color.RedString(dot), "1h ago"}, // status red because last error came later than last sync
{"r02leaf02", "partition-a", "rack02", "", color.RedString(dot), "10m ago"}, // status red because last sync is too long ago
{"r03leaf01", "partition-a", "rack03", "", color.YellowString(dot), "0s ago"}, // status yellow because last sync duration was too long
{"r03leaf02", "partition-a", "rack03", "", color.YellowString(dot), ""}, // status yellow because not all connceted ports are up
{"r01leaf01", "partition-a", "rack01", "🦔", "", color.GreenString(dot), "0s ago"}, // status green but error because one port is not in its desired state
{"r01leaf02", "partition-a", "rack01", "🐢", "", nbr + color.RedString(dot), "0s ago"}, // status red because in replace mode
{"r02leaf01", "partition-a", "rack02", apiv2.SwitchOSVendor_SWITCH_OS_VENDOR_UNSPECIFIED.String(), "", color.RedString(dot), "1h ago"}, // status red because last error came later than last sync
{"r02leaf02", "partition-a", "rack02", "", "", color.RedString(dot), "10m ago"}, // status red because last sync is too long ago
{"r03leaf01", "partition-a", "rack03", "", "", color.YellowString(dot), "0s ago"}, // status yellow because last sync duration was too long
{"r03leaf02", "partition-a", "rack03", "", "", color.YellowString(dot), ""}, // status yellow because not all connceted ports are up
},
},
{
Expand Down
24 changes: 12 additions & 12 deletions tests/e2e/admin/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func Test_AdminSwitchCmd_List(t *testing.T) {
},
}),
WantTable: new(`
ID PARTITION RACK OS STATUS LAST SYNC
leaf01 fra-equ01 rack-1 🦔
leaf02 fra-equ01 rack-1 🦔 ●
ID PARTITION RACK OS METALCORE STATUS LAST SYNC
leaf01 fra-equ01 rack-1 🦔 v0.9.1 (abc1234) ●
leaf02 fra-equ01 rack-1 🦔 v0.9.1 (abc1234)
`),
WantWideTable: new(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST ERROR
Expand All @@ -99,10 +99,10 @@ leaf01 fra-equ01
leaf02 fra-equ01
`),
WantMarkdown: new(`
| ID | PARTITION | RACK | OS | STATUS | LAST SYNC |
|--------|-----------|--------|----|--------|-----------|
| leaf01 | fra-equ01 | rack-1 | 🦔 | ● | |
| leaf02 | fra-equ01 | rack-1 | 🦔 | ● | |
| ID | PARTITION | RACK | OS | METALCORE | STATUS | LAST SYNC |
|--------|-----------|--------|----|------------------|--------|-----------|
| leaf01 | fra-equ01 | rack-1 | 🦔 | v0.9.1 (abc1234) | ● | |
| leaf02 | fra-equ01 | rack-1 | 🦔 | v0.9.1 (abc1234) | ● | |
`),
},
}
Expand Down Expand Up @@ -167,8 +167,8 @@ func Test_AdminSwitchCmd_Update(t *testing.T) {
},
}),
WantTable: new(`
ID PARTITION RACK OS STATUS LAST SYNC
leaf02 fra-equ01 rack-1 🦔 ●
ID PARTITION RACK OS METALCORE STATUS LAST SYNC
leaf02 fra-equ01 rack-1 🦔 v0.9.1 (abc1234)
`),
WantWideTable: new(`
ID PARTITION RACK OS METALCORE IP MODE LAST SYNC SYNC DURATION LAST ERROR
Expand All @@ -177,9 +177,9 @@ func Test_AdminSwitchCmd_Update(t *testing.T) {
Template: new("{{ .id }} {{ .os.metal_core_version }}"),
WantTemplate: new(`leaf02 v0.9.1 (abc1234), tags/v0.9.1`),
WantMarkdown: new(`
| ID | PARTITION | RACK | OS | STATUS | LAST SYNC |
|--------|-----------|--------|----|--------|-----------|
| leaf02 | fra-equ01 | rack-1 | 🦔 | ● | |
| ID | PARTITION | RACK | OS | METALCORE | STATUS | LAST SYNC |
|--------|-----------|--------|----|------------------|--------|-----------|
| leaf02 | fra-equ01 | rack-1 | 🦔 | v0.9.1 (abc1234) | ● | |
`),
},
}
Expand Down
Loading