diff --git a/lock.go b/lock.go index e915c71..9e91f70 100644 --- a/lock.go +++ b/lock.go @@ -17,6 +17,7 @@ func acquireDistributedLock( runnerFactory runnerFactory, addresses []address, failOnError bool, + noConnFail bool, ) (*distributedLock, error) { var ( cluster = &distributedLock{ @@ -34,13 +35,22 @@ func acquireDistributedLock( err := connectToNode(cluster, runnerFactory, nodeAddress, mutex) if err != nil { - debugf(`%4d/%d connection established: %s`, - atomic.AddInt64(&nodeIndex, 1), - len(addresses), - nodeAddress, - ) + if noConnFail { + warningf("%s", err.Error()) + errors <- nil + } else { + errors <- err + } + + return } + debugf(`%4d/%d connection established: %s`, + atomic.AddInt64(&nodeIndex, 1), + len(addresses), + nodeAddress, + ) + errors <- err }(nodeAddress) } diff --git a/main.go b/main.go index d8c3bad..af8d4b3 100644 --- a/main.go +++ b/main.go @@ -116,6 +116,7 @@ Options: behaviour, this option can be used. -t --no-lock-fail Try to obtain global lock, but only print warning if it cannot be done, do not stop execution. + -w --no-conn-fail Skip unreachable servers whatsoever. -r --root Specify root dir to extract files into. By default, orgalorg will create temporary directory inside of '$ROOT'. @@ -551,6 +552,8 @@ func connectAndLock( rootDir, _ = args["--root"].(string) sshKeyPath, _ = args["--key"].(string) lockFile, _ = args["--lock-file"].(string) + + noConnFail = args["--no-conn-fail"].(bool) ) addresses, err := parseAddresses(hosts, defaultUser, fromStdin) @@ -592,6 +595,7 @@ func connectAndLock( runners, addresses, failOnError, + noConnFail, ) if err != nil { return nil, hierr.Errorf( diff --git a/tests/testcases/can-skip-unreachable-servers-if-flag-is-given.test.sh b/tests/testcases/can-skip-unreachable-servers-if-flag-is-given.test.sh new file mode 100644 index 0000000..ee76f86 --- /dev/null +++ b/tests/testcases/can-skip-unreachable-servers-if-flag-is-given.test.sh @@ -0,0 +1,13 @@ +tests:not tests:ensure :orgalorg:with-key -o example.com -C whoami + +tests:ensure :orgalorg:with-key -o example.com -w -C whoami + +tests:assert-stderr-re "WARNING.*can't create runner.*example.com" + +:check-node-output() { + local container_ip="$2" + + tests:assert-stdout "$container_ip $orgalorg_user" +} + +containers:do :check-node-output