Skip to content

Commit

Permalink
Merge pull request #104 from gmacf/resolve
Browse files Browse the repository at this point in the history
Refactor ResolveChassis() to return a bpb.Chassis.
  • Loading branch information
melzhan authored Dec 4, 2023
2 parents b8d7fb3 + 5eaa3c7 commit 2ea6d44
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion server/emulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (
bootzAddr = flag.String("bootz_addr", "15006", "The [ip:]port to start the Bootz server. When ip is not specified, the server starts on localhost")
dhcpIntf = flag.String("dhcp_intf", "", "Network interface to use for dhcp server.")
inventoryConfig = flag.String("inv_config", "../../testdata/inventory_local.prototxt", "Devices' config files to be loaded by inventory manager")
generateOVsFor = flag.String("generate_ovs_for", "123A", "Comma-separated list of control card serial numbers to generate OVs for.")
generateOVsFor = flag.String("generate_ovs_for", "123A,123B", "Comma-separated list of control card serial numbers to generate OVs for.")
)

// Convert address to localhost when no ip is specified.
Expand Down
4 changes: 2 additions & 2 deletions server/entitymanager/entitymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ type InMemoryEntityManager struct {

// ResolveChassis returns an entity based on the provided lookup.
// If a control card serial is provided, it also looks up chassis' by its control cards.
func (m *InMemoryEntityManager) ResolveChassis(ctx context.Context, lookup *service.EntityLookup, ccSerial string) (*service.ChassisEntity, error) {
func (m *InMemoryEntityManager) ResolveChassis(ctx context.Context, lookup *service.EntityLookup, ccSerial string) (*bpb.Chassis, error) {
chassis, err := m.lookupChassis(lookup, ccSerial)
if err != nil {
return nil, err
}
return &service.ChassisEntity{BootMode: chassis.GetBootMode()}, nil
return &bpb.Chassis{BootMode: chassis.BootMode}, nil
}

func (m *InMemoryEntityManager) lookupChassis(lookup *service.EntityLookup, ccSerial string) (*epb.Chassis, error) {
Expand Down
6 changes: 3 additions & 3 deletions server/entitymanager/entitymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ func TestResolveChassis(t *testing.T) {
tests := []struct {
desc string
input *service.EntityLookup
want *service.ChassisEntity
want *bpb.Chassis
wantErr bool
}{{
desc: "Default device",
input: &service.EntityLookup{
SerialNumber: "123",
Manufacturer: "Cisco",
},
want: &service.ChassisEntity{
want: &bpb.Chassis{
BootMode: bpb.BootMode_BOOT_MODE_SECURE,
},
}, {
Expand All @@ -247,7 +247,7 @@ func TestResolveChassis(t *testing.T) {
if (err != nil) != test.wantErr {
t.Fatalf("ResolveChassis(%v) err = %v, want %v", test.input, err, test.wantErr)
}
if !cmp.Equal(got, test.want) {
if !cmp.Equal(got, test.want, protocmp.Transform()) {
t.Errorf("ResolveChassis(%v) got %v, want %v", test.input, got, test.want)
}
})
Expand Down
8 changes: 1 addition & 7 deletions server/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,9 @@ type EntityLookup struct {
SerialNumber string
}

// ChassisEntity provides the mode that the system is currently
// configured.
type ChassisEntity struct {
BootMode bpb.BootMode
}

// EntityManager maintains the entities and their states.
type EntityManager interface {
ResolveChassis(context.Context, *EntityLookup, string) (*ChassisEntity, error)
ResolveChassis(context.Context, *EntityLookup, string) (*bpb.Chassis, error)
GetBootstrapData(context.Context, *EntityLookup, *bpb.ControlCard) (*bpb.BootstrapDataResponse, error)
SetStatus(context.Context, *bpb.ReportStatusRequest) error
Sign(context.Context, *bpb.GetBootstrapDataResponse, *EntityLookup, string) error
Expand Down
2 changes: 1 addition & 1 deletion testdata/inventory_local.prototxt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
options {
bootzserver: "bootzip:...."
gnsi_global_config:{
authz_upload_file:"../testdata/authz.prototext"
authz_upload_file:"../../testdata/authz.prototext"
}
}
chassis {
Expand Down

0 comments on commit 2ea6d44

Please sign in to comment.