Skip to content

Commit

Permalink
Machine Registration must now contain Partition (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Nov 12, 2024
1 parent 0b41d8d commit 0d83e33
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 203 deletions.
6 changes: 5 additions & 1 deletion cmd/metal-api/internal/datastore/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ func (rs *RethinkStore) SetVrfAtSwitches(m *metal.Machine, vrf string) (metal.Sw
}

func (rs *RethinkStore) ConnectMachineWithSwitches(m *metal.Machine) error {
switches, err := rs.ListSwitches()
if m.PartitionID == "" {
return fmt.Errorf("partitionID is empty in machine:%s", m.ID)
}
var switches metal.Switches
err := rs.SearchSwitches(&SwitchSearchQuery{PartitionID: &m.PartitionID}, &switches)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/metal-api/internal/grpc/boot-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@ func (b *BootService) Register(ctx context.Context, req *v1.BootServiceRegisterR
Value: metal.LEDStateOff,
Description: "Machine registered",
},
Tags: req.Tags,
IPMI: ipmi,
Tags: req.Tags,
IPMI: ipmi,
PartitionID: req.PartitionId,
}

err = b.ds.CreateMachine(m)
Expand Down Expand Up @@ -269,7 +270,7 @@ func (b *BootService) Register(ctx context.Context, req *v1.BootServiceRegisterR
old := *m
err = retry.Do(
func() error {
// RackID and PartitionID is set
// RackID is set here
err := b.ds.ConnectMachineWithSwitches(m)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/metal-api/internal/grpc/boot-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func TestBootService_Register(t *testing.T) {
testdata.InitMockDBData(mock)

req := &v1.BootServiceRegisterRequest{
Uuid: tt.uuid,
Uuid: tt.uuid,
PartitionId: "1",
Hardware: &v1.MachineHardware{
Memory: tt.memory,
Disks: []*v1.MachineBlockDevice{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ func TestMachineAllocationIntegrationFullCycle(t *testing.T) {

// Register a machine
mrr := &grpcv1.BootServiceRegisterRequest{
Uuid: "test-uuid",
Uuid: "test-uuid",
PartitionId: "test-partition",
Bios: &grpcv1.MachineBIOS{
Version: "a",
Vendor: "metal",
Expand Down
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/service/switch-service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func TestConnectMachineWithSwitches(t *testing.T) {
for i := range tests {
tt := tests[i]
ds, mock := datastore.InitMockDB(t)
mock.On(r.DB("mockdb").Table("switch")).Return(testSwitches, nil)
mock.On(r.DB("mockdb").Table("switch").Filter(r.MockAnything())).Return(testSwitches, nil)
mock.On(r.DB("mockdb").Table("switch").Get(r.MockAnything()).Replace(r.MockAnything())).Return(testdata.EmptyResult, nil)

t.Run(tt.name, func(t *testing.T) {
Expand Down
402 changes: 206 additions & 196 deletions pkg/api/v1/boot.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions proto/api/v1/boot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ message BootServiceRegisterRequest {
MachineIPMI ipmi = 4;
repeated string tags = 5;
string metal_hammer_version = 6;
string partition_id = 7;
}

message BootServiceRegisterResponse {
Expand Down

0 comments on commit 0d83e33

Please sign in to comment.