Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 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
33 changes: 25 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,35 @@ docker-build:
docker build -t $(IMAGE_REGISTRY)/carbide-psm:$(IMAGE_TAG) -f $(DOCKERFILE_DIR)/Dockerfile.carbide-psm .
docker build -t $(IMAGE_REGISTRY)/carbide-nsm:$(IMAGE_TAG) -f $(DOCKERFILE_DIR)/Dockerfile.carbide-nsm .

carbide-proto:
if [ -d "carbide-core" ]; then cd carbide-core && git pull; else git clone ssh://git@github.com/nvidia/carbide-core.git; fi
ls carbide-core/rpc/proto
@for file in carbide-core/rpc/proto/*.proto; do \
core-proto: core-proto-fetch core-proto-fmt core-protogen

core-proto-clean:
@echo "Cleaning up Core proto and protobuf files"
rm -rf workflow-schema/site-agent/workflows/v1/*_carbide.proto
rm -rf workflow-schema/schema/site-agent/workflows/v1/*.pb.go

core-proto-repo ?= NVIDIA/ncx-infra-controller-core
Comment thread
pbreton marked this conversation as resolved.
core-proto-repo-ssh:=ssh://git@github.com/$(core-proto-repo).git
core-proto-ref ?= origin/main
core-proto-fetch:
@echo "Fetching Core protobuf files from $(core-proto-repo-ssh) at $(core-proto-ref). Customize with make core-proto-repo=your-repo core-proto-ref=your-ref"
if [ -d "nico-core" ]; then rm -rf nico-core; fi
git clone $(core-proto-repo-ssh) nico-core;
cd nico-core && git fetch $(core-proto-repo-ssh) && git reset --hard $(core-proto-ref);
ls nico-core/crates/rpc/proto
@for file in nico-core/crates/rpc/proto/*.proto; do \
cp "$$file" "workflow-schema/site-agent/workflows/v1/$$(basename "$$file" .proto)_carbide.proto"; \
echo "Copied: $$file"; \
./workflow-schema/scripts/add-go-package-option.sh "workflow-schema/site-agent/workflows/v1/$$(basename "$$file" .proto)_carbide.proto" "github.com/NVIDIA/ncx-infra-controller-rest/workflow-schema/proto"; \
done
rm -rf carbide-core
echo "Successfully copied Core protobuf files"
rm -rf nico-core

carbide-protogen:
echo "Generating protobuf for Carbide"
core-proto-fmt:
@echo "Formatting Core protobuf files"
cd workflow-schema/cmd/core-proto-fmt && go run main.go

core-protogen:
echo "Generating protobuf for Core"
cd workflow-schema && buf generate

rla-proto:
Expand Down
4 changes: 2 additions & 2 deletions api/pkg/api/handler/expectedpowershelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (cepsh CreateExpectedPowerShelfHandler) Handle(c echo.Context) error {
}

if expectedPowerShelf.IpAddress != nil {
createExpectedPowerShelfRequest.IpAddress = *expectedPowerShelf.IpAddress
createExpectedPowerShelfRequest.BmcIpAddress = *expectedPowerShelf.IpAddress
}

if expectedPowerShelf.RackID != nil {
Expand Down Expand Up @@ -725,7 +725,7 @@ func (uepsh UpdateExpectedPowerShelfHandler) Handle(c echo.Context) error {
}

if updatedExpectedPowerShelf.IpAddress != nil {
updateExpectedPowerShelfRequest.IpAddress = *updatedExpectedPowerShelf.IpAddress
updateExpectedPowerShelfRequest.BmcIpAddress = *updatedExpectedPowerShelf.IpAddress
}

if updatedExpectedPowerShelf.RackID != nil {
Expand Down
10 changes: 5 additions & 5 deletions api/pkg/api/handler/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (cih CreateInstanceHandler) buildInstanceCreateRequestOsConfig(c echo.Conte
RunProvisioningInstructionsOnEveryBoot: *apiRequest.AlwaysBootWithCustomIpxe, // Set by the earlier call to ValidateAndSetOperatingSystemData
PhoneHomeEnabled: *apiRequest.PhoneHomeEnabled, // Set by the earlier call to ValidateAndSetOperatingSystemData
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *apiRequest.IpxeScript,
},
},
Expand Down Expand Up @@ -193,7 +193,7 @@ func (cih CreateInstanceHandler) buildInstanceCreateRequestOsConfig(c echo.Conte
RunProvisioningInstructionsOnEveryBoot: *apiRequest.AlwaysBootWithCustomIpxe,
PhoneHomeEnabled: *apiRequest.PhoneHomeEnabled,
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *apiRequest.IpxeScript,
},
},
Expand Down Expand Up @@ -1858,7 +1858,7 @@ func (uih UpdateInstanceHandler) buildInstanceUpdateRequestOsConfig(c echo.Conte
RunProvisioningInstructionsOnEveryBoot: instance.AlwaysBootWithCustomIpxe,
PhoneHomeEnabled: *apiRequest.PhoneHomeEnabled, // Set by the earlier call to ValidateAndSetOperatingSystemData
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *apiRequest.IpxeScript,
},
},
Expand Down Expand Up @@ -2000,7 +2000,7 @@ func (uih UpdateInstanceHandler) buildInstanceUpdateRequestOsConfig(c echo.Conte
RunProvisioningInstructionsOnEveryBoot: alwaysBootWithCustomIpxe,
PhoneHomeEnabled: phoneHomeEnabled,
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *ipxeScript,
},
},
Expand All @@ -2023,7 +2023,7 @@ func (uih UpdateInstanceHandler) buildInstanceUpdateRequestOsConfig(c echo.Conte
RunProvisioningInstructionsOnEveryBoot: alwaysBootWithCustomIpxe,
PhoneHomeEnabled: phoneHomeEnabled,
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *ipxeScript,
},
},
Expand Down
4 changes: 2 additions & 2 deletions api/pkg/api/handler/instancebatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (bcih BatchCreateInstanceHandler) buildBatchInstanceCreateRequestOsConfig(c
RunProvisioningInstructionsOnEveryBoot: *apiRequest.AlwaysBootWithCustomIpxe, // Set by the earlier call to ValidateAndSetOperatingSystemData
PhoneHomeEnabled: *apiRequest.PhoneHomeEnabled, // Set by the earlier call to ValidateAndSetOperatingSystemData
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *apiRequest.IpxeScript,
},
},
Expand Down Expand Up @@ -194,7 +194,7 @@ func (bcih BatchCreateInstanceHandler) buildBatchInstanceCreateRequestOsConfig(c
RunProvisioningInstructionsOnEveryBoot: *apiRequest.AlwaysBootWithCustomIpxe,
PhoneHomeEnabled: *apiRequest.PhoneHomeEnabled,
Variant: &cwssaws.OperatingSystem_Ipxe{
Ipxe: &cwssaws.IpxeOperatingSystem{
Ipxe: &cwssaws.InlineIpxe{
IpxeScript: *apiRequest.IpxeScript,
},
},
Expand Down
21 changes: 11 additions & 10 deletions site-agent/pkg/components/carbide_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,22 +203,23 @@ func TestCarbideSubnet(t *testing.T) {
case "get":
ctx := context.Background()
ctx, span := otel.Tracer(os.Getenv("LS_SERVICE_NAME")).Start(ctx, "CarbideTest-GetNetworkSegment")
response, err := grpcClient.Networks().GetNetworkSegment(ctx, &wflows.UUID{Value: created.Id.Value})
response, err := grpcClient.Networks().FindNetworkSegmentsByIds(ctx, &wflows.NetworkSegmentsByIdsRequest{NetworkSegmentsIds: []*wflows.NetworkSegmentId{created.Id}})
span.End()
if err != nil {
t.Log(err.Error())
}
assert.Nil(t, err)
assert.NotNil(t, response)
assert.Equal(t, created.Name, response.Name)
assert.Equal(t, created.Id.Value, response.Id.Value)
assert.Equal(t, created.Mtu, response.Mtu)
assert.Equal(t, created.SubdomainId.Value, response.SubdomainId.Value)
assert.Equal(t, created.VpcId.Value, response.VpcId.Value)
assert.Equal(t, len(created.Prefixes), len(response.Prefixes))
assert.Equal(t, created.Prefixes[0].Prefix, response.Prefixes[0].Prefix)
assert.Equal(t, created.Prefixes[0].Gateway, response.Prefixes[0].Gateway)
assert.Equal(t, created.Prefixes[0].ReserveFirst, response.Prefixes[0].ReserveFirst)
responseSegment := response.NetworkSegments[0]
assert.Equal(t, created.Name, responseSegment.Name)
assert.Equal(t, created.Id.Value, responseSegment.Id.Value)
assert.Equal(t, created.Mtu, responseSegment.Mtu)
assert.Equal(t, created.SubdomainId.Value, responseSegment.SubdomainId.Value)
assert.Equal(t, created.VpcId.Value, responseSegment.VpcId.Value)
assert.Equal(t, len(created.Prefixes), len(responseSegment.Prefixes))
assert.Equal(t, created.Prefixes[0].Prefix, responseSegment.Prefixes[0].Prefix)
assert.Equal(t, created.Prefixes[0].Gateway, responseSegment.Prefixes[0].Gateway)
assert.Equal(t, created.Prefixes[0].ReserveFirst, responseSegment.Prefixes[0].ReserveFirst)
t.Log("GRPCResponse", response)
Comment on lines 211 to 223
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add bounds check before accessing slice element to prevent panic.

Line 213 accesses response.NetworkSegments[0] without verifying the slice is non-empty. If the server returns an empty list (which would indicate a test regression), this will panic rather than fail gracefully with a descriptive assertion error.

Proposed fix using `require`
 				assert.Nil(t, err)
 				assert.NotNil(t, response)
+				require.NotEmpty(t, response.NetworkSegments, "expected at least one network segment in response")
 				responseSegment := response.NetworkSegments[0]
 				assert.Equal(t, created.Name, responseSegment.Name)

Note: You may need to add "github.com/stretchr/testify/require" to imports.

As per coding guidelines, use testify (assert/require) for test assertions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@site-agent/pkg/components/carbide_test.go` around lines 211 - 223, The test
accesses response.NetworkSegments[0] without checking the slice length, which
can cause a panic; update the test in carbide_test.go to assert the slice is
non-empty before indexing (e.g., use require.NotEmpty(t,
response.NetworkSegments) or require.Greater(t, len(response.NetworkSegments),
0)) and then assign responseSegment := response.NetworkSegments[0]; add the
"github.com/stretchr/testify/require" import if needed so the test fails with a
clear assertion instead of panicking.

case "delete":
v := &wflows.DeleteSubnetRequest{
Expand Down
12 changes: 5 additions & 7 deletions site-agent/pkg/components/instance_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func (s *CreateDeprecatedInstanceTestSuite) TestDeprecatedCreateInstanceWorkflow
MachineId: &wflows.MachineId{Id: testInstance.MachineId.Id},
TenantOrg: "test-tenant-org",
Interfaces: testInstance.Config.Network.Interfaces,
CustomIpxe: &testInstance.Config.Tenant.CustomIpxe,
UserData: testInstance.Config.Tenant.UserData,
CustomIpxe: &testInstance.Config.Os.GetIpxe().IpxeScript,
UserData: testInstance.Config.Os.GetIpxe().UserData,
TenantKeysetIds: []string{uuid.NewString()},
}

Expand Down Expand Up @@ -165,8 +165,8 @@ func (s *CreateDeprecatedInstanceFailureTestSuite) TestDeprecatedCreateInstanceW
MachineId: &wflows.MachineId{Id: uuid.NewString()},
TenantOrg: "test-tenant-org",
Interfaces: testInstance.Config.Network.Interfaces,
CustomIpxe: &testInstance.Config.Tenant.CustomIpxe,
UserData: testInstance.Config.Tenant.UserData,
CustomIpxe: &testInstance.Config.Os.GetIpxe().IpxeScript,
UserData: testInstance.Config.Os.GetIpxe().UserData,
TenantKeysetIds: []string{uuid.NewString()},
}

Expand Down Expand Up @@ -320,8 +320,6 @@ func TestInstanceWorkflows(t *testing.T) {
Config: &wflows.InstanceConfig{
Tenant: &wflows.TenantConfig{
TenantOrganizationId: "test-tenant-org",
CustomIpxe: "sample-ipxe-script",
UserData: &testUserData,
},
Network: &wflows.InstanceNetworkConfig{
Interfaces: []*wflows.InstanceInterfaceConfig{
Expand All @@ -338,7 +336,7 @@ func TestInstanceWorkflows(t *testing.T) {
Os: &wflows.OperatingSystem{
RunProvisioningInstructionsOnEveryBoot: true,
Variant: &wflows.OperatingSystem_Ipxe{
Ipxe: &wflows.IpxeOperatingSystem{
Ipxe: &wflows.InlineIpxe{
IpxeScript: "#!ipxe",
},
},
Expand Down
7 changes: 0 additions & 7 deletions site-agent/pkg/components/managers/sshkeygroup/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ func (skgm *sshkgWorkflowMetadata) DoSiteControllerOP(ctx context.Context,
return ManagerAccess.Data.EB.Managers.Carbide.GetClient().Compute().UpdateSSHKeyGroup(ctx, req.(*wflows.UpdateSSHKeyGroupRequest))
case activityDelete:
return ManagerAccess.Data.EB.Managers.Carbide.GetClient().Compute().DeleteSSHKeyGroup(ctx, req.(*wflows.DeleteSSHKeyGroupRequest))
case activityGet:
return ManagerAccess.Data.EB.Managers.Carbide.GetClient().Compute().GetSSHKeyGroup(ctx, req.(*wflows.GetSSHKeyGroup))
default:
panic(fmt.Sprintf("invalid activity type: %v", skgm.activity))
}
Expand All @@ -106,11 +104,6 @@ func (skgm *sshkgWorkflowMetadata) ActivityInvoke() (act interface{}) {
act = sshkgwflowinstance.UpdateSSHKeyGroupActivity
case activityDelete:
act = sshkgwflowinstance.DeleteSSHKeyGroupActivity
case activityGet:
act = sshkgwflowinstance.GetSSHKeyGroupActivity
// No need for this activity yet
// case activityGetList:
// act = sshkgwflowinstance.CollectSSHKeyGroupListActivity
}

return
Expand Down
34 changes: 0 additions & 34 deletions site-workflow/pkg/activity/dpuextensionservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
tmocks "go.temporal.io/sdk/mocks"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func TestManageDpuExtensionService_CreateDpuExtensionServiceOnSite(t *testing.T) {
Expand Down Expand Up @@ -417,7 +415,6 @@ func TestManageDpuExtensionServiceInventory_DiscoverDpuExtensionServiceInventory
}
type args struct {
wantTotalItems int
findIDsError error
}
tests := []struct {
name string
Expand Down Expand Up @@ -450,34 +447,6 @@ func TestManageDpuExtensionServiceInventory_DiscoverDpuExtensionServiceInventory
wantTotalItems: 195,
},
},
{
name: "test collecting and publishing dpu extension service inventory fallback, empty inventory",
fields: fields{
siteID: uuid.New(),
carbideAtomicClient: carbideAtomicClient,
temporalPublishQueue: "test-queue",
sitePageSize: 100,
cloudPageSize: 25,
},
args: args{
wantTotalItems: 0,
findIDsError: status.Error(codes.Unimplemented, "not implemented"),
},
},
{
name: "test collecting and publishing dpu extension service inventory fallback, normal inventory",
fields: fields{
siteID: uuid.New(),
carbideAtomicClient: carbideAtomicClient,
temporalPublishQueue: "test-queue",
sitePageSize: 100,
cloudPageSize: 25,
},
args: args{
wantTotalItems: 195,
findIDsError: status.Error(codes.Unimplemented, "not implemented"),
},
},
}

for _, tt := range tests {
Expand All @@ -498,9 +467,6 @@ func TestManageDpuExtensionServiceInventory_DiscoverDpuExtensionServiceInventory

ctx := context.Background()
ctx = context.WithValue(ctx, "wantCount", tt.args.wantTotalItems)
if tt.args.findIDsError != nil {
ctx = context.WithValue(ctx, "wantError", tt.args.findIDsError)
}

totalPages := tt.args.wantTotalItems / tt.fields.cloudPageSize
if tt.args.wantTotalItems%tt.fields.cloudPageSize > 0 {
Expand Down
4 changes: 2 additions & 2 deletions site-workflow/pkg/activity/expectedpowershelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ func expectedPowerShelfToRLAComponent(eps *cwssaws.ExpectedPowerShelf) *rlav1.Co
component.Position = pos
}

if eps.GetIpAddress() != "" {
ipAddr := eps.GetIpAddress()
if eps.GetBmcIpAddress() != "" {
ipAddr := eps.GetBmcIpAddress()
component.Bmcs[0].IpAddress = &ipAddr
}

Expand Down
2 changes: 1 addition & 1 deletion site-workflow/pkg/activity/expectedpowershelf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func Test_expectedPowerShelfToRLAComponent(t *testing.T) {
ExpectedPowerShelfId: &cwssaws.UUID{Value: "eps-001"},
BmcMacAddress: "AA:BB:CC:DD:EE:FF",
ShelfSerialNumber: "SHELF-001",
IpAddress: "10.0.0.1",
BmcIpAddress: "10.0.0.1",
RackId: &cwssaws.RackId{Id: "rack-001"},
Name: strPtr("pdu-shelf-1"),
Manufacturer: strPtr("Vertiv"),
Expand Down
13 changes: 0 additions & 13 deletions site-workflow/pkg/activity/ibpartition.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func (mmi *ManageInfiniBandPartitionInventory) DiscoverInfiniBandPartitionInvent
internalFindIDs: ibpFindIDs,
internalFindByIDs: ibpFindByIDs,
internalPagedInventory: ibpPagedInventory,
internalFindFallback: ibpFindFallback,
}
return inventoryImpl.CollectAndPublishInventory(ctx, &logger)
}
Expand Down Expand Up @@ -98,18 +97,6 @@ func ibpPagedInventory(allItemIDs []*cwssaws.IBPartitionId, pagedItems []*cwssaw
return inventory
}

func ibpFindFallback(ctx context.Context, carbideClient *cClient.CarbideClient) ([]*cwssaws.IBPartitionId, []*cwssaws.IBPartition, error) {
items, err := carbideClient.Networks().ListInfiniBandPartition(ctx)
if err != nil {
return nil, nil, err
}
var ids []*cwssaws.IBPartitionId
for _, it := range items.GetIbPartitions() {
ids = append(ids, it.Id)
}
return ids, items.GetIbPartitions(), nil
}

// ManageInfiniBandPartition is an activity wrapper for InfiniBand Partition management
type ManageInfiniBandPartition struct {
CarbideAtomicClient *client.CarbideAtomicClient
Expand Down
34 changes: 0 additions & 34 deletions site-workflow/pkg/activity/ibpartition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
tmocks "go.temporal.io/sdk/mocks"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func TestManageIBPartitionInventory_DiscoverInfiniBandPartitionInventory(t *testing.T) {
Expand All @@ -50,7 +48,6 @@ func TestManageIBPartitionInventory_DiscoverInfiniBandPartitionInventory(t *test
}
type args struct {
wantTotalItems int
findIDsError error
}
tests := []struct {
name string
Expand Down Expand Up @@ -83,34 +80,6 @@ func TestManageIBPartitionInventory_DiscoverInfiniBandPartitionInventory(t *test
wantTotalItems: 195,
},
},
{
name: "test collecting and publishing ib partition inventory fallback, empty inventory",
fields: fields{
siteID: uuid.New(),
carbideAtomicClient: carbideAtomicClient,
temporalPublishQueue: "test-queue",
sitePageSize: 100,
cloudPageSize: 25,
},
args: args{
wantTotalItems: 0,
findIDsError: status.Error(codes.Unimplemented, "not implemented"),
},
},
{
name: "test collecting and publishing ib partition inventory fallback, normal inventory",
fields: fields{
siteID: uuid.New(),
carbideAtomicClient: carbideAtomicClient,
temporalPublishQueue: "test-queue",
sitePageSize: 100,
cloudPageSize: 25,
},
args: args{
wantTotalItems: 195,
findIDsError: status.Error(codes.Unimplemented, "not implemented"),
},
},
}

for _, tt := range tests {
Expand All @@ -131,9 +100,6 @@ func TestManageIBPartitionInventory_DiscoverInfiniBandPartitionInventory(t *test

ctx := context.Background()
ctx = context.WithValue(ctx, "wantCount", tt.args.wantTotalItems)
if tt.args.findIDsError != nil {
ctx = context.WithValue(ctx, "wantError", tt.args.findIDsError)
}

totalPages := tt.args.wantTotalItems / tt.fields.cloudPageSize
if tt.args.wantTotalItems%tt.fields.cloudPageSize > 0 {
Expand Down
Loading