Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine Registration must now contain Partition #583

Merged
merged 7 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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
Loading
Loading