Permalink
Browse files

allows syncing of tokens even if roots mismatch but other user editab…

…le fields agree (#540)
  • Loading branch information...
shamsimam authored and pschorf committed Dec 19, 2018
1 parent ef320b5 commit 081ffd98adb70807c4ec519f7d94b5db3d4f6e2b
@@ -78,7 +78,8 @@
[{:keys [store-token]} cluster-urls token latest-token-description cluster-url->token-data]
(pc/map-from-keys
(fn [cluster-url]
(let [cluster-result
(let [ignored-root-mismatch-equality-comparison-keys ["last-update-time" "last-update-user" "previous" "root"]
cluster-result
(try
(let [{:keys [description error status] :as token-data} (get cluster-url->token-data cluster-url)
latest-root (get latest-token-description "root")
@@ -96,7 +97,10 @@
{:code :error/token-read
:details {:message "token root missing from latest token description"}}

(and (seq description) (not= latest-root cluster-root))
(and (seq description)
(not= latest-root cluster-root)
(not= (apply dissoc description ignored-root-mismatch-equality-comparison-keys)
(apply dissoc latest-token-description ignored-root-mismatch-equality-comparison-keys)))
{:code :error/root-mismatch
:details {:cluster description
:latest latest-token-description}}
@@ -245,6 +245,68 @@
:latest token-description}}}
(sync-token-on-clusters waiter-api cluster-urls test-token token-description cluster-url->token-data)))))

(testing "sync cluster same parameters and owner but different root"
(let [cluster-urls ["www.cluster-1.com" "www.cluster-2.com"]
test-token "test-token-1"
token-description {"cpus" 1
"mem" 1024
"name" "test-name"
"owner" "test-user-1"}
token-description-1 (assoc token-description "root" "cluster-1")
token-description-2 (assoc token-description "root" "cluster-2")
cluster-url->token-data {"www.cluster-1.com" {:description token-description-1
:token-etag (str test-token-etag ".1")
:status 200}
"www.cluster-2.com" {:description token-description-2
:token-etag (str test-token-etag ".2")
:status 200}}]
(is (= {"www.cluster-1.com" {:code :success/token-match}
"www.cluster-2.com" {:code :success/sync-update
:details {:etag (str test-token-etag ".2.new")
:status 200}}}
(sync-token-on-clusters waiter-api cluster-urls test-token token-description-1 cluster-url->token-data)))))

(testing "sync cluster same owner, soft-deleted on one and different root"
(let [cluster-urls ["www.cluster-1.com" "www.cluster-2.com"]
test-token "test-token-1"
token-description {"cpus" 1
"mem" 1024
"name" "test-name"
"owner" "test-user-1"}
token-description-1 (assoc token-description "deleted" true "root" "cluster-1")
token-description-2 (assoc token-description "root" "cluster-2")
cluster-url->token-data {"www.cluster-1.com" {:description token-description-1
:token-etag (str test-token-etag ".1")
:status 200}
"www.cluster-2.com" {:description token-description-2
:token-etag (str test-token-etag ".2")
:status 200}}]
(is (= {"www.cluster-1.com" {:code :success/token-match}
"www.cluster-2.com" {:code :error/root-mismatch
:details {:cluster token-description-2
:latest token-description-1}}}
(sync-token-on-clusters waiter-api cluster-urls test-token token-description-1 cluster-url->token-data)))))

(testing "sync cluster same owner, different parameters and root"
(let [cluster-urls ["www.cluster-1.com" "www.cluster-2.com"]
test-token "test-token-1"
token-description {"mem" 1024
"name" "test-name"
"owner" "test-user-1"}
token-description-1 (assoc token-description "cpus" 1 "root" "cluster-1")
token-description-2 (assoc token-description "cpus" 2 "root" "cluster-2")
cluster-url->token-data {"www.cluster-1.com" {:description token-description-1
:token-etag (str test-token-etag ".1")
:status 200}
"www.cluster-2.com" {:description token-description-2
:token-etag (str test-token-etag ".2")
:status 200}}]
(is (= {"www.cluster-1.com" {:code :success/token-match}
"www.cluster-2.com" {:code :error/root-mismatch
:details {:cluster token-description-2
:latest token-description-1}}}
(sync-token-on-clusters waiter-api cluster-urls test-token token-description-1 cluster-url->token-data)))))

(testing "sync cluster with missing owners"
(let [cluster-urls ["www.cluster-1.com" "www.cluster-2.com"]
test-token "test-token-1"

0 comments on commit 081ffd9

Please sign in to comment.