serverspec

serverspecとは

Rubyで実装されたサーバの状態をテストするためのフレームワーク
サーバがどのような状態であるかを確認できる
構成管理ツール実行後などに利用する

具体的には
・パッケージがインストールされているかどうか、起動しているかどうか
・ファイルの所有者や中身に特定の文字列があるかどうか
・コマンドの実行結果を確認
などを確認できる

特別なエージェントは必要ない
バックエンド処理用フレームワークのspecinfraにてOSによるコマンドの違いは吸収されている

インストール

root@hostname:/home/shimizu# gem install serverspec
...
Done installing documentation for multi_json, net-scp, net-ssh, net-telnet, rspec-its, serverspec, sfl, specinfra after 8 seconds
8 gems installed

### 初期化処理 ###
root@hostname:/home/shimizu# serverspec-init
Select OS type:

  1) UN*X
  2) Windows

Select number: 1

Select a backend type:

  1) SSH
  2) Exec (local)

Select number: 2

 + spec/
 + spec/localhost/
 + spec/localhost/sample_spec.rb
 + spec/spec_helper.rb
 + Rakefile
 + .rspec

### Rakefileがおいてある場所で、rakeコマンドを実行する ###
root@hostname:/home/shimizu# rake
/usr/bin/ruby2.1 -I/var/lib/gems/2.1.0/gems/rspec-support-3.3.0/lib:/var/lib/gems/2.1.0/gems/rspec-core-3.3.1/lib /var/lib/gems/2.1.0/gems/rspec-core-3.3.1/exe/rspec --pattern spec/localhost/\*_spec.rb

Port "80"
  should be listening

Finished in 0.03736 seconds (files took 0.87202 seconds to load)
1 example, 0 failures

参考URL

serverspecを使ってサーバの状態をテストしてみよう
http://tech-sketch.jp/2014/04/serverspec.html
「Serverspec」を使ってサーバー環境を自動テストしよう
http://knowledge.sakura.ad.jp/tech/2596/
Serverspecの使い方入門、Chefで構成管理するサーバー環境をテスト
http://easyramble.com/serverspec-for-chef-server.html