This is an automated email from the ASF dual-hosted git repository. DImuthuUpe pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
commit bee6bdb330b69a264a9d618b28aafdd7b604c36d Author: DImuthuUpe <[email protected]> AuthorDate: Sat May 23 16:24:25 2026 -0400 Validation of association creation in SLURM side --- .../internal/operations/associations.go | 41 ++++++++++++++++++++++ .../subscribers/accountsub_integration_test.go | 3 +- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/connectors/SLURM/Association-Mapper/internal/operations/associations.go b/connectors/SLURM/Association-Mapper/internal/operations/associations.go index 4852daf5c..1ecf66033 100644 --- a/connectors/SLURM/Association-Mapper/internal/operations/associations.go +++ b/connectors/SLURM/Association-Mapper/internal/operations/associations.go @@ -4,6 +4,7 @@ package operations import ( "errors" "log" + "log/slog" "net/url" ) @@ -76,9 +77,49 @@ func (c *Client) UpsertAssociation(a Association) error { return errors.New("association not found after upsert") } + log.Printf("Fetched upserted association: %+v", assos[0]) + fetchedAssociation := assos[0] + if fetchedAssociation.Account != a.Account || fetchedAssociation.User != a.User || + fetchedAssociation.Cluster != a.Cluster || fetchedAssociation.Partition != a.Partition { + log.Printf("Fetched association does not match upserted association: got %+v, want %+v", fetchedAssociation, a) + return errors.New("fetched association does not match upserted association") + } + + fetchedLimits := fetchedAssociation.Limits + upsertedLimits := a.Limits + + if !tresSliceEqualUnordered(fetchedLimits.GrpTRES, upsertedLimits.GrpTRES) { + slog.Error("Fetched association limits GrpTRES does not match upserted association limits GrpTRES", "got", fetchedLimits.GrpTRES, "want", upsertedLimits.GrpTRES) + return errors.New("fetched association limits GrpTRES does not match upserted association limits GrpTRES") + } + + if !tresSliceEqualUnordered(fetchedLimits.GrpTRESMins, upsertedLimits.GrpTRESMins) { + slog.Error("Fetched association limits GrpTRESMins does not match upserted association limits GrpTRESMins", "got", fetchedLimits.GrpTRESMins, "want", upsertedLimits.GrpTRESMins) + return errors.New("fetched association limits GrpTRESMins does not match upserted association limits GrpTRESMins") + } + return nil } +// tresSliceEqualUnordered reports whether two TRES slices contain the same +// elements regardless of order. nil and empty slices are treated as equal. +func tresSliceEqualUnordered(a, b []TRES) bool { + if len(a) != len(b) { + return false + } + counts := make(map[TRES]int, len(a)) + for _, t := range a { + counts[t]++ + } + for _, t := range b { + counts[t]-- + if counts[t] < 0 { + return false + } + } + return true +} + func (c *Client) DeleteAssociation(f AssocFilter) error { path := "/slurmdb/v0.0." + c.apiVersion + "/association" if q := f.query(); q != "" { diff --git a/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go b/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go index 2490e1297..5e5758d07 100644 --- a/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go +++ b/connectors/SLURM/Association-Mapper/internal/subscribers/accountsub_integration_test.go @@ -1,7 +1,6 @@ package subscribers import ( - //"log" "context" "fmt" operations "github.com/apache/airavata-custos/connectors/SLURM/Association-Mapper/internal/operations" @@ -251,7 +250,7 @@ func TestSubscribeToComputeAllocationResourceMappingCreation(t *testing.T) { return &models.ComputeAllocation{ID: id, Name: computeAllocationName, ComputeClusterID: clusterID}, nil }, GetComputeAllocationResourceFunc: func(ctx context.Context, id string) (*models.ComputeAllocationResource, error) { - return &models.ComputeAllocationResource{ID: id, Name: partitionName, ResourceType: "cpu8", ResourceAmount: 1000}, nil + return &models.ComputeAllocationResource{ID: id, Name: partitionName, ResourceType: "cpu", ResourceAmount: 1000}, nil }, ListAllAuditEventsFunc: func(ctx context.Context) ([]*models.AuditEvent, error) { return auditEvents, nil
