æ¦è¦
Test Kitchenã®å½¹å²
以ä¸ãèªåã§ãã£ã¦ããã¾ãã
- Dockerã³ã³ããèµ·å
- èµ·åããDockerã³ã³ããã«Chefã¬ã·ããé©ç¨
- ãã®å¾Serverspecå®è¡
- Dockerã³ã³ããç ´æ£
ç°å¢
OS
CentOS 6.5 |
ãã®ãã¹ãã§Test KichenãDockerãåããã¾ãã
é¢é£ããã«ã¦ã§ã¢
äºåã«ã¤ã³ã¹ãã¼ã«ãã¦ããã¾ãã
ãã¼ã¸ã§ã³ã¯ä»¥ä¸ã®ãã®ã使ç¨ãã¾ããã
docker-io-1.0.0-6 |
test-kitchen-1.2.1-1 |
kitchen-docker-1.5.0-1 |
serverspec-1.11.0-1 |
ãã¹ãããã¬ã·ã
CentOS6ç³»ã®ãµã¼ãã¼ã«é©ç¨ããã¬ã·ãã§ãã
/root/chef/repo/site-cookbooks/centos6/recipes/httpd.rb
- httpdã®ã¤ã³ã¹ãã¼ã«
- ãã¼ã¢ã³èµ·å
- èªåèµ·åè¨å®
ããããè¡ãã¬ã·ããDockerã¨Serverspecã§ãã¹ããã¾ãã
äºåæºå(Test Kitchen)
Test Kitchenãåãããã¹ãã§
visudo
ãå®è¡ãã¦ä»¥ä¸ã®ããã«å¤æ´ãã¾ãã
Defaults requiretty
â
Defaults !requiretty
ã»ãã¥ãªãã£ä¸è¯ããªããã©ã¬ã·ãé©ç¨ãã¹ãå°ç¨ãã¹ãã ããã²ã¨ã¾ãããã¨ããã
ãã以å¤å¯¾å¦æ³ãåãããªãã£ãã
ããããããªãã¨ãå¾ã«å®è¡ãããã¨ã«ãªãkitchen test
ã§ã¨ã©ã¼ãåºãã
-----> Starting Kitchen (v1.2.1) >>>>>> ------Exception------- >>>>>> Class: Kitchen::UserError >>>>>> Message: You must first install the Docker CLI tool http://www.docker.io/gettingstarted/ >>>>>> ---------------------- >>>>>> Please see .kitchen/logs/kitchen.log for more details >>>>>> Also try running `kitchen diagnose --all` for configuration
ãããªã¨ã©ã¼ã
.kichen.yml
ã®ä½æ
ãã¹ããè¡ãã¬ã·ããå ¥ã£ã¦ããã¯ãã¯ããã¯ã®ãã£ã¬ã¯ããªã¸ç§»åãã¾ãã
cd /root/chef/repo/site-cookbooks/centos6/
ãã£ã¬ã¯ããªç§»åå¾ãè¨å®ãã¡ã¤ã«ãä½æãã¾ãã
ä»åã¯Dockerã使ç¨ãã¾ãã®ã§ãã©ã¤ãã«kitchen-dockerãæå®ãã¾ãã
kitchen init --driver=kitchen-docker
ããã©ã«ãã§ä½æããã.kichen.yml
--- driver: name: docker provisioner: name: chef_solo platforms: - name: ubuntu-12.04 - name: centos-6.4 suites: - name: default run_list: attributes:
ãããä»åãã¹ãããç°å¢ã«åããã¦ä¿®æ£ãã¾ãã
--- driver: name: docker provisioner: name: chef_solo platforms: - name: centos-6.5 suites: - name: default run_list: - recipe[centos6::httpd] attributes:
äºåæºå(Serverspec)
Serverspecã®specãã¡ã¤ã«ã決ãããããã£ã¬ã¯ããªã«é
ç½®ãã¾ãã
ãããªæãã§ç½®ãã¾ããã
/root/chef/repo/site-cookbooks/centos6/test/integration/default/serverspec/localhost/httpd_spec.rb
ããããã®ãã£ã¬ã¯ããªåã®èª¬æ
Chefãªãã¸ããªã«åå¨ããªãå ´åã¯mkdirã³ãã³ãã§ä½æãã¦ãã ããã
/root/chef/repo/site-cookbooks/centos6/ âââ test âââ integration âââ default âââ serverspec âââ localhost âââ httpd_spec.rb
/root/chef/repo/site-cookbooks/centos6/
ããã¯çè
ã®Chefãªãã¸ããªãã¡ã¤ã«ãä¿åãã¦ãããã£ã¬ã¯ããªåãªã®ã§é©å®èªã¿æ¿ãã¦ãã ããã
test/integration/
ããã¯ããã©ã«ãã§ãã®ãã£ã¬ã¯ããªåã決ã¾ã£ã¦ãã¾ãã
default/
ããã¯å
ç¨ä½æãã.kichen.yml
ãã¡ã¤ã«ã®
suites: - name: default
ããã¨åããã¦ãã ããã
serverspec/
ããã¯ãã¹ãã©ã¤ãã©ãªåã¨åããã¦ãã ããã
ä»åã¯Serverspecã使ç¨ããã®ã§serverspecã¨ãã¦ãã¾ãã
æå¾ã«httpd_spec.rb
ã§ãã
specãã¡ã¤ã«åã¯ä½ã§ãããã®ã§ããããã¡ã¤ã«åã¯å¿
ã_spec.rb
ã§çµããããã«ããå¿
è¦ãããã¾ãã
Serverspecã®ãã¡ã¤ã«ã¯ä»¥ä¸ã®ãããªãã®ãæºåãã¦ããã¾ãã
require 'serverspec' include Serverspec::Helper::Exec include Serverspec::Helper::DetectOS 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
Test Kitchenå®è¡
æºåãå®äºããããããããã¹ãã®å®è¡ã§ãã
kitchen test
ãã¹ããå®è¡ããã¨ã³ã³ãããèµ·åãã¦Chefã®é©ç¨ãServerspecãå®è¡ããã¾ãã
ãã¹ããç¡äºéãã¨ä»¥ä¸ã®ãããªè¡¨ç¤ºã«ãªãã¾ãã
-----> Starting Kitchen (v1.2.1) -----> Cleaning up any prior instances of <default-centos-65> -----> Destroying <default-centos-65>... (ç¥) Finished destroying <default-centos-65> (0m2.43s). Finished testing <default-centos-65> (4m39.76s). -----> Kitchen is finished. (4m39.86s)
ããã§ãã¹ãç°å¢ãä½æã§ãã¾ããï¼
ä»å¾ã¯Gitã®hookã§Jenkinsçµç±ã®å®è¡ãªã©ã試ãã¦ã¿ããã¨æãã¾ãã