2013-06-25 Tue

[別の年の同じ日: 2002 2003 2006 2007 2008 2009 2010 2011

serverspec の Solaris 対応について はてぶ


自分以外に Solaris で serverspec を使いたい人がいるとは思わず、
とりあえず、Oracle Solaris 11 だけを考えて Solaris 対応としてきたけど、
そろそろ Solaris のバージョン違い、
OpenIndiana などのディストリビューションを考えた方がよさげ。

仕事で Solaris 10 な環境もあるし。

Solaris 10 と Oracle Solaris 11 は uname で区別できるとして、
OpenIndiana なんかはどう区別すればいいんだろ。

#jposug のパッケージビルド用に OpenIndiana の環境も作った方がよいし、
環境を作ってみるか。

Solaris 上の serversepc で be_installed.with_version はてぶ

@netmarkjp さんが
add feature package installed with version
https://github.com/mizzy/serverspec/pull/164
という pull request を投げていて、
0.6.8 で
"Support with_version chain with be_installed matcher without by chain (But currently supported only on Red Hat family)"
と取り込まれたので、Solaris 対応して pull request を送ってみた
(0.6.10 で取り込まれた)。

https://github.com/mizzy/serverspec/pull/166

Solaris の場合、以下のように、いろいろなバージョンがくっついてくるので、
もっと厳格にチェックした方がいい気はしているけど、とりあえず。

% pkg list -H entire
entire (solaris)                                  0.5.11-0.175.1.8.0.4.0     i--
% pkg list -Hv entire
pkg://solaris/[email protected],5.11-0.175.1.8.0.4.0:20130531T203415Z            i--


Solaris 上の serverspec で be_reachable はてぶ

あるホストへの到達性をチェックする 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