serverspec at hbstudy #45
DESCRIPTION
TRANSCRIPT
![Page 1: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/1.jpg)
serverspechbstudy #452013/06/21
Gosuke Miyashita
![Page 2: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/2.jpg)
自己紹介
![Page 3: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/3.jpg)
宮下 剛輔mizzy.org
@gosukenator
![Page 4: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/4.jpg)
paperboy&co.テクニカル
マネージャー
![Page 5: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/5.jpg)
理学部情報工学科の三年生
![Page 6: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/6.jpg)
学割でGitHub Micro Plan
無料です
![Page 7: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/7.jpg)
Amazon Student入ってます
![Page 8: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/8.jpg)
hbstudy #8Puppet のススメ
![Page 9: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/9.jpg)
サーバプロビジョニン
グ
![Page 10: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/10.jpg)
Cloud or VMImage Launch
OSInstall
SystemConfiguration
Provisioning Toolchain by Lee Thompson at Velocity 2010
Application ServiceOrchestration
Bootstrapping
Configuration
OrchestrationCapistranoFabric
PuppetChef
EC2OpenStack
![Page 11: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/11.jpg)
サーバプロビジョニン
グと
テスト
![Page 12: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/12.jpg)
監視とは継続的なテストである
by @kazuho
![Page 13: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/13.jpg)
Cloud or VMImage Launch
OSInstall
SystemConfiguration
Application ServiceOrchestration
Bootstrapping
Configuration
Orchestration NagiosZabbix
serverspec
???
![Page 14: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/14.jpg)
Zabbix/Nagios による Apache のテスト(監視)
httpd プロセスが動いているか80 番ポートに外からアクセスできるか80 番ポートが正しいレスポンスを
返すか
![Page 15: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/15.jpg)
serverspec による Apache のテスト
httpd プロセスが動いているか80 番ポートを Listen しているかhttpd パッケージが入っているか自動起動するようになっているか設定ファイルが存在するか正しい設定がされているか
![Page 16: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/16.jpg)
Orchestration 領域のテストZabbixNagiosConfiguration 領域のテストserverspec
![Page 17: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/17.jpg)
Configurationと
テスト
![Page 18: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/18.jpg)
みなさんどうやってますか?
![Page 19: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/19.jpg)
![Page 20: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/20.jpg)
シェルコマンド叩く?
シェルスクリプト?実際にサービスに
アクセスする?
![Page 21: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/21.jpg)
ConfigurationManagementFramework
![Page 22: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/22.jpg)
![Page 23: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/23.jpg)
![Page 24: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/24.jpg)
![Page 25: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/25.jpg)
ConfigurationManagement Framework
とテスト
![Page 26: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/26.jpg)
これはテストどうやってますか?
![Page 27: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/27.jpg)
シェルコマンド叩く?
シェルスクリプト?実際にサービスに
アクセスする?
![Page 28: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/28.jpg)
この界隈は様々なテストツールが存在
![Page 29: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/29.jpg)
シンタックスチェックFoodcriticknife cookbook testpuppet-lint
![Page 30: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/30.jpg)
ユニットテストChefspecrspec-puppet
![Page 31: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/31.jpg)
結合テストMinitest Chef HandlerCucumber ChefTest Kitchenrspec-systemserverspec
![Page 32: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/32.jpg)
Infrastructure as Codeからの自然な流れ
![Page 33: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/33.jpg)
これだけテストツールが存在するのにな
ぜわざわざserverspec をつくっ
たのか?
![Page 34: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/34.jpg)
既存ツールは機能が多すぎたり、特定のツールに依存してた
りするのがイヤ
![Page 35: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/35.jpg)
![Page 36: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/36.jpg)
![Page 37: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/37.jpg)
Puppet や Chef使っていてそもそも
serverspec って必要?
![Page 38: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/38.jpg)
そもそもPuppet や Chef に
テストって必要?
![Page 39: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/39.jpg)
一度書いたマニフェストやレシピを更新しないのであればたぶん不
要
![Page 40: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/40.jpg)
マニフェストやレシピを継続的に更新す
るなら必要
![Page 41: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/41.jpg)
プログラムのリファクタリングと一緒
![Page 42: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/42.jpg)
継続的に更新するならテストも継続的に実行する必要がある
![Page 43: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/43.jpg)
なのでテストを自動化することが必要
![Page 44: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/44.jpg)
テストコード自体もメンテナンスが必要
![Page 45: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/45.jpg)
なのでテストコードの読みやすさや
書きやすさも重要
![Page 46: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/46.jpg)
テストツール自体のシンプルさも重要
![Page 47: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/47.jpg)
severspec
![Page 48: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/48.jpg)
サーバのテストを簡潔に書くための仕組
み
![Page 49: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/49.jpg)
サーバのテストをRSpec で記述
![Page 50: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/50.jpg)
RSpec?
![Page 51: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/51.jpg)
Ruby のテストフレームワーク
![Page 52: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/52.jpg)
describe Array, "when empty" do before do @empty_array = [] end
it "should be empty" do @empty_array.should be_empty end
it "should size 0" do @empty_array.size.should == 0 endend
![Page 53: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/53.jpg)
@empty_array.should be_empty@empty_array.should_not
be_empty
![Page 54: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/54.jpg)
serverspec によるテスト
![Page 55: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/55.jpg)
describe package('httpd') do it { should be_installed }end
describe service('httpd') do it { should be_enabled } it { should be_running }end
describe port(80) do it { should be_listening }end
![Page 56: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/56.jpg)
最近推奨の書き方expect(file ‘/etc/passwd’).to be_file
非推奨な書き方file(‘/etc/passwd’).should be_file
![Page 57: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/57.jpg)
![Page 58: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/58.jpg)
![Page 59: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/59.jpg)
テストコードが簡単に書けて結果がわかり
やすくても内部が複雑なら意味がない
![Page 60: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/60.jpg)
serverspec は基本的に
シェルコマンド叩いて
チェックしてるだけ
![Page 61: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/61.jpg)
テスト対象のサーバに SSH で接続して
コマンドを叩く
![Page 62: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/62.jpg)
シェルコマンド実行によるサーバのテストをスマートにやれるようにしたのが
serverspec
![Page 63: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/63.jpg)
serverspec の始め方
![Page 64: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/64.jpg)
# yum install rubygems# gem install serverspec rake# serverspec-init# rake spec
![Page 65: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/65.jpg)
デモ
![Page 66: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/66.jpg)
serverspecが産まれた経緯
![Page 67: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/67.jpg)
2007 年
![Page 68: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/68.jpg)
Puppet を導入することにした
![Page 69: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/69.jpg)
Puppet でサーバ構築は自動化できた
![Page 70: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/70.jpg)
じゃあテストはどうしよう?
![Page 71: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/71.jpg)
Assurer という Perl 製のツールを書いた
![Page 72: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/72.jpg)
![Page 73: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/73.jpg)
Assurer は面倒すぎて実用には
耐えなかった
![Page 74: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/74.jpg)
テスト駆動サーバ構築のことは
しばらく忘れた
![Page 75: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/75.jpg)
2013 年
![Page 76: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/76.jpg)
Puppet マニフェストの
リファクタリングをやろうと思った
![Page 77: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/77.jpg)
コードをリファクタリングするならテス
ト必要だろ
![Page 78: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/78.jpg)
rspec-pupet はモジュールのテスト
にしか使えない
![Page 79: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/79.jpg)
Puppet 適用後の実際のサーバの
状態をテストしたい
![Page 80: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/80.jpg)
@hiboma が何かやってたそういえば
http://d.hatena.ne.jp/hiboma/20130513/1368411746
![Page 81: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/81.jpg)
それパクろうそして gem にしよう
![Page 82: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/82.jpg)
serverspec誕生
![Page 83: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/83.jpg)
もう少し詳しいserverspec の話
![Page 84: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/84.jpg)
リソースタイプ
![Page 85: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/85.jpg)
command cron default_gateway file group host ipfilter ipnat
iptables kernel_module linux_kernel_parrameter package
port routing_table selinuxservice user zfs
http://serverspec.org/resource_types.html
![Page 86: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/86.jpg)
複数 OS サポート
![Page 87: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/87.jpg)
DebianGentooRed HatSolarisDarwin
![Page 88: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/88.jpg)
root ユーザじゃない場合は sudo つけて
コマンド実行( SSH の場合のみ
Exec ではつけない)
![Page 89: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/89.jpg)
PATH の追加設定できます
![Page 90: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/90.jpg)
spec/spec_helper.rb で
RSpec.configure do |c| c.path = ‘/sbin:/usr/sbin:$PATH’ …end
![Page 91: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/91.jpg)
describe package(‘serverspec') do let(:path){ ‘/usr/local/rbenv/shims:$PATH’ }
it { should be_installed.by(‘gem’) }end
![Page 92: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/92.jpg)
pre_command
![Page 93: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/93.jpg)
describe package(‘serverspec') do let(:path){ ‘/usr/local/rbenv/shims:$PATH’ } let(:pre_command) { ‘eval “$(rbenv init -)”’ } it { should be_installed.by(‘gem’) }end
![Page 94: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/94.jpg)
サーバ単位じゃなくロール単位でのテス
ト
![Page 95: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/95.jpg)
サーバ固有属性を扱う
![Page 96: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/96.jpg)
詳しくはウェブでhttp://mizzy.org/
http://serverspec.org/
![Page 97: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/97.jpg)
インフラの継続的インテグレーション
![Page 98: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/98.jpg)
![Page 99: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/99.jpg)
![Page 100: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/100.jpg)
プログラム内部の話
![Page 101: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/101.jpg)
describe file(‘/etc/passwd’) do it { should be_file }end
が実行されるとどうなるか( Exec Backend の場合)
![Page 102: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/102.jpg)
この辺が主に呼ばれる
serverspec/type/file.rbserverspec/backend/exec.rbserverspec/commands/redhat.rb
実際にコードを見てみましょう
![Page 103: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/103.jpg)
SSH の場合は?
Backend::Exec の代わりに Backend::Ssh
が呼ばれる
![Page 104: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/104.jpg)
chain する場合は?
describe package('serverspec') do it { should be_installed.by('gem') }end
matchers/be_installed.rb が呼ばれる
![Page 105: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/105.jpg)
serverspec 自身のテスト
![Page 106: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/106.jpg)
テストコードは 2 パターン
コマンドのテストリソースマッチャのテスト
![Page 107: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/107.jpg)
コマンドのテスト
serverspec がテストのために実行するシェルコマンドが正しく生成されるかどうかをチェック
![Page 108: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/108.jpg)
リソースマッチャのテスト
テスト用シェルコマンドが実行されたという「仮定」の元で、リソースのテストが想定通りの結果を返すかどうかをチェック
![Page 109: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/109.jpg)
GitHub でのコントリビュート
1. フォークする2. ブランチをつくる
git checkout –b my-new-feature3. コード書いてコミットしてプッ
シュgit push origin my-new-feature
4. プルリクエストを送る
![Page 110: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/110.jpg)
プルリクエストは日本語で OK途中状態でいったんプルリクしてくれ
ても OKあとからまた push すればいいその場合は頭に [WIP] とつけてくださ
い動作確認は自分が使ってる OS だけで
OK完璧に実装しなくて大丈夫です
テストコードも書いてもらえるとうれしいです書き方わからなければお気軽に相談
を
![Page 111: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/111.jpg)
プルリクエストはお気軽に
![Page 112: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/112.jpg)
まとめ
![Page 113: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/113.jpg)
serverspec は読みやすい書きやすい
わかりやすい
![Page 114: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/114.jpg)
要するに簡潔
![Page 115: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/115.jpg)
簡潔さ超重要
![Page 116: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/116.jpg)
ビジネス要件は絶えず変化する
![Page 117: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/117.jpg)
それに伴いシステムも変化し複雑に
![Page 118: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/118.jpg)
複雑さと変化に対応するためには継続的
なテスト重要
![Page 119: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/119.jpg)
テストコード自体もシステムに伴い変化し複雑になる
![Page 120: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/120.jpg)
なのでできるだけ簡潔に記述できる
ことが重要
![Page 121: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/121.jpg)
serverspec とは
![Page 122: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/122.jpg)
現実のシステムの複雑さと変化に対応するために
![Page 123: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/123.jpg)
システムのあるべき状態を簡潔に記述し継続的にテストする
ためのもの
![Page 124: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/124.jpg)
おまけ
![Page 125: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/125.jpg)
![Page 126: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/126.jpg)
![Page 127: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/127.jpg)
![Page 128: Serverspec at hbstudy #45](https://reader031.vdocuments.pub/reader031/viewer/2022012922/553add2e5503466f348b461d/html5/thumbnails/128.jpg)
おしまい