Skip to content

Commit

Permalink
Merge pull request #1246 from katiewasnothere/endpoint_settings_add_nic
Browse files Browse the repository at this point in the history
Add endpoint settings to add nic call
  • Loading branch information
katiewasnothere authored Jan 6, 2022
2 parents e093fbd + bfd6382 commit 422eb31
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 132 deletions.
27 changes: 27 additions & 0 deletions cmd/ncproxy/ncproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ func (s *grpcService) AddNIC(ctx context.Context, req *ncproxygrpc.AddNICRequest
return nil, err
}

settings := req.EndpointSettings.GetHcnEndpoint()
if settings != nil && settings.Policies != nil && settings.Policies.IovPolicySettings != nil {
log.G(ctx).WithField("iov settings", settings.Policies.IovPolicySettings).Info("AddNIC iov settings")
iovReqSettings := settings.Policies.IovPolicySettings
if iovReqSettings.IovOffloadWeight != 0 {
// IOV policy was set during add nic request, update the hcn endpoint
hcnIOVSettings := &hcn.IovPolicySetting{
IovOffloadWeight: iovReqSettings.IovOffloadWeight,
QueuePairsRequested: iovReqSettings.QueuePairsRequested,
InterruptModeration: iovReqSettings.InterruptModeration,
}
rawJSON, err := json.Marshal(hcnIOVSettings)
if err != nil {
return nil, err
}

iovPolicy := hcn.EndpointPolicy{
Type: hcn.IOV,
Settings: rawJSON,
}
policies := []hcn.EndpointPolicy{iovPolicy}
if err := modifyEndpoint(ctx, ep.Id, policies, hcn.RequestTypeUpdate); err != nil {
return nil, errors.Wrap(err, "failed to add policy to endpoint")
}
}
}

agent, err := s.containerIDToComputeAgent.get(req.ContainerID)
if err == nil {
caReq := &computeagent.AddNICInternalRequest{
Expand Down
41 changes: 33 additions & 8 deletions cmd/ncproxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,12 @@ func TestAddNIC_HCN(t *testing.T) {
mockedService.EXPECT().AddNIC(gomock.Any(), gomock.Any()).Return(&computeagent.AddNICInternalResponse{}, nil).AnyTimes()

type config struct {
name string
containerID string
nicID string
endpointName string
errorExpected bool
name string
containerID string
nicID string
endpointName string
iovPolicySettings *ncproxygrpc.IovEndpointPolicySetting
errorExpected bool
}
tests := []config{
{
Expand Down Expand Up @@ -197,22 +198,46 @@ func TestAddNIC_HCN(t *testing.T) {
endpointName: "",
errorExpected: true,
},
{
name: "AddNIC returns no error with iov policy set",
containerID: containerID,
nicID: testNICID,
endpointName: "",
iovPolicySettings: &ncproxygrpc.IovEndpointPolicySetting{
IovOffloadWeight: 100,
},
errorExpected: false,
},
}

for _, test := range tests {
t.Run(test.name, func(_ *testing.T) {
t.Run(test.name, func(subtest *testing.T) {
endpointSettings := &ncproxygrpc.HcnEndpointSettings{}
if test.iovPolicySettings != nil {
if osversion.Build() < osversion.V21H1 {
subtest.Skip("Requires build +21H1")
}
endpointSettings.Policies = &ncproxygrpc.HcnEndpointPolicies{
IovPolicySettings: test.iovPolicySettings,
}
}
req := &ncproxygrpc.AddNICRequest{
ContainerID: test.containerID,
NicID: test.nicID,
EndpointName: test.endpointName,
EndpointSettings: &ncproxygrpc.EndpointSettings{
Settings: &ncproxygrpc.EndpointSettings_HcnEndpoint{
HcnEndpoint: endpointSettings,
},
},
}

_, err := gService.AddNIC(ctx, req)
if test.errorExpected && err == nil {
t.Fatalf("expected AddNIC to return an error")
subtest.Fatalf("expected AddNIC to return an error")
}
if !test.errorExpected && err != nil {
t.Fatalf("expected AddNIC to return no error, instead got %v", err)
subtest.Fatalf("expected AddNIC to return no error, instead got %v", err)
}
})
}
Expand Down
Loading

0 comments on commit 422eb31

Please sign in to comment.