あるホストへの到達性をチェックする be_reachable が
Solaris で動かなかったので Solaris 用のコマンドを書いて
pull request を送った(0.6.9 で取り込まれている)。
be_reachable は
- ping によるチェック
- nc によるポートチェック
の 2 種類のチェックを行なえる
describe host('target.example.jp') do # ping it { should be_reachable } # port it { should be_reachable.with( :port => 22, :proto => 'tcp' ) } end
lib/serverspec/commands/base.rb で
def check_reachable(host, port, proto, timeout) if port.nil? "ping -n #{escape(host)} -w #{escape(timeout)} -c 2" else "nc -vvvvz#{escape(proto[0].chr)} #{escape(host)} #{escape(port)} -w #{escape(timeout)}" end end
Solaris の ping は '-w' がなく、
'-c' は traffic_class の指定で count ではないので動かない。
nc の方は host と port を最後に書かなくてはいけないので、
'-w #{escape(timeout)} が最後にきている上のものでは動かない。
ということで、lib/serverspec/commands/solaris.rb で以下のように定義してみた。
def check_reachable(host, port, proto, timeout) if port.nil? "ping -n #{escape(host)} #{escape(timeout)}" else "nc -vvvvz#{escape(proto[0].chr)} -w #{escape(timeout)} #{escape(host)} #{escape(port)}" end end