Skip to content

Commit

Permalink
kill-container
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoKramer committed Feb 23, 2020
1 parent d944ebc commit 6d51bd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/bob/execution/internals.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@
"Kills a running container using SIGKILL.
Returns the name or the error if any."
[name]
(if (f/failed? (f/try* (docker/kill states/docker-conn name)))
(do (log/errorf "Error killing container %s" name)
(f/fail "Could not kill %s" name))
name))
(let [containers (docker/client {:category :containers
:conn states/docker-conn})
result (docker/invoke containers {:op :ContainerKill :params {:id name}})]
(if (clojure.string/blank? result)
name
(do (log/errorf "Error killing container %s" name)
(f/fail "Could not kill %s" name)))))

(defn pull
"Pulls in an image if it's not present locally.
Expand Down Expand Up @@ -116,7 +119,6 @@
(comment
(def images (docker/client {:category :images
:conn states/docker-conn}))
(clojure.pprint/pprint images)
(filter #(= (:RepoTags %) ["nginx:latest"]) (docker/invoke images {:op :ImageList}))
(filter #(= (:RepoTags %) ["img"]) [{:RepoTags ["img"]}])

Expand Down
8 changes: 4 additions & 4 deletions test/bob/execution/internals_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@

(deftest container-kill
(testing "successful kill"
(with-redefs-fn {#'docker/kill (fn [_ name]
(tu/check-and-fail
#(= "c1" name)))}
(with-redefs-fn {#'docker/client (constantly nil)
#'docker/invoke (constantly "")}
#(is (= "c1" (kill-container "c1")))))

(testing "unsuccessful kill"
(with-redefs-fn {#'docker/kill (constantly (f/fail "Failed"))}
(with-redefs-fn {#'docker/client (constantly nil)
#'docker/invoke (constantly "{:message \"Cannot kill container\"}")}
#(let [result (kill-container "c1")]
(is (and (f/failed? result)
(= "Could not kill c1"
Expand Down

0 comments on commit 6d51bd2

Please sign in to comment.