You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by la...@apache.org on 2026/10/06 17:31:56 UTC

(airavata-custos) branch master updated: delete slurm associations one at a time (#600)

This is an automated email from the ASF dual-hosted git repository.

lahirujayathilake pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git


The following commit(s) were added to refs/heads/master by this push:
     new 272602934 delete slurm associations one at a time (#600)
272602934 is described below

commit 272602934ed064dcbad7e1585aa0e73916d245ee
Author: Yasith Jayawardana <ya...@icloud.com>
AuthorDate: Tue Oct 6 13:31:50 2026 -0400

    delete slurm associations one at a time (#600)
---
 .../SLURM/Rest-Client/pkg/client/associations.go      | 19 ++++++++++++++-----
 .../SLURM/Rest-Client/pkg/client/associations_test.go |  6 +++++-
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/connectors/SLURM/Rest-Client/pkg/client/associations.go b/connectors/SLURM/Rest-Client/pkg/client/associations.go
index b1eca11be..bea87454f 100644
--- a/connectors/SLURM/Rest-Client/pkg/client/associations.go
+++ b/connectors/SLURM/Rest-Client/pkg/client/associations.go
@@ -137,11 +137,20 @@ func tresSliceEqualUnordered(a, b []TRES) bool {
 	return true
 }
 
+// DeleteAssociation deletes the user associations matching f one at a time, as slurmrestd requires.
 func (c *Client) DeleteAssociation(f AssocFilter) error {
-	path := "/slurmdb/v0.0." + c.apiVersion + "/association"
-	if q := f.query(); q != "" {
-		path += "?" + q
+	matched, err := c.ListAssociations(f)
+	if err != nil {
+		return err
 	}
-	_, err := c.do("DELETE", path, nil, nil)
-	return err
+	for _, assoc := range matched {
+		if assoc.User == "" {
+			continue
+		}
+		item := AssocFilter{Cluster: assoc.Cluster, Account: assoc.Account, User: assoc.User, Partition: assoc.Partition}
+		if _, err := c.do("DELETE", "/slurmdb/v0.0."+c.apiVersion+"/association?"+item.query(), nil, nil); err != nil {
+			return err
+		}
+	}
+	return nil
 }
diff --git a/connectors/SLURM/Rest-Client/pkg/client/associations_test.go b/connectors/SLURM/Rest-Client/pkg/client/associations_test.go
index bd9bd3b49..24d610104 100644
--- a/connectors/SLURM/Rest-Client/pkg/client/associations_test.go
+++ b/connectors/SLURM/Rest-Client/pkg/client/associations_test.go
@@ -87,6 +87,10 @@ func TestCreateAssociation(t *testing.T) {
 
 func TestDeleteAssociation(t *testing.T) {
 	srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		if r.Method == "GET" {
+			_, _ = w.Write([]byte(`{"associations":[{"account":"eng","cluster":"artisan","user":""},{"account":"eng","cluster":"artisan","user":"alice"}]}`))
+			return
+		}
 		if r.Method != "DELETE" || r.URL.Path != "/slurmdb/v0.0.41/association" {
 			t.Fatalf("unexpected %s %s", r.Method, r.URL.Path)
 		}
@@ -97,7 +101,7 @@ func TestDeleteAssociation(t *testing.T) {
 	}))
 	defer srv.Close()
 	c := New(srv.URL, "root", "t", "41")
-	if err := c.DeleteAssociation(AssocFilter{Account: "eng", User: "alice"}); err != nil {
+	if err := c.DeleteAssociation(AssocFilter{Account: "eng"}); err != nil {
 		t.Fatal(err)
 	}
 }