OSSのサーバテスト自動化ツール徹底検証 2016年版 〜Infrataster編――手間取るテストエビデンス作成をどう自動化するか〜実際に検証済み!OSS徹底比較(6)サーバテスト自動化【後編】(2/6 ページ)

» 2016年09月29日 05時00分 公開
[森元敏雄,TIS]

Infratasterのプロフィール

 Infratasterは、クックパッドの荒井良太氏が開発した「サーバ上のサービスへのアクセスやネットワーク通信などの自動テストを行う製品」である。製品の名称はinfraのtester(テスト実施者)ではなく、infraのtaster(毒見役)という意味である。荒井氏は、サーバ構築自動化ソフトのItamaeの作者でもある。テストスクリプトの制御にはInfrataster同様に、Rubyのテストフレームワーク製品であるRSpecを使用している。

 2014年4月27日にVer 0.1.0としてリリースされ、最新バージョンは2015年11月19にリリースされたVer 0.3.2である。ライセンスはMIT Licenseとなっている。前回の製品紹介でも触れたが、Serverspecの補完製品として開発されており、Serverspecがサーバの内部からホワイトテストを実施する機能が中心であるのに対し、Infratasterはサーバの外部から、サーバで提供しているサービスに対してブラックボックステストを行う機能を主としている。

Infratasterのインストール

 Infratasterは管理サーバ側にのみインストール作業が必要で、ノード側には前述のssh接続と特権ユーザーの利用の設定以外には、特にインストールは不要である。インストールの手順は以下の通り。

1.Rubyのインストール

 2016年5月現在、CentOSの標準リポジトリではVer 2.0.0がインストールされる。Rubyとしては最新のstable版ではないが、Infratasterの動作に問題はない。

$ sudo yum install -y ruby

2.「Nokogiri」に必要となるパッケージのインストール

 InfratasterはWebスクレイピング(Webサイトから取得したHTMLデータを加工・整形する技術)に「nokogiri」を使用している。そのnokogiriをインストールするために必要な標準パッケージをあらかじめインストールしておく。

$ sudo yum install -y gcc ruby-devel zlib-devel libxml2 libxslt libxml2-devel libxslt-devel

3.Nokogiriのインストール

$ sudo gem install nokogiri -- --use-system-libraries

4.Bundlerのインストール

 Infratasterをインストールするためにgemの管理ツールであるBundlerもインストールする。

$ sudo gem install bundler

5.Infratasterインストール用のGemfileの作成

$ vi ~/Gemfile
source 'https://rubygems.org'
gem 'infrataster'

6.Infratasterのインストール

$ sudo /usr/local/bin/bundle install

7.Infratasterのインストール結果の確認

 以下のコマンドを実行して、Infratasterのhelpメッセージが表示されればInfratasterのインストールは正常に行えている。

$ sudo /usr/local/bin/infrataster help
Commands:
  infrataster help [COMMAND]  # Describe available commands or one specific command
  infrataster init            # Initialize Infrataster specs.

8.Infrataster用のフォルダの作成

 Serverspecと競合するファイルが存在するため、Infrataster用の作業フォルダを作成する。テストスクリプトなども当該フォルダ以下で作成する。

$ mkdir ~/infrataster
$ cd ~/infrataster

9.Infratasterの初期設定

 対話型形式で、テスト対象ノードのテストスクリプト用フォルダとサンプルテストスクリプトを作成する。Gemfile、Rakefileがすでに存在していると作成がスキップされるため、別フォルダに移しておくなどの対応が必要だ。今回、Vagrantは使用しないので、nを選択する。

$ /usr/local/bin/Infrataster init
$ /usr/local/bin/infrataster init
Created: Gemfile
Created: Rakefile
Use Vagrant? (y/N): n
Created: spec_helper.rb
Created: app_spec.rb

 作成されるフォルダ構成およびファイルは以下の通り。

$ tree
├── Gemfile
├── Rakefile
├── spec
    ├── app_spec.rb
    └── spec_helper.rb

10.Gemfileに使用するinfrataster-pluginを追記

infrataster-plugin-mysqlとinfrataster-plugin-firewallを追加する。

$ vi ~/infrataster/Gemfile
# Generated by `infrataster init`
source "https://rubygems.org"
gem "infrataster"
# If you would like to test mysql, uncomment the next line.
# gem "infrataster-plugin-mysql"
gem "infrataster-plugin-mysql"
gem "infrataster-plugin-firewall"

11.infrataster-plugin-mysqlが使用するMariaDB(client)とmysql-develをインストール

$ sudo yum install -y mariadb mysql-devel

 以下のコマンドで、先ほど編集したGemfileを読み込んで"infrataster-plugin-mysql"とinfrataster-plugin-firewallとinfrataster-plugin-firewallがインストールされる。

$ sudo /usr/local/bin/bundle install

12.infrataster-plugin-mysqlとinfrataster-plugin-firewallをインストール

ataster-plugin-firewall 0.1.4
Installing infrataster-plugin-mysql 0.2.0
Bundle complete! 3 Gemfile dependencies, 32 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.

13.infrataster-plugin-firewallのファイルがrootにしか読み取り権限がないため、全ユーザーに読み取り権限を付与

$ sudo chmod -R a+r /usr/local/share/gems/gems/infrataster-plugin-firewall-0.1.4

 以上でInfrataster、および今回使用するinfrataster-pluginのインストールは終了である。

Copyright © ITmedia, Inc. All Rights Reserved.

RSSについて

アイティメディアIDについて

メールマガジン登録

@ITのメールマガジンは、 もちろん、すべて無料です。ぜひメールマガジンをご購読ください。